class Webby::Filters::Cursor - webby-0.9.4 Documentation

# class Webby::Filters::Cursor

Instances of this class handle processing a set of filters for a given renderer and page. Note: The instance is passed as the second argument to filters

    that require two parameters and can be used to access
    information on the renderer, page, or filters being
    processed.

### Attributes

filters[R]
page[R]
renderer[R]

### Public Class Methods

new(renderer, page) click to toggle source

    # File lib/webby/filters.rb, line 36
    def initialize(renderer, page)
      @renderer, @page = renderer, page
      @filters = Array(page.filter)
      @log = Logging::Logger[Webby::Renderer]
      @processed = 0
      @prev_cursor = nil
    end

### Public Instance Methods

_handle(filter, handler, *args) click to toggle source

Process arguments through a single filter

    # File lib/webby/filters.rb, line 69
    def _handle(filter, handler, *args)
      result = handler.call(*args)
      @processed += 1
      result
    rescue StandardError => err
      raise ::Webby::Error, "#{filter} filter error: #{err.message.inspect}"
    end

current_filter() click to toggle source

The name of the current filter

    # File lib/webby/filters.rb, line 64
    def current_filter
      filters[@processed]
    end

remaining_filters() click to toggle source

The list of filters yet to be processed

    # File lib/webby/filters.rb, line 59
    def remaining_filters
      filters[@processed..-1]
    end

start_for(input) click to toggle source

    # File lib/webby/filters.rb, line 44
    def start_for(input)
      @prev_cursor = @renderer.instance_variable_get(:@_cursor)
      @renderer.instance_variable_set(:@_cursor, self)
      filters.inject(input) do |result, filter|
        handler = Filters[filter]
        raise ::Webby::Error, "unknown filter: #{filter.inspect}" if handler.nil?

        args = [result, self][0, handler.arity]
        _handle(filter, handler, *args)
      end
    ensure
      @renderer.instance_variable_set(:@_cursor, @prev_cursor)
    end