Module: Erubis::InterpolationEnhancer
- Defined in:
- lib/erubis_rails_helper/template_handlers/erubis.rb
Overview
convert “<h1><%=title%></h1>” into “@output_buffer << %Q`<h1>#title</h1>‘”
this is only for Eruby.
Class Method Summary collapse
-
.desc ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #_add_text_to_str(str, text) ⇒ Object
- #add_expr_escaped(str, code) ⇒ Object
- #add_expr_literal(str, code) ⇒ Object
- #add_text(src, text) ⇒ Object
- #convert_input(src, input) ⇒ Object
Class Method Details
.desc ⇒ Object
:nodoc:
9 10 11 |
# File 'lib/erubis_rails_helper/template_handlers/erubis.rb', line 9 def self.desc # :nodoc: "convert '<p><%=text%></p>' into '@output_buffer << %Q`<p>\#{text}</p>`'" end |
Instance Method Details
#_add_text_to_str(str, text) ⇒ Object
79 80 81 82 83 |
# File 'lib/erubis_rails_helper/template_handlers/erubis.rb', line 79 def _add_text_to_str(str, text) return if !text || text.empty? text.gsub!(/['\#\\]/, '\\\\\&') str << text end |
#add_expr_escaped(str, code) ⇒ Object
85 86 87 |
# File 'lib/erubis_rails_helper/template_handlers/erubis.rb', line 85 def add_expr_escaped(str, code) str << "\#{#{escaped_expr(code)}}" end |
#add_expr_literal(str, code) ⇒ Object
89 90 91 |
# File 'lib/erubis_rails_helper/template_handlers/erubis.rb', line 89 def add_expr_literal(str, code) str << "\#{#{code}}" end |
#add_text(src, text) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/erubis_rails_helper/template_handlers/erubis.rb', line 68 def add_text(src, text) return if !text || text.empty? #src << " _buf << %Q`" << text << "`;" if text[-1] == ?\n text[-1] = "\\n" src << " @output_buffer << %Q`" << text << "`\n" else src << " @output_buffer << %Q`" << text << "`;" end end |
#convert_input(src, input) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/erubis_rails_helper/template_handlers/erubis.rb', line 13 def convert_input(src, input) pat = @pattern regexp = pat.nil? || pat == '<% %>' ? Basic::Converter::DEFAULT_REGEXP : pattern_regexp(pat) pos = 0 is_bol = true # is beginning of line str = '' input.scan(regexp) do |indicator, code, tailch, rspace| match = Regexp.last_match() len = match.begin(0) - pos text = input[pos, len] pos = match.end(0) ch = indicator ? indicator[0] : nil lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol) is_bol = rspace ? true : false _add_text_to_str(str, text) ## * when '<%= %>', do nothing ## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>' if ch == ?= # <%= %> rspace = nil if tailch && !tailch.empty? str << lspace if lspace add_expr(str, code, indicator) str << rspace if rspace elsif ch == ?\# # <%# %> n = code.count("\n") + (rspace ? 1 : 0) if @trim && lspace && rspace add_text(src, str) str = '' add_stmt(src, "\n" * n) else str << lspace if lspace add_text(src, str) str = '' add_stmt(src, "\n" * n) str << rspace if rspace end else # <% %> if @trim && lspace && rspace add_text(src, str) str = '' add_stmt(src, "#{lspace}#{code}#{rspace}") else str << lspace if lspace add_text(src, str) str = '' add_stmt(src, code) str << rspace if rspace end end end #rest = $' || input # ruby1.8 rest = pos == 0 ? input : input[pos..-1] # ruby1.9 _add_text_to_str(str, rest) add_text(src, str) end |