Class: HamlI18nLint::Config
- Inherits:
-
Object
- Object
- HamlI18nLint::Config
- Defined in:
- lib/haml_i18n_lint/config.rb
Overview
Configuration for the lint
Instance Method Summary collapse
-
#files ⇒ Array<String>
The list of files to be linted.
-
#ignore_keys ⇒ String
The list of key of attributes hash.
-
#ignore_methods ⇒ String
The list of methods, which takes string.
-
#initialize(options) ⇒ Config
constructor
Returns a new lint configuration by given options.
-
#need_i18n?(content) ⇒ true, false
The content need i18n or not.
-
#report(result_set) ⇒ Object
Output the formatted result.
Constructor Details
#initialize(options) ⇒ Config
Returns a new lint configuration by given options
7 8 9 10 11 12 |
# File 'lib/haml_i18n_lint/config.rb', line 7 def initialize() @options = if (@options.config_path) load_config(@options.config_content) end end |
Instance Method Details
#files ⇒ Array<String>
Returns the list of files to be linted.
41 42 43 |
# File 'lib/haml_i18n_lint/config.rb', line 41 def files Dir[*@options.files].uniq end |
#ignore_keys ⇒ String
Returns the list of key of attributes hash. The key is no translation required.
61 62 63 |
# 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 ⇒ String
Returns the list of methods, which takes string. The string is no translation required.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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) ⇒ true, false
Returns the content need i18n or not.
16 17 18 |
# File 'lib/haml_i18n_lint/config.rb', line 16 def need_i18n?(content) /^[\s]+$/ !~ content && /\p{Alpha}/ =~ content end |
#report(result_set) ⇒ Object
Output the formatted result
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |