class Hamlit::Filters::TiltBase

Public Class Methods

render(name, source, indent_width: 0) click to toggle source
# File lib/hamlit/filters/tilt_base.rb, line 6
def self.render(name, source, indent_width: 0)
  text = ::Tilt["t.#{name}"].new { source }.render
  return text if indent_width == 0
  text.gsub!(/^/, ' ' * indent_width)
end

Public Instance Methods

explicit_require?() click to toggle source
# File lib/hamlit/filters/tilt_base.rb, line 12
def explicit_require?
  Gem::Version.new(Tilt::VERSION) >= Gem::Version.new('2.0.0')
end

Private Instance Methods

compile_with_tilt(node, name, indent_width: 0) click to toggle source
# File lib/hamlit/filters/tilt_base.rb, line 18
def compile_with_tilt(node, name, indent_width: 0)
  if ::Hamlit::HamlUtil.contains_interpolation?(node.value[:text])
    dynamic_compile(node, name, indent_width: indent_width)
  else
    static_compile(node, name, indent_width: indent_width)
  end
end
dynamic_compile(node, name, indent_width: 0) click to toggle source
# File lib/hamlit/filters/tilt_base.rb, line 34
def dynamic_compile(node, name, indent_width: 0)
  # original: Haml::Filters#compile
  text = ::Hamlit::HamlUtil.slow_unescape_interpolation(node.value[:text]).gsub(/(\+)n/) do |s|
    escapes = $1.size
    next s if escapes % 2 == 0
    "#{'\\' * (escapes - 1)}\n"
  end
  text.prepend("\n").sub!(/\n"\z/, '"')

  [:dynamic, "::Hamlit::Filters::TiltBase.render('#{name}', #{text}, indent_width: #{indent_width})"]
end
static_compile(node, name, indent_width: 0) click to toggle source
# File lib/hamlit/filters/tilt_base.rb, line 26
def static_compile(node, name, indent_width: 0)
  temple = [:multi, [:static, TiltBase.render(name, node.value[:text], indent_width: indent_width)]]
  node.value[:text].split("\n").size.times do
    temple << [:newline]
  end
  temple
end