Sha256: fe7d1bc7b72293fa2b658959a8c5d6ec1b179ff95b32d8b6e071b04fd3192c69
Contents?: true
Size: 1.09 KB
Versions: 49
Compression:
Stored size: 1.09 KB
Contents
module Temple module ERB # Example ERB parser # # @api public class Parser include Mixins::Options ERB_PATTERN = /(\n|<%%|%%>)|<%(==?|\#)?(.*?)?-?%>/m def call(input) result = [:multi] pos = 0 input.scan(ERB_PATTERN) do |token, indicator, code| text = input[pos...$~.begin(0)] pos = $~.end(0) if token case token when "\n" result << [:static, "#{text}\n"] << [:newline] when '<%%', '%%>' result << [:static, text] unless text.empty? token.slice!(1) result << [:static, token] end else result << [:static, text] unless text.empty? case indicator when '#' result << [:code, "\n" * code.count("\n")] when /=/ result << [:escape, indicator.size <= 1, [:dynamic, code]] else result << [:code, code] end end end result << [:static, input[pos..-1]] end end end end
Version data entries
49 entries across 49 versions & 2 rubygems