Class: FastHaml::Compiler

Inherits:
Temple::Parser
  • Object
show all
Defined in:
lib/fast_haml/compiler.rb

Defined Under Namespace

Classes: UnparsableRubyCode

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

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



25
26
27
28
# File 'lib/fast_haml/compiler.rb', line 25

def initialize(*)
  super
  @text_compiler = TextCompiler.new
end

Class Method Details

.find_and_preserve(input) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/fast_haml/compiler.rb', line 34

def self.find_and_preserve(input)
  # Taken from the original haml code
  re = /<(#{options[: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



43
44
45
46
# File 'lib/fast_haml/compiler.rb', line 43

def self.preserve(input)
  # Taken from the original haml code
  input.to_s.chomp("\n").gsub(/\n/, '&#x000A;').gsub(/\r/, '')
end

Instance Method Details

#call(ast) ⇒ Object



30
31
32
# File 'lib/fast_haml/compiler.rb', line 30

def call(ast)
  compile(ast)
end