Sha256: aa49df6c23a6eead86442a9cf97de185026add56cf7dee0e3543fe77cf43cc0e

Contents?: true

Size: 1.96 KB

Versions: 32

Compression:

Stored size: 1.96 KB

Contents

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

module Rouge
  module Lexers
    class Handlebars < TemplateLexer
      title "Handlebars"
      desc 'the Handlebars and Mustache templating languages'
      tag 'handlebars'
      aliases 'hbs', 'mustache'
      filenames '*.handlebars', '*.hbs', '*.mustache'
      mimetypes 'text/x-handlebars', 'text/x-mustache'

      id = %r([\w$-]+)

      state :root do
        # escaped slashes
        rule(/\\{+/) { delegate parent }

        # block comments
        rule /{{!--/, Comment, :comment
        rule /{{!.*?}}/, Comment

        rule /{{{?/ do
          token Keyword
          push :stache
          push :open_sym
        end

        rule(/(.+?)(?=\\|{{)/m) { delegate parent }

        # if we get here, there's no more mustache tags, so we eat
        # the rest of the doc
        rule(/.+/m) { delegate parent }
      end

      state :comment do
        rule(/{{/) { token Comment; push }
        rule(/}}/) { token Comment; pop! }
        rule(/[^{}]+/m) { token Comment }
        rule(/[{}]/) { token Comment }
      end

      state :stache do
        rule /}}}?/, Keyword, :pop!
        rule /\s+/m, Text
        rule /[=]/, Operator
        rule /[\[\]]/, Punctuation
        rule /[.](?=[}\s])/, Name::Variable
        rule /[.][.]/, Name::Variable
        rule %r([/.]), Punctuation
        rule /"(\\.|.)*?"/, Str::Double
        rule /'(\\.|.)*?'/, Str::Single
        rule /\d+(?=}\s)/, Num
        rule /(true|false)(?=[}\s])/, Keyword::Constant
        rule /else(?=[}\s])/, Keyword
        rule /this(?=[}\s])/, Name::Builtin::Pseudo
        rule /@#{id}/, Name::Attribute
        rule id, Name::Variable
      end

      state :open_sym do
        rule %r([#/]) do
          token Keyword
          goto :block_name
        end

        rule /[>^&]/, Keyword

        rule(//) { pop! }
      end

      state :block_name do
        rule /if(?=[}\s])/, Keyword
        rule id, Name::Namespace, :pop!
        rule(//) { pop! }
      end
    end
  end
end

Version data entries

32 entries across 30 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/handlebars.rb
rouge-3.2.1 lib/rouge/lexers/handlebars.rb
rouge-3.2.0 lib/rouge/lexers/handlebars.rb
rouge_ecl-1.0.0 lib/rouge/lexers/handlebars.rb
rouge_ecl-0.0.1 lib/rouge/lexers/handlebars.rb
rouge-3.1.1 lib/rouge/lexers/handlebars.rb
rouge-3.1.0 lib/rouge/lexers/handlebars.rb
rouge-3.0.0 lib/rouge/lexers/handlebars.rb
rouge-2.2.1 lib/rouge/lexers/handlebars.rb
rouge-2.2.0 lib/rouge/lexers/handlebars.rb
rougegal-2.1.2 lib/rouge/lexers/handlebars.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/rouge-2.0.7/lib/rouge/lexers/handlebars.rb
tdiary-5.0.5 vendor/bundle/gems/rouge-2.0.7/lib/rouge/lexers/handlebars.rb
tdiary-5.0.5 vendor/bundle/gems/rouge-2.1.1/lib/rouge/lexers/handlebars.rb
rouge-2.1.1 lib/rouge/lexers/handlebars.rb
rouge-2.1.0 lib/rouge/lexers/handlebars.rb
tdiary-5.0.4 vendor/bundle/gems/rouge-2.0.7/lib/rouge/lexers/handlebars.rb
rouge-2.0.7 lib/rouge/lexers/handlebars.rb
rouge-2.0.6 lib/rouge/lexers/handlebars.rb
rouge-2.0.5 lib/rouge/lexers/handlebars.rb