Module | Erubis::Basic::Converter |
In: |
merb-core/lib/merb-core/gem_ext/erubis.rb
|
This adds support for embedding the return value of a block call:
<%= foo do %>...<% end =%>
:api: private
# File merb-core/lib/merb-core/gem_ext/erubis.rb, line 8 8: def convert_input(src, input) 9: pat = @pattern 10: regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat) 11: pos = 0 12: is_bol = true # is beginning of line 13: input.scan(regexp) do |indicator, code, tailch, rspace| 14: match = Regexp.last_match() 15: len = match.begin(0) - pos 16: text = input[pos, len] 17: pos = match.end(0) 18: ch = indicator ? indicator[0] : nil 19: lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol) 20: is_bol = rspace ? true : false 21: add_text(src, text) if text && !text.empty? 22: ## * when '<%= %>', do nothing 23: ## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>' 24: if ch == ?= # <%= %> 25: rspace = nil if tailch && !tailch.empty? 26: add_text(src, lspace) if lspace 27: add_expr(src, code, indicator) 28: add_text(src, rspace) if rspace 29: elsif ch == ?\# # <%# %> 30: n = code.count("\n") + (rspace ? 1 : 0) 31: if @trim && lspace && rspace 32: add_stmt(src, "\n" * n) 33: else 34: add_text(src, lspace) if lspace 35: add_stmt(src, "\n" * n) 36: add_text(src, rspace) if rspace 37: end 38: elsif ch == ?% # <%% %> 39: s = "#{lspace}#{@prefix||='<%'}#{code}#{tailch}#{@postfix||='%>'}#{rspace}" 40: add_text(src, s) 41: else # <% %> 42: if @trim && lspace && rspace 43: if respond_to?(:add_stmt2) 44: add_stmt2(src, "#{lspace}#{code}#{rspace}", tailch) 45: else 46: add_stmt(src, "#{lspace}#{code}#{rspace}") 47: end 48: else 49: add_text(src, lspace) if lspace 50: if respond_to?(:add_stmt2) 51: add_stmt2(src, code, tailch) 52: else 53: add_stmt(src, code) 54: end 55: add_text(src, rspace) if rspace 56: end 57: end 58: end 59: #rest = $' || input # ruby1.8 60: rest = pos == 0 ? input : input[pos..-1] # ruby1.9 61: add_text(src, rest) 62: end