Sha256: a82a1c4f491ffe142f72e7be3a0bf6214fbd6e4d579d6fa9c1c04163f2607ecc

Contents?: true

Size: 737 Bytes

Versions: 1

Compression:

Stored size: 737 Bytes

Contents

module Haml
  # Ruby code generator, which is a limited version of Temple::Generator.
  # Limit methods since Haml doesn't need most of them.
  class Generator
    include Temple::Mixins::CompiledDispatcher
    include Temple::Mixins::Options

    define_options freeze_static: RUBY_VERSION >= '2.1'

    def call(exp)
      compile(exp)
    end

    def on_multi(*exp)
      exp.map { |e| compile(e) }.join('; ')
    end

    def on_static(text)
      concat(options[:freeze_static] ? "#{Util.inspect_obj(text)}.freeze" : Util.inspect_obj(text))
    end

    def on_dynamic(code)
      concat(code)
    end

    def on_code(exp)
      exp
    end

    private

    def concat(str)
      "_hamlout.buffer << (#{str});"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
haml-5.0.0.beta.2 lib/haml/generator.rb