Sha256: e03aff2264a2eaee2207ef0fb9119e70291cd6a05d5a6326526514e1b55e02fa

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

module HamlI18nLint
  # Configuration for the lint
  class Config
    # Returns a new lint configuration by given options
    #
    # @param options [Options]
    def initialize(options)
      @options = options
      if (@options.config_path)
        load_config(@options.config_content)
      end
    end

    # @param content [String] the text content found in haml template
    # @return [true, false] the content need i18n or not.
    def need_i18n?(content)
      /^[\s]+$/ !~ content && /\p{Alpha}/ =~ content
    end

    # Output the formatted result
    #
    # @param result [Linter::Result] the lint result
    def report(result)
      print '.' and return if result.success?

      puts
      file = File.readlines(result.filename)
      result.matched_nodes.each do |node|
        puts "#{result.filename}:#{node.line}"
        puts "#{node.line-1}:  #{file[node.line - 2]}" if file[node.line - 2] && !(node.line - 2).negative?
        puts "#{node.line}:  #{file[node.line - 1]}"
        puts "#{node.line+1}:  #{file[node.line]}" if file[node.line]
        puts '-' * 16
      end
      puts
    end

    # @return [Array<String>] the list of files to be linted.
    def files
      Dir[*@options.files].uniq
    end

    # @return [String] the list of methods, which takes string. The string is no translation required.
    def ignore_methods
      %w(t render)
    end

    # @return [String] the list of key of attributes hash. The key is no translation required.
    def ignore_keys
      %w(id class method controller action type lang selected checked src href rel language media)
    end

    private

    def load_config(config_content)
      singleton_class.class_eval { eval(config_content, binding) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
haml_i18n_lint-0.6.0 lib/haml_i18n_lint/config.rb