Class: Haml::Compiler::ScriptCompiler
- Inherits:
-
Object
- Object
- Haml::Compiler::ScriptCompiler
- Defined in:
- lib/haml/compiler/script_compiler.rb
Class Method Summary collapse
Instance Method Summary collapse
- #compile(node, &block)
-
#initialize(identity, options) ⇒ ScriptCompiler
constructor
A new instance of ScriptCompiler.
Constructor Details
#initialize(identity, options) ⇒ ScriptCompiler
Returns a new instance of ScriptCompiler.
18 19 20 21 |
# File 'lib/haml/compiler/script_compiler.rb', line 18
def initialize(identity, options)
@identity = identity
@disable_capture = options[:disable_capture]
end
|
Class Method Details
.find_and_preserve(input, tags)
9 10 11 12 13 14 15 16 |
# File 'lib/haml/compiler/script_compiler.rb', line 9
def self.find_and_preserve(input, tags)
tags = tags.map { |tag| Regexp.escape(tag) }.join('|')
re = /<(#{tags})([^>]*)>(.*?)(<\/\1>)/im
input.to_s.gsub(re) do |s|
s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible
"<#{$1}#{$2}>#{Haml::Helpers.preserve($3)}</#{$1}>"
end
end
|
Instance Method Details
#compile(node, &block)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/haml/compiler/script_compiler.rb', line 23
def compile(node, &block)
unless Ripper.respond_to?(:lex) # No Ripper.lex in truffleruby
return dynamic_compile(node, &block)
end
no_children = node.children.empty?
case
when no_children && node.value[:escape_interpolation]
compile_interpolated_plain(node)
when no_children && RubyExpression.string_literal?(node.value[:text])
delegate_optimization(node)
when no_children && Temple::StaticAnalyzer.static?(node.value[:text])
static_compile(node)
else
dynamic_compile(node, &block)
end
end
|