Sha256: ddc8a7279183aa7fbc1ecb4127df21db2c7c1a13fd3c872b4a5da54e66d8b765

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

require "temple"
require "erbse/parser"

module Erbse
  class BlockFilter < Temple::Filter
    # Highly inspired by https://github.com/slim-template/slim/blob/master/lib/slim/controls.rb#on_slim_output
    def on_erb_block(code, content_ast)
      # this is for <%= do %>
      outter_i = unique_name
      inner_i  = unique_name

      # this still needs the Temple::Filters::ControlFlow run-through.
      [:multi,
        [:block, "#{outter_i} = #{code}",
          [:capture, inner_i, compile(content_ast)]
        ],
        [:dynamic, outter_i] # return the outter buffer. # DISCUSS: why do we need that, again?
      ]
    end

    # assign all code in the block to new local output buffer without outputting it.
    # handles <%@ do %>
    def on_capture_block(code, content_ast)
      [:multi,
        [:block, code, # var = capture do
          [:capture, unique_name, compile(content_ast)]
        ]
      ]
    end
  end

  class Engine < Temple::Engine
    use Parser
    use BlockFilter

    # filter :MultiFlattener
    # filter :StaticMerger
    # filter :DynamicInliner
    filter :ControlFlow

    generator :ArrayBuffer
  end
  # DISCUSS: can we add more optimizers?
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
erbse-0.1.4 lib/erbse.rb
erbse-0.1.3 lib/erbse.rb
erbse-0.1.2 lib/erbse.rb
erbse-0.1.1 lib/erbse.rb