Sha256: 2e05f0a2b7f82620e9b014b3d8290e7b03a64f569c4f91abc6211c61f83823df

Contents?: true

Size: 1.5 KB

Versions: 8

Compression:

Stored size: 1.5 KB

Contents

require 'spiderfw/templates/template_blocks'

module Spider; module TemplateBlocks
    
    class Each < Block
        
        def initialize(el, template=nil, allowed_blocks=nil)
            @repeated = []
            super
        end
        
        def compile(options={})
            init = ""
            rep_type = nil
            rep = nil
            ['sp:each', 'sp:each_index'].each do |name|
                if (@el.attributes[name])
                    rep_type = name[3..-1]
                    rep = @el.attributes[name]
                    @el.remove_attribute(name)
                    break
                end
            end
            return nil unless rep_type
            if (rep =~ /\s*(.+)\s*\|\s*(.+)\s*\|/)
                repeated = $1.strip
                arguments = $2.strip
            end
            c = "#{vars_to_scene(repeated)}.#{rep_type} do |#{arguments}|\n"
            content = Spider::TemplateBlocks.parse_element(@el, @allowed_blocks, @template).compile(options)
            content.run_code.each_line do |line|
                c += '  '+line
            end
            c += '   $out << "\n"'
            c += "\n"
            c += "end\n"
            init += content.init_code if content.init_code
            return CompiledBlock.new(init, c)
        end
        
        def get_following(el)
            return false if (el.class == ::Hpricot::Text)
            if (el.name == 'sp:repeated')
                @repeated << el
            end
        end
        
    end
    
    
end; end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
spiderfw-0.5.7 lib/spiderfw/templates/blocks/each.rb
spiderfw-0.5.6 lib/spiderfw/templates/blocks/each.rb
spiderfw-0.5.5 lib/spiderfw/templates/blocks/each.rb
spiderfw-0.5.4 lib/spiderfw/templates/blocks/each.rb
spiderfw-0.5.3 lib/spiderfw/templates/blocks/each.rb
spiderfw-0.5.2 lib/spiderfw/templates/blocks/each.rb
spiderfw-0.5.1 lib/spiderfw/templates/blocks/each.rb
spiderfw-0.5 lib/spiderfw/templates/blocks/each.rb