tilt 1.3.4 → 1.4.1
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.
- data/CHANGELOG.md +44 -0
- data/README.md +22 -1
- data/TEMPLATES.md +2 -2
- data/lib/tilt/erb.rb +1 -1
- data/lib/tilt/template.rb +73 -27
- data/lib/tilt.rb +3 -3
- data/test/tilt_csv_test.rb +2 -6
- data/test/tilt_markdown_test.rb +1 -1
- data/test/tilt_template_test.rb +158 -2
- data/tilt.gemspec +3 -2
- metadata +5 -3
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
## master
|
|
2
|
+
|
|
3
|
+
## 1.4.1 (2013-05-08)
|
|
4
|
+
|
|
5
|
+
* Support Arrays in pre/postambles (#193, jbwiv)
|
|
6
|
+
|
|
7
|
+
## 1.4.0 (2013-05-01)
|
|
8
|
+
|
|
9
|
+
* Better encoding support
|
|
10
|
+
|
|
11
|
+
## 1.3.7 (2013-04-09)
|
|
12
|
+
|
|
13
|
+
* Erubis: Check for the correct constant (#183, mattwildig)
|
|
14
|
+
* Don't fail when BasicObject is defined in 1.8 (#182, technobrat, judofyr)
|
|
15
|
+
|
|
16
|
+
## 1.3.6 (2013-03-17)
|
|
17
|
+
|
|
18
|
+
* Accept Hash that implements #path as options (#180, lawso017)
|
|
19
|
+
* Changed extension for CsvTemplate from '.csv' to '.rcsv' (#177, alexgb)
|
|
20
|
+
|
|
21
|
+
## 1.3.5 (2013-03-06)
|
|
22
|
+
|
|
23
|
+
* Fixed extension for PlainTemplate (judofyr)
|
|
24
|
+
* Improved local variables regexp (#174, razorinc)
|
|
25
|
+
* Added CHANGELOG.md
|
|
26
|
+
|
|
27
|
+
## 1.3.4 (2013-02-28)
|
|
28
|
+
|
|
29
|
+
* Support RDoc 4.0 (#168, judofyr)
|
|
30
|
+
* Add mention of Org-Mode support (#165, aslakknutsen)
|
|
31
|
+
* Add AsciiDoctorTemplate (#163, #164, aslakknutsen)
|
|
32
|
+
* Add PlainTextTemplate (nathanaeljones)
|
|
33
|
+
* Restrict locals to valid variable names (#158, thinkerbot)
|
|
34
|
+
* ERB: Improve trim mode support (#156, ssimeonov)
|
|
35
|
+
* Add CSVTemplate (#153, alexgb)
|
|
36
|
+
* Remove special case for 1.9.1 (#147, guilleiguaran)
|
|
37
|
+
* Add allows\_script? method to Template (#143, bhollis)
|
|
38
|
+
* Default to using Redcarpet2 (#139, DAddYE)
|
|
39
|
+
* Allow File/Tempfile as filenames (#134, jamesotron)
|
|
40
|
+
* Add EtanniTemplate (#131, manveru)
|
|
41
|
+
* Support RDoc 3.10 (#112, timfel)
|
|
42
|
+
* Always compile templates; remove old source evaluator (rtomayko)
|
|
43
|
+
* Less: Options are now being passed to the parser (#106, cowboyd)
|
|
44
|
+
|
data/README.md
CHANGED
|
@@ -47,7 +47,7 @@ Support for these template engines is included with the package:
|
|
|
47
47
|
Creole (Wiki markup) .wiki, .creole creole
|
|
48
48
|
WikiCloth (Wiki markup) .wiki, .mediawiki, .mw wikicloth
|
|
49
49
|
Yajl .yajl yajl-ruby
|
|
50
|
-
CSV .
|
|
50
|
+
CSV .rcsv none (Ruby >= 1.9), fastercsv (Ruby < 1.9)
|
|
51
51
|
|
|
52
52
|
These template engines ship with their own Tilt integration:
|
|
53
53
|
|
|
@@ -194,6 +194,27 @@ template, but if you depend on a specific implementation, you should use #prefer
|
|
|
194
194
|
When a file extension has a preferred template class, Tilt will *always* use
|
|
195
195
|
that class, even if it raises an exception.
|
|
196
196
|
|
|
197
|
+
Encodings
|
|
198
|
+
---------
|
|
199
|
+
|
|
200
|
+
Tilt needs to know the encoding of the template in order to work properly:
|
|
201
|
+
|
|
202
|
+
Tilt will use `Encoding.default_external` as the encoding when reading external
|
|
203
|
+
files. If you're mostly working with one encoding (e.g. UTF-8) we *highly*
|
|
204
|
+
recommend setting this option. When providing a custom reader block (`Tilt.new
|
|
205
|
+
{ custom_string }`) you'll have ensure the string is properly encoded yourself.
|
|
206
|
+
|
|
207
|
+
Most of the template engines in Tilt also allows you to override the encoding
|
|
208
|
+
using the `:default_encoding`-option:
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
tmpl = Tilt.new('hello.erb', :default_encoding => 'Big5')
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Ultimately it's up to the template engine how to handle the encoding: It might
|
|
215
|
+
respect `:default_encoding`, it might always assume it's UTF-8 (like
|
|
216
|
+
CoffeScript), or it can do its own encoding detection.
|
|
217
|
+
|
|
197
218
|
Template Compilation
|
|
198
219
|
--------------------
|
|
199
220
|
|
data/TEMPLATES.md
CHANGED
|
@@ -305,9 +305,9 @@ time when using this template engine within a threaded environment.
|
|
|
305
305
|
|
|
306
306
|
### See also
|
|
307
307
|
|
|
308
|
-
* [Liquid for Programmers](
|
|
308
|
+
* [Liquid for Programmers](https://wiki.github.com/Shopify/liquid/liquid-for-programmers)
|
|
309
309
|
* [Liquid Docs](http://liquid.rubyforge.org/)
|
|
310
|
-
* GitHub: [
|
|
310
|
+
* GitHub: [Shopify/liquid](https://github.com/Shopify/liquid/)
|
|
311
311
|
|
|
312
312
|
|
|
313
313
|
<a name='radius'></a>
|
data/lib/tilt/erb.rb
CHANGED
data/lib/tilt/template.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Tilt
|
|
2
|
-
TOPOBJECT =
|
|
2
|
+
TOPOBJECT = Object.superclass || Object
|
|
3
3
|
|
|
4
4
|
# Base class for template implementations. Subclasses must implement
|
|
5
5
|
# the #prepare method and one of the #evaluate or #precompiled_template
|
|
@@ -41,9 +41,9 @@ module Tilt
|
|
|
41
41
|
[options, line, file].compact.each do |arg|
|
|
42
42
|
case
|
|
43
43
|
when arg.respond_to?(:to_str) ; @file = arg.to_str
|
|
44
|
-
when arg.respond_to?(:path) ; @file = arg.path
|
|
45
44
|
when arg.respond_to?(:to_int) ; @line = arg.to_int
|
|
46
45
|
when arg.respond_to?(:to_hash) ; @options = arg.to_hash.dup
|
|
46
|
+
when arg.respond_to?(:path) ; @file = arg.path
|
|
47
47
|
else raise TypeError
|
|
48
48
|
end
|
|
49
49
|
end
|
|
@@ -65,11 +65,37 @@ module Tilt
|
|
|
65
65
|
@default_encoding = @options.delete :default_encoding
|
|
66
66
|
|
|
67
67
|
# load template data and prepare (uses binread to avoid encoding issues)
|
|
68
|
-
@reader = block || lambda { |t|
|
|
68
|
+
@reader = block || lambda { |t| read_template_file }
|
|
69
69
|
@data = @reader.call(self)
|
|
70
|
+
|
|
71
|
+
if @data.respond_to?(:force_encoding)
|
|
72
|
+
@data.force_encoding(default_encoding) if default_encoding
|
|
73
|
+
|
|
74
|
+
if !@data.valid_encoding?
|
|
75
|
+
raise Encoding::InvalidByteSequenceError, "#{eval_file} is not valid #{@data.encoding}"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
70
79
|
prepare
|
|
71
80
|
end
|
|
72
81
|
|
|
82
|
+
# The encoding of the source data. Defaults to the
|
|
83
|
+
# default_encoding-option if present. You may override this method
|
|
84
|
+
# in your template class if you have a better hint of the data's
|
|
85
|
+
# encoding.
|
|
86
|
+
def default_encoding
|
|
87
|
+
@default_encoding
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def read_template_file
|
|
91
|
+
data = File.open(file, 'rb') { |io| io.read }
|
|
92
|
+
if data.respond_to?(:force_encoding)
|
|
93
|
+
# Set it to the default external (without verifying)
|
|
94
|
+
data.force_encoding(Encoding.default_external) if Encoding.default_external
|
|
95
|
+
end
|
|
96
|
+
data
|
|
97
|
+
end
|
|
98
|
+
|
|
73
99
|
# Render the template in the given scope with the locals specified. If a
|
|
74
100
|
# block is given, it is typically available within the template via
|
|
75
101
|
# +yield+.
|
|
@@ -156,26 +182,32 @@ module Tilt
|
|
|
156
182
|
def precompiled(locals)
|
|
157
183
|
preamble = precompiled_preamble(locals)
|
|
158
184
|
template = precompiled_template(locals)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
185
|
+
postamble = precompiled_postamble(locals)
|
|
186
|
+
source = ''
|
|
187
|
+
|
|
188
|
+
# Ensure that our generated source code has the same encoding as the
|
|
189
|
+
# the source code generated by the template engine.
|
|
190
|
+
if source.respond_to?(:force_encoding)
|
|
191
|
+
template_encoding = extract_encoding(template)
|
|
192
|
+
|
|
193
|
+
source.force_encoding(template_encoding)
|
|
194
|
+
template.force_encoding(template_encoding)
|
|
164
195
|
end
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
]
|
|
170
|
-
|
|
196
|
+
|
|
197
|
+
# https://github.com/rtomayko/tilt/issues/193
|
|
198
|
+
warn "precompiled_preamble should return String (not Array)" if preamble.is_a?(Array)
|
|
199
|
+
warn "precompiled_postamble should return String (not Array)" if postamble.is_a?(Array)
|
|
200
|
+
source << [preamble, template, postamble].join("\n")
|
|
201
|
+
|
|
202
|
+
[source, preamble.count("\n")+1]
|
|
171
203
|
end
|
|
172
204
|
|
|
173
205
|
# A string containing the (Ruby) source code for the template. The
|
|
174
|
-
# default Template#evaluate implementation requires either this
|
|
175
|
-
# or the #precompiled method be overridden. When defined,
|
|
176
|
-
# Template guarantees correct file/line handling, locals
|
|
177
|
-
# scopes, and support for template
|
|
178
|
-
#
|
|
206
|
+
# default Template#evaluate implementation requires either this
|
|
207
|
+
# method or the #precompiled method be overridden. When defined,
|
|
208
|
+
# the base Template guarantees correct file/line handling, locals
|
|
209
|
+
# support, custom scopes, proper encoding, and support for template
|
|
210
|
+
# compilation.
|
|
179
211
|
def precompiled_template(locals)
|
|
180
212
|
raise NotImplementedError
|
|
181
213
|
end
|
|
@@ -187,7 +219,7 @@ module Tilt
|
|
|
187
219
|
# reporting in Kernel::caller and backtraces.
|
|
188
220
|
def precompiled_preamble(locals)
|
|
189
221
|
locals.map do |k,v|
|
|
190
|
-
if k.to_s =~ /\A[a-
|
|
222
|
+
if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/
|
|
191
223
|
"#{k} = locals[#{k.inspect}]"
|
|
192
224
|
else
|
|
193
225
|
raise "invalid locals key: #{k.inspect} (keys must be variable names)"
|
|
@@ -212,8 +244,13 @@ module Tilt
|
|
|
212
244
|
def compile_template_method(locals)
|
|
213
245
|
source, offset = precompiled(locals)
|
|
214
246
|
method_name = "__tilt_#{Thread.current.object_id.abs}"
|
|
215
|
-
method_source =
|
|
216
|
-
|
|
247
|
+
method_source = ""
|
|
248
|
+
|
|
249
|
+
if method_source.respond_to?(:force_encoding)
|
|
250
|
+
method_source.force_encoding(source.encoding)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
method_source << <<-RUBY
|
|
217
254
|
TOPOBJECT.class_eval do
|
|
218
255
|
def #{method_name}(locals)
|
|
219
256
|
Thread.current[:tilt_vars] = [self, locals]
|
|
@@ -234,13 +271,22 @@ module Tilt
|
|
|
234
271
|
method
|
|
235
272
|
end
|
|
236
273
|
|
|
274
|
+
def extract_encoding(script)
|
|
275
|
+
extract_magic_comment(script) || script.encoding
|
|
276
|
+
end
|
|
277
|
+
|
|
237
278
|
def extract_magic_comment(script)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
comment
|
|
241
|
-
elsif @default_encoding
|
|
242
|
-
"# coding: #{@default_encoding}"
|
|
279
|
+
binary script do
|
|
280
|
+
script[/\A[ \t]*\#.*coding\s*[=:]\s*([[:alnum:]\-_]+).*$/n, 1]
|
|
243
281
|
end
|
|
244
282
|
end
|
|
283
|
+
|
|
284
|
+
def binary(string)
|
|
285
|
+
original_encoding = string.encoding
|
|
286
|
+
string.force_encoding(Encoding::BINARY)
|
|
287
|
+
yield
|
|
288
|
+
ensure
|
|
289
|
+
string.force_encoding(original_encoding)
|
|
290
|
+
end
|
|
245
291
|
end
|
|
246
292
|
end
|
data/lib/tilt.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Tilt
|
|
2
|
-
VERSION = '1.
|
|
2
|
+
VERSION = '1.4.1'
|
|
3
3
|
|
|
4
4
|
@preferred_mappings = Hash.new
|
|
5
5
|
@template_mappings = Hash.new { |h, k| h[k] = [] }
|
|
@@ -154,7 +154,7 @@ module Tilt
|
|
|
154
154
|
register LessTemplate, 'less'
|
|
155
155
|
|
|
156
156
|
require 'tilt/csv'
|
|
157
|
-
register CSVTemplate, '
|
|
157
|
+
register CSVTemplate, 'rcsv'
|
|
158
158
|
|
|
159
159
|
require 'tilt/coffee'
|
|
160
160
|
register CoffeeScriptTemplate, 'coffee'
|
|
@@ -200,5 +200,5 @@ module Tilt
|
|
|
200
200
|
register AsciidoctorTemplate, 'ad', 'adoc', 'asciidoc'
|
|
201
201
|
|
|
202
202
|
require 'tilt/plain'
|
|
203
|
-
register PlainTemplate, '
|
|
203
|
+
register PlainTemplate, 'html'
|
|
204
204
|
end
|
data/test/tilt_csv_test.rb
CHANGED
|
@@ -10,12 +10,8 @@ begin
|
|
|
10
10
|
|
|
11
11
|
class CSVTemplateTest < Test::Unit::TestCase
|
|
12
12
|
|
|
13
|
-
test "
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test "registered for '.csv' files" do
|
|
18
|
-
assert Tilt.mappings['csv'].include?(Tilt::CSVTemplate)
|
|
13
|
+
test "registered for '.rcsv' files" do
|
|
14
|
+
assert Tilt.mappings['rcsv'].include?(Tilt::CSVTemplate)
|
|
19
15
|
end
|
|
20
16
|
|
|
21
17
|
test "compiles and evaluates the template on #render" do
|
data/test/tilt_markdown_test.rb
CHANGED
data/test/tilt_template_test.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# coding: utf-8
|
|
1
2
|
require 'contest'
|
|
2
3
|
require 'tilt'
|
|
3
4
|
require 'tempfile'
|
|
@@ -30,6 +31,17 @@ class TiltTemplateTest < Test::Unit::TestCase
|
|
|
30
31
|
assert_equal File.basename(tempfile.path), inst.basename
|
|
31
32
|
end
|
|
32
33
|
|
|
34
|
+
class SillyHash < Hash
|
|
35
|
+
def path(arg)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
test "initialize with hash that implements #path" do
|
|
40
|
+
options = SillyHash[:key => :value]
|
|
41
|
+
inst = MockTemplate.new(options) {}
|
|
42
|
+
assert_equal :value, inst.options[:key]
|
|
43
|
+
end
|
|
44
|
+
|
|
33
45
|
test "uses correct eval_file" do
|
|
34
46
|
inst = MockTemplate.new('foo.erb', 55) {}
|
|
35
47
|
assert_equal 'foo.erb', inst.eval_file
|
|
@@ -135,9 +147,57 @@ class TiltTemplateTest < Test::Unit::TestCase
|
|
|
135
147
|
end
|
|
136
148
|
|
|
137
149
|
test "template_source with locals having non-variable keys raises error" do
|
|
138
|
-
inst = SourceGeneratingMockTemplate.new { |t| '1 + 2 = #{
|
|
139
|
-
err = assert_raise(RuntimeError) { inst.render(Object.new, 'ANSWER' =>
|
|
150
|
+
inst = SourceGeneratingMockTemplate.new { |t| '1 + 2 = #{_answer}' }
|
|
151
|
+
err = assert_raise(RuntimeError) { inst.render(Object.new, 'ANSWER' => 3) }
|
|
140
152
|
assert_equal "invalid locals key: \"ANSWER\" (keys must be variable names)", err.message
|
|
153
|
+
assert_equal "1 + 2 = 3", inst.render(Object.new, '_answer' => 3)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
class CustomGeneratingMockTemplate < PreparingMockTemplate
|
|
157
|
+
def precompiled_template(locals)
|
|
158
|
+
data
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def precompiled_preamble(locals)
|
|
162
|
+
options.fetch(:preamble)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def precompiled_postamble(locals)
|
|
166
|
+
options.fetch(:postamble)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
test "supports pre/postamble" do
|
|
171
|
+
inst = CustomGeneratingMockTemplate.new(
|
|
172
|
+
:preamble => 'buf = []',
|
|
173
|
+
:postamble => 'buf.join'
|
|
174
|
+
) { 'buf << 1' }
|
|
175
|
+
|
|
176
|
+
assert_equal "1", inst.render
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Special-case for Haml
|
|
180
|
+
# https://github.com/rtomayko/tilt/issues/193
|
|
181
|
+
test "supports Array pre/postambles" do
|
|
182
|
+
inst = CustomGeneratingMockTemplate.new(
|
|
183
|
+
:preamble => ['buf = ', '[]'],
|
|
184
|
+
:postamble => ['buf.', 'join']
|
|
185
|
+
) { 'buf << 1' }
|
|
186
|
+
|
|
187
|
+
# TODO: Use assert_output when we swicth to MiniTest
|
|
188
|
+
warns = <<-EOF
|
|
189
|
+
precompiled_preamble should return String (not Array)
|
|
190
|
+
precompiled_postamble should return String (not Array)
|
|
191
|
+
EOF
|
|
192
|
+
|
|
193
|
+
begin
|
|
194
|
+
require 'stringio'
|
|
195
|
+
$stderr = StringIO.new
|
|
196
|
+
assert_equal "1", inst.render
|
|
197
|
+
assert_equal warns, $stderr.string
|
|
198
|
+
ensure
|
|
199
|
+
$stderr = STDERR
|
|
200
|
+
end
|
|
141
201
|
end
|
|
142
202
|
|
|
143
203
|
class Person
|
|
@@ -164,4 +224,100 @@ class TiltTemplateTest < Test::Unit::TestCase
|
|
|
164
224
|
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{CONSTANT}!' }
|
|
165
225
|
assert_equal "Hey Bob!", inst.render(Person.new("Joe"))
|
|
166
226
|
end
|
|
227
|
+
|
|
228
|
+
##
|
|
229
|
+
# Encodings
|
|
230
|
+
|
|
231
|
+
class DynamicMockTemplate < MockTemplate
|
|
232
|
+
def precompiled_template(locals)
|
|
233
|
+
options[:code]
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
class UTF8Template < MockTemplate
|
|
238
|
+
def default_encoding
|
|
239
|
+
Encoding::UTF_8
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
if ''.respond_to?(:encoding)
|
|
244
|
+
original_encoding = Encoding.default_external
|
|
245
|
+
|
|
246
|
+
setup do
|
|
247
|
+
@file = Tempfile.open('template')
|
|
248
|
+
@file.puts "stuff"
|
|
249
|
+
@file.close
|
|
250
|
+
@template = @file.path
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
teardown do
|
|
254
|
+
Encoding.default_external = original_encoding
|
|
255
|
+
Encoding.default_internal = nil
|
|
256
|
+
@file.delete
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
test "reading from file assumes default external encoding" do
|
|
260
|
+
Encoding.default_external = 'Big5'
|
|
261
|
+
inst = MockTemplate.new(@template)
|
|
262
|
+
assert_equal 'Big5', inst.data.encoding.to_s
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
test "reading from file with a :default_encoding overrides default external" do
|
|
266
|
+
Encoding.default_external = 'Big5'
|
|
267
|
+
inst = MockTemplate.new(@template, :default_encoding => 'GBK')
|
|
268
|
+
assert_equal 'GBK', inst.data.encoding.to_s
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
test "reading from file with default_internal set does no transcoding" do
|
|
272
|
+
Encoding.default_internal = 'utf-8'
|
|
273
|
+
Encoding.default_external = 'Big5'
|
|
274
|
+
inst = MockTemplate.new(@template)
|
|
275
|
+
assert_equal 'Big5', inst.data.encoding.to_s
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
test "using provided template data verbatim when given as string" do
|
|
279
|
+
Encoding.default_internal = 'Big5'
|
|
280
|
+
inst = MockTemplate.new(@template) { "blah".force_encoding('GBK') }
|
|
281
|
+
assert_equal 'GBK', inst.data.encoding.to_s
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
test "uses the template from the generated source code" do
|
|
285
|
+
tmpl = "ふが"
|
|
286
|
+
code = tmpl.inspect.encode('Shift_JIS')
|
|
287
|
+
inst = DynamicMockTemplate.new(:code => code) { '' }
|
|
288
|
+
res = inst.render
|
|
289
|
+
assert_equal 'Shift_JIS', res.encoding.to_s
|
|
290
|
+
assert_equal tmpl, res.encode(tmpl.encoding)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
test "uses the magic comment from the generated source code" do
|
|
294
|
+
tmpl = "ふが"
|
|
295
|
+
code = ("# coding: Shift_JIS\n" + tmpl.inspect).encode('Shift_JIS')
|
|
296
|
+
# Set it to an incorrect encoding
|
|
297
|
+
code.force_encoding('UTF-8')
|
|
298
|
+
|
|
299
|
+
inst = DynamicMockTemplate.new(:code => code) { '' }
|
|
300
|
+
res = inst.render
|
|
301
|
+
assert_equal 'Shift_JIS', res.encoding.to_s
|
|
302
|
+
assert_equal tmpl, res.encode(tmpl.encoding)
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
test "uses #default_encoding instead of default_external" do
|
|
306
|
+
Encoding.default_external = 'Big5'
|
|
307
|
+
inst = UTF8Template.new(@template)
|
|
308
|
+
assert_equal 'UTF-8', inst.data.encoding.to_s
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
test "uses #default_encoding instead of current encoding" do
|
|
312
|
+
tmpl = "".force_encoding('Big5')
|
|
313
|
+
inst = UTF8Template.new(@template) { tmpl }
|
|
314
|
+
assert_equal 'UTF-8', inst.data.encoding.to_s
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
test "raises error if the encoding is not valid" do
|
|
318
|
+
assert_raises(Encoding::InvalidByteSequenceError) do
|
|
319
|
+
UTF8Template.new(@template) { "\xe4" }
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
end
|
|
167
323
|
end
|
data/tilt.gemspec
CHANGED
|
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
4
4
|
|
|
5
5
|
s.name = 'tilt'
|
|
6
|
-
s.version = '1.
|
|
7
|
-
s.date = '2013-
|
|
6
|
+
s.version = '1.4.1'
|
|
7
|
+
s.date = '2013-05-08'
|
|
8
8
|
|
|
9
9
|
s.description = "Generic interface to multiple Ruby template engines"
|
|
10
10
|
s.summary = s.description
|
|
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
|
|
16
16
|
# = MANIFEST =
|
|
17
17
|
s.files = %w[
|
|
18
|
+
CHANGELOG.md
|
|
18
19
|
COPYING
|
|
19
20
|
Gemfile
|
|
20
21
|
HACKING
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tilt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: asciidoctor
|
|
@@ -386,6 +386,7 @@ executables:
|
|
|
386
386
|
extensions: []
|
|
387
387
|
extra_rdoc_files: []
|
|
388
388
|
files:
|
|
389
|
+
- CHANGELOG.md
|
|
389
390
|
- COPYING
|
|
390
391
|
- Gemfile
|
|
391
392
|
- HACKING
|
|
@@ -481,7 +482,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
481
482
|
version: '0'
|
|
482
483
|
requirements: []
|
|
483
484
|
rubyforge_project:
|
|
484
|
-
rubygems_version: 1.8.
|
|
485
|
+
rubygems_version: 1.8.25
|
|
485
486
|
signing_key:
|
|
486
487
|
specification_version: 2
|
|
487
488
|
summary: Generic interface to multiple Ruby template engines
|
|
@@ -517,3 +518,4 @@ test_files:
|
|
|
517
518
|
- test/tilt_test.rb
|
|
518
519
|
- test/tilt_wikiclothtemplate_test.rb
|
|
519
520
|
- test/tilt_yajltemplate_test.rb
|
|
521
|
+
has_rdoc:
|