Sha256: ce7c364f8cde1abd151838dd3d0decff567ea01495c82d7e7799f39fd0632cca

Contents?: true

Size: 1.03 KB

Versions: 26

Compression:

Stored size: 1.03 KB

Contents

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

module Rouge
  module Lexers
    class ERB < TemplateLexer
      title "ERB"
      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

26 entries across 24 versions & 6 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/rouge-2.2.1/lib/rouge/lexers/erb.rb
rouge_ecl-1.0.0 lib/rouge/lexers/erb.rb
rouge-2.2.1 lib/rouge/lexers/erb.rb
rouge-2.2.0 lib/rouge/lexers/erb.rb
rougegal-2.1.2 lib/rouge/lexers/erb.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/rouge-2.0.7/lib/rouge/lexers/erb.rb
tdiary-5.0.5 vendor/bundle/gems/rouge-2.1.1/lib/rouge/lexers/erb.rb
tdiary-5.0.5 vendor/bundle/gems/rouge-2.0.7/lib/rouge/lexers/erb.rb
rouge-2.1.1 lib/rouge/lexers/erb.rb
rouge-2.1.0 lib/rouge/lexers/erb.rb
tdiary-5.0.4 vendor/bundle/gems/rouge-2.0.7/lib/rouge/lexers/erb.rb
rouge-2.0.7 lib/rouge/lexers/erb.rb
rouge-2.0.6 lib/rouge/lexers/erb.rb
rouge-2.0.5 lib/rouge/lexers/erb.rb
rouge-2.0.3 lib/rouge/lexers/erb.rb
rouge-2.0.2 lib/rouge/lexers/erb.rb
rouge-2.0.1 lib/rouge/lexers/erb.rb
rouge-2.0.0 lib/rouge/lexers/erb.rb
rouge-1.11.1 lib/rouge/lexers/erb.rb
rouge-1.11.0 lib/rouge/lexers/erb.rb