class HamlI18nLint::Linter
Linter
linting a Haml template
Public Class Methods
new(config)
click to toggle source
@param config [Config] the configuration @return [Lint] new linter with given configuration
# File lib/haml_i18n_lint/linter.rb, line 48 def initialize(config) @config = config end
Public Instance Methods
lint(filename:, template:)
click to toggle source
Linting given template
@param filename [String] the filename @param template [String] the Haml template @return [Linter::ResultSet] the result of lint @raise [Linter::AttributesParseError] if failed to parse attributes hash in the template.
# File lib/haml_i18n_lint/linter.rb, line 58 def lint(filename:, template:) haml_options = ::Haml::Options.new haml_options[:filename] = filename node = parse(haml_options, template) compiler(haml_options).compile(node) end
Private Instance Methods
compiler(haml_options)
click to toggle source
Calls superclass method
# File lib/haml_i18n_lint/linter.rb, line 75 def compiler(haml_options) config = @config result_set = ResultSet.new ext = compiler_extension compiler_result_extension = Module.new do include ext define_method(:compile) do |node| super(node) result_set end private define_method(:lint_config) do config end define_method(:lint_add) do |text| result_set.add_result(Result.new(haml_options[:filename], @node, text)) end end ::Haml::Compiler.new(haml_options).tap { |c| c.extend(compiler_result_extension, compiler_extension) } end
compiler_extension()
click to toggle source
# File lib/haml_i18n_lint/linter.rb, line 71 def compiler_extension self.class::CompilerExtension end
parse(haml_options, template)
click to toggle source
# File lib/haml_i18n_lint/linter.rb, line 67 def parse(haml_options, template) ::Haml::Parser.new(template, haml_options).parse end