idiom 0.0.3.2 → 0.0.4

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.
@@ -1,3 +1,9 @@
1
- == 0.0.2 (1/22/2010)
1
+ == 0.0.4 2010-01-22
2
+ * minor enhancements
3
+ * use wildcards for Idiom::Base.translate
4
+ * bug fixes
5
+ * smarter understanding of what is a directory
6
+
7
+ == 0.0.2 2010-01-22
2
8
  * major enhancements
3
9
  * don't write duplicate keys
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Capital Thought
1
+ Copyright (c) 2010 Capital Thought
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3.2
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{idiom}
8
- s.version = "0.0.3.2"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeff Coleman"]
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'active_support'
2
3
  require 'rtranslate'
3
4
  require 'timer'
4
5
  require 'yrb'
@@ -33,7 +34,7 @@ module Idiom #:nodoc:
33
34
  "id-ID" => "id",
34
35
  "pt-BR" => "PORTUGUESE",
35
36
  "zh-Hant-HK" => "zh-CN",
36
- }
37
+ }
37
38
 
38
39
  # Original filename to translate.
39
40
  #
@@ -58,7 +59,7 @@ module Idiom #:nodoc:
58
59
  @destination = options[:destination]
59
60
  @use_dirs = options[:use_dirs]
60
61
  Timer.new.time do
61
- @source.to_a.each do |path|
62
+ Dir[@source].each do |path|
62
63
  $stdout.puts "Processing #{path}"
63
64
  if path =~ /\.yml$/i
64
65
  Idiom::Yaml.new({:source => path}.merge(options)).generate
@@ -73,7 +74,7 @@ module Idiom #:nodoc:
73
74
  end
74
75
 
75
76
  def initialize(options={})
76
- @source = options[:source]
77
+ @source = File.expand_path(options[:source])
77
78
  @overwrite = options[:overwrite]
78
79
  @languages = options[:languages]
79
80
 
@@ -2,11 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Idiom" do
4
4
  before(:each) do
5
- stub_timer
6
- stub_yrb
7
- stub_yaml
8
- stub_screen_io
9
- stub_file_io
5
+ stub_io
10
6
  end
11
7
 
12
8
  describe "base" do
@@ -17,13 +13,17 @@ describe "Idiom" do
17
13
  end
18
14
 
19
15
  it "should create an Idiom for each Yaml file" do
16
+ @source = "path.yml"
17
+ Dir.stub!(:[]).and_return([@source])
20
18
  Idiom::Yaml.should_receive(:new).and_return(@translator)
21
- Idiom::Base.translate(:source => "path.yml")
19
+ Idiom::Base.translate(:source => @source)
22
20
  end
23
21
 
24
22
  it "should create an Idiom for each YRB file" do
23
+ @source = "path.pres"
24
+ Dir.stub!(:[]).and_return([@source])
25
25
  Idiom::Yrb.should_receive(:new).and_return(@translator)
26
- Idiom::Base.translate(:source => "path.pres")
26
+ Idiom::Base.translate(:source => @source)
27
27
  end
28
28
  end
29
29
 
@@ -41,14 +41,14 @@ SECOND=second key
41
41
 
42
42
  it "should create the destination path if it does not exist" do
43
43
  Idiom::Yrb::LOCALES.each do |lang, code|
44
- FileUtils.should_receive(:mkdir_p).with("./translations") unless lang == "en-US"
44
+ FileUtils.should_receive(:mkdir_p).with(/\/translations/) unless lang == "en-US"
45
45
  end
46
46
  Idiom::Yrb.new(:source => @source).generate
47
47
  end
48
48
 
49
49
  it "should write to the destination path" do
50
50
  Idiom::Yrb::LOCALES.each do |lang, code|
