haml-i18n-extractor 0.0.12 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/TODO +3 -0
- data/haml-i18n-extractor.gemspec +2 -2
- data/lib/haml-i18n-extractor/core-ext/hash.rb +2 -0
- data/lib/haml-i18n-extractor/version.rb +1 -1
- data/lib/haml-i18n-extractor/yaml_tool.rb +23 -19
- data/test/extractor_test.rb +7 -1
- data/test/yaml_tool_test.rb +38 -2
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTY3NzcyNDcwZjBhZDJkMGJmMGI1OGViMGQzZmQ1ZWQ3MTQzNjViYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjcwNjMxZDg2ZWE3NTI3NjI3NDUyYWY1MDFjOGE3YjIyZDVmMTU1ZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjQwYThlMzcxMzdhNGNjNTdlNmE1YmM5MDI3N2YwNGYxZjU1NWRjZDVjZWVj
|
10
|
+
ZTk2YmJmMjlkYzE1NGI5MGQ0YTVkNGJlZTE3MmE4OTllY2VkN2E4ZjVjY2U4
|
11
|
+
NDBjYzc1ZmM5NzFjMTE1MTFhNTBlMGE3Y2MyZTU4YmJlMTRiZTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmE2YWJjODY5MTA5OGU4MjZiODI4NWJiMDNhZmMxMDRhZDNkNDg5N2Y4MDRm
|
14
|
+
NzU0ZDNmZjYwYTU1NzgzOGRjMmIzYjE4NzkwYzkxMGJlMmQ2ZWM3MWUzYThm
|
15
|
+
ODQ3Y2EzNTZkZmE0NDMxNmMzZTExZmRkMWI5ZDhiY2ViZjQ1MmE=
|
data/TODO
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
- add herbgobbler (ERB) and this to another more generalized repo for translating templates?
|
11
11
|
- Refactor tests: split out what is integration vs unit, too much coupling.
|
12
12
|
|
13
|
+
- Make dependencies for gem install haml-i18n-extractor work (highline and haml do not install with it?)
|
14
|
+
|
13
15
|
## workflow todo's
|
14
16
|
|
15
17
|
make sure yaml keys are in one file
|
@@ -17,6 +19,7 @@
|
|
17
19
|
either way when yaml is written, it should just write itself to config/locales/en.yml
|
18
20
|
wether its one-off, or project mode. and that's something yaml_tool should do.
|
19
21
|
merge itself in.
|
22
|
+
concept of project directory of whereever we expect that to be?
|
20
23
|
|
21
24
|
give user more context on line changes (like grep -C 4)
|
22
25
|
agreegate yaml:
|
data/haml-i18n-extractor.gemspec
CHANGED
@@ -19,12 +19,12 @@ Gem::Specification.new do |gem|
|
|
19
19
|
|
20
20
|
gem.add_dependency "tilt"
|
21
21
|
gem.add_dependency "haml"
|
22
|
+
gem.add_dependency "activesupport"
|
23
|
+
gem.add_dependency "highline"
|
22
24
|
|
23
|
-
gem.add_development_dependency 'rails', '>= 3.0.0'
|
24
25
|
gem.add_development_dependency 'rbench'
|
25
26
|
gem.add_development_dependency 'pry'
|
26
27
|
gem.add_development_dependency 'minitest'
|
27
28
|
gem.add_development_dependency 'nokogiri'
|
28
|
-
gem.add_development_dependency 'highline'
|
29
29
|
|
30
30
|
end
|
@@ -10,11 +10,13 @@ module Haml
|
|
10
10
|
|
11
11
|
attr_accessor :locales_dir, :locale_hash
|
12
12
|
|
13
|
+
# this requires passing an absolute path.
|
14
|
+
# meaning run from a given rails root...
|
15
|
+
# ok? change?
|
13
16
|
def initialize(locales_dir = nil)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@locales_dir = File.expand_path("./config/locales/")
|
17
|
+
@locales_dir = locales_dir ? locales_dir : "./config/locales/"
|
18
|
+
if ! File.exists?(@locales_dir)
|
19
|
+
FileUtils.mkdir_p(@locales_dir)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -30,22 +32,24 @@ module Haml
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def locale_file
|
33
|
-
|
34
|
-
pth = @locale_hash.map{|_,h| h[:path] }.compact.first
|
35
|
-
if pth
|
36
|
-
full_path = Pathname.new(pth)
|
37
|
-
base_name = full_path.basename.to_s
|
38
|
-
if ! File.exist?(@locales_dir)
|
39
|
-
FileUtils.mkdir_p(@locales_dir)
|
40
|
-
end
|
41
|
-
File.expand_path(File.join( @locales_dir, standardized_viewname(full_path) + ".#{base_name}.yml"))
|
42
|
-
end
|
43
|
-
end || "haml-i18-extractor.yml"
|
35
|
+
File.join(@locales_dir, "#{i18n_scope}.yml")
|
44
36
|
end
|
45
37
|
|
46
|
-
def write_file
|
47
|
-
|
48
|
-
|
38
|
+
def write_file(filename = nil)
|
39
|
+
pth = filename.nil? ? locale_file : filename
|
40
|
+
if File.exist?(pth)
|
41
|
+
str = File.read(pth)
|
42
|
+
if str.empty?
|
43
|
+
existing_yaml_hash = {}
|
44
|
+
else
|
45
|
+
existing_yaml_hash = YAML.load(str)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
existing_yaml_hash = {}
|
49
|
+
end
|
50
|
+
final_yaml_hash = existing_yaml_hash.deep_merge!(yaml_hash)
|
51
|
+
f = File.open(pth, "w+")
|
52
|
+
f.puts final_yaml_hash.to_yaml
|
49
53
|
f.flush
|
50
54
|
end
|
51
55
|
|
@@ -54,7 +58,7 @@ module Haml
|
|
54
58
|
# {:foo => {:bar => {:baz => :mam}, :barrr => {:bazzz => :mammm} }}
|
55
59
|
def hashify(my_hash)
|
56
60
|
if my_hash.is_a?(HashWithIndifferentAccess)
|
57
|
-
result =
|
61
|
+
result = Hash.new
|
58
62
|
my_hash.each do |k, v|
|
59
63
|
result[k.to_s] = hashify(v)
|
60
64
|
end
|
data/test/extractor_test.rb
CHANGED
@@ -39,6 +39,7 @@ module Haml
|
|
39
39
|
end
|
40
40
|
|
41
41
|
test "with a prompt_per_line option takes user input into consideration for yaml" do
|
42
|
+
hax_shit
|
42
43
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :prompt_per_line => true)
|
43
44
|
user_input = "D" # dump
|
44
45
|
File.readlines(file_path("ex1.haml")).size.times do
|
@@ -72,8 +73,13 @@ module Haml
|
|
72
73
|
assert_equal File.exists?(@ex1.haml_writer.path), true
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
+
def hax_shit
|
76
77
|
Dir.glob("*yml").map {|p| FileUtils.rm(p) } # HAX, TODO: handle with yaml files correctly (config/en.yml)
|
78
|
+
Dir.glob("config/locales/*yml").map {|p| FileUtils.rm(p) } # HAX, TODO: handle with yaml files correctly (config/en.yml)
|
79
|
+
end
|
80
|
+
|
81
|
+
test "it writes the locale info to an out file when run" do
|
82
|
+
hax_shit
|
77
83
|
assert_equal File.exists?(@ex1.yaml_tool.locale_file), false
|
78
84
|
@ex1.run
|
79
85
|
assert_equal File.exists?(@ex1.yaml_tool.locale_file), true
|
data/test/yaml_tool_test.rb
CHANGED
@@ -4,7 +4,7 @@ module Haml
|
|
4
4
|
class YamlToolTest < MiniTest::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@temp_locale_dir =
|
7
|
+
@temp_locale_dir = "./test/tmp/"
|
8
8
|
end
|
9
9
|
|
10
10
|
def setup_locale_hash
|
@@ -12,6 +12,33 @@ module Haml
|
|
12
12
|
@ex1.run
|
13
13
|
end
|
14
14
|
|
15
|
+
def locale_config_dir
|
16
|
+
dir = File.expand_path(File.join(File.dirname(__FILE__), "/tmp/config/locales"))
|
17
|
+
if ! File.exists?(dir)
|
18
|
+
FileUtils.mkdir_p(dir)
|
19
|
+
end
|
20
|
+
dir
|
21
|
+
end
|
22
|
+
|
23
|
+
def locale_config_file
|
24
|
+
File.join(locale_config_dir, "en.yml")
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup_locale_file
|
28
|
+
File.open(locale_config_file, "w+") do |f|
|
29
|
+
f.write(existing_yaml_hash.to_yaml)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def existing_yaml_hash
|
34
|
+
{"en" => {
|
35
|
+
"viewname" => {
|
36
|
+
"translate_key" => "Translate Key"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
15
42
|
def ex1_yaml_hash
|
16
43
|
{"en"=>
|
17
44
|
{"support"=>
|
@@ -30,7 +57,7 @@ module Haml
|
|
30
57
|
|
31
58
|
test "locale dir defaults to config/locales/" do
|
32
59
|
yaml_tool = Haml::I18n::Extractor::YamlTool.new
|
33
|
-
assert_equal yaml_tool.locales_dir,
|
60
|
+
assert_equal yaml_tool.locales_dir, "./config/locales/"
|
34
61
|
end
|
35
62
|
|
36
63
|
test "you can set the locale_dir" do
|
@@ -38,6 +65,15 @@ module Haml
|
|
38
65
|
assert_equal yaml_tool.locales_dir, @temp_locale_dir
|
39
66
|
end
|
40
67
|
|
68
|
+
test "it can merge with an existing yml file" do
|
69
|
+
setup_locale_hash
|
70
|
+
setup_locale_file
|
71
|
+
@ex1.yaml_tool.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
|
+
|
41
77
|
test "it relies on the locale_hash having a certain format" do
|
42
78
|
setup_locale_hash
|
43
79
|
@ex1.yaml_tool.locale_hash.each do |line_no, info_for_line|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml-i18n-extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shai Rosenfeld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -39,27 +39,27 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: highline
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
type: :
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rbench
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ! '>='
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: minitest
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: nokogiri
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ! '>='
|