Class: Faml::Compiler

Inherits:
Temple::Parser
  • Object
show all
Defined in:
lib/faml/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.



30
31
32
33
34
# File 'lib/faml/compiler.rb', line 30

def initialize(*)
  super
  @text_compiler = TextCompiler.new
  @filename = options[:filename]
end

Class Method Details

.find_and_preserve(input) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/faml/compiler.rb', line 45

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}>#{Helpers.preserve($3)}</#{$1}>"
  end
end

Instance Method Details

#call(ast) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/faml/compiler.rb', line 36

def call(ast)
  compile(ast)
rescue Error => e
  if @filename && e.lineno
    e.backtrace.unshift "#{@filename}:#{e.lineno}"
  end
  raise e
end