class Haml::Compiler::TagCompiler
Public Class Methods
new(identity, options)
click to toggle source
# File lib/haml/compiler/tag_compiler.rb, line 9 def initialize(identity, options) @autoclose = options[:autoclose] @identity = identity @attribute_compiler = AttributeCompiler.new(identity, options) end
Public Instance Methods
compile(node, &block)
click to toggle source
# File lib/haml/compiler/tag_compiler.rb, line 15 def compile(node, &block) attrs = @attribute_compiler.compile(node) contents = compile_contents(node, &block) [:html, :tag, node.value[:name], attrs, contents] end
Private Instance Methods
compile_contents(node) { |node| ... }
click to toggle source
# File lib/haml/compiler/tag_compiler.rb, line 23 def compile_contents(node, &block) case when !node.children.empty? yield(node) when node.value[:value].nil? && self_closing?(node) nil when node.value[:parse] return compile_interpolated_plain(node) if node.value[:escape_interpolation] if Ripper.respond_to?(:lex) # No Ripper.lex in truffleruby return delegate_optimization(node) if RubyExpression.string_literal?(node.value[:value]) return delegate_optimization(node) if Temple::StaticAnalyzer.static?(node.value[:value]) end var = @identity.generate [:multi, [:code, "#{var} = (#{node.value[:value]}"], [:newline], [:code, ')'], [:escape, node.value[:escape_html], [:dynamic, var]] ] else [:static, node.value[:value]] end end
compile_interpolated_plain(node)
click to toggle source
We should handle interpolation here to escape only interpolated values.
# File lib/haml/compiler/tag_compiler.rb, line 57 def compile_interpolated_plain(node) temple = [:multi] StringSplitter.compile(node.value[:value]).each do |type, value| case type when :static temple << [:static, value] when :dynamic temple << [:escape, node.value[:escape_interpolation], [:dynamic, value]] end end temple << [:newline] end
delegate_optimization(node)
click to toggle source
:dynamic is optimized in other filters: StringSplitter
or StaticAnalyzer
# File lib/haml/compiler/tag_compiler.rb, line 49 def delegate_optimization(node) [:multi, [:escape, node.value[:escape_html], [:dynamic, node.value[:value]]], [:newline], ] end
self_closing?(node)
click to toggle source
# File lib/haml/compiler/tag_compiler.rb, line 70 def self_closing?(node) return true if @autoclose && @autoclose.include?(node.value[:name]) node.value[:self_closing] end