haml-i18n-extractor 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/.gitignore +1 -1
  2. data/TODO +6 -0
  3. data/lib/haml-i18n-extractor/extraction/extractor.rb +36 -26
  4. data/lib/haml-i18n-extractor/extraction/{exception_finder.rb → finder/exception_finder.rb} +0 -0
  5. data/lib/haml-i18n-extractor/extraction/{text_finder.rb → finder/text_finder.rb} +18 -12
  6. data/lib/haml-i18n-extractor/extraction/replacer/interpolation_helper.rb +51 -0
  7. data/lib/haml-i18n-extractor/extraction/replacer/replacer_result.rb +24 -0
  8. data/lib/haml-i18n-extractor/extraction/{text_replacer.rb → replacer/text_replacer.rb} +38 -33
  9. data/lib/haml-i18n-extractor/extraction/{tagging_tool.rb → tagging_writer.rb} +1 -1
  10. data/lib/haml-i18n-extractor/extraction/{yaml_tool.rb → yaml_writer.rb} +9 -12
  11. data/lib/haml-i18n-extractor/flow/prompter.rb +1 -1
  12. data/lib/haml-i18n-extractor/helpers.rb +38 -0
  13. data/lib/haml-i18n-extractor/version.rb +1 -1
  14. data/lib/haml-i18n-extractor.rb +8 -5
  15. data/scripts/renew_test_syntax +18 -0
  16. data/test/cli_test.rb +2 -2
  17. data/test/exception_finder_test.rb +2 -2
  18. data/test/extractor_test.rb +23 -23
  19. data/test/haml_parser_test.rb +3 -3
  20. data/test/haml_reader_test.rb +3 -3
  21. data/test/haml_writer_test.rb +4 -2
  22. data/test/integration_test.rb +13 -11
  23. data/test/interpolation_helper_test.rb +43 -0
  24. data/test/prompter_test.rb +3 -3
  25. data/test/support/ex1.yml +15 -0
  26. data/test/support/ex2.output.haml +1 -1
  27. data/test/support/ex5.haml +4 -0
  28. data/test/support/ex5.output.haml +4 -0
  29. data/test/support/ex5.yml +8 -0
  30. data/test/{tagging_tool_test.rb → tagging_writer_test.rb} +6 -6
  31. data/test/test_helper.rb +2 -2
  32. data/test/text_finder_test.rb +22 -20
  33. data/test/text_replacer_test.rb +29 -27
  34. data/test/workflow_test.rb +5 -5
  35. data/test/yaml_writer_test.rb +120 -0
  36. metadata +27 -14
  37. data/test/yaml_tool_test.rb +0 -110
@@ -3,65 +3,67 @@ require 'test_helper'
3
3
  module Haml
4
4
  class TextReplacerTest < MiniTest::Unit::TestCase
5
5
 
6
- test "it initializes with the line it is going to replace and the match to replace" do
7
- Haml::I18n::Extractor::TextReplacer.new("this is whatever", "this is whatever", :plain)
6
+ def test_it_initializes_with_the_line_it_is_going_to_replace_and_the_match_to_replace
7
+ Haml::I18n::Extractor::TextReplacer.new("this is whatever", "this is whatever", :plain, "/path/to/doesntmatter.haml")
8
8
  end
9
9
 
10
- test "but it raises if passed a wrong line type" do
10
+ def test_but_it_raises_if_passed_a_wrong_line_type
11
11
  begin
12
- replacer = Haml::I18n::Extractor::TextReplacer.new("regular text", "regular text", :this_is_not_defined)
12
+ replacer = Haml::I18n::Extractor::TextReplacer.new("regular text", "regular text", :this_is_not_defined, "/path/to/doesntmatter.haml")
13
13
  assert false, 'should raise'
14
14
  rescue Haml::I18n::Extractor::NotDefinedLineType
15
15
  assert true, 'raised NotDefinedLineType'
