basic converter which supports ’<% … %>’ notation.
DEFAULT_REGEXP = /(.*?)(^[ t]*)?<%(=+|#)?(.*?)-?%>([ t]*r?n)?/m DEFAULT_REGEXP = /(^[ t]*)?<%(=+|#)?(.*?)-?%>([ t]*r?n)?/m DEFAULT_REGEXP = /<%(=+|#)?(.*?)-?%>([ t]*r?n)?/m
return regexp of pattern to parse eRuby script
# File lib/erubis/converter.rb, line 112 112: def pattern_regexp(pattern) 113: @prefix, @postfix = pattern.split() # '<% %>' => '<%', '%>' 114: #return /(.*?)(^[ \t]*)?#{@prefix}(=+|\#)?(.*?)-?#{@postfix}([ \t]*\r?\n)?/m 115: #return /(^[ \t]*)?#{@prefix}(=+|\#)?(.*?)-?#{@postfix}([ \t]*\r?\n)?/m 116: return /#{@prefix}(=+|-|\#|%)?(.*?)([-=])?#{@postfix}([ \t]*\r?\n)?/ 117: end
add expression code to src
# File lib/erubis/converter.rb, line 176 176: def add_expr(src, code, indicator) 177: case indicator 178: when '=' 179: @escape ? add_expr_escaped(src, code) : add_expr_literal(src, code) 180: when '==' 181: @escape ? add_expr_literal(src, code) : add_expr_escaped(src, code) 182: when '===' 183: add_expr_debug(src, code) 184: end 185: end
# File lib/erubis/converter.rb, line 127 127: def convert_input(src, input) 128: pat = @pattern 129: regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat) 130: pos = 0 131: is_bol = true # is beginning of line 132: input.scan(regexp) do |indicator, code, tailch, rspace| 133: match = Regexp.last_match() 134: len = match.begin(0) - pos 135: text = input[pos, len] 136: pos = match.end(0) 137: ch = indicator ? indicator[0] : nil 138: lspace = ch == == ? nil : detect_spaces_at_bol(text, is_bol) 139: is_bol = rspace ? true : false 140: add_text(src, text) if text && !text.empty? 141: ## * when '<%= %>', do nothing 142: ## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>' 143: if ch == == # <%= %> 144: rspace = nil if tailch && !tailch.empty? 145: add_text(src, lspace) if lspace 146: add_expr(src, code, indicator) 147: add_text(src, rspace) if rspace 148: elsif ch == \#\ # <%# %> 149: n = code.count("\n") + (rspace ? 1 : 0) 150: if @trim && lspace && rspace 151: add_stmt(src, "\n" * n) 152: else 153: add_text(src, lspace) if lspace 154: add_stmt(src, "\n" * n) 155: add_text(src, rspace) if rspace 156: end 157: elsif ch == %% # <%% %> 158: s = "#{lspace}#{@prefix||='<%'}#{code}#{tailch}#{@postfix||='%>'}#{rspace}" 159: add_text(src, s) 160: else # <% %> 161: if @trim && lspace && rspace 162: add_stmt(src, "#{lspace}#{code}#{rspace}") 163: else 164: add_text(src, lspace) if lspace 165: add_stmt(src, code) 166: add_text(src, rspace) if rspace 167: end 168: end 169: end 170: #rest = $' || input # ruby1.8 171: rest = pos == 0 ? input : input[pos..1] # ruby1.9 172: add_text(src, rest) 173: end
return regexp of pattern to parse eRuby script
# File lib/erubis/converter.rb, line 112 112: def pattern_regexp(pattern) 113: @prefix, @postfix = pattern.split() # '<% %>' => '<%', '%>' 114: #return /(.*?)(^[ \t]*)?#{@prefix}(=+|\#)?(.*?)-?#{@postfix}([ \t]*\r?\n)?/m 115: #return /(^[ \t]*)?#{@prefix}(=+|\#)?(.*?)-?#{@postfix}([ \t]*\r?\n)?/m 116: return /#{@prefix}(=+|-|\#|%)?(.*?)([-=])?#{@postfix}([ \t]*\r?\n)?/ 117: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.