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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDE3ZjJhMzg1OGM5MTIxYjJjZjljMWE0NDMzMjZkNmNkNDJjZGU0OA==
4
+ YWYyNWM2YWQ5YTA3OTdlNmUyN2Y5NTJkZmI0ZDc1YzdkMzcxNWM4Mw==
5
5
  data.tar.gz: !binary |-
6
- YzBhODViNGViM2VlYjM4YzY1ZjhmMjM2YTJmNzkxNWViMzI1Y2EzZQ==
6
+ MThkMzY5ZGFiZWY3ZTNhOGZjNTEyZjUyN2UzNWIzNjg4NjczMjM2ZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDE0ZDFkYjZkOTg2Y2Q3MTRhOGY4ZWUwN2UzOTliMWExYTIxNGY5ZTBhOTE4
10
- YmY3YTg2MmY1YTQ3MzdmMmQwMDA3YjQ0ZDZhZDBlYmE4ZThjZDU0Y2M5OGY3
11
- MTBmNDViNzc2NzU0MGIxYWI0YWI4ZmNkYmIwZjY4ZjlkZTdiNzY=
9
+ YzFhNmIyNzIwZDhhNGE0N2IzNjQ0NzQwMzg1YjgyZjA1OWM4ZWMwMTA2N2Q0
10
+ NjBhNjM2MGNhMWE4YTAyMjNhOThhOWQ1ZWYyNzJmYjkwNjEwZjIxOGE3YzQ3
11
+ OTU5Y2JjNzUzODQ3ZjAzOThhNDYzM2JhZDI0NTIzODVmZTA3MGQ=
12
12
  data.tar.gz: !binary |-
13
- NDEzZjMyODk1YWM5YWU2ZGI0OWE0NmVmYWVmNjQxYzVhMjE1ZjZlODg1Yzg0
14
- MzY5MDI0ZDYyZGY0YmM3MGQyMWQ2NTBlYzJkMGIwMzM5Mzc4YjgzN2FlYmQ1
15
- MjFlZDUxMThmMDE3MWE3NjZhZjI1NTc2OGY5ZjZlOWU4YzBhOWQ=
13
+ MGZlOTZjZjA5YjlmYTMxMTAzNDlkY2VkYzRmZjgwZWMxZjM0MDZkNTQ4ZjVj
14
+ OWU2YTU2ZGM3ZDZhMWEwZGM4M2FhYmU0YWY0NjYxNDQzMTgxOGVmY2YxYTky
15
+ OWRiMzRkYjVhM2MzMTY4Y2JjYzI1ZDQ1MGEwZmUxOGU2NzVmZjA=
data/README.md CHANGED
@@ -25,7 +25,7 @@ end
25
25
 
26
26
  - Per-project basis, with the binary. See demo below for usage of the binary.
27
27
 
28
- `cd your-rails-app-to-translate && haml-i18n-extractor .`
28
+ `cd your-rails-app-to-translate && haml-i18n-extractor --help`
29
29
 
30
30
  ## Demo using interactive mode
31
31
 
@@ -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 -p <path> [--interactive|--non-interactive] [--other-options]
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 = []
@@ -1,7 +1,7 @@
1
1
  module Haml
2
2
  module I18n
3
3
  class Extractor
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -8,12 +8,14 @@ module Haml
8
8
  class Extractor
9
9
  class YamlTool
10
10
 
11
- attr_accessor :locales_dir, :locale_hash, :yaml_file
11
+ attr_accessor :locale_hash, :yaml_file, :i18n_scope
12
12
 
13
- def initialize(locales_dir = nil)
14
- @locales_dir = locales_dir ? locales_dir : "./config/locales/"
15
- if ! File.exists?(@locales_dir)
16
- FileUtils.mkdir_p(@locales_dir)
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 = [@yaml_file,standardized_viewnames(info[:path]), standarized_keyname(info[:keyname]),
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? ? locale_file : filename
36
+ pth = filename.nil? ? @yaml_file : filename
39
37
  if File.exist?(pth)
40
38
  str = File.read(pth)
41
39
  if str.empty?
@@ -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.locale_file)), {}
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.locale_file), false
108
+ assert_equal File.exists?(@ex1.yaml_tool.yaml_file), false
109
109
  @ex1.run
110
- assert_equal File.exists?(@ex1.yaml_tool.locale_file), true
111
- assert_equal YAML.load(File.read(@ex1.yaml_tool.locale_file)), @ex1.yaml_tool.yaml_hash
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
@@ -25,7 +25,7 @@ module Haml
25
25
  File.join(locale_config_dir, "en.yml")
26
26
  end
27
27
 
28
- def setup_locale_file
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 "locale dir defaults to config/locales/" do
59
+ test "defaults for empty init" do
60
60
  yaml_tool = Haml::I18n::Extractor::YamlTool.new
61
- assert_equal yaml_tool.locales_dir, "./config/locales/"
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 set the locale_dir" do
65
- yaml_tool = Haml::I18n::Extractor::YamlTool.new(@temp_locale_dir)
66
- assert_equal yaml_tool.locales_dir, @temp_locale_dir
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
- setup_locale_file
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 => "jp"})
80
- assert_equal @ex1.yaml_tool.yaml_file, :jp
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.2.1
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-07-31 00:00:00.000000000 Z
11
+ date: 2013-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tilt