16
16
  end
17
17
  end
18
18
 
19
+
20
+
19
21
  # some text replacement examples
20
- test "it can replace the body of haml with t() characters" do
21
- replacer = Haml::I18n::Extractor::TextReplacer.new("this is whatever", "this is whatever", :plain)
22
+ def test_it_can_replace_the_body_of_haml_with_t_characters
23
+ replacer = Haml::I18n::Extractor::TextReplacer.new("this is whatever", "this is whatever", :plain, "/path/to/doesntmatter.haml")
22
24
  assert_equal replacer.replace_hash, { :modified_line => "= t('.this_is_whatever')",
23
- :keyname => "t('.this_is_whatever')", :replaced_text => "this is whatever" }
25
+ :t_name => "this_is_whatever", :replaced_text => "this is whatever", :path => "/path/to/doesntmatter.haml" }
24
26
  end
25
27
 
26
- test "it can replace the body of haml with t() characters example" do
27
- replacer = Haml::I18n::Extractor::TextReplacer.new("%span Admin Dashboard", "Admin Dashboard", :tag)
28
+ def test_it_can_replace_the_body_of_haml_with_t_characters_example
29
+ replacer = Haml::I18n::Extractor::TextReplacer.new("%span Admin Dashboard", "Admin Dashboard", :tag, "/path/to/doesntmatter.haml")
28
30
  assert_equal replacer.replace_hash, { :modified_line => "%span= t('.admin_dashboard')",
29
- :keyname => "t('.admin_dashboard')", :replaced_text => "Admin Dashboard" }
31
+ :t_name => "admin_dashboard", :replaced_text => "Admin Dashboard", :path => "/path/to/doesntmatter.haml" }
30
32
  end
31
33
 
32
- test "it won't replace already replaced t() characters if they are not ruby evaled" do
33
- replacer = Haml::I18n::Extractor::TextReplacer.new("%span t('.admin_dashboard')", "t('.admin_dashboard')", :tag)
34
+ def test_it_wont_replace_already_replaced_t_characters_if_they_are_not_ruby_evaled
35
+ replacer = Haml::I18n::Extractor::TextReplacer.new("%span t('.admin_dashboard')", "t('.admin_dashboard')", :tag, "/path/to/doesntmatter.haml")
34
36
  assert_equal replacer.replace_hash, { :modified_line => "%span t('.admin_dashboard')",
35
- :keyname => "t('.admin_dashboard')", :replaced_text => "t('.admin_dashboard')" }
37
+ :t_name => "admin_dashboard", :replaced_text => "t('.admin_dashboard')", :path => "/path/to/doesntmatter.haml" }
36
38
  end
37
39
 
38
- test "it won't replace already replaced t() characters that are ruby evaled" do
39
- replacer = Haml::I18n::Extractor::TextReplacer.new("%span= t('.admin_dashboard')", "t('.admin_dashboard')", :script)
40
+ def test_it_wont_replace_already_replaced_t_characters_that_are_ruby_evaled
41
+ replacer = Haml::I18n::Extractor::TextReplacer.new("%span= t('.admin_dashboard')", "t('.admin_dashboard')", :script, "/path/to/doesntmatter.haml")
40
42
  assert_equal replacer.replace_hash, { :modified_line => "%span= t('.admin_dashboard')",
41
- :keyname => "t('.admin_dashboard')", :replaced_text => "t('.admin_dashboard')" }
43
+ :t_name => "admin_dashboard", :replaced_text => "t('.admin_dashboard')", :path => "/path/to/doesntmatter.haml" }
42
44
  end
43
45
 
