class HamlI18nLint::Config
Configuration for the lint
Public Class Methods
new(options)
click to toggle source
Returns a new lint configuration by given options
@param options [Options]
# File lib/haml_i18n_lint/config.rb, line 7 def initialize(options) @options = options if (@options.config_path) load_config(@options.config_content) end end
Public Instance Methods
files()
click to toggle source
@return [Array<String>] the list of files to be linted.
# File lib/haml_i18n_lint/config.rb, line 41 def files Dir[*@options.files].uniq end
ignore_keys()
click to toggle source
@return [String] the list of key of attributes hash. The key is no translation required.
# File lib/haml_i18n_lint/config.rb, line 61 def ignore_keys %w(id class style type lang selected checked href src language rel media method controller action) end
ignore_methods()
click to toggle source
@return [String] the list of methods, which takes string. The string is no translation required.
# File lib/haml_i18n_lint/config.rb, line 46 def ignore_methods %w( asset_path image_path image_tag javascript_include_tag pluralize render singularize stylesheet_link_tag t ) end
need_i18n?(content)
click to toggle source
@param content [String] the text content found in haml template @return [true, false] the content need i18n or not.
# File lib/haml_i18n_lint/config.rb, line 16 def need_i18n?(content) /^[\s]+$/ !~ content && /\p{Alpha}/ =~ content end
report(result_set)
click to toggle source
Output the formatted result
@param result [Linter::ResultSet] the lint result
# File lib/haml_i18n_lint/config.rb, line 23 def report(result_set) print '.' and return if result_set.success? puts files = Hash.new { |h, k| h[k] = File.readlines(k) } result_set.each do |result| file = files[result.filename] node = result.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
Private Instance Methods
load_config(config_content)
click to toggle source
# File lib/haml_i18n_lint/config.rb, line 67 def load_config(config_content) singleton_class.class_eval { eval(config_content, binding) } end