Module | Erubis::InterpolationEnhancer |
In: |
lib/erubis/enhancer.rb
|
convert "<h1><%=title%></h1>" into "_buf << %Q`<h1>#{title}</h1>`"
this is only for Eruby.
# File lib/erubis/enhancer.rb, line 664 664: def _add_text_to_str(str, text) 665: return if !text || text.empty? 666: text.gsub!(/['\#\\]/, '\\\\\&') 667: str << text 668: end
# File lib/erubis/enhancer.rb, line 670 670: def add_expr_escaped(str, code) 671: str << "\#{#{escaped_expr(code)}}" 672: end
# File lib/erubis/enhancer.rb, line 674 674: def add_expr_literal(str, code) 675: str << "\#{#{code}}" 676: end
# File lib/erubis/enhancer.rb, line 653 653: def add_text(src, text) 654: return if !text || text.empty? 655: #src << " _buf << %Q`" << text << "`;" 656: if text[-1] == ?\n 657: text[-1] = "\\n" 658: src << " _buf << %Q`" << text << "`\n" 659: else 660: src << " _buf << %Q`" << text << "`;" 661: end 662: end
# File lib/erubis/enhancer.rb, line 598 598: def convert_input(src, input) 599: pat = @pattern 600: regexp = pat.nil? || pat == '<% %>' ? Basic::Converter::DEFAULT_REGEXP : pattern_regexp(pat) 601: pos = 0 602: is_bol = true # is beginning of line 603: str = '' 604: input.scan(regexp) do |indicator, code, tailch, rspace| 605: match = Regexp.last_match() 606: len = match.begin(0) - pos 607: text = input[pos, len] 608: pos = match.end(0) 609: ch = indicator ? indicator[0] : nil 610: lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol) 611: is_bol = rspace ? true : false 612: _add_text_to_str(str, text) 613: ## * when '<%= %>', do nothing 614: ## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>' 615: if ch == ?= # <%= %> 616: rspace = nil if tailch && !tailch.empty? 617: str << lspace if lspace 618: add_expr(str, code, indicator) 619: str << rspace if rspace 620: elsif ch == ?\# # <%# %> 621: n = code.count("\n") + (rspace ? 1 : 0) 622: if @trim && lspace && rspace 623: add_text(src, str) 624: str = '' 625: add_stmt(src, "\n" * n) 626: else 627: str << lspace if lspace 628: add_text(src, str) 629: str = '' 630: add_stmt(src, "\n" * n) 631: str << rspace if rspace 632: end 633: else # <% %> 634: if @trim && lspace && rspace 635: add_text(src, str) 636: str = '' 637: add_stmt(src, "#{lspace}#{code}#{rspace}") 638: else 639: str << lspace if lspace 640: add_text(src, str) 641: str = '' 642: add_stmt(src, code) 643: str << rspace if rspace 644: end 645: end 646: end 647: #rest = $' || input # ruby1.8 648: rest = pos == 0 ? input : input[pos..-1] # ruby1.9 649: _add_text_to_str(str, rest) 650: add_text(src, str) 651: end