Class: Opal::ERB::Compiler
Constant Summary
- BLOCK_EXPR =
/\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
Instance Method Summary collapse
- #compile(source, file_name = '(erb)') ⇒ Object
- #find_code ⇒ Object
- #find_contents ⇒ Object
- #fix_quotes ⇒ Object
- #wrap_compiled ⇒ Object
Instance Method Details
#compile(source, file_name = '(erb)') ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'opal/lib/opal/erb.rb', line 10 def compile(source, file_name = '(erb)') @source, @file_name, @result = source, file_name, source self.fix_quotes self.find_contents self.find_code self.wrap_compiled Opal.compile @result end |
#find_code ⇒ Object
39 40 41 42 43 |
# File 'opal/lib/opal/erb.rb', line 39 def find_code @result = @result.gsub(/<%([\s\S]+?)%>/) do "\")\n#{ $1 }\noutput_buffer.append(\"" end end |
#find_contents ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'opal/lib/opal/erb.rb', line 27 def find_contents @result = @result.gsub(/<%=([\s\S]+?)%>/) do inner = $1.gsub(/\\'/, "'").gsub(/\\"/, '"') if inner =~ BLOCK_EXPR "\")\noutput_buffer.append= #{ inner }\noutput_buffer.append(\"" else "\")\noutput_buffer.append=(#{ inner })\noutput_buffer.append(\"" end end end |
#fix_quotes ⇒ Object
21 22 23 |
# File 'opal/lib/opal/erb.rb', line 21 def fix_quotes @result = @result.gsub '"', '\\"' end |
#wrap_compiled ⇒ Object
45 46 47 |
# File 'opal/lib/opal/erb.rb', line 45 def wrap_compiled @result = "Template.new('#@file_name') do |output_buffer|\noutput_buffer.append(\"#@result\")\noutput_buffer.join\nend\n" end |