haml-magic-translations 4.0.2 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/haml-magic-translations.gemspec +5 -5
- data/spec/haml/magic_translations/tasks_spec.rb +8 -8
- data/spec/haml/magic_translations/xgettext/haml_parser_spec.rb +12 -12
- data/spec/haml/magic_translations_spec.rb +25 -25
- data/spec/spec_helper.rb +6 -0
- metadata +4 -4
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ time with translations.
|
|
23
23
|
gem.add_development_dependency "actionpack"
|
24
24
|
gem.add_development_dependency "gettext", ">= 2.3"
|
25
25
|
gem.add_development_dependency "fast_gettext"
|
26
|
-
gem.add_development_dependency "rspec", ">= 2"
|
26
|
+
gem.add_development_dependency "rspec", ">= 2.11"
|
27
27
|
gem.add_development_dependency "rdoc", ">= 2.4.2"
|
28
28
|
gem.add_development_dependency "maruku"
|
29
29
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.0.
|
1
|
+
4.0.3
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{haml-magic-translations}
|
8
|
-
s.version = "4.0.
|
8
|
+
s.version = "4.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kriss Kowalik", "potager.org"]
|
12
|
-
s.date = %q{2014-05-
|
12
|
+
s.date = %q{2014-05-05}
|
13
13
|
s.description = %q{This plugin provides "magical translations" in your .haml files. What does it
|
14
14
|
mean? It's mean that all your raw texts in templates will be automatically
|
15
15
|
translated by GetText, FastGettext or Gettext backend from I18n. No more
|
@@ -56,7 +56,7 @@ time with translations.
|
|
56
56
|
s.add_development_dependency(%q<actionpack>, [">= 0"])
|
57
57
|
s.add_development_dependency(%q<gettext>, [">= 2.3"])
|
58
58
|
s.add_development_dependency(%q<fast_gettext>, [">= 0"])
|
59
|
-
s.add_development_dependency(%q<rspec>, [">= 2"])
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 2.11"])
|
60
60
|
s.add_development_dependency(%q<rdoc>, [">= 2.4.2"])
|
61
61
|
s.add_development_dependency(%q<maruku>, [">= 0"])
|
62
62
|
else
|
@@ -65,7 +65,7 @@ time with translations.
|
|
65
65
|
s.add_dependency(%q<actionpack>, [">= 0"])
|
66
66
|
s.add_dependency(%q<gettext>, [">= 2.3"])
|
67
67
|
s.add_dependency(%q<fast_gettext>, [">= 0"])
|
68
|
-
s.add_dependency(%q<rspec>, [">= 2"])
|
68
|
+
s.add_dependency(%q<rspec>, [">= 2.11"])
|
69
69
|
s.add_dependency(%q<rdoc>, [">= 2.4.2"])
|
70
70
|
s.add_dependency(%q<maruku>, [">= 0"])
|
71
71
|
end
|
@@ -75,7 +75,7 @@ time with translations.
|
|
75
75
|
s.add_dependency(%q<actionpack>, [">= 0"])
|
76
76
|
s.add_dependency(%q<gettext>, [">= 2.3"])
|
77
77
|
s.add_dependency(%q<fast_gettext>, [">= 0"])
|
78
|
-
s.add_dependency(%q<rspec>, [">= 2"])
|
78
|
+
s.add_dependency(%q<rspec>, [">= 2.11"])
|
79
79
|
s.add_dependency(%q<rdoc>, [">= 2.4.2"])
|
80
80
|
s.add_dependency(%q<maruku>, [">= 0"])
|
81
81
|
end
|
@@ -61,22 +61,22 @@ module Haml::MagicTranslations::Tasks
|
|
61
61
|
task.app_version = 'test 1.0'
|
62
62
|
end
|
63
63
|
it 'should call update_pofiles' do
|
64
|
-
GetText.
|
64
|
+
expect(GetText).to receive(:update_pofiles).with(
|
65
65
|
task.text_domain, task.files, task.app_version, {})
|
66
66
|
run
|
67
67
|
end
|
68
68
|
it 'should add a parser for ".haml" files to XGetText' do
|
69
|
-
GetText.
|
70
|
-
GetText::Tools::XGetText.
|
71
|
-
haml_parser.
|
72
|
-
haml_parser.
|
69
|
+
allow(GetText).to receive(:update_pofiles)
|
70
|
+
expect(GetText::Tools::XGetText).to receive(:add_parser) do |haml_parser|
|
71
|
+
expect(haml_parser).to respond_to(:parse)
|
72
|
+
expect(haml_parser).to be_a_target('example.haml')
|
73
73
|
end
|
74
74
|
run
|
75
75
|
end
|
76
76
|
context 'with lang set' do
|
77
77
|
it 'should pass lang in options' do
|
78
78
|
task.lang = 'pl'
|
79
|
-
GetText.
|
79
|
+
allow(GetText).to receive(:update_pofiles).with(
|
80
80
|
task.text_domain, task.files, task.app_version,
|
81
81
|
hash_including(:lang => task.lang))
|
82
82
|
run
|
@@ -85,7 +85,7 @@ module Haml::MagicTranslations::Tasks
|
|
85
85
|
context 'with po_root set' do
|
86
86
|
it 'should pass po_root in options' do
|
87
87
|
task.po_root = 'test/po'
|
88
|
-
GetText.
|
88
|
+
expect(GetText).to receive(:update_pofiles).with(
|
89
89
|
task.text_domain, task.files, task.app_version,
|
90
90
|
hash_including(:po_root => task.po_root))
|
91
91
|
run
|
@@ -94,7 +94,7 @@ module Haml::MagicTranslations::Tasks
|
|
94
94
|
context 'with verbose set' do
|
95
95
|
it 'should pass verbose in options' do
|
96
96
|
task.verbose = true
|
97
|
-
GetText.
|
97
|
+
expect(GetText).to receive(:update_pofiles).with(
|
98
98
|
task.text_domain, task.files, task.app_version,
|
99
99
|
hash_including(:verbose => task.verbose))
|
100
100
|
run
|
@@ -18,14 +18,14 @@ module Haml::MagicTranslations::XGetText
|
|
18
18
|
|
19
19
|
describe '.parse' do
|
20
20
|
it 'should properly instanciate a Parser' do
|
21
|
-
HamlParser::XGetTextParser.
|
22
|
-
and_return(
|
21
|
+
expect(HamlParser::XGetTextParser).to receive(:new).with('test.haml').
|
22
|
+
and_return(double('XGetTextParser').as_null_object)
|
23
23
|
HamlParser.parse('test.haml')
|
24
24
|
end
|
25
25
|
it 'should run the parser' do
|
26
|
-
parser =
|
27
|
-
parser.
|
28
|
-
HamlParser::XGetTextParser.
|
26
|
+
parser = double('XGetTextParser')
|
27
|
+
expect(parser).to receive(:parse)
|
28
|
+
allow(HamlParser::XGetTextParser).to receive(:new).and_return(parser)
|
29
29
|
HamlParser.parse('test.haml')
|
30
30
|
end
|
31
31
|
end
|
@@ -34,20 +34,20 @@ module Haml::MagicTranslations::XGetText
|
|
34
34
|
describe '#initialize' do
|
35
35
|
context 'when given "test.haml"' do
|
36
36
|
before(:each) do
|
37
|
-
File.
|
37
|
+
allow(File).to receive(:open).and_return(StringIO.new('It works!'))
|
38
38
|
@parser = HamlParser::XGetTextParser.new('test.haml')
|
39
39
|
end
|
40
40
|
it 'should set file attribute' do
|
41
|
-
@parser.file.
|
41
|
+
expect(@parser.file).to be == 'test.haml'
|
42
42
|
end
|
43
43
|
it 'should put the file content in the content attribute' do
|
44
|
-
@parser.content.
|
44
|
+
expect(@parser.content).to be == 'It works!'
|
45
45
|
end
|
46
46
|
end
|
47
47
|
context 'when given a IO-like object' do
|
48
48
|
let (:parser) { HamlParser::XGetTextParser.new(StringIO.new('It works!')) }
|
49
|
-
it { parser.file.
|
50
|
-
it { parser.content.
|
49
|
+
it { expect(parser.file).to be == '(haml)' }
|
50
|
+
it { expect(parser.content).to be == 'It works!' }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -143,7 +143,7 @@ module Haml::MagicTranslations::XGetText
|
|
143
143
|
HAML
|
144
144
|
end
|
145
145
|
it 'should appear only once in the targets' do
|
146
|
-
subject.collect { |t| t[0] }.
|
146
|
+
expect(subject.collect { |t| t[0] }).to have(1).item
|
147
147
|
end
|
148
148
|
it 'should record two target locations' do
|
149
149
|
should == [['Hello!', '(haml):1', '(haml):2']]
|
@@ -198,7 +198,7 @@ module Haml::MagicTranslations::XGetText
|
|
198
198
|
context 'after extracting translations' do
|
199
199
|
it 'should still allow Haml::Engine to build templates' do
|
200
200
|
HamlParser::XGetTextParser.new(StringIO.new('test')).parse
|
201
|
-
Haml::Engine.new('%p It works!').render.
|
201
|
+
expect(Haml::Engine.new('%p It works!').render).to be == <<-'HTML'.strip_heredoc
|
202
202
|
<p>It works!</p>
|
203
203
|
HTML
|
204
204
|
end
|
@@ -23,21 +23,21 @@ module Haml
|
|
23
23
|
after { Haml::MagicTranslations.disable }
|
24
24
|
context 'when using :i18n as backend' do
|
25
25
|
before { Haml::MagicTranslations.enable :i18n }
|
26
|
-
it { Haml::MagicTranslations.
|
27
|
-
it { Haml::MagicTranslations::Compiler.
|
28
|
-
magic_translations_helpers.
|
26
|
+
it { expect(Haml::MagicTranslations).to be_enabled }
|
27
|
+
it { expect(Haml::MagicTranslations::Compiler.
|
28
|
+
magic_translations_helpers).to be == I18n::Gettext::Helpers }
|
29
29
|
end
|
30
30
|
context 'when using :gettext as backend' do
|
31
31
|
before { Haml::MagicTranslations.enable :gettext }
|
32
|
-
it { Haml::MagicTranslations.
|
33
|
-
it { Haml::MagicTranslations::Compiler.
|
34
|
-
magic_translations_helpers.
|
32
|
+
it { expect(Haml::MagicTranslations).to be_enabled }
|
33
|
+
it { expect(Haml::MagicTranslations::Compiler.
|
34
|
+
magic_translations_helpers).to be == GetText }
|
35
35
|
end
|
36
36
|
context 'when using :fast_gettext as backend' do
|
37
37
|
before { Haml::MagicTranslations.enable :fast_gettext }
|
38
|
-
it { Haml::MagicTranslations.
|
39
|
-
it { Haml::MagicTranslations::Compiler.
|
40
|
-
magic_translations_helpers.
|
38
|
+
it { expect(Haml::MagicTranslations).to be_enabled }
|
39
|
+
it { expect(Haml::MagicTranslations::Compiler.
|
40
|
+
magic_translations_helpers).to be == FastGettext::Translation }
|
41
41
|
end
|
42
42
|
context 'when giving another backend' do
|
43
43
|
it 'should raise an error' do
|
@@ -45,20 +45,20 @@ module Haml
|
|
45
45
|
Haml::MagicTranslations.enable :whatever
|
46
46
|
}.to raise_error(ArgumentError)
|
47
47
|
end
|
48
|
-
it { Haml::MagicTranslations.
|
48
|
+
it { expect(Haml::MagicTranslations).to_not be_enabled }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe '.disable' do
|
53
53
|
it 'should set Haml::MagicTranslations.enabled to false' do
|
54
54
|
Haml::MagicTranslations.disable
|
55
|
-
Haml::MagicTranslations.
|
55
|
+
expect(Haml::MagicTranslations).to_not be_enabled
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
shared_examples 'Haml magic translations' do
|
60
60
|
it 'should translate text using existing locales' do
|
61
|
-
render(<<-'HAML'.strip_heredoc).
|
61
|
+
expect(render(<<-'HAML'.strip_heredoc)).to be == <<-'HTML'.strip_heredoc
|
62
62
|
%p Magic translations works!
|
63
63
|
%p Here with interpolation, and everything thanks to #{I18n.name} and #{GetText.name}
|
64
64
|
HAML
|
@@ -68,7 +68,7 @@ module Haml
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should leave text without changes when translation is not available' do
|
71
|
-
render(<<-'HAML'.strip_heredoc).
|
71
|
+
expect(render(<<-'HAML'.strip_heredoc)).to be == <<-'HTML'.strip_heredoc
|
72
72
|
%p Untranslated thanks to #{I18n.name} and #{GetText.name}
|
73
73
|
HAML
|
74
74
|
<p>Untranslated thanks to I18n and GetText</p>
|
@@ -76,7 +76,7 @@ module Haml
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'should translate text with multiline plain text' do
|
79
|
-
render(<<-'HAML'.strip_heredoc).
|
79
|
+
expect(render(<<-'HAML'.strip_heredoc)).to be == <<-'HTML'.strip_heredoc
|
80
80
|
%p Magic translations works!
|
81
81
|
%p
|
82
82
|
Now we will check multiline strings,
|
@@ -93,7 +93,7 @@ module Haml
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'should translate escaped tags' do
|
96
|
-
render(<<-HAML.strip_heredoc).
|
96
|
+
expect(render(<<-HAML.strip_heredoc)).to be == <<-HTML.strip_heredoc
|
97
97
|
%p& Magic translations works!
|
98
98
|
HAML
|
99
99
|
<p>Magiczne tłumaczenie działa!</p>
|
@@ -101,7 +101,7 @@ module Haml
|
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'should translate unescaped tags' do
|
104
|
-
render(<<-HAML.strip_heredoc).
|
104
|
+
expect(render(<<-HAML.strip_heredoc)).to be == <<-HTML.strip_heredoc
|
105
105
|
%p! Magic translations works!
|
106
106
|
HAML
|
107
107
|
<p>Magiczne tłumaczenie działa!</p>
|
@@ -109,7 +109,7 @@ module Haml
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should not translate evaluated tags' do
|
112
|
-
render(<<-HAML.strip_heredoc).
|
112
|
+
expect(render(<<-HAML.strip_heredoc)).to be == <<-HTML.strip_heredoc
|
113
113
|
%p= 'Magic translations works!'
|
114
114
|
HAML
|
115
115
|
<p>Magic translations works!</p>
|
@@ -117,7 +117,7 @@ module Haml
|
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'should not translate escaped evaluated tags' do
|
120
|
-
render(<<-HAML.strip_heredoc).
|
120
|
+
expect(render(<<-HAML.strip_heredoc)).to be == <<-HTML.strip_heredoc
|
121
121
|
%p&= 'Magic translations works!'
|
122
122
|
HAML
|
123
123
|
<p>Magic translations works!</p>
|
@@ -125,7 +125,7 @@ module Haml
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'should not translate unescaped evaluated tags' do
|
128
|
-
render(<<-HAML.strip_heredoc).
|
128
|
+
expect(render(<<-HAML.strip_heredoc)).to be == <<-HTML.strip_heredoc
|
129
129
|
%p!= 'Magic translations works!'
|
130
130
|
HAML
|
131
131
|
<p>Magic translations works!</p>
|
@@ -134,7 +134,7 @@ module Haml
|
|
134
134
|
|
135
135
|
context 'when translating strings in JavaScript' do
|
136
136
|
it "should translate strings inside _('')" do
|
137
|
-
render(<<-'HAML'.strip_heredoc).translate_unicode.
|
137
|
+
expect(render(<<-'HAML'.strip_heredoc).translate_unicode).to be == <<-'HTML'.strip_heredoc.translate_unicode
|
138
138
|
:javascript
|
139
139
|
var text = _('Magic translations works!');
|
140
140
|
HAML
|
@@ -146,7 +146,7 @@ module Haml
|
|
146
146
|
HTML
|
147
147
|
end
|
148
148
|
it 'should translate strings inside _("")' do
|
149
|
-
render(<<-'HAML'.strip_heredoc).translate_unicode.
|
149
|
+
expect(render(<<-'HAML'.strip_heredoc).translate_unicode).to be == <<-'HTML'.strip_heredoc.translate_unicode
|
150
150
|
:javascript
|
151
151
|
var text = _("Magic translations works!");
|
152
152
|
HAML
|
@@ -158,7 +158,7 @@ module Haml
|
|
158
158
|
HTML
|
159
159
|
end
|
160
160
|
it 'should not choke on single-quote' do
|
161
|
-
render(<<-'HAML'.strip_heredoc).
|
161
|
+
expect(render(<<-'HAML'.strip_heredoc)).to be == <<-'HTML'.strip_heredoc
|
162
162
|
:javascript
|
163
163
|
var text = _("Don't you think?");
|
164
164
|
HAML
|
@@ -170,7 +170,7 @@ module Haml
|
|
170
170
|
HTML
|
171
171
|
end
|
172
172
|
it 'should not choke on double-quote' do
|
173
|
-
render(<<-'HAML'.strip_heredoc).
|
173
|
+
expect(render(<<-'HAML'.strip_heredoc)).to be == <<-'HTML'.strip_heredoc
|
174
174
|
:javascript
|
175
175
|
var text = _('One "quote" here');
|
176
176
|
HAML
|
@@ -185,7 +185,7 @@ module Haml
|
|
185
185
|
|
186
186
|
context 'when translating strings in Markdown' do
|
187
187
|
it "should translate strings inside _('')" do
|
188
|
-
render(<<-'HAML'.strip_heredoc).
|
188
|
+
expect(render(<<-'HAML'.strip_heredoc).lstrip).to be == <<-'HTML'.strip_heredoc
|
189
189
|
:maruku
|
190
190
|
Now we will check multiline strings,
|
191
191
|
which should be also translated.
|
@@ -198,7 +198,7 @@ module Haml
|
|
198
198
|
context 'when disabling magic translations' do
|
199
199
|
it 'should leave text untranslated' do
|
200
200
|
Haml::MagicTranslations.disable
|
201
|
-
render(<<-'HAML'.strip_heredoc).
|
201
|
+
expect(render(<<-'HAML'.strip_heredoc)).to be == <<-'HTML'.strip_heredoc
|
202
202
|
%p Magic translations works!
|
203
203
|
HAML
|
204
204
|
<p>Magic translations works!</p>
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,12 @@ require 'action_view'
|
|
12
12
|
|
13
13
|
require 'haml/magic_translations'
|
14
14
|
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.expect_with :rspec do |c|
|
17
|
+
c.syntax = :expect
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
Haml::Options.defaults[:ugly] = false
|
16
22
|
Haml::Options.defaults[:format] = :xhtml
|
17
23
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml-magic-translations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-05-
|
13
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: haml
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
requirements:
|
100
100
|
- - ! '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '2'
|
102
|
+
version: '2.11'
|
103
103
|
type: :development
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2'
|
110
|
+
version: '2.11'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rdoc
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|