haml-magic-translations 0.2.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,256 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'tmpdir'
5
+ require 'gettext/tools'
6
+
7
+ # Stolen from ActiveSupport. We have to cut and paste it here so it
8
+ # does not turn the encoding back to US-ASCII. Strange issue.
9
+ class String
10
+ def strip_heredoc
11
+ indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
12
+ gsub(/^[ \t]{#{indent}}/, '')
13
+ end
14
+ end
15
+
16
+ module Haml
17
+ describe MagicTranslations do
18
+ describe '.enable' do
19
+ after { Haml::MagicTranslations.disable }
20
+ context 'when using :i18n as backend' do
21
+ before { Haml::MagicTranslations.enable :i18n }
22
+ it { Haml::MagicTranslations.should be_enabled }
23
+ it { Haml::MagicTranslations::EngineMethods.
24
+ magic_translations_helpers.should == I18n::Gettext::Helpers }
25
+ end
26
+ context 'when using :gettext as backend' do
27
+ before { Haml::MagicTranslations.enable :gettext }
28
+ it { Haml::MagicTranslations.should be_enabled }
29
+ it { Haml::MagicTranslations::EngineMethods.
30
+ magic_translations_helpers.should == GetText }
31
+ end
32
+ context 'when using :fast_gettext as backend' do
33
+ before { Haml::MagicTranslations.enable :fast_gettext }
34
+ it { Haml::MagicTranslations.should be_enabled }
35
+ it { Haml::MagicTranslations::EngineMethods.
36
+ magic_translations_helpers.should == FastGettext::Translation }
37
+ end
38
+ context 'when giving another backend' do
39
+ it 'should raise an error' do
40
+ expect {
41
+ Haml::MagicTranslations.enable :whatever
42
+ }.to raise_error(ArgumentError)
43
+ end
44
+ it { Haml::MagicTranslations.should_not be_enabled }
45
+ end
46
+ end
47
+
48
+ describe '.disable' do
49
+ it 'should set Haml::MagicTranslations.enabled to false' do
50
+ Haml::MagicTranslations.disable
51
+ Haml::MagicTranslations.should_not be_enabled
52
+ end
53
+ end
54
+
55
+ shared_examples 'Haml magic translations' do
56
+ it 'should translate text using existing locales' do
57
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
58
+ %p Magic translations works!
59
+ %p Here with interpolation, and everything thanks to #{I18n.name} and #{GetText.name}
60
+ HAML
61
+ <p>Magiczne tłumaczenie działa!</p>
62
+ <p>A tutaj razem z interpolacją, a to wszystko dzięki połączeniu I18n i GetText</p>
63
+ HTML
64
+ end
65
+
66
+ it 'should leave text without changes when translation is not available' do
67
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
68
+ %p Untranslated thanks to #{I18n.name} and #{GetText.name}
69
+ HAML
70
+ <p>Untranslated thanks to I18n and GetText</p>
71
+ HTML
72
+ end
73
+
74
+ it 'should translate text with multiline plain text' do
75
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
76
+ %p Magic translations works!
77
+ %p
78
+ Now we will check multiline strings,
79
+ which should be also translated,
80
+ with interpolation #{'Interpolation'.upcase}
81
+ HAML
82
+ <p>Magiczne tłumaczenie działa!</p>
83
+ <p>
84
+ Kolejny wieloliniowy tekst,
85
+ który powinien zostać przetłumaczony,
86
+ interpolacja INTERPOLATION też działa!
87
+ </p>
88
+ HTML
89
+ end
90
+
91
+ it 'should translate escaped tags' do
92
+ render(<<-HAML.strip_heredoc).should == <<-HTML.strip_heredoc
93
+ %p& Magic translations works!
94
+ HAML
95
+ <p>Magiczne tłumaczenie działa!</p>
96
+ HTML
97
+ end
98
+
99
+ it 'should translate unescaped tags' do
100
+ render(<<-HAML.strip_heredoc).should == <<-HTML.strip_heredoc
101
+ %p! Magic translations works!
102
+ HAML
103
+ <p>Magiczne tłumaczenie działa!</p>
104
+ HTML
105
+ end
106
+
107
+ it 'should not translate evaluated tags' do
108
+ render(<<-HAML.strip_heredoc).should == <<-HTML.strip_heredoc
109
+ %p= 'Magic translations works!'
110
+ HAML
111
+ <p>Magic translations works!</p>
112
+ HTML
113
+ end
114
+
115
+ it 'should not translate escaped evaluated tags' do
116
+ render(<<-HAML.strip_heredoc).should == <<-HTML.strip_heredoc
117
+ %p&= 'Magic translations works!'
118
+ HAML
119
+ <p>Magic translations works!</p>
120
+ HTML
121
+ end
122
+
123
+ it 'should not translate unescaped evaluated tags' do
124
+ render(<<-HAML.strip_heredoc).should == <<-HTML.strip_heredoc
125
+ %p!= 'Magic translations works!'
126
+ HAML
127
+ <p>Magic translations works!</p>
128
+ HTML
129
+ end
130
+
131
+ context 'when translating strings in Javascript' do
132
+ it "should translate strings inside _('')" do
133
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
134
+ :javascript
135
+ var text = _('Magic translations works!');
136
+ HAML
137
+ <script type='text/javascript'>
138
+ //<![CDATA[
139
+ var text = "Magiczne tłumaczenie działa!";
140
+ //]]>
141
+ </script>
142
+ HTML
143
+ end
144
+ it 'should translate strings inside _("")' do
145
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
146
+ :javascript
147
+ var text = _("Magic translations works!");
148
+ HAML
149
+ <script type='text/javascript'>
150
+ //<![CDATA[
151
+ var text = "Magiczne tłumaczenie działa!";
152
+ //]]>
153
+ </script>
154
+ HTML
155
+ end
156
+ it 'should not choke on single-quote' do
157
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
158
+ :javascript
159
+ var text = _("Don't you think?");
160
+ HAML
161
+ <script type='text/javascript'>
162
+ //<![CDATA[
163
+ var text = "Don't you think?";
164
+ //]]>
165
+ </script>
166
+ HTML
167
+ end
168
+ it 'should not choke on double-quote' do
169
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
170
+ :javascript
171
+ var text = _('One "quote" here');
172
+ HAML
173
+ <script type='text/javascript'>
174
+ //<![CDATA[
175
+ var text = "One \"quote\" here";
176
+ //]]>
177
+ </script>
178
+ HTML
179
+ end
180
+ end
181
+
182
+ context 'when translating strings in Markdown' do
183
+ it "should translate strings inside _('')" do
184
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
185
+ :markdown
186
+ Now we will check multiline strings,
187
+ which should be also translated.
188
+ HAML
189
+ <p>Kolejny wieloliniowy tekst, który powinien zostać przetłumaczony.</p>
190
+ HTML
191
+ end
192
+ end
193
+
194
+ context 'when disabling magic translations' do
195
+ it 'should leave text untranslated' do
196
+ Haml::MagicTranslations.disable
197
+ render(<<-'HAML'.strip_heredoc).should == <<-'HTML'.strip_heredoc
198
+ %p Magic translations works!
199
+ HAML
200
+ <p>Magic translations works!</p>
201
+ HTML
202
+ end
203
+ end
204
+ end
205
+
206
+ context 'with I18n as backend' do
207
+ before(:each) do
208
+ Haml::MagicTranslations.enable :i18n
209
+ I18n.locale = :pl
210
+ I18n.load_path += Dir[File.join(File.dirname(__FILE__), "../locales/*.po")]
211
+ end
212
+ it_should_behave_like 'Haml magic translations'
213
+ end
214
+
215
+ context 'with GetText as backend' do
216
+ # set up locales file as GetText expects
217
+ around do |example|
218
+ Dir.mktmpdir("haml-magic-translations") do |tmpdir|
219
+ src_dir = File.expand_path('../../locales', __FILE__)
220
+ Dir.glob(File.join(src_dir, '*.po')).each do |src|
221
+ lang = File.basename(src).gsub(/\.po$/, '')
222
+ dest = File.join(tmpdir, lang, 'LC_MESSAGES', 'test.mo')
223
+ FileUtils.mkdir_p(File.dirname(dest))
224
+ GetText.rmsgfmt(src, dest)
225
+ end
226
+ Haml::MagicTranslations.enable :gettext
227
+ GetText.bindtextdomain 'test', :path => tmpdir
228
+ GetText.setlocale 'pl'
229
+ example.run
230
+ end
231
+ end
232
+ it_should_behave_like 'Haml magic translations'
233
+ end
234
+
235
+ context 'with FastGettext as backend' do
236
+ # set up locales file as FastGettext expects
237
+ around do |example|
238
+ Dir.mktmpdir("haml-magic-translations") do |tmpdir|
239
+ src_dir = File.expand_path('../../locales', __FILE__)
240
+ Dir.glob(File.join(src_dir, '*.po')).each do |src|
241
+ lang = File.basename(src).gsub(/\.po$/, '')
242
+ dest = File.join(tmpdir, lang, 'test.po')
243
+ FileUtils.mkdir_p(File.dirname(dest))
244
+ FileUtils.copy(src, dest)
245
+ end
246
+ Haml::MagicTranslations.enable :fast_gettext
247
+ FastGettext.add_text_domain 'test', :path => tmpdir, :type => :po
248
+ FastGettext.text_domain = 'test'
249
+ FastGettext.locale = 'pl'
250
+ example.run
251
+ end
252
+ end
253
+ it_should_behave_like 'Haml magic translations'
254
+ end
255
+ end
256
+ end
data/spec/locales/en.po CHANGED
@@ -1,3 +1,7 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Content-Type: text/plain; charset=us-ascii\n"
4
+ "Content-Transfer-Encoding: 8bit\n"
1
5
 
2
6
  msgid "Magic translations works!"
3
7
  msgstr ""
data/spec/locales/pl.po CHANGED
@@ -1,3 +1,7 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Content-Type: text/plain; charset=utf-8\n"
4
+ "Content-Transfer-Encoding: 8bit\n"
1
5
 
2
6
  msgid "Magic translations works!"
3
7
  msgstr "Magiczne tłumaczenie działa!"
@@ -14,3 +18,9 @@ msgstr "który powinien zostać przetłumaczony,"
14
18
  msgid "with interpolation %s"
15
19
  msgstr "interpolacja %s też działa!"
16
20
 
21
+ msgid ""
22
+ "Now we will check multiline strings,\n"
23
+ "which should be also translated."
24
+ msgstr ""
25
+ "Kolejny wieloliniowy tekst,\n"
26
+ "który powinien zostać przetłumaczony."
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  ENV["RAILS_ENV"] = "test"
2
4
  require 'rubygems'
3
- require 'spec'
5
+ require 'rspec'
4
6
 
5
7
  $:.unshift File.dirname(__FILE__)
6
8
  $:.unshift File.join(File.dirname(__FILE__), '../lib')
metadata CHANGED
@@ -1,36 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-magic-translations
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 17
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Kriss Kowalik
14
+ - potager.org
13
15
  autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-07-21 00:00:00 +02:00
18
- default_executable:
19
+ date: 2012-04-09 00:00:00 Z
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: haml
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 3
32
+ - 1
29
33
  - 0
34
+ version: 3.1.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: actionpack
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
30
47
  - 0
31
- version: 3.0.0
48
+ version: "0"
32
49
  type: :development
33
- version_requirements: *id001
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: gettext
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: fast_gettext
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 7
88
+ segments:
89
+ - 2
90
+ version: "2"
91
+ type: :development
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: rdoc
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 27
102
+ segments:
103
+ - 2
104
+ - 4
105
+ - 2
106
+ version: 2.4.2
107
+ type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: maruku
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ type: :development
122
+ version_requirements: *id007
34
123
  description: |
35
124
  This plugin provides "magical translations" in your .haml files. What does it
36
125
  mean? It's mean that all your raw texts in templates will be automatically
@@ -41,7 +130,7 @@ description: |
41
130
  are also more readable and easier to translate, thanks to it you save your
42
131
  time with translations.
43
132
 
44
- email: kriss.kowalik@gmail.com
133
+ email: jardiniers@potager.org
45
134
  executables: []
46
135
 
47
136
  extensions: []
@@ -49,51 +138,56 @@ extensions: []
49
138
  extra_rdoc_files:
50
139
  - LICENSE
51
140
  - README.rdoc
52
- - TODO
53
141
  files:
54
142
  - LICENSE
55
143
  - README.rdoc
56
144
  - Rakefile
57
- - TODO
58
145
  - VERSION
59
146
  - haml-magic-translations.gemspec
60
147
  - init.rb
61
148
  - lib/haml-magic-translations.rb
62
149
  - lib/haml/magic_translations.rb
150
+ - lib/haml/magic_translations/rgettext/haml_parser.rb
151
+ - lib/haml/magic_translations/tasks.rb
152
+ - spec/haml/magic_translations/rgettext/haml_parser_spec.rb
153
+ - spec/haml/magic_translations/tasks_spec.rb
154
+ - spec/haml/magic_translations_spec.rb
63
155
  - spec/locales/en.po
64
156
  - spec/locales/pl.po
65
- - spec/magic_translations/i18n_spec.rb
66
157
  - spec/spec_helper.rb
67
- has_rdoc: true
68
- homepage: http://github.com/kriss/haml-magic-translations
158
+ homepage: http://github.com/potager/haml-magic-translations
69
159
  licenses: []
70
160
 
71
161
  post_install_message:
72
- rdoc_options:
73
- - --charset=UTF-8
162
+ rdoc_options: []
163
+
74
164
  require_paths:
75
165
  - lib
76
166
  required_ruby_version: !ruby/object:Gem::Requirement
167
+ none: false
77
168
  requirements:
78
169
  - - ">="
79
170
  - !ruby/object:Gem::Version
171
+ hash: 3
80
172
  segments:
81
173
  - 0
82
174
  version: "0"
83
175
  required_rubygems_version: !ruby/object:Gem::Requirement
176
+ none: false
84
177
  requirements:
85
178
  - - ">="
86
179
  - !ruby/object:Gem::Version
180
+ hash: 3
87
181
  segments:
88
182
  - 0
89
183
  version: "0"
90
184
  requirements: []
91
185
 
92
186
  rubyforge_project:
93
- rubygems_version: 1.3.6
187
+ rubygems_version: 1.8.15
94
188
  signing_key:
95
189
  specification_version: 3
96
190
  summary: Provides automaticaly translations in haml templates
97
- test_files:
98
- - spec/spec_helper.rb
99
- - spec/magic_translations/i18n_spec.rb
191
+ test_files: []
192
+
193
+ has_rdoc: