Class: Nydp::Html::HamlToHtml
- Inherits:
-
Object
- Object
- Nydp::Html::HamlToHtml
- Includes:
- Builtin::Base
- Defined in:
- lib/nydp/html.rb
Instance Method Summary collapse
- #builtin_invoke(vm, args) ⇒ Object
- #convert_from_haml(convertible) ⇒ Object
- #normalise_indentation(txt) ⇒ Object
Instance Method Details
#builtin_invoke(vm, args) ⇒ Object
61 62 63 |
# File 'lib/nydp/html.rb', line 61 def builtin_invoke vm, args vm.push_arg Nydp::StringAtom.new convert_from_haml(args.car.to_s) end |
#convert_from_haml(convertible) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nydp/html.rb', line 47 def convert_from_haml convertible Haml::Engine.new(normalise_indentation(convertible), suppress_eval: true).render rescue Exception => e if e.line lines = convertible.split(/\n/) beginning = e.line - 2 beginning = 0 if beginning < 0 selection = lines[beginning...(e.line + 1)].join "\n" "#{e.message}<br/>line #{e.line}<br/><br/><pre>#{selection}</pre>" else e. end end |
#normalise_indentation(txt) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/nydp/html.rb', line 38 def normalise_indentation txt lines = txt.split(/\n/).select { |line| line.strip != "" } return txt if lines.length == 0 indentation = /^ +/.match(lines.first) return txt unless indentation indentation = indentation.to_s txt.gsub(/^#{indentation}/, "") end |