Module | Erubis::PI::Converter |
In: |
lib/erubis/converter.rb
|
Processing Instructions (PI) converter for XML. this class converts ’<?rb … ?>’ and ’${…}’ notation.
pi | [RW] | |
prefix | [RW] |
# File lib/erubis/converter.rb, line 225 225: def convert(input) 226: code = super(input) 227: return @header || @footer ? "#{@header}#{code}#{@footer}" : code 228: end
# File lib/erubis/converter.rb, line 216 216: def init_converter(properties={}) 217: super(properties) 218: @trim = properties.fetch(:trim, true) 219: @pi = properties[:pi] if properties[:pi] 220: @embchar = properties[:embchar] || '@' 221: @pattern = properties[:pattern] 222: @pattern = '<% %>' if @pattern.nil? #|| @pattern == true 223: end
# File lib/erubis/converter.rb, line 232 232: def convert_input(codebuf, input) 233: unless @regexp 234: @pi ||= 'e' 235: ch = Regexp.escape(@embchar) 236: if @pattern 237: left, right = @pattern.split(' ') 238: @regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/m 239: else 240: @regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}/m 241: end 242: end 243: # 244: is_bol = true 245: pos = 0 246: input.scan(@regexp) do |pi_arg, stmt, rspace, 247: indicator1, expr1, indicator2, expr2| 248: match = Regexp.last_match 249: len = match.begin(0) - pos 250: text = input[pos, len] 251: pos = match.end(0) 252: lspace = stmt ? detect_spaces_at_bol(text, is_bol) : nil 253: is_bol = stmt && rspace ? true : false 254: add_text(codebuf, text) # unless text.empty? 255: # 256: if stmt 257: if @trim && lspace && rspace 258: add_pi_stmt(codebuf, "#{lspace}#{stmt}#{rspace}", pi_arg) 259: else 260: add_text(codebuf, lspace) if lspace 261: add_pi_stmt(codebuf, stmt, pi_arg) 262: add_text(codebuf, rspace) if rspace 263: end 264: else 265: add_pi_expr(codebuf, expr1 || expr2, indicator1 || indicator2) 266: end 267: end 268: #rest = $' || input # ruby1.8 269: rest = pos == 0 ? input : input[pos..-1] # ruby1.9 270: add_text(codebuf, rest) 271: end