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

Version Path
classiccms-0.3.5 vendor/bundle/gems/temple-0.4.0/lib/temple/erb/parser.rb
classiccms-0.3.4 vendor/bundle/gems/temple-0.4.0/lib/temple/erb/parser.rb
classiccms-0.3.3 vendor/bundle/gems/temple-0.4.0/lib/temple/erb/parser.rb
classiccms-0.3.2 vendor/bundle/gems/temple-0.4.0/lib/temple/erb/parser.rb
classiccms-0.3.1 vendor/bundle/gems/temple-0.4.0/lib/temple/erb/parser.rb
classiccms-0.3.0 vendor/bundle/gems/temple-0.4.0/lib/temple/erb/parser.rb
classiccms-0.2.4.pre vendor/bundle/gems/temple-0.4.0/lib/temple/erb/parser.rb
temple-0.4.0 lib/temple/erb/parser.rb
temple-0.3.5 lib/temple/erb/parser.rb