Sha256: 5f5822696f1740aed52b70dbc8a37a1e1d3c569885e13135498e3869fe444b92

Contents?: true

Size: 968 Bytes

Versions: 8

Compression:

Stored size: 968 Bytes

Contents

require 'temple'
require 'tilt'
require 'faml/filter_compilers/base'
require 'faml/text_compiler'

module Faml
  module FilterCompilers
    class TiltBase < Base
      include Temple::Utils

      def self.render_with_tilt(name, source)
        ::Tilt["t.#{name}"].new { source }.render
      end

      protected

      def compile_with_tilt(temple, name, ast)
        source = ast.texts.join("\n")
        if TextCompiler.contains_interpolation?(source)
          text_temple = [:multi]
          compile_texts(text_temple, ast.lineno, ast.texts)
          sym = unique_name
          temple << [:capture, sym, text_temple]
          temple << [:dynamic, "::Faml::FilterCompilers::TiltBase.render_with_tilt(#{name.inspect}, #{sym})"]
        else
          compiled = self.class.render_with_tilt(name, source)
          temple << [:static, compiled]
          temple.concat([[:newline]] * (ast.texts.size - 1))
        end
        temple
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
faml-0.2.14 lib/faml/filter_compilers/tilt_base.rb
faml-0.2.13 lib/faml/filter_compilers/tilt_base.rb
faml-0.2.12 lib/faml/filter_compilers/tilt_base.rb
faml-0.2.11 lib/faml/filter_compilers/tilt_base.rb
faml-0.2.10 lib/faml/filter_compilers/tilt_base.rb
faml-0.2.9 lib/faml/filter_compilers/tilt_base.rb
faml-0.2.8 lib/faml/filter_compilers/tilt_base.rb
faml-0.2.7 lib/faml/filter_compilers/tilt_base.rb