Sha256: 9d3c4694682c977ec2dead300ea7c609a2a5914afe36cb4c2e4e85811c028723

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

# -*- coding: utf-8 -*- #

module Rouge
  module Lexers
    class ERB < TemplateLexer
      desc "Embedded ruby template files"

      tag 'erb'
      aliases 'eruby', 'rhtml'

      filenames '*.erb', '*.erubis', '*.rhtml', '*.eruby'

      def self.analyze_text(text)
        return 0.4 if text =~ /<%.*%>/
      end

      def initialize(opts={})
        @ruby_lexer = Ruby.new(opts)

        super(opts)
      end

      start do
        parent.reset!
        @ruby_lexer.reset!
      end

      open  = /<%%|<%=|<%#|<%-|<%/
      close = /%%>|-%>|%>/

      state :root do
        rule /<%#/, Comment, :comment

        rule open, Comment::Preproc, :ruby

        rule /.+?(?=#{open})|.+/m do
          delegate parent
        end
      end

      state :comment do
        rule close, Comment, :pop!
        rule /.+(?=#{close})|.+/m, Comment
      end

      state :ruby do
        rule close, Comment::Preproc, :pop!

        rule /.+?(?=#{close})|.+/m do
          delegate @ruby_lexer
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rouge-1.7.7 lib/rouge/lexers/erb.rb
rouge-1.7.4 lib/rouge/lexers/erb.rb
rouge-1.7.3 lib/rouge/lexers/erb.rb
rouge-1.7.2 lib/rouge/lexers/erb.rb
rouge-1.7.1 lib/rouge/lexers/erb.rb
rouge-1.7.0 lib/rouge/lexers/erb.rb
rouge-1.6.2 lib/rouge/lexers/erb.rb
rouge-1.6.1 lib/rouge/lexers/erb.rb
rouge-1.5.1 lib/rouge/lexers/erb.rb