Sha256: a77297cfa2af3b8c023c99ae5c81549d55bc7d3d03bb387cd8f825ec11dbe756

Contents?: true

Size: 1013 Bytes

Versions: 11

Compression:

Stored size: 1013 Bytes

Contents

module FastHaml
  class FilterParser
    def initialize(indent_tracker)
      @ast = nil
      @indent_level = nil
      @indent_tracker = indent_tracker
    end

    def enabled?
      !!@ast
    end

    def start(name)
      @ast = Ast::Filter.new
      @ast.name = name
    end

    def append(line)
      indent, text = @indent_tracker.split(line)
      if text.empty?
        @ast.texts << ''
        return
      end
      indent_level = indent.size

      if @indent_level
        if indent_level < @indent_level
          # Finish filter
          @indent_level = nil
          ast = @ast
          @ast = nil
          return ast
        end
      else
        if indent_level > @indent_tracker.current_level
          # Start filter
          @indent_level = indent_level
        else
          # Empty filter
          @ast = nil
          return nil
        end
      end

      text = line[@indent_level .. -1]
      @ast.texts << text
      nil
    end

    def finish
      @ast
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fast_haml-0.1.10 lib/fast_haml/filter_parser.rb
fast_haml-0.1.9 lib/fast_haml/filter_parser.rb
fast_haml-0.1.8 lib/fast_haml/filter_parser.rb
fast_haml-0.1.7 lib/fast_haml/filter_parser.rb
fast_haml-0.1.6 lib/fast_haml/filter_parser.rb
fast_haml-0.1.5 lib/fast_haml/filter_parser.rb
fast_haml-0.1.4 lib/fast_haml/filter_parser.rb
fast_haml-0.1.3 lib/fast_haml/filter_parser.rb
fast_haml-0.1.2 lib/fast_haml/filter_parser.rb
fast_haml-0.1.1 lib/fast_haml/filter_parser.rb
fast_haml-0.1.0 lib/fast_haml/filter_parser.rb