i18n_checker 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb149cd7bb8d4dc510e28605739ad8b191839ad8
4
- data.tar.gz: 96d3c647d3f15268a4639bb0612bc32f193f43d2
3
+ metadata.gz: d3aa0725f4c247f4ab4ed612ecb97dec782c73b4
4
+ data.tar.gz: 8b5c1d22ca006e77bccabb050db792846e622765
5
5
  SHA512:
6
- metadata.gz: 54b267ed14371c0a00e11b6e47b2960da250d7e15512be760e9766a2c0648501e0b71f148cd654bcaeb7e95c497376dd956d35db834be6d61a4fb62215189a93
7
- data.tar.gz: 8a657e258b13c286b0a25bdd9eff0bbe0f73b218bf44a6f8888d33c6a0293e059961dc9d792904ee244c59d5b7ab078c2fb90969e5239703856f3be442e0bb63
6
+ metadata.gz: 6a8a1898e458c0951ab6f31731c8b286837670621b18060ad595addbd73f16183bddc195ed85118843c10c61bb15b96340f583ca5690b23f5a50e08b4f4f3837
7
+ data.tar.gz: aad50cda3a20a0213b6c9c4007a5f3000e5ceebce318862df5667f8857fa2c14cce24029e7a0f6aab49a9adf08166acab4878ac7a395f1067f1e2af9de28bf01
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n_checker (0.8.3)
4
+ i18n_checker (0.8.4)
5
5
  colorator (~> 1.1.0)
6
6
  haml_parser (~> 0.4)
7
7
  parser
@@ -36,29 +36,43 @@ module I18nChecker
36
36
  end
37
37
 
38
38
  def collect_locale_text(ast)
39
+ return locale_text_from_text(ast) if ast.is_a?(HamlParser::Ast::Text)
39
40
  return locale_text_from_script(ast) if ast.is_a?(HamlParser::Ast::Script)
40
41
  return unless ast.respond_to?(:oneline_child)
41
- return unless ast.oneline_child.is_a?(HamlParser::Ast::Script)
42
- locale_text_from_script(ast.oneline_child)
42
+ if ast.oneline_child.is_a?(HamlParser::Ast::Text)
43
+ locale_text_from_text(ast.oneline_child)
44
+ elsif ast.oneline_child.is_a?(HamlParser::Ast::Script)
45
+ locale_text_from_script(ast.oneline_child)
46
+ end
47
+ end
48
+
49
+ def locale_text_from_text(text_node)
50
+ return if text_node.text == '""'
51
+ translate_scripts = translate_scripts_from_node(text_node)
52
+ return if translate_scripts.empty?
53
+ create_node_result(text_node, translate_scripts)
43
54
  end
44
55
 
45
56
  def locale_text_from_script(script_node)
46
57
  return if script_node.script == '""'
47
- translate_scripts = translate_scripts_from_script(script_node)
58
+ translate_scripts = translate_scripts_from_node(script_node)
48
59
  return if translate_scripts.empty?
60
+ create_node_result(script_node, translate_scripts)
61
+ end
49
62
 
63
+ def create_node_result(ast_node, translate_scripts)
50
64
  translate_scripts.map do |script_params|
51
65
  (text_key, line, column) = script_params
52
66
 
53
67
  locale_text = if text_key =~ /^\.(.+)/
54
- action_view = action_view_name_from_script(script_node)
68
+ action_view = action_view_name_from_script(ast_node)
55
69
  "#{action_view}#{text_key}"
56
70
  else
57
71
  text_key
58
72
  end
59
73
 
60
74
  I18nChecker::Locale::Text.new(
61
- file: script_node.filename,
75
+ file: ast_node.filename,
62
76
  line: line,
63
77
  column: column,
64
78
  text: locale_text,
@@ -66,15 +80,21 @@ module I18nChecker
66
80
  end
67
81
  end
68
82
 
69
- def translate_scripts_from_script(script_node)
83
+ def translate_scripts_from_node(ast_node)
70
84
  results = []
71
- file_cache = file_caches.read(script_node.filename)
72
- script_lines = script_node.script.split("\n")
73
- script_lines.each_with_index do |script_line, i|
85
+ file_cache = file_caches.read(ast_node.filename)
86
+
87
+ node_lines = if ast_node.is_a?(HamlParser::Ast::Text)
88
+ ast_node.text.split("\n")
89
+ elsif ast_node.is_a?(HamlParser::Ast::Script)
90
+ ast_node.script.split("\n")
91
+ end
92
+
93
+ node_lines.each_with_index do |node_line, i|
74
94
  offset_at = 0
75
- translate_scripts = script_line.scan(/t\('[^']+'\)/)
95
+ translate_scripts = node_line.scan(/t\('[^']+'\)/)
76
96
  map_results = translate_scripts.map do |script|
77
- line = script_node.lineno + i
97
+ line = ast_node.lineno + i
78
98
  text_key = script.gsub!(/t\('|'\)/, '')
79
99
  column = file_cache[line].start_of(text_key, offset_at)
80
100
  offset_at = column + 1
@@ -1,3 +1,3 @@
1
1
  module I18nChecker
2
- VERSION = '0.8.3'.freeze
2
+ VERSION = '0.8.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - holyshared