Sha256: 660f52c41f1b7b6ef110f8494041fec67135fed29ae2d54293e773502ee0dd81

Contents?: true

Size: 1.24 KB

Versions: 21

Compression:

Stored size: 1.24 KB

Contents

module Liquid
  
  # Hols variables. Variables are only loaded "just in time"
  # they are not evaluated as part of the render stage
  class Variable    
    attr_accessor :filters, :name
    
    def initialize(markup)
      @markup = markup                            
      @name = markup.match(/\s*(#{QuotedFragment})/)[1]
      if markup.match(/#{FilterSperator}\s*(.*)/)
        filters = Regexp.last_match(1).split(/#{FilterSperator}/)
        
        @filters = filters.collect do |f|          
          filtername = f.match(/\s*(\w+)/)[1]
          filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten            
          [filtername.to_sym, filterargs]
        end
      else
        @filters = []
      end
    end                        

    def render(context)      
      output = context[@name]
      @filters.inject(output) do |output, filter|
        filterargs = filter[1].to_a.collect do |a|
         context[a]
        end
        begin
          output = context.invoke(filter[0], output, *filterargs)
        rescue FilterNotFound
          raise FilterNotFound, "Error - filter '#{filter[0]}' in '#{@markup.strip}' could not be found."
        end
      end  
      output
    end
  end
end

Version data entries

21 entries across 21 versions & 8 rubygems

Version Path
aslakjo-aslakjo-comatose-2.0.5.1 lib/liquid/variable.rb
aslakjo-comatose-2.0.5.2 lib/liquid/variable.rb
aslakjo-comatose-2.0.5.3 lib/liquid/variable.rb
darthapo-comatose-2.0.3 lib/liquid/variable.rb
darthapo-comatose-2.0.4 lib/liquid/variable.rb
darthapo-comatose-2.0.5 lib/liquid/variable.rb
darthapo-comatose-2.0 lib/liquid/variable.rb
jcnetdev-comatose-2.0.1 lib/liquid/variable.rb
staugaard-comatose-2.0.2 lib/liquid/variable.rb
staugaard-comatose-2.0.3 lib/liquid/variable.rb
comatose-2.0.5 lib/liquid/variable.rb
comatose-2.0.1 lib/liquid/variable.rb
aslakjo-comatose-2.0.5.12 lib/liquid/variable.rb
aslakjo-comatose-2.0.5.11 lib/liquid/variable.rb
aslakjo-comatose-2.0.5.10 lib/liquid/variable.rb
aslakjo-comatose-2.0.5.9 lib/liquid/variable.rb
aslakjo-comatose-2.0.5.8 lib/liquid/variable.rb
aslakjo-comatose-2.0.5.7 lib/liquid/variable.rb
liquid-1.7.0 lib/liquid/variable.rb
merb_comatose-0.0.2 lib/liquid/variable.rb