haml-i18n-extractor 0.1.0 → 0.2.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjgwZDJiZjM2NDdkYmUwZDNlODFmNmY4NWYwZWYzMmVjNGM0YjVmMA==
4
+ OWE4MmIxYTMzMzQwMWU3YWRkYjg1ZDYyNjNkZmM4ZTgxMzY1ZTQ5Yg==
5
5
  data.tar.gz: !binary |-
6
- NjZhOTA5YTVmMDE2YmQxMzcyNmUxMDk3NzFkODNkN2FmMWY5MGM1OQ==
6
+ ZmE2OTQ5MjFmNmZiYTI1YzFiMmU1MzVlMWVmNGUwZDFlODBjMWU1ZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzU2NTgwNDVlMTE5NDlkMzFhMmViNTYwY2FhZmFiNzJhNTVjNGIzNmM0MTli
10
- NWZlYjc2ZDg5MTM2ZDU5NTEwNjQyZDdlNWRiYjIxMGZjNDIwYWMyNzk1MmRk
11
- OGRiMmJmNmE3ZjcwNmM4YTA4ZDQ0ZmI2MWFlZjQ1NGExODhkN2Y=
9
+ MWRkY2QyNGU2NDhhYTQzYWM4MTJiNGI0NmY3MjFmMWIyYWFhZjNlNzBjNzRi
10
+ NmU4MGYxNDM3ODYwNDFmMDNiZDI4NGQ2NWU4NDgyZjRmNzU0MTFkZjg2MWI4
11
+ NGEyNDJiMWNiNjMxYjRmNDM2YTUwYWY4MDBkZTExY2JlMTIzOGI=
12
12
  data.tar.gz: !binary |-
13
- YWRmZjIwNzUyZWM1ODhmYWQ0N2Q3ODk3MmYxZGE0NjBiNmQ5ODI3MmUyYzgz
14
- Y2NjZTE3MzI5ZjU1YjU1NjQ3YjgyZTM5M2NmNTRmMDgzNzhiNGNjOTM5MjRk
15
- MzE0OWE5YjVhMTNkMjNlNzU5ZDQ0MzFhZDI4N2NjMDljMjZjMDI=
13
+ ODE5MGJiZWQ4MGNhZWQzMDczZTRmNWJiYTMwNDUxMWYzOTI2M2YyZmYxM2Ew
14
+ YmFkZjBkYmMwNGZmYWVlMzJmMTRjMjc0M2FiZjM2MjViZjA1ZTA5NzRjZWNj
15
+ MTJkNjhiOGFkYzk1YjM0YTkwMzhhYzk0YzdiZTlmMDUyNmY4ZDM=
data/.gitignore CHANGED
@@ -19,3 +19,5 @@ tmp
19
19
  # hacks, these should not appear where thye are.
20
20
  *.yml
21
21
  test/support/ex1.i18n-extractor.haml
22
+ config
23
+ .tags.haml-i18n-extractor
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: i18n_scope (issue#5)
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
@@ -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) && @options[:interactive]
21
- extractor = Haml::I18n::Extractor.new(pth, :type => :overwrite, :interactive => true)
22
- extractor.run
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 = []
@@ -1,7 +1,7 @@
1
1
  module Haml
2
2
  module I18n
3
3
  class Extractor
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -67,10 +67,9 @@ module Haml
67
67
 
68
68
  def process(haml_path, type)
69
69
  @prompter.process(haml_path, type)
70
- options = {:type => type} # overwrite or dump haml
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, options)
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 = [i18n_scope,standardized_viewnames(info[:path]), standarized_keyname(info[:keyname]),
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, "#{i18n_scope}.yml")
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)
@@ -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.1.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
File without changes