haml-magic-translations 0.5.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/haml-magic-translations.gemspec +8 -5
- data/lib/haml/magic_translations.rb +72 -73
- data/lib/haml/magic_translations/xgettext/haml_parser.rb +66 -60
- data/spec/haml/magic_translations/xgettext/haml_parser_spec.rb +9 -9
- data/spec/haml/magic_translations_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -3
- metadata +20 -4
data/Rakefile
CHANGED
@@ -18,7 +18,8 @@ time with translations.
|
|
18
18
|
gem.email = "jardiniers@potager.org"
|
19
19
|
gem.homepage = "https://github.com/potager/haml-magic-translations"
|
20
20
|
gem.authors = ["Kriss Kowalik", "potager.org"]
|
21
|
-
gem.add_dependency "haml", "~>
|
21
|
+
gem.add_dependency "haml", "~> 4.0"
|
22
|
+
gem.add_development_dependency "haml-contrib", ">= 1.0"
|
22
23
|
gem.add_development_dependency "actionpack"
|
23
24
|
gem.add_development_dependency "gettext", ">= 2.3"
|
24
25
|
gem.add_development_dependency "fast_gettext"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
4.0.0
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{haml-magic-translations}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "4.0.0"
|
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{2013-
|
12
|
+
s.date = %q{2013-05-28}
|
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
|
@@ -51,7 +51,8 @@ time with translations.
|
|
51
51
|
s.specification_version = 3
|
52
52
|
|
53
53
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
-
s.add_runtime_dependency(%q<haml>, ["~>
|
54
|
+
s.add_runtime_dependency(%q<haml>, ["~> 4.0"])
|
55
|
+
s.add_development_dependency(%q<haml-contrib>, [">= 1.0"])
|
55
56
|
s.add_development_dependency(%q<actionpack>, [">= 0"])
|
56
57
|
s.add_development_dependency(%q<gettext>, [">= 2.3"])
|
57
58
|
s.add_development_dependency(%q<fast_gettext>, [">= 0"])
|
@@ -59,7 +60,8 @@ time with translations.
|
|
59
60
|
s.add_development_dependency(%q<rdoc>, [">= 2.4.2"])
|
60
61
|
s.add_development_dependency(%q<maruku>, [">= 0"])
|
61
62
|
else
|
62
|
-
s.add_dependency(%q<haml>, ["~>
|
63
|
+
s.add_dependency(%q<haml>, ["~> 4.0"])
|
64
|
+
s.add_dependency(%q<haml-contrib>, [">= 1.0"])
|
63
65
|
s.add_dependency(%q<actionpack>, [">= 0"])
|
64
66
|
s.add_dependency(%q<gettext>, [">= 2.3"])
|
65
67
|
s.add_dependency(%q<fast_gettext>, [">= 0"])
|
@@ -68,7 +70,8 @@ time with translations.
|
|
68
70
|
s.add_dependency(%q<maruku>, [">= 0"])
|
69
71
|
end
|
70
72
|
else
|
71
|
-
s.add_dependency(%q<haml>, ["~>
|
73
|
+
s.add_dependency(%q<haml>, ["~> 4.0"])
|
74
|
+
s.add_dependency(%q<haml-contrib>, [">= 1.0"])
|
72
75
|
s.add_dependency(%q<actionpack>, [">= 0"])
|
73
76
|
s.add_dependency(%q<gettext>, [">= 2.3"])
|
74
77
|
s.add_dependency(%q<fast_gettext>, [">= 0"])
|
@@ -43,12 +43,65 @@ require 'json'
|
|
43
43
|
#
|
44
44
|
module Haml::MagicTranslations
|
45
45
|
def self.included(haml) # :nodoc:
|
46
|
-
haml.send(:include, EngineMethods)
|
47
46
|
if defined? Haml::Template
|
48
47
|
Haml::Template.send(:extend, TemplateMethods)
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
51
|
+
class Parser < Haml::Parser
|
52
|
+
# Overriden function that parses Haml tags. Injects gettext call for all plain
|
53
|
+
# text lines.
|
54
|
+
def parse_tag(line)
|
55
|
+
tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
56
|
+
nuke_inner_whitespace, action, value, last_line = super(line)
|
57
|
+
|
58
|
+
if !value.empty?
|
59
|
+
unless action && action == '=' || action == '!' && value[0] == ?= || action == '&' && value[0] == ?=
|
60
|
+
value, interpolation_arguments = Haml::MagicTranslations.prepare_i18n_interpolation(value)
|
61
|
+
value = "\#{_('#{value.gsub(/'/, "\\\\'")}') % #{interpolation_arguments}\}\n"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
[tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
65
|
+
nuke_inner_whitespace, action, value, last_line]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Magical translations will be also used for plain text.
|
69
|
+
def plain(text, escape_html = nil)
|
70
|
+
value, interpolation_arguments = Haml::MagicTranslations.prepare_i18n_interpolation(text, escape_html)
|
71
|
+
value = "_('#{value.gsub(/'/, "\\\\'")}') % #{interpolation_arguments}\n"
|
72
|
+
script(value, !:escape_html)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Compiler < Haml::Compiler
|
77
|
+
class << self
|
78
|
+
attr_accessor :magic_translations_helpers
|
79
|
+
end
|
80
|
+
|
81
|
+
def compile_filter
|
82
|
+
case @node.value[:name]
|
83
|
+
when 'markdown', 'maruku'
|
84
|
+
@node.value[:text] = "\#{_(<<-'END_OF_TRANSLATABLE_MARKDOWN'.rstrip
|
85
|
+
#{@node.value[:text].rstrip.gsub(/\n/, '\n')}
|
86
|
+
END_OF_TRANSLATABLE_MARKDOWN
|
87
|
+
)}"
|
88
|
+
when 'javascript'
|
89
|
+
@node.value[:text].gsub!(/_\(('(([^']|\\')+)'|"(([^"]|\\")+)")\)/) do |m|
|
90
|
+
to_parse = $1[1..-2].gsub(/"/, '\"')
|
91
|
+
parsed_string = JSON.parse("[\"#{to_parse}\"]")[0]
|
92
|
+
parsed_string.gsub!(/'/, "\\\\'")
|
93
|
+
"\#{_('#{parsed_string}').to_json}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
super
|
97
|
+
end
|
98
|
+
|
99
|
+
def compile_root
|
100
|
+
@precompiled << "extend #{Compiler.magic_translations_helpers};"
|
101
|
+
super
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
52
105
|
# It discovers all fragments of code embeded in text and replacing with
|
53
106
|
# simple string interpolation parameters.
|
54
107
|
#
|
@@ -72,13 +125,13 @@ module Haml::MagicTranslations
|
|
72
125
|
gsub(/\"/, '\"').
|
73
126
|
gsub(/\\/, '\\\\')
|
74
127
|
|
75
|
-
rest = Haml::
|
128
|
+
rest = Haml::Util.handle_interpolation '"' + str + '"' do |scan|
|
76
129
|
escapes = (scan[2].size - 1) / 2
|
77
130
|
res << scan.matched[0...-3 - escapes]
|
78
131
|
if escapes % 2 == 1
|
79
132
|
res << '#{'
|
80
133
|
else
|
81
|
-
content = eval('"' + Haml::
|
134
|
+
content = eval('"' + Haml::Util.balance(scan, ?{, ?}, 1)[0][0...-1] + '"')
|
82
135
|
content = "Haml::Helpers.html_escape(#{content.to_s})" if escape_html
|
83
136
|
args << content
|
84
137
|
res << '%s'
|
@@ -103,30 +156,42 @@ module Haml::MagicTranslations
|
|
103
156
|
# +:gettext+:: Use GetText from 'gettext'
|
104
157
|
# +:fast_gettext+:: Use FastGettext::Translation from 'fast_gettext'
|
105
158
|
def self.enable(backend = :i18n)
|
159
|
+
return if @enabled
|
160
|
+
|
106
161
|
case backend
|
107
162
|
when :i18n
|
108
163
|
require 'i18n'
|
109
164
|
require 'i18n/backend/gettext'
|
110
165
|
require 'i18n/gettext/helpers'
|
111
166
|
I18n::Backend::Simple.send(:include, I18n::Backend::Gettext)
|
112
|
-
|
167
|
+
Compiler.magic_translations_helpers = I18n::Gettext::Helpers
|
113
168
|
when :gettext
|
114
169
|
require 'gettext'
|
115
|
-
|
170
|
+
Compiler.magic_translations_helpers = GetText
|
116
171
|
when :fast_gettext
|
117
172
|
require 'fast_gettext'
|
118
|
-
|
173
|
+
Compiler.magic_translations_helpers = FastGettext::Translation
|
119
174
|
else
|
120
175
|
@enabled = false
|
121
176
|
raise ArgumentError, "Backend #{backend.to_s} is not available in Haml::MagicTranslations"
|
122
177
|
end
|
178
|
+
@original_parser = Haml::Options.defaults[:parser_class]
|
179
|
+
Haml::Options.defaults[:parser_class] = Parser
|
180
|
+
@original_compiler = Haml::Options.defaults[:compiler_class]
|
181
|
+
Haml::Options.defaults[:compiler_class] = Compiler
|
123
182
|
@enabled = true
|
124
183
|
end
|
125
184
|
|
126
185
|
# Disable magic translations
|
127
186
|
def self.disable
|
128
|
-
|
187
|
+
return unless @enabled
|
188
|
+
|
129
189
|
@enabled = false
|
190
|
+
Haml::Options.defaults[:compiler_class] = @original_compiler
|
191
|
+
@original_compiler = nil
|
192
|
+
Haml::Options.defaults[:parser_class] = @original_parser
|
193
|
+
@original_parser = nil
|
194
|
+
Compiler.magic_translations_helpers = nil
|
130
195
|
end
|
131
196
|
|
132
197
|
module TemplateMethods # :nodoc:all
|
@@ -135,72 +200,6 @@ module Haml::MagicTranslations
|
|
135
200
|
Haml::MagicTranslations.enable backend
|
136
201
|
end
|
137
202
|
end
|
138
|
-
|
139
|
-
module EngineMethods # :nodoc:all
|
140
|
-
class << self
|
141
|
-
attr_accessor :magic_translations_helpers
|
142
|
-
end
|
143
|
-
|
144
|
-
def magic_translations?
|
145
|
-
return self.options[:magic_translations] unless self.options[:magic_translations].nil?
|
146
|
-
|
147
|
-
Haml::MagicTranslations.enabled?
|
148
|
-
end
|
149
|
-
|
150
|
-
# Overriden function that parses Haml tags. Injects gettext call for all plain
|
151
|
-
# text lines.
|
152
|
-
def parse_tag(line)
|
153
|
-
tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
154
|
-
nuke_inner_whitespace, action, value, last_line = super(line)
|
155
|
-
|
156
|
-
if magic_translations? && !value.empty?
|
157
|
-
unless action && action == '=' || action == '!' && value[0] == ?= || action == '&' && value[0] == ?=
|
158
|
-
value, interpolation_arguments = Haml::MagicTranslations.prepare_i18n_interpolation(value)
|
159
|
-
value = "\#{_('#{value.gsub(/'/, "\\\\'")}') % #{interpolation_arguments}\}\n"
|
160
|
-
end
|
161
|
-
end
|
162
|
-
[tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
163
|
-
nuke_inner_whitespace, action, value, last_line]
|
164
|
-
end
|
165
|
-
|
166
|
-
# Magical translations will be also used for plain text.
|
167
|
-
def plain(text, escape_html = nil)
|
168
|
-
if magic_translations?
|
169
|
-
value, interpolation_arguments = Haml::MagicTranslations.prepare_i18n_interpolation(text, escape_html)
|
170
|
-
value = "_('#{value.gsub(/'/, "\\\\'")}') % #{interpolation_arguments}\n"
|
171
|
-
script(value, !:escape_html)
|
172
|
-
else
|
173
|
-
super
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def compile_filter
|
178
|
-
super unless magic_translations?
|
179
|
-
|
180
|
-
case @node.value[:name]
|
181
|
-
when 'markdown', 'maruku'
|
182
|
-
@node.value[:text] = "\#{_(<<-'END_OF_TRANSLATABLE_MARKDOWN'.rstrip
|
183
|
-
#{@node.value[:text].rstrip.gsub(/\n/, '\n')}
|
184
|
-
END_OF_TRANSLATABLE_MARKDOWN
|
185
|
-
)}"
|
186
|
-
when 'javascript'
|
187
|
-
@node.value[:text].gsub!(/_\(('(([^']|\\')+)'|"(([^"]|\\")+)")\)/) do |m|
|
188
|
-
to_parse = $1[1..-2].gsub(/"/, '\"')
|
189
|
-
parsed_string = JSON.parse("[\"#{to_parse}\"]")[0]
|
190
|
-
parsed_string.gsub!(/'/, "\\\\'")
|
191
|
-
"\#{_('#{parsed_string}').to_json}"
|
192
|
-
end
|
193
|
-
end
|
194
|
-
super
|
195
|
-
end
|
196
|
-
|
197
|
-
def compile_root
|
198
|
-
if magic_translations?
|
199
|
-
@precompiled << "extend #{EngineMethods.magic_translations_helpers};"
|
200
|
-
end
|
201
|
-
super
|
202
|
-
end
|
203
|
-
end
|
204
203
|
end
|
205
204
|
|
206
205
|
Haml::Engine.send(:include, Haml::MagicTranslations)
|
@@ -20,10 +20,10 @@ module Haml::MagicTranslations::XGetText # :nodoc:
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def parse(file) # :nodoc:
|
23
|
-
|
23
|
+
XGetTextParser.new(file).parse
|
24
24
|
end
|
25
25
|
|
26
|
-
class
|
26
|
+
class XGetTextParser # :nodoc:all
|
27
27
|
attr_reader :file
|
28
28
|
attr_reader :content
|
29
29
|
def initialize(file)
|
@@ -37,107 +37,113 @@ module Haml::MagicTranslations::XGetText # :nodoc:
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def parse
|
40
|
-
|
41
|
-
|
40
|
+
# Engine#initialize parses and compiles
|
41
|
+
HamlEngineCompiler.filename = @file
|
42
|
+
Haml::Engine.new(
|
42
43
|
content, :filename => @file,
|
43
|
-
:
|
44
|
-
:
|
44
|
+
:parser_class => HamlEngineParser,
|
45
|
+
:compiler_class => HamlEngineCompiler)
|
46
|
+
targets = HamlEngineCompiler.targets
|
47
|
+
HamlEngineCompiler.reset_targets
|
48
|
+
targets
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
48
|
-
|
49
|
-
def
|
50
|
-
@targets = {} if @targets.nil?
|
51
|
-
unless text.empty?
|
52
|
-
@targets[text] = [] unless @targets[text]
|
53
|
-
@targets[text].push("#{options[:filename]}:#{lineno}")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def targets
|
58
|
-
(@targets || {}).keys.sort.collect do |k|
|
59
|
-
[k] + @targets[k]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# We can't piggyback `compile_tag` because the following gets no
|
64
|
-
# distinction at all:
|
65
|
-
#
|
66
|
-
# %p= "Hello"
|
67
|
-
#
|
68
|
-
# and:
|
69
|
-
#
|
70
|
-
# %p #{"Hello"}
|
71
|
-
#
|
72
|
-
# So let's hook in the parser, just for this specific case.
|
73
|
-
def parse_tag(line)
|
74
|
-
return super unless self.options[:xgettext]
|
75
|
-
|
52
|
+
class HamlEngineParser < Haml::Parser
|
53
|
+
def tag(line)
|
76
54
|
tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
77
|
-
nuke_inner_whitespace, action, value, last_line =
|
55
|
+
nuke_inner_whitespace, action, value, last_line = parse_tag(line)
|
78
56
|
if action && (action == '=' || (action == '!' && value[0] == ?=) ||
|
79
57
|
(action == '&' && value[0] == ?=))
|
80
|
-
|
81
|
-
value.gsub(/_\('(([^']|\\')+)'\)/) do |m|
|
82
|
-
parsed_string = "#{$1}"
|
83
|
-
add_target(parsed_string, last_line)
|
84
|
-
end
|
58
|
+
parsed_tag = true
|
85
59
|
else
|
86
|
-
|
87
|
-
add_target(interpolated[0], last_line)
|
60
|
+
parsed_tag = false
|
88
61
|
end
|
89
|
-
|
90
|
-
|
62
|
+
node = super(line)
|
63
|
+
node[:value][:parsed_tag] = parsed_tag
|
64
|
+
node
|
91
65
|
end
|
66
|
+
end
|
92
67
|
|
93
|
-
|
94
|
-
|
68
|
+
class HamlEngineCompiler < Haml::Compiler
|
69
|
+
class << self
|
70
|
+
attr_accessor :filename
|
71
|
+
|
72
|
+
def add_target(text, lineno)
|
73
|
+
@targets = {} if @targets.nil?
|
74
|
+
unless text.empty?
|
75
|
+
@targets[text] = [] unless @targets[text]
|
76
|
+
@targets[text].push("#{filename}:#{lineno}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def reset_targets
|
81
|
+
@targets = {}
|
82
|
+
end
|
83
|
+
|
84
|
+
def targets
|
85
|
+
(@targets || {}).keys.sort.collect do |k|
|
86
|
+
[k] + @targets[k]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
95
90
|
|
96
|
-
|
91
|
+
def compile(node)
|
92
|
+
super(node)
|
93
|
+
end
|
94
|
+
|
95
|
+
def compile_plain
|
96
|
+
HamlEngineCompiler.add_target(@node.value[:text], @node.line)
|
97
97
|
end
|
98
98
|
|
99
99
|
def compile_doctype
|
100
|
-
|
100
|
+
# do nothing
|
101
101
|
end
|
102
102
|
|
103
103
|
def compile_script
|
104
|
-
return super unless self.options[:xgettext]
|
105
|
-
|
106
104
|
yield if block_given?
|
107
105
|
end
|
108
106
|
|
109
107
|
def compile_silent_script
|
110
|
-
return super unless self.options[:xgettext]
|
111
|
-
|
112
108
|
yield if block_given?
|
113
109
|
end
|
114
110
|
|
115
111
|
def compile_tag
|
116
|
-
|
117
|
-
|
112
|
+
if @node.value[:parsed_tag]
|
113
|
+
# Search for explicitely translated strings
|
114
|
+
@node.value[:value].gsub(/_\('(([^']|\\')+)'\)/) do |m|
|
115
|
+
parsed_string = "#{$1}"
|
116
|
+
HamlEngineCompiler.add_target(parsed_string, @node.line)
|
117
|
+
end
|
118
|
+
else
|
119
|
+
value = @node.value[:value]
|
120
|
+
if value
|
121
|
+
# strip quotes if needed
|
122
|
+
value = value[1..-2] if @node.value[:parse]
|
123
|
+
value, args = Haml::MagicTranslations.prepare_i18n_interpolation(value)
|
124
|
+
HamlEngineCompiler.add_target(value, @node.line)
|
125
|
+
end
|
126
|
+
end
|
118
127
|
# handle explicit translations in attributes
|
119
128
|
@node.value[:attributes_hashes].each do |hash_string|
|
120
129
|
hash_string.gsub(/_\('(([^']|\\')+)'\)/) do |m|
|
121
|
-
add_target($1)
|
130
|
+
HamlEngineCompiler.add_target($1, @node.line)
|
122
131
|
end
|
123
132
|
end
|
124
|
-
# targets have been already handled in parse_tag
|
125
133
|
yield if @node.value[:value].nil? && block_given?
|
126
134
|
end
|
127
135
|
|
128
136
|
def compile_filter
|
129
|
-
return super unless self.options[:xgettext]
|
130
|
-
|
131
137
|
case @node.value[:name]
|
132
138
|
when 'markdown', 'maruku'
|
133
|
-
add_target(@node.value[:text].rstrip)
|
139
|
+
HamlEngineCompiler.add_target(@node.value[:text].rstrip, @node.line)
|
134
140
|
when 'javascript'
|
135
141
|
lineno = 0
|
136
142
|
@node.value[:text].split(/\r\n|\r|\n/).each do |line|
|
137
143
|
lineno += 1
|
138
144
|
line.gsub(/_\('(([^']|\\')+)'\)/) do |m|
|
139
145
|
parsed_string = JSON.parse("[\"#{$1}\"]")[0]
|
140
|
-
add_target(parsed_string, @node.line + lineno)
|
146
|
+
HamlEngineCompiler.add_target(parsed_string, @node.line + lineno)
|
141
147
|
end
|
142
148
|
end
|
143
149
|
end
|
@@ -18,24 +18,24 @@ module Haml::MagicTranslations::XGetText
|
|
18
18
|
|
19
19
|
describe '.parse' do
|
20
20
|
it 'should properly instanciate a Parser' do
|
21
|
-
HamlParser::
|
22
|
-
and_return(mock('
|
21
|
+
HamlParser::XGetTextParser.should_receive(:new).with('test.haml').
|
22
|
+
and_return(mock('XGetTextParser').as_null_object)
|
23
23
|
HamlParser.parse('test.haml')
|
24
24
|
end
|
25
25
|
it 'should run the parser' do
|
26
|
-
parser = mock('
|
26
|
+
parser = mock('XGetTextParser')
|
27
27
|
parser.should_receive(:parse)
|
28
|
-
HamlParser::
|
28
|
+
HamlParser::XGetTextParser.stub!(:new).and_return(parser)
|
29
29
|
HamlParser.parse('test.haml')
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe HamlParser::
|
33
|
+
describe HamlParser::XGetTextParser do
|
34
34
|
describe '#initialize' do
|
35
35
|
context 'when given "test.haml"' do
|
36
36
|
before(:each) do
|
37
37
|
File.stub!(:open).and_return(StringIO.new('It works!'))
|
38
|
-
@parser = HamlParser::
|
38
|
+
@parser = HamlParser::XGetTextParser.new('test.haml')
|
39
39
|
end
|
40
40
|
it 'should set file attribute' do
|
41
41
|
@parser.file.should == 'test.haml'
|
@@ -45,14 +45,14 @@ module Haml::MagicTranslations::XGetText
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
context 'when given a IO-like object' do
|
48
|
-
let (:parser) { HamlParser::
|
48
|
+
let (:parser) { HamlParser::XGetTextParser.new(StringIO.new('It works!')) }
|
49
49
|
it { parser.file.should == '(haml)' }
|
50
50
|
it { parser.content.should == 'It works!' }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe '#parse' do
|
55
|
-
subject { HamlParser::
|
55
|
+
subject { HamlParser::XGetTextParser.new(StringIO.new(template)).parse }
|
56
56
|
context 'for an empty content' do
|
57
57
|
let(:template) { '' }
|
58
58
|
it 'should return no targets' do
|
@@ -197,7 +197,7 @@ module Haml::MagicTranslations::XGetText
|
|
197
197
|
end
|
198
198
|
context 'after extracting translations' do
|
199
199
|
it 'should still allow Haml::Engine to build templates' do
|
200
|
-
HamlParser::
|
200
|
+
HamlParser::XGetTextParser.new(StringIO.new('test')).parse
|
201
201
|
Haml::Engine.new('%p It works!').render.should == <<-'HTML'.strip_heredoc
|
202
202
|
<p>It works!</p>
|
203
203
|
HTML
|
@@ -24,19 +24,19 @@ module Haml
|
|
24
24
|
context 'when using :i18n as backend' do
|
25
25
|
before { Haml::MagicTranslations.enable :i18n }
|
26
26
|
it { Haml::MagicTranslations.should be_enabled }
|
27
|
-
it { Haml::MagicTranslations::
|
27
|
+
it { Haml::MagicTranslations::Compiler.
|
28
28
|
magic_translations_helpers.should == I18n::Gettext::Helpers }
|
29
29
|
end
|
30
30
|
context 'when using :gettext as backend' do
|
31
31
|
before { Haml::MagicTranslations.enable :gettext }
|
32
32
|
it { Haml::MagicTranslations.should be_enabled }
|
33
|
-
it { Haml::MagicTranslations::
|
33
|
+
it { Haml::MagicTranslations::Compiler.
|
34
34
|
magic_translations_helpers.should == GetText }
|
35
35
|
end
|
36
36
|
context 'when using :fast_gettext as backend' do
|
37
37
|
before { Haml::MagicTranslations.enable :fast_gettext }
|
38
38
|
it { Haml::MagicTranslations.should be_enabled }
|
39
|
-
it { Haml::MagicTranslations::
|
39
|
+
it { Haml::MagicTranslations::Compiler.
|
40
40
|
magic_translations_helpers.should == FastGettext::Translation }
|
41
41
|
end
|
42
42
|
context 'when giving another backend' do
|
data/spec/spec_helper.rb
CHANGED
@@ -7,14 +7,14 @@ require 'rspec'
|
|
7
7
|
$:.unshift File.dirname(__FILE__)
|
8
8
|
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
9
9
|
|
10
|
-
require '
|
10
|
+
require 'active_support'
|
11
11
|
require 'action_view'
|
12
12
|
|
13
13
|
require 'haml/magic_translations'
|
14
14
|
require 'haml/template'
|
15
15
|
|
16
|
-
Haml::
|
17
|
-
Haml::
|
16
|
+
Haml::Options.defaults[:ugly] = false
|
17
|
+
Haml::Options.defaults[:format] = :xhtml
|
18
18
|
|
19
19
|
def render(text, options = {}, &block)
|
20
20
|
scope = options.delete(:scope) || Object.new
|
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: 0.
|
4
|
+
version: 4.0.0
|
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: 2013-
|
13
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: haml
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '4.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,7 +27,23 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
30
|
+
version: '4.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: haml-contrib
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
31
47
|
- !ruby/object:Gem::Dependency
|
32
48
|
name: actionpack
|
33
49
|
requirement: !ruby/object:Gem::Requirement
|