haml-i18n-extractor 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +2 -0
- data/TODO +1 -1
- data/bin/haml-i18n-extractor +1 -0
- data/lib/haml-i18n-extractor/cli.rb +4 -6
- data/lib/haml-i18n-extractor/extractor.rb +1 -0
- data/lib/haml-i18n-extractor/version.rb +1 -1
- data/lib/haml-i18n-extractor/workflow.rb +2 -3
- data/lib/haml-i18n-extractor/yaml_tool.rb +3 -9
- data/test/yaml_tool_test.rb +5 -0
- metadata +1 -2
- data/.tags.haml-i18n-extractor +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWE4MmIxYTMzMzQwMWU3YWRkYjg1ZDYyNjNkZmM4ZTgxMzY1ZTQ5Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmE2OTQ5MjFmNmZiYTI1YzFiMmU1MzVlMWVmNGUwZDFlODBjMWU1ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWRkY2QyNGU2NDhhYTQzYWM4MTJiNGI0NmY3MjFmMWIyYWFhZjNlNzBjNzRi
|
10
|
+
NmU4MGYxNDM3ODYwNDFmMDNiZDI4NGQ2NWU4NDgyZjRmNzU0MTFkZjg2MWI4
|
11
|
+
NGEyNDJiMWNiNjMxYjRmNDM2YTUwYWY4MDBkZTExY2JlMTIzOGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODE5MGJiZWQ4MGNhZWQzMDczZTRmNWJiYTMwNDUxMWYzOTI2M2YyZmYxM2Ew
|
14
|
+
YmFkZjBkYmMwNGZmYWVlMzJmMTRjMjc0M2FiZjM2MjViZjA1ZTA5NzRjZWNj
|
15
|
+
MTJkNjhiOGFkYzk1YjM0YTkwMzhhYzk0YzdiZTlmMDUyNmY4ZDM=
|
data/.gitignore
CHANGED
data/TODO
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
* Issues
|
12
12
|
|
13
|
-
- CLI options: Extractor.new accepts options. pass through workflow. First up:
|
13
|
+
- CLI options: Extractor.new accepts options. pass through workflow. First up: yaml_file (issue#5)
|
14
14
|
- add a ~/.haml-i18n-extractor file/dir/config file etc. to keep preferences of interactive mode or not?
|
15
15
|
|
16
16
|
* Ideas
|
data/bin/haml-i18n-extractor
CHANGED
@@ -9,6 +9,7 @@ option_parser = Trollop::Parser.new do
|
|
9
9
|
opt :interactive, "interactive mode", :short => 'i'
|
10
10
|
opt :non_interactive, "non interactive mode", :short => 'n'
|
11
11
|
opt :path, "path", :type => String
|
12
|
+
opt :yaml_file, "yaml file, defaults to en", :type => String
|
12
13
|
end
|
13
14
|
|
14
15
|
opts = Trollop::with_standard_exception_handling option_parser do
|
@@ -17,11 +17,9 @@ class Haml::I18n::Extractor
|
|
17
17
|
if File.directory?(pth)
|
18
18
|
workflow = Haml::I18n::Extractor::Workflow.new(pth, @options)
|
19
19
|
workflow.run
|
20
|
-
elsif File.exists?(pth)
|
21
|
-
|
22
|
-
extractor.
|
23
|
-
elsif File.exists?(pth) && @options[:non_interactive]
|
24
|
-
extractor = Haml::I18n::Extractor.new(pth, :type => :overwrite, :interactive => false)
|
20
|
+
elsif File.exists?(pth)
|
21
|
+
@options.merge!(:type => :overwrite)
|
22
|
+
extractor = Haml::I18n::Extractor.new(pth, @options)
|
25
23
|
extractor.run
|
26
24
|
end
|
27
25
|
end
|
@@ -30,7 +28,7 @@ class Haml::I18n::Extractor
|
|
30
28
|
private
|
31
29
|
|
32
30
|
def check_interactive_or_not_passed
|
33
|
-
if !@options[:interactive] && !@options[:non_interactive]
|
31
|
+
if (!@options[:interactive] && !@options[:non_interactive]) || (@options[:interactive] && @options[:non_interactive])
|
34
32
|
@prompter.puts("You must choose either one of interactive mode or non interactive mode.")
|
35
33
|
@prompter.puts("See haml-i18n-extractor --help")
|
36
34
|
raise CliError
|
@@ -28,6 +28,7 @@ module Haml
|
|
28
28
|
validate_haml(@haml_reader.body)
|
29
29
|
@haml_writer = Haml::I18n::Extractor::HamlWriter.new(haml_path, {:type => @type})
|
30
30
|
@yaml_tool = Haml::I18n::Extractor::YamlTool.new
|
31
|
+
@yaml_tool.yaml_file = (@options[:yaml_file] || :en).to_sym
|
31
32
|
@tagging_tool ||= Haml::I18n::Extractor::TaggingTool.new
|
32
33
|
# hold all the processed lines
|
33
34
|
@body = []
|
@@ -67,10 +67,9 @@ module Haml
|
|
67
67
|
|
68
68
|
def process(haml_path, type)
|
69
69
|
@prompter.process(haml_path, type)
|
70
|
-
|
71
|
-
options.merge!({:interactive => @passed_options[:interactive]}) # per-line prompts
|
70
|
+
@passed_options.merge!({:type => type}) # overwrite or dump haml
|
72
71
|
begin
|
73
|
-
@extractor = Haml::I18n::Extractor.new(haml_path,
|
72
|
+
@extractor = Haml::I18n::Extractor.new(haml_path, @passed_options)
|
74
73
|
@extractors << @extractor
|
75
74
|
@extractor.run
|
76
75
|
rescue Haml::I18n::Extractor::InvalidSyntax
|
@@ -8,11 +8,8 @@ module Haml
|
|
8
8
|
class Extractor
|
9
9
|
class YamlTool
|
10
10
|
|
11
|
-
attr_accessor :locales_dir, :locale_hash
|
11
|
+
attr_accessor :locales_dir, :locale_hash, :yaml_file
|
12
12
|
|
13
|
-
# this requires passing an absolute path.
|
14
|
-
# meaning run from a given rails root...
|
15
|
-
# ok? change?
|
16
13
|
def initialize(locales_dir = nil)
|
17
14
|
@locales_dir = locales_dir ? locales_dir : "./config/locales/"
|
18
15
|
if ! File.exists?(@locales_dir)
|
@@ -25,7 +22,7 @@ module Haml
|
|
25
22
|
yml = Hash.new
|
26
23
|
@locale_hash.map do |line_no, info|
|
27
24
|
unless info[:keyname].nil?
|
28
|
-
keyspace = [
|
25
|
+
keyspace = [@yaml_file,standardized_viewnames(info[:path]), standarized_keyname(info[:keyname]),
|
29
26
|
info[:replaced_text]].flatten
|
30
27
|
yml.deep_merge!(nested_hash({},keyspace))
|
31
28
|
end
|
@@ -34,7 +31,7 @@ module Haml
|
|
34
31
|
end
|
35
32
|
|
36
33
|
def locale_file
|
37
|
-
File.join(@locales_dir, "#{
|
34
|
+
File.join(@locales_dir, "#{@yaml_file}.yml")
|
38
35
|
end
|
39
36
|
|
40
37
|
def write_file(filename = nil)
|
@@ -81,9 +78,6 @@ module Haml
|
|
81
78
|
end
|
82
79
|
hash
|
83
80
|
end
|
84
|
-
def i18n_scope
|
85
|
-
:en
|
86
|
-
end
|
87
81
|
|
88
82
|
# comes in like "t('.some_place')", return .some_place
|
89
83
|
def standarized_keyname(name)
|
data/test/yaml_tool_test.rb
CHANGED
@@ -75,6 +75,11 @@ module Haml
|
|
75
75
|
assert_equal really_written['en']['support'], ex1_yaml_hash['en']['support']
|
76
76
|
end
|
77
77
|
|
78
|
+
test "it can accept a different yml file" do
|
79
|
+
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"), {:yaml_file => "jp"})
|
80
|
+
assert_equal @ex1.yaml_tool.yaml_file, :jp
|
81
|
+
end
|
82
|
+
|
78
83
|
test "it relies on the locale_hash having a certain format" do
|
79
84
|
setup_locale_hash
|
80
85
|
@ex1.yaml_tool.locale_hash.each do |line_no, info_for_line|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shai Rosenfeld
|
@@ -202,7 +202,6 @@ extra_rdoc_files: []
|
|
202
202
|
files:
|
203
203
|
- .gitignore
|
204
204
|
- .rvmrc
|
205
|
-
- .tags.haml-i18n-extractor
|
206
205
|
- Gemfile
|
207
206
|
- LICENSE
|
208
207
|
- README.md
|
data/.tags.haml-i18n-extractor
DELETED
File without changes
|