51
- File.should_receive(:open).with("./translations/path_#{lang}.pres", "a") unless lang == "en-US"
51
+ File.should_receive(:open).with(/\/translations\/path_#{lang}.pres/, "a") unless lang == "en-US"
52
52
  end
53
53
  Idiom::Yrb.new(:source => @source).generate
54
54
  end
@@ -60,17 +60,24 @@ SECOND=second key
60
60
 
61
61
  it "should write to directories" do
62
62
  Idiom::Yrb::LOCALES.each do |lang, code|
63
- File.should_receive(:open).with("./translations/#{lang}/path_#{lang}.pres", "a") unless lang == "en-US"
63
+ File.should_receive(:open).with(/\/translations\/#{lang}\/path_#{lang}.pres/, "a") unless lang == "en-US"
64
64
  end
65
65
  Idiom::Yrb.new(:source => @source, :use_dirs => true).generate
66
66
  end
67
67
 
68
68
  it "should create the destination path with directories if it does not exist" do
69
69
  Idiom::Yrb::LOCALES.each do |lang, code|
70
- FileUtils.should_receive(:mkdir_p).with("./translations/#{lang}") unless lang == "en-US"
70
+ FileUtils.should_receive(:mkdir_p).with(/\/translations\/#{lang}/) unless lang == "en-US"
71
71
  end
72
72
  Idiom::Yrb.new(:source => @source, :use_dirs => true).generate
73
73
  end
74
+
75
+ it "should recognize a directory" do
76
+ Idiom::Yrb::LOCALES.each do |lang, code|
77
+ File.should_receive(:open).with(/\/#{lang}\/path_#{lang}.pres/, "a") unless lang == "en-US"
78
+ end
79
+ Idiom::Yrb.new(:source => "en-US/path.pres", :use_dirs => true).generate
80
+ end
74
81
  end
75
82
 
76
83
  it "should translate the first string" do
@@ -83,30 +90,14 @@ SECOND=second key
83
90
  Idiom::Yrb.new(:source => @source).generate
84
91
  end
85
92
 
86
- # describe "key exists" do
87
- # before(:each) do
88
- # YRB.stub!(:load_file).and_return({"FIRST" => "old translated first key"})
89
- # end
90
- #
91
- # it "should not translate a key that is already translated" do
92
- # @file.should_not_receive(:puts).with(/FIRST=translated first key/)
93
- # Idiom::Yrb.new(:source => @source).generate
94
- # end
95
- #
96
- # it "should translate a key that is already translated if overwrite is true" do
97
- # @file.should_receive(:puts).with(/FIRST=translated first key/)
98
- # Idiom::Yrb.new(:source => @source, :overwrite => true).generate
99
- # end
100
- # end
101
-
102
93
  describe "languages" do
103
94
  it "should only translate the specified set of languages" do
104
95
  @languages = ["de-DE", "zh-Hant-HK"]
105
96
  Idiom::Yrb::LOCALES.each do |lang, code|
106
97
  if @languages.include?(lang)
107
- File.should_receive(:open).with("./translations/path_#{lang}.pres", "a")
98
+ File.should_receive(:open).with(/\/translations\/path_#{lang}.pres/, "a")
108
99
  else
109
- File.should_not_receive(:open).with("./translations/path_#{lang}.pres", "a")
100
+ File.should_not_receive(:open).with(/\/translations\/path_#{lang}.pres/, "a")
110
101
  end
111
102
  end
112
103
  Idiom::Yrb.new(:source => @source, :languages => @languages).generate
@@ -128,14 +119,14 @@ second: second key
128
119
 
129
120
  it "should create the destination path if it does not exist" do
130
121
  Idiom::Yaml::LOCALES.each do |lang, code|
131
- FileUtils.should_receive(:mkdir_p).with("./translations") unless lang == "en-US"
122
+ FileUtils.should_receive(:mkdir_p).with(/\/translations/) unless lang == "en-US"
132
123
  end
133
124
  Idiom::Yaml.new(:source => @source).generate
134
125
  end
135
126
 
136
127
  it "should write to the destination path" do
137
128
  Idiom::Yaml::LOCALES.each do |lang, code|
138
- File.should_receive(:open).with("./translations/path_#{lang}.yml", "a") unless lang == "en-US"
129
+ File.should_receive(:open).with(/\/translations\/path_#{lang}.yml/, "a") unless lang == "en-US"
139
130
  end
140
131
  Idiom::Yaml.new(:source => @source).generate
141
132
  end
@@ -147,14 +138,14 @@ second: second key
147
138
 
148
139
  it "should write to directories" do
149
140
  Idiom::Yaml::LOCALES.each do |lang, code|
150
- File.should_receive(:open).with("./translations/#{lang}/path_#{lang}.yml", "a") unless lang == "en-US"
141
+ File.should_receive(:open).with(/\/translations\/#{lang}\/path_#{lang}.yml/, "a") unless lang == "en-US"
151
142
  end
152
143
  Idiom::Yaml.new(:source => @source, :use_dirs => true).generate
153
144
  end
154
145
 
155
146
  it "should create the destination path with directories if it does not exist" do
156
147
  Idiom::Yrb::LOCALES.each do |lang, code|
157
- FileUtils.should_receive(:mkdir_p).with("./translations/#{lang}") unless lang == "en-US"
148
+ FileUtils.should_receive(:mkdir_p).with(/\/translations\/#{lang}/) unless lang == "en-US"
158
149
  end
159
150
  Idiom::Yrb.new(:source => @source, :use_dirs => true).generate
160
151
  end
@@ -170,32 +161,14 @@ second: second key
170
161
  Idiom::Yaml.new(:source => @source).generate
171
162
  end
172
163
 
173
- # describe "key exists" do
174
- # before(:each) do
175
- # Dir.stub!(:[]).and_return(["./translations/path_lang-CODE.yml"])
176
- # File.should_receive(:exists?).with("./translations/path_lang-CODE.yml").and_return(true)
177
- # YAML.should_receive(:load_file).and_return({"first" => "old translated first key"})
178
- # end
179
- #
180
- # it "should not translate a key that is already translated" do
181
- # @file.should_not_receive(:puts).with(/first: translated first key/)
182
- # Idiom::Yaml.new(:source => @source).generate
183
- # end
184
- #
185
- # it "should translate a key that is already translated if overwrite is true" do
186
- # @file.should_receive(:puts).with(/first: translated first key/)
187
- # Idiom::Yaml.new(:source => @source, :overwrite => true).generate
188
- # end
189
- # end
190
-
191
164
  describe "languages" do
192
165
  it "should only translate the specified set of languages" do
193
166
  @languages = ["de-DE", "zh-Hant-HK"]
194
167
  Idiom::Yaml::LOCALES.each do |lang, code|
195
168
  if @languages.include?(lang)
196
- File.should_receive(:open).with("./translations/path_#{lang}.yml", "a")
169
+ File.should_receive(:open).with(/\/translations\/path_#{lang}.yml/, "a")
197
170
  else
198
- File.should_not_receive(:open).with("./translations/path_#{lang}.yml", "a")
171
+ File.should_not_receive(:open).with(/\/translations\/path_#{lang}.yml/, "a")
199
172
  end
200
173
  end
201
174
  Idiom::Yaml.new(:source => @source, :languages => @languages).generate
@@ -30,11 +30,6 @@ def stub_file_utils
30
30
  FileUtils.stub!(:rm_rf)
31
31
  FileUtils.stub!(:cp_r)
32
32
  FileUtils.stub!(:mkdir_p)
33
- F.stub!(:concat_files)
34
- F.stub!(:get_line_from_file).and_return("")
35
- F.stub!(:save_to_file)
36
- F.stub!(:save_to_tmp_file)
37
- F.stub!(:execute).and_return("")
38
33
  end
39
34
 
40
35
  def stub_yaml(output_hash={})
@@ -45,32 +40,6 @@ def stub_yrb(output_hash={})
45
40
  YRB.stub!(:load_file).and_return(output_hash)
46
41
  end
47
42
 
48
- def stub_erb(processed_file="")
49
- @erb ||= mock('erb').as_null_object
50
- @erb.stub!(:result).and_return(processed_file)
51
- ERB.stub!(:new).and_return(@erb)
52
- end
53
-
54
- def stub_haml_class
55
- eval %(
56
- module Haml
57
- class Engine
58
- end
59
- end
60
- )
61
- end
62
-
63
- def stub_haml(processed_file)
64
- @haml = mock('haml').as_null_object
65
- @haml.stub!(:render).and_return(processed_file)
66
- Haml::Engine.stub!(:new).and_return(@haml)
67
- end
68
-
69
- def stub_git_helper
70
- @git_helper = mock('git_helper').as_null_object
71
- YMDP::GitHelper.stub!(:new).and_return(@git_helper)
72
- end
73
-
74
43
  def stub_timer
75
44
  @timer = mock('timer').as_null_object
76
45
  @timer.stub!(:time).and_yield
@@ -87,12 +56,3 @@ def reset_constant(constant, value)
87
56
  Object.send(:remove_const, constant)
88
57
  Object.const_set(constant, value)
89
58
  end
90
-
91
- def stub_config
92
- @config = mock('config')
93
- @config.stub!(:[]).with("doctype").and_return("HTML 4.0 Transitional")
94
- @config.stub!(:validate_html?).and_return(false)
95
- @config.stub!(:compress_embedded_js?).and_return(false)
96
- @config.stub!(:verbose?).and_return(false)
97
- reset_constant(:CONFIG, @config)
98
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idiom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Coleman