44
- test "it can replace the body of haml with t() characters example for link_to and removes surrounding quotes as well" do
45
- replacer = Haml::I18n::Extractor::TextReplacer.new(%{%p#brand= link_to 'Some Place', '/'}, "Some Place", :script)
46
+ def test_it_can_replace_the_body_of_haml_with_t_characters_example_for_link_to_and_removes_surrounding_quotes_as_well
47
+ replacer = Haml::I18n::Extractor::TextReplacer.new(%{%p#brand= link_to 'Some Place', '/'}, "Some Place", :script, "/path/to/doesntmatter.haml")
46
48
  assert_equal replacer.replace_hash, { :modified_line => %{%p#brand= link_to t('.some_place'), '/'} ,
47
- :keyname => "t('.some_place')", :replaced_text => "Some Place" }
49
+ :t_name => "some_place", :replaced_text => "Some Place", :path => "/path/to/doesntmatter.haml" }
48
50
 
49
- replacer = Haml::I18n::Extractor::TextReplacer.new(%{%p#brand= link_to "Some Place", "/"}, "Some Place", :script)
51
+ replacer = Haml::I18n::Extractor::TextReplacer.new(%{%p#brand= link_to "Some Place", "/"}, "Some Place", :script, "/path/to/doesntmatter.haml")
50
52
  assert_equal replacer.replace_hash, { :modified_line => %{%p#brand= link_to t('.some_place'), "/"} ,
51
- :keyname => "t('.some_place')", :replaced_text => "Some Place" }
53
+ :t_name => "some_place", :replaced_text => "Some Place", :path => "/path/to/doesntmatter.haml" }
52
54
  end
53
55
 
54
56
  # keyname restrictions
55
- test "it limits the characters of the t namespace it provides to LIMIT_KEY_NAME" do
56
- replacer = Haml::I18n::Extractor::TextReplacer.new("this is whatever" * 80, "this is whatever" * 80, :plain)
57
- assert_equal replacer.replace_hash[:modified_line].size, Haml::I18n::Extractor::TextReplacer::LIMIT_KEY_NAME + 8 # = t('.')
57
+ def test_it_limits_the_characters_of_the_t_namespace_it_provides_to_limit_key_name
58
+ replacer = Haml::I18n::Extractor::TextReplacer.new("this is whatever" * 80, "this is whatever" * 80, :plain, "/path/to/doesntmatter.haml")
59
+ assert_equal replacer.replace_hash[:modified_line].size, Haml::I18n::Extractor::Helpers::StringHelpers::LIMIT_KEY_NAME + 8 # = t('.')
58
60
  end
59
61
 
60
- test "it does not allow weird characters in the keyname" do
62
+ def test_it_does_not_allow_weird_characters_in_the_keyname
61
63
  weird_line = "thi:s = (is \"' `ch@racter ~ ma?dne{}ss!"
62
- replacer = Haml::I18n::Extractor::TextReplacer.new(weird_line, weird_line, :plain)
64
+ replacer = Haml::I18n::Extractor::TextReplacer.new(weird_line, weird_line, :plain, "/path/to/doesntmatter.haml")
63
65
  assert_equal replacer.replace_hash, { :modified_line => "= t('.this_is_chracter_madness')",
64
- :keyname => "t('.this_is_chracter_madness')", :replaced_text => weird_line }
66
+ :t_name => "this_is_chracter_madness", :replaced_text => weird_line, :path => "/path/to/doesntmatter.haml" }
65
67
  end
66
68
 
67
69
  end
@@ -5,14 +5,14 @@ module Haml
5
5
 
6
6
  def setup
7
7
  TestHelper.setup_project_directory! # tests here rely on this setup...
8
- @workflow = TestHelper.mock_full_project_user_interaction!
8
+ @workflow = TestHelper.mock_full_project_user_interaction!
9
9
  end
10
10
 
11
11
  def teardown
12
12
  TestHelper.teardown_project_directory!
13
13
  end
14
14
 
15
- test "it_should_work_on_a_directory_mkay" do
15
+ def test_it_should_work_on_a_directory_mkay
16
16
  begin
17
17
  filename = "#{TestHelper::PROJECT_DIR}app/views/bar/thang.haml"
18
18
  bad_worfklow = Haml::I18n::Extractor::Workflow.new(filename)
@@ -22,18 +22,18 @@ module Haml
22
22
  end
23
23
  end
24
24
 
25
- test "it_finds_all_haml_files" do
25
+ def test_it_finds_all_haml_files
26
26
  assert_equal @workflow.files.size, 9
27
27
  end
28
28
 
29
- test "outputs_stats" do
29
+ def test_outputs_stats
30
30
  with_highline do
31
31
  @workflow.start_message
32
32
  assert @output.string.match(/Found \d haml files/), "Outputs stats"
33
33
  end
34
34
  end
35
35
 
36
- test "yaml_file_in_config" do
36
+ def test_yaml_file_in_config
37
37
  TestHelper.mock_full_project_user_interaction!
38
38
  end
39
39
 
@@ -0,0 +1,120 @@
1
+ require 'test_helper'
2
+
3
+ module Haml
4
+ class YamlWriterTest < MiniTest::Unit::TestCase
5
+
6
+ def setup
7
+ @temp_locale_dir = "./test/tmp/"
8
+ TestHelper.setup_project_directory!
9
+ end
10
+
11
+ def setup_info_for_yaml
12
+ @ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
13
+ @ex1.run
14
+ end
15
+
16
+ def locale_config_dir
17
+ dir = File.expand_path(File.join(File.dirname(__FILE__), "/tmp/config/locales"))
18
+ if ! File.exists?(dir)
19
+ FileUtils.mkdir_p(dir)
20
+ end
21
+ dir
22
+ end
23
+
24
+ def locale_config_file
25
+ File.join(locale_config_dir, "en.yml")
26
+ end
27
+
28
+ def setup_yaml_file
29
+ File.open(locale_config_file, "w+") do |f|
30
+ f.write(existing_yaml_hash.to_yaml)
31
+ end
32
+ end
33
+
34
+ def existing_yaml_hash
35
+ {"en" => {
36
+ "viewname" => {
37
+ "translate_key" => "Translate Key"
38
+ }
39
+ }
40
+ }
41
+ end
42
+
43
+ def ex1_yaml_hash
44
+ YAML.load File.read(file_path("ex1.yml"))
45
+ end
46
+
47
+ def ex5_yaml_hash
48
+ YAML.load File.read(file_path("ex5.yml"))
49
+ end
50
+
51
+ def test_it_can_deal_with_interpolated_vars
52
+ @ex5 = Haml::I18n::Extractor.new(file_path("ex5.haml"))
53
+ @ex5.run
54
+ assert_equal @ex5.yaml_writer.yaml_hash, ex5_yaml_hash
55
+ end
56
+
57
+ def test_defaults_for_empty_init
58
+ yaml_writer = Haml::I18n::Extractor::YamlWriter.new
59
+ assert_equal yaml_writer.yaml_file, "./config/locales/en.yml"
60
+ assert_equal yaml_writer.i18n_scope, :en
61
+ end
62
+
63
+ def test_you_can_pass_a_yaml_file
64
+ yaml_writer = Haml::I18n::Extractor::YamlWriter.new(nil, @temp_locale_dir)
65
+ assert_equal yaml_writer.yaml_file, @temp_locale_dir
66
+ end
67
+
68
+ def test_it_can_merge_with_an_existing_yml_file
69
+ setup_info_for_yaml
70
+ setup_yaml_file
71
+ @ex1.yaml_writer.write_file(locale_config_file)
72
+ really_written = YAML.load(File.read(locale_config_file))
73
+ assert_equal really_written['en']['viewname'], existing_yaml_hash['en']['viewname']
74
+ assert_equal really_written['en']['support'], ex1_yaml_hash['en']['support']
75
+ end
76
+
77
+ def test_it_can_accept_a_different_yml_file
78
+ @ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"), {:yaml_file => "/tmp/foo.yml"})
79
+ assert_equal @ex1.yaml_writer.yaml_file, "/tmp/foo.yml"
80
+ end
81
+
82
+ def test_it_knows_about_i18n_scope
83
+ @ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"), {:i18n_scope => "he"})
84
+ assert_equal @ex1.yaml_writer.i18n_scope, :he
85
+ end
86
+
87
+ def test_it_knows_about_i18n_scope_defaults_to_en
88
+ @ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
89
+ assert_equal @ex1.yaml_writer.i18n_scope, :en
90
+ end
91
+
92
+ def test_it_will_assume_yaml_file_according_to_i18n_scope_if_no_yaml_file_is_passed
93
+ yaml_writer = Haml::I18n::Extractor::YamlWriter.new("he", nil)
94
+ assert_equal yaml_writer.yaml_file, "./config/locales/he.yml"
95
+ end
96
+
97
+ def test_it_will_not_assume_yaml_file_according_to_i18n_scope_if_yaml_file_is_passed
98
+ yaml_writer = Haml::I18n::Extractor::YamlWriter.new("he", "/tmp/foo.yml")
99
+ assert_equal yaml_writer.yaml_file, "/tmp/foo.yml"
100
+ end
101
+
102
+ def test_it_relies_on_the_info_for_yaml_having_a_certain_format
103
+ setup_info_for_yaml
104
+ @ex1.yaml_writer.info_for_yaml.each do |line_no, info_for_line|
105
+ assert info_for_line.has_key?(:modified_line), "hash info has :modified_line key"
106
+ assert info_for_line.has_key?(:t_name), "hash info has :t_name key"
107
+ assert info_for_line.has_key?(:replaced_text), "hash info has :replaced_text key"
108
+ # FIXME: since the scope right now is we're running this per file this will be the same, but keeping this right now.
109
+ assert info_for_line.has_key?(:path), "hash info has :path key"
110
+ end
111
+ end
112
+
113
+ def test_constructs_a_yaml_hash_according_to_the_view_in_rails_mode
114
+ setup_info_for_yaml
115
+ yaml_writer = @ex1.yaml_writer
116
+ assert_equal yaml_writer.yaml_hash, ex1_yaml_hash
117
+ end
118
+
119
+ end
120
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-i18n-extractor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shai Rosenfeld
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-09-05 00:00:00 Z
18
+ date: 2013-09-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: tilt
@@ -223,21 +223,24 @@ files:
223
223
  - haml-i18n-extractor.gemspec
224
224
  - lib/haml-i18n-extractor.rb
225
225
  - lib/haml-i18n-extractor/core-ext/hash.rb
226
- - lib/haml-i18n-extractor/extraction/exception_finder.rb
227
226
  - lib/haml-i18n-extractor/extraction/extractor.rb
227
+ - lib/haml-i18n-extractor/extraction/finder/exception_finder.rb
228
+ - lib/haml-i18n-extractor/extraction/finder/text_finder.rb
228
229
  - lib/haml-i18n-extractor/extraction/haml_parser.rb
229
230
  - lib/haml-i18n-extractor/extraction/haml_reader.rb
230
231
  - lib/haml-i18n-extractor/extraction/haml_writer.rb
231
- - lib/haml-i18n-extractor/extraction/tagging_tool.rb
232
- - lib/haml-i18n-extractor/extraction/text_finder.rb
233
- - lib/haml-i18n-extractor/extraction/text_replacer.rb
234
- - lib/haml-i18n-extractor/extraction/yaml_tool.rb
232
+ - lib/haml-i18n-extractor/extraction/replacer/interpolation_helper.rb
233
+ - lib/haml-i18n-extractor/extraction/replacer/replacer_result.rb
234
+ - lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb
235
+ - lib/haml-i18n-extractor/extraction/tagging_writer.rb
236
+ - lib/haml-i18n-extractor/extraction/yaml_writer.rb
235
237
  - lib/haml-i18n-extractor/flow/cli.rb
236
238
  - lib/haml-i18n-extractor/flow/prompter.rb
237
239
  - lib/haml-i18n-extractor/flow/user_action.rb
238
240
  - lib/haml-i18n-extractor/flow/workflow.rb
239
241
  - lib/haml-i18n-extractor/helpers.rb
240
242
  - lib/haml-i18n-extractor/version.rb
243
+ - scripts/renew_test_syntax
241
244
  - test/cli_test.rb
242
245
  - test/exception_finder_test.rb
243
246
  - test/extractor_test.rb
@@ -245,24 +248,29 @@ files:
245
248
  - test/haml_reader_test.rb
246
249
  - test/haml_writer_test.rb
247
250
  - test/integration_test.rb
251
+ - test/interpolation_helper_test.rb
248
252
  - test/prompter_test.rb
249
253
  - test/support/bad.haml
250
254
  - test/support/ex1.haml
251
255
  - test/support/ex1.output.haml
256
+ - test/support/ex1.yml
252
257
  - test/support/ex2.haml
253
258
  - test/support/ex2.output.haml
254
259
  - test/support/ex3.haml
255
260
  - test/support/ex3.output.haml
256
261
  - test/support/ex4.haml
257
262
  - test/support/ex4.output.haml
263
+ - test/support/ex5.haml
264
+ - test/support/ex5.output.haml
265
+ - test/support/ex5.yml
258
266
  - test/support/nothing_to_translate.haml
259
267
  - test/support/nothing_to_translate.i18n-extractor.haml
260
- - test/tagging_tool_test.rb
268
+ - test/tagging_writer_test.rb
261
269
  - test/test_helper.rb
262
270
  - test/text_finder_test.rb
263
271
  - test/text_replacer_test.rb
264
272
  - test/workflow_test.rb
265
- - test/yaml_tool_test.rb
273
+ - test/yaml_writer_test.rb
266
274
  homepage: https://github.com/shaiguitar/haml-i18n-extractor
267
275
  licenses:
268
276
  - MIT
@@ -304,21 +312,26 @@ test_files:
304
312
  - test/haml_reader_test.rb
305
313
  - test/haml_writer_test.rb
306
314
  - test/integration_test.rb
315
+ - test/interpolation_helper_test.rb
307
316
  - test/prompter_test.rb
308
317
  - test/support/bad.haml
309
318
  - test/support/ex1.haml
310
319
  - test/support/ex1.output.haml
320
+ - test/support/ex1.yml
311
321
  - test/support/ex2.haml
312
322
  - test/support/ex2.output.haml
313
323
  - test/support/ex3.haml
314
324
  - test/support/ex3.output.haml
315
325
  - test/support/ex4.haml
316
326
  - test/support/ex4.output.haml
327
+ - test/support/ex5.haml
328
+ - test/support/ex5.output.haml
329
+ - test/support/ex5.yml
317
330
  - test/support/nothing_to_translate.haml
318
331
  - test/support/nothing_to_translate.i18n-extractor.haml
319
- - test/tagging_tool_test.rb
332
+ - test/tagging_writer_test.rb
320
333
  - test/test_helper.rb
321
334
  - test/text_finder_test.rb
322
335
  - test/text_replacer_test.rb
323
336
  - test/workflow_test.rb
324
- - test/yaml_tool_test.rb
337
+ - test/yaml_writer_test.rb
@@ -1,110 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Haml
4
- class YamlToolTest < MiniTest::Unit::TestCase
5
-
6
- def setup
7
- @temp_locale_dir = "./test/tmp/"
8
- TestHelper.setup_project_directory!
9
- end
10
-
11
- def setup_locale_hash
12
- @ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
13
- @ex1.run
14
- end
15
-
16
- def locale_config_dir
17
- dir = File.expand_path(File.join(File.dirname(__FILE__), "/tmp/config/locales"))
18
- if ! File.exists?(dir)
19
- FileUtils.mkdir_p(dir)
20
- end
21
- dir
22
- end
23
-
24
- def locale_config_file
25
- File.join(locale_config_dir, "en.yml")
26
- end
27
-
28
- def setup_yaml_file
29
- File.open(locale_config_file, "w+") do |f|
30
- f.write(existing_yaml_hash.to_yaml)
31
- end
32
- end
33
-
34
- def existing_yaml_hash
35
- {"en" => {
36
- "viewname" => {
37
- "translate_key" => "Translate Key"
38
- }
39
- }
40
- }
41
- end
42
-
43
- def ex1_yaml_hash
44
- YAML.load File.read(file_path("ex1.yml"))
45
- end
46
-
47
- test "defaults for empty init" do
48
- yaml_tool = Haml::I18n::Extractor::YamlTool.new
49
- assert_equal yaml_tool.yaml_file, "./config/locales/en.yml"
50
- assert_equal yaml_tool.i18n_scope, :en
51
- end
52
-
53
- test "you can pass a yaml_file" do
54
- yaml_tool = Haml::I18n::Extractor::YamlTool.new(nil, @temp_locale_dir)
55
- assert_equal yaml_tool.yaml_file, @temp_locale_dir
56
- end
57
-
58
- test "it can merge with an existing yml file" do
59
- setup_locale_hash
60
- setup_yaml_file
61
- @ex1.yaml_tool.write_file(locale_config_file)
62
- really_written = YAML.load(File.read(locale_config_file))
63
- assert_equal really_written['en']['viewname'], existing_yaml_hash['en']['viewname']
64
- assert_equal really_written['en']['support'], ex1_yaml_hash['en']['support']
65
- end
66
-
67
- test "it can accept a different yml file" do
68
- @ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"), {:yaml_file => "/tmp/foo.yml"})
69
- assert_equal @ex1.yaml_tool.yaml_file, "/tmp/foo.yml"
70
- end
71
-
72
- test "it knows about i18n scope" do
73
- @ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"), {:i18n_scope => "he"})
74
- assert_equal @ex1.yaml_tool.i18n_scope, :he
75
- end
76
-
77
- test "it knows about i18n scope, defaults to :en" do
78
- @ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
79
- assert_equal @ex1.yaml_tool.i18n_scope, :en
80
- end
81
-
82
- test "it will assume yaml_file according to i18n_scope if no yaml_file is passed" do
83
- yaml_tool = Haml::I18n::Extractor::YamlTool.new("he", nil)
84
- assert_equal yaml_tool.yaml_file, "./config/locales/he.yml"
85
- end
86
-
87
- test "it will not assume yaml_file according to i18n_scope if yaml_file is passed" do
88
- yaml_tool = Haml::I18n::Extractor::YamlTool.new("he", "/tmp/foo.yml")
89
- assert_equal yaml_tool.yaml_file, "/tmp/foo.yml"
90
- end
91
-
92
- test "it relies on the locale_hash having a certain format" do
93
- setup_locale_hash
94
- @ex1.yaml_tool.locale_hash.each do |line_no, info_for_line|
95
- assert info_for_line.has_key?(:modified_line), "hash info has :modified_line key"
96
- assert info_for_line.has_key?(:keyname), "hash info has :keyname key"
97
- assert info_for_line.has_key?(:replaced_text), "hash info has :replaced_text key"
98
- # FIXME: since the scope right now is we're running this per file this will be the same, but keeping this right now.
99
- assert info_for_line.has_key?(:path), "hash info has :path key"
100
- end
101
- end
102
-
103
- test "constructs a yaml hash according to the view in rails mode" do
104
- setup_locale_hash
105
- yaml_tool = @ex1.yaml_tool
106
- assert_equal yaml_tool.yaml_hash, ex1_yaml_hash
107
- end
108
-
109
- end
110
- end