Class: FastHaml::Compiler
- Inherits:
-
Temple::Parser
- Object
- Temple::Parser
- FastHaml::Compiler
- Defined in:
- lib/fast_haml/compiler.rb
Constant Summary collapse
- DEFAULT_AUTO_CLOSE_TAGS =
%w[ area base basefont br col command embed frame hr img input isindex keygen link menuitem meta param source track wbr ]
- DEFAULT_PRESERVE_TAGS =
%w[pre textarea code]
Class Method Summary collapse
Instance Method Summary collapse
- #call(ast) ⇒ Object
-
#initialize ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize ⇒ Compiler
Returns a new instance of Compiler.
21 22 23 24 |
# File 'lib/fast_haml/compiler.rb', line 21 def initialize(*) super @text_compiler = TextCompiler.new end |
Class Method Details
.find_and_preserve(input) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/fast_haml/compiler.rb', line 30 def self.find_and_preserve(input) # Taken from the original haml code re = /<(#{[:preserve].map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\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}>#{preserve($3)}</#{$1}>" end end |
.preserve(input) ⇒ Object
39 40 41 42 |
# File 'lib/fast_haml/compiler.rb', line 39 def self.preserve(input) # Taken from the original haml code input.to_s.chomp("\n").gsub(/\n/, '
').gsub(/\r/, '') end |
Instance Method Details
#call(ast) ⇒ Object
26 27 28 |
# File 'lib/fast_haml/compiler.rb', line 26 def call(ast) compile(ast) end |