Module | Erubis::PI::Converter |
In: |
erubis/converter.rb
|
Processing Instructions (PI) converter for XML. this class converts ’<?rb … ?>’ and ’${…}’ notation.
pi | [RW] | |
prefix | [RW] |
# File erubis/converter.rb, line 224 def convert(input) code = super(input) return @header || @footer ? "#{@header}#{code}#{@footer}" : code end
# File erubis/converter.rb, line 215 def init_converter(properties={}) super(properties) @trim = properties.fetch(:trim, true) @pi = properties[:pi] if properties[:pi] @embchar = properties[:embchar] || '@' @pattern = properties[:pattern] @pattern = '<% %>' if @pattern.nil? #|| @pattern == true end
# File erubis/converter.rb, line 231 def convert_input(codebuf, input) unless @regexp @pi ||= 'e' ch = Regexp.escape(@embchar) if @pattern left, right = @pattern.split(' ') @regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/m else @regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}/m end end # is_bol = true pos = 0 input.scan(@regexp) do |pi_arg, stmt, rspace, indicator1, expr1, indicator2, expr2| match = Regexp.last_match len = match.begin(0) - pos text = input[pos, len] pos = match.end(0) lspace = stmt ? detect_spaces_at_bol(text, is_bol) : nil is_bol = stmt && rspace ? true : false add_text(codebuf, text) # unless text.empty? # if stmt if @trim && lspace && rspace add_pi_stmt(codebuf, "#{lspace}#{stmt}#{rspace}", pi_arg) else add_text(codebuf, lspace) if lspace add_pi_stmt(codebuf, stmt, pi_arg) add_text(codebuf, rspace) if rspace end else add_pi_expr(codebuf, expr1 || expr2, indicator1 || indicator2) end end #rest = $' || input # ruby1.8 rest = pos == 0 ? input : input[pos..-1] # ruby1.9 add_text(codebuf, rest) end