haml-i18n-extractor 0.2.1 → 0.3.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.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/bin/haml-i18n-extractor +8 -3
- data/lib/haml-i18n-extractor/extractor.rb +1 -2
- data/lib/haml-i18n-extractor/version.rb +1 -1
- data/lib/haml-i18n-extractor/yaml_tool.rb +9 -11
- data/test/extractor_test.rb +4 -4
- data/test/yaml_tool_test.rb +30 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWYyNWM2YWQ5YTA3OTdlNmUyN2Y5NTJkZmI0ZDc1YzdkMzcxNWM4Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MThkMzY5ZGFiZWY3ZTNhOGZjNTEyZjUyN2UzNWIzNjg4NjczMjM2ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzFhNmIyNzIwZDhhNGE0N2IzNjQ0NzQwMzg1YjgyZjA1OWM4ZWMwMTA2N2Q0
|
10
|
+
NjBhNjM2MGNhMWE4YTAyMjNhOThhOWQ1ZWYyNzJmYjkwNjEwZjIxOGE3YzQ3
|
11
|
+
OTU5Y2JjNzUzODQ3ZjAzOThhNDYzM2JhZDI0NTIzODVmZTA3MGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGZlOTZjZjA5YjlmYTMxMTAzNDlkY2VkYzRmZjgwZWMxZjM0MDZkNTQ4ZjVj
|
14
|
+
OWU2YTU2ZGM3ZDZhMWEwZGM4M2FhYmU0YWY0NjYxNDQzMTgxOGVmY2YxYTky
|
15
|
+
OWRiMzRkYjVhM2MzMTY4Y2JjYzI1ZDQ1MGEwZmUxOGU2NzVmZjA=
|
data/README.md
CHANGED
data/bin/haml-i18n-extractor
CHANGED
@@ -7,15 +7,15 @@ require 'haml-i18n-extractor'
|
|
7
7
|
option_parser = Trollop::Parser.new do
|
8
8
|
banner <<-EOB
|
9
9
|
|
10
|
-
haml-i18n-extractor
|
10
|
+
haml-i18n-extractor <path> [--interactive|--non-interactive] [--other-options]
|
11
11
|
|
12
12
|
See options list:
|
13
13
|
EOB
|
14
14
|
version "Current version: #{Haml::I18n::Extractor::VERSION}"
|
15
|
-
opt :path, "path", :type => String
|
16
15
|
opt :interactive, "interactive mode", :short => 'i'
|
17
16
|
opt :non_interactive, "non interactive mode", :short => 'n'
|
18
|
-
opt :yaml_file, "yaml file, defaults to en", :type => String
|
17
|
+
opt :yaml_file, "yaml file path, defaults to config/locales/en.yml", :type => String, :short => 'y'
|
18
|
+
opt :i18n_scope, "top level i18n scope, defaults to :en", :type => String, :short => 's'
|
19
19
|
end
|
20
20
|
|
21
21
|
opts = Trollop::with_standard_exception_handling option_parser do
|
@@ -23,6 +23,11 @@ opts = Trollop::with_standard_exception_handling option_parser do
|
|
23
23
|
option_parser.parse ARGV
|
24
24
|
end
|
25
25
|
|
26
|
+
path_to_extract = File.expand_path(ARGV[0])
|
27
|
+
if File.exist?(path_to_extract)
|
28
|
+
opts[:path] = path_to_extract
|
29
|
+
end
|
30
|
+
|
26
31
|
begin
|
27
32
|
Haml::I18n::Extractor::CLI.new(opts).start
|
28
33
|
rescue Haml::I18n::Extractor::CLI::CliError
|
@@ -27,8 +27,7 @@ module Haml
|
|
27
27
|
@haml_reader = Haml::I18n::Extractor::HamlReader.new(haml_path)
|
28
28
|
validate_haml(@haml_reader.body)
|
29
29
|
@haml_writer = Haml::I18n::Extractor::HamlWriter.new(haml_path, {:type => @type})
|
30
|
-
@yaml_tool = Haml::I18n::Extractor::YamlTool.new
|
31
|
-
@yaml_tool.yaml_file = (@options[:yaml_file] || :en).to_sym
|
30
|
+
@yaml_tool = Haml::I18n::Extractor::YamlTool.new(@options[:i18n_scope], @options[:yaml_file])
|
32
31
|
@tagging_tool ||= Haml::I18n::Extractor::TaggingTool.new
|
33
32
|
# hold all the processed lines
|
34
33
|
@body = []
|
@@ -8,12 +8,14 @@ module Haml
|
|
8
8
|
class Extractor
|
9
9
|
class YamlTool
|
10
10
|
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :locale_hash, :yaml_file, :i18n_scope
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
15
|
-
|
16
|
-
|
13
|
+
def initialize(i18n_scope = nil, yaml_file = nil)
|
14
|
+
@i18n_scope = i18n_scope && i18n_scope.to_sym || :en
|
15
|
+
@yaml_file = yaml_file || "./config/locales/#{@i18n_scope}.yml"
|
16
|
+
locales_dir = Pathname.new(@yaml_file).dirname
|
17
|
+
if ! File.exists?(locales_dir)
|
18
|
+
FileUtils.mkdir_p(locales_dir)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -22,7 +24,7 @@ module Haml
|
|
22
24
|
yml = Hash.new
|
23
25
|
@locale_hash.map do |line_no, info|
|
24
26
|
unless info[:keyname].nil?
|
25
|
-
keyspace = [@
|
27
|
+
keyspace = [@i18n_scope,standardized_viewnames(info[:path]), standarized_keyname(info[:keyname]),
|
26
28
|
info[:replaced_text]].flatten
|
27
29
|
yml.deep_merge!(nested_hash({},keyspace))
|
28
30
|
end
|
@@ -30,12 +32,8 @@ module Haml
|
|
30
32
|
yml = hashify(yml)
|
31
33
|
end
|
32
34
|
|
33
|
-
def locale_file
|
34
|
-
File.join(@locales_dir, "#{@yaml_file}.yml")
|
35
|
-
end
|
36
|
-
|
37
35
|
def write_file(filename = nil)
|
38
|
-
pth = filename.nil? ?
|
36
|
+
pth = filename.nil? ? @yaml_file : filename
|
39
37
|
if File.exist?(pth)
|
40
38
|
str = File.read(pth)
|
41
39
|
if str.empty?
|
data/test/extractor_test.rb
CHANGED
@@ -62,7 +62,7 @@ module Haml
|
|
62
62
|
h.run
|
63
63
|
end
|
64
64
|
# no changes were made cause user was all like 'uhhh, no thxk'
|
65
|
-
assert_equal YAML.load(File.read(h.yaml_tool.
|
65
|
+
assert_equal YAML.load(File.read(h.yaml_tool.yaml_file)), {}
|
66
66
|
end
|
67
67
|
|
68
68
|
test "with a interactive option user can tag a line for later review" do
|
@@ -105,10 +105,10 @@ module Haml
|
|
105
105
|
|
106
106
|
test "it writes the locale info to an out file when run" do
|
107
107
|
TestHelper.hax_shit
|
108
|
-
assert_equal File.exists?(@ex1.yaml_tool.
|
108
|
+
assert_equal File.exists?(@ex1.yaml_tool.yaml_file), false
|
109
109
|
@ex1.run
|
110
|
-
assert_equal File.exists?(@ex1.yaml_tool.
|
111
|
-
assert_equal YAML.load(File.read(@ex1.yaml_tool.
|
110
|
+
assert_equal File.exists?(@ex1.yaml_tool.yaml_file), true
|
111
|
+
assert_equal YAML.load(File.read(@ex1.yaml_tool.yaml_file)), @ex1.yaml_tool.yaml_hash
|
112
112
|
end
|
113
113
|
|
114
114
|
test "sends a hash over of replacement info to its yaml tool when run" do
|
data/test/yaml_tool_test.rb
CHANGED
@@ -25,7 +25,7 @@ module Haml
|
|
25
25
|
File.join(locale_config_dir, "en.yml")
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def setup_yaml_file
|
29
29
|
File.open(locale_config_file, "w+") do |f|
|
30
30
|
f.write(existing_yaml_hash.to_yaml)
|
31
31
|
end
|
@@ -56,19 +56,20 @@ module Haml
|
|
56
56
|
}
|
57
57
|
end
|
58
58
|
|
59
|
-
test "
|
59
|
+
test "defaults for empty init" do
|
60
60
|
yaml_tool = Haml::I18n::Extractor::YamlTool.new
|
61
|
-
assert_equal yaml_tool.
|
61
|
+
assert_equal yaml_tool.yaml_file, "./config/locales/en.yml"
|
62
|
+
assert_equal yaml_tool.i18n_scope, :en
|
62
63
|
end
|
63
64
|
|
64
|
-
test "you can
|
65
|
-
yaml_tool = Haml::I18n::Extractor::YamlTool.new(@temp_locale_dir)
|
66
|
-
assert_equal yaml_tool.
|
65
|
+
test "you can pass a yaml_file" do
|
66
|
+
yaml_tool = Haml::I18n::Extractor::YamlTool.new(nil, @temp_locale_dir)
|
67
|
+
assert_equal yaml_tool.yaml_file, @temp_locale_dir
|
67
68
|
end
|
68
69
|
|
69
70
|
test "it can merge with an existing yml file" do
|
70
71
|
setup_locale_hash
|
71
|
-
|
72
|
+
setup_yaml_file
|
72
73
|
@ex1.yaml_tool.write_file(locale_config_file)
|
73
74
|
really_written = YAML.load(File.read(locale_config_file))
|
74
75
|
assert_equal really_written['en']['viewname'], existing_yaml_hash['en']['viewname']
|
@@ -76,8 +77,28 @@ module Haml
|
|
76
77
|
end
|
77
78
|
|
78
79
|
test "it can accept a different yml file" do
|
79
|
-
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"), {:yaml_file => "
|
80
|
-
assert_equal @ex1.yaml_tool.yaml_file,
|
80
|
+
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"), {:yaml_file => "/tmp/foo.yml"})
|
81
|
+
assert_equal @ex1.yaml_tool.yaml_file, "/tmp/foo.yml"
|
82
|
+
end
|
83
|
+
|
84
|
+
test "it knows about i18n scope" do
|
85
|
+
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"), {:i18n_scope => "he"})
|
86
|
+
assert_equal @ex1.yaml_tool.i18n_scope, :he
|
87
|
+
end
|
88
|
+
|
89
|
+
test "it knows about i18n scope, defaults to :en" do
|
90
|
+
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
|
91
|
+
assert_equal @ex1.yaml_tool.i18n_scope, :en
|
92
|
+
end
|
93
|
+
|
94
|
+
test "it will assume yaml_file according to i18n_scope if no yaml_file is passed" do
|
95
|
+
yaml_tool = Haml::I18n::Extractor::YamlTool.new("he", nil)
|
96
|
+
assert_equal yaml_tool.yaml_file, "./config/locales/he.yml"
|
97
|
+
end
|
98
|
+
|
99
|
+
test "it will not assume yaml_file according to i18n_scope if yaml_file is passed" do
|
100
|
+
yaml_tool = Haml::I18n::Extractor::YamlTool.new("he", "/tmp/foo.yml")
|
101
|
+
assert_equal yaml_tool.yaml_file, "/tmp/foo.yml"
|
81
102
|
end
|
82
103
|
|
83
104
|
test "it relies on the locale_hash having a certain format" do
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|