Sha256: 3e5db62eb1bc6fbd204275035de3483c1833c9d02bc2dda7a344c1b2a2e1c9c3

Contents?: true

Size: 1.06 KB

Versions: 15

Compression:

Stored size: 1.06 KB

Contents

# Hamlit::Parser uses original Haml::Parser to generate Haml AST.
# hamlit/parser/haml_* are modules originally in haml gem.

require 'hamlit/parser/haml_error'
require 'hamlit/parser/haml_util'
require 'hamlit/parser/haml_buffer'
require 'hamlit/parser/haml_compiler'
require 'hamlit/parser/haml_parser'
require 'hamlit/parser/haml_helpers'
require 'hamlit/parser/haml_options'

module Hamlit
  class Parser
    AVAILABLE_OPTIONS = %i[
      autoclose
      escape_html
      escape_attrs
    ].freeze

    def initialize(options = {})
      @options = HamlOptions.defaults.dup
      AVAILABLE_OPTIONS.each do |key|
        @options[key] = options[key]
      end
    end

    def call(template)
      HamlParser.new(template, HamlOptions.new(@options)).parse
    rescue ::Hamlit::HamlError => e
      error_with_lineno(e)
    end

    private

    def error_with_lineno(error)
      return error if error.line

      trace = error.backtrace.first
      return error unless trace

      line = trace.match(/\d+\z/).to_s.to_i
      HamlSyntaxError.new(error.message, line)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
hamlit-2.2.4 lib/hamlit/parser.rb
hamlit-2.6.1 lib/hamlit/parser.rb
hamlit-2.6.0 lib/hamlit/parser.rb
hamlit-2.5.0 lib/hamlit/parser.rb
hamlit-2.4.2 lib/hamlit/parser.rb
hamlit-2.4.1 lib/hamlit/parser.rb
hamlit-2.4.0 lib/hamlit/parser.rb
hamlit-2.3.1 lib/hamlit/parser.rb
hamlit-2.3.0 lib/hamlit/parser.rb
hamlit-2.2.3 lib/hamlit/parser.rb
hamlit-2.2.2 lib/hamlit/parser.rb
hamlit-2.2.1 lib/hamlit/parser.rb
hamlit-2.2.0 lib/hamlit/parser.rb
hamlit-2.1.2 lib/hamlit/parser.rb
hamlit-2.1.1 lib/hamlit/parser.rb