tilt 2.0.4 → 2.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69824d0f8d59718a45a289673dbbc34b6e083c83
4
- data.tar.gz: a655207744e9fa92153589e77587d8593cbbd005
3
+ metadata.gz: 736fe3309d9aab2be73d9ec2fd4d9b110d6736ac
4
+ data.tar.gz: 236969d204a43624049b69dee61983bf410b57d8
5
5
  SHA512:
6
- metadata.gz: 7c5c9bfae55c46fb9cb82e0ba9612a649d6a3283fcf8b9a1bcc20b115299f0c34619b751420b8b77c94d65e76ab53a6d88b8f83cb77c5a1abcc87088e3a5bcda
7
- data.tar.gz: ef8c85a45a30d284d8fb61b7480cc223bca9254fba2d5a026106aeb52024133f629dcab8bcf6f90606a1c211dcc41a2fa0ff6908b164f70f6325fd34dda2b5f3
6
+ metadata.gz: c30008417646c5d8273b32cb357c57635d6c34c879957f8712c2a52dac00b1915a44cb6937093eb2459c216d999a5b22aa1844381de8a94eb28610b6e24e13af
7
+ data.tar.gz: 2d4d093a48e787e69431b8e34d89ce983dd648b90820bdc393e83ba2f71015e63203031c81908ae6445dd7cc6138213bc78f9d999ad3968c6c307d9ab081b559
@@ -1,3 +1,8 @@
1
+ ## 2.0.5 (2016-06-02)
2
+
3
+ * Add support for reST using Pandoc (#284, mfenner)
4
+ * Make lazy loading thread-safe; remove warning (judofyr)
5
+
1
6
  ## 2.0.4 (2016-05-16)
2
7
 
3
8
  * Fix regression in BuilderTemplate (#283, judofyr)
data/COPYING CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Ryan Tomayko <http://tomayko.com/about>
1
+ Copyright (c) 2010-2016 Ryan Tomayko <http://tomayko.com/about>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to
data/README.md CHANGED
@@ -41,6 +41,7 @@ Support for these template engines is included with the package:
41
41
  | BlueCloth | .markdown, .mkd, .md | bluecloth | Community |
42
42
  | Kramdown | .markdown, .mkd, .md | kramdown | Community |
43
43
  | Pandoc | .markdown, .mkd, .md | pandoc | Community |
44
+ | reStructuredText | .rst | pandoc | Community |
44
45
  | Maruku | .markdown, .mkd, .md | maruku | Community |
45
46
  | CommonMarker | .markdown, .mkd, .md | commonmarker | Community |
46
47
  | RedCloth | .textile | redcloth | Community |
@@ -33,10 +33,11 @@ Tilt also includes support for CSS processors like [LessCSS][lesscss] and
33
33
  * CoffeeScript - `Tilt::CoffeeScriptTemplate`
34
34
  * Literate CoffeeScript - `Tilt::CoffeeScriptLiterateTemplate`
35
35
  * [Textile](#redcloth) - `Tilt::RedClothTemplate`
36
+ * reStructuredText - `Tilt::RstPandocTemplate`
36
37
  * Creole - `Tilt::CreoleTemplate`
37
38
  * [RDoc](#rdoc) - `Tilt::RDocTemplate`
38
39
 
39
- Tilt has extensive support for Markdown, backed by one of four different
40
+ Tilt has extensive support for Markdown, backed by one of seven different
40
41
  implementations (depending on which are available on your system):
41
42
 
42
43
  * [Markdown](#markdown) - Generic Markdown implementation
@@ -45,6 +46,7 @@ implementations (depending on which are available on your system):
45
46
  * BlueCloth - `Tilt::BlueClothTemplate`
46
47
  * Kramdown - `Tilt::KramdownTemplate`
47
48
  * Pandoc - `Tilt::PandocTemplate`
49
+ * CommonMarker - `Tilt::CommonMarkerTemplate`
48
50
  * Maruku - `Tilt::MarukuTemplate`
49
51
 
50
52
  <a name='erb'></a>
@@ -393,6 +395,31 @@ when using this template engine in a threaded environment.
393
395
 
394
396
  * [RedCloth][redcloth]
395
397
 
398
+ <a name='rst'></a>
399
+ reStructuredText (`rst`)
400
+ -------------------
401
+
402
+ reStructuredText is a lightweight markup language originally developed by David Goodger,
403
+ based on StructuredText and Setext. reStructuredText is primarily used for technical
404
+ documentation in the Python programming language community, e.g. by the
405
+ [Sphinx](http://www.sphinx-doc.org/en/stable/rest.html) Python documentation generator.
406
+
407
+ reStructuredText formatted texts are converted to HTML with [Pandoc][pandoc], which
408
+ is an application written in Haskell, with a Ruby wrapper provided by the
409
+ [pandoc-ruby][pandoc-ruby] gem.
410
+
411
+ ### Example
412
+
413
+ Hello Rst Templates
414
+ ===================
415
+
416
+ Hello World. This is a paragraph.
417
+
418
+ ### See Also
419
+
420
+ * [Pandoc][pandoc]
421
+ * [pandoc-ruby][pandoc-ruby]
422
+
396
423
 
397
424
  <a name='rdoc'></a>
398
425
  RDoc (`rdoc`)
@@ -523,3 +550,5 @@ using this template engine within a threaded environment.
523
550
  [rdiscount]: http://github.com/rtomayko/rdiscount/ "RDiscount"
524
551
  [smartypants]: http://daringfireball.net/projects/smartypants/ "Smarty Pants"
525
552
  [markdown]: http://en.wikipedia.org/wiki/Markdown "Markdown"
553
+ [pandoc]: http://pandoc.org/ "Pandoc"
554
+ [pandoc-ruby]: https://github.com/alphabetum/pandoc-ruby "pandoc-ruby"
@@ -4,7 +4,7 @@ require 'tilt/template'
4
4
  # Namespace for Tilt. This module is not intended to be included anywhere.
5
5
  module Tilt
6
6
  # Current version.
7
- VERSION = '2.0.4'
7
+ VERSION = '2.0.5'
8
8
 
9
9
  @default_mapping = Mapping.new
10
10
 
@@ -146,6 +146,7 @@ module Tilt
146
146
  register_lazy :RDocTemplate, 'tilt/rdoc', 'rdoc'
147
147
  register_lazy :RadiusTemplate, 'tilt/radius', 'radius'
148
148
  register_lazy :RedClothTemplate, 'tilt/redcloth', 'textile'
149
+ register_lazy :RstPandocTemplate, 'tilt/rst-pandoc', 'rst'
149
150
  register_lazy :SassTemplate, 'tilt/sass', 'sass'
150
151
  register_lazy :ScssTemplate, 'tilt/sass', 'scss'
151
152
  register_lazy :StringTemplate, 'tilt/string', 'str'
@@ -1,3 +1,5 @@
1
+ require 'monitor'
2
+
1
3
  module Tilt
2
4
  # Tilt::Mapping associates file extensions with template implementations.
3
5
  #
@@ -214,9 +216,14 @@ module Tilt
214
216
  @template_map[ext] || lazy_load(ext)
215
217
  end
216
218
 
219
+ LOCK = Monitor.new
220
+
217
221
  def lazy_load(pattern)
218
222
  return unless @lazy_map.has_key?(pattern)
219
223
 
224
+ LOCK.enter
225
+ entered = true
226
+
220
227
  choices = @lazy_map[pattern]
221
228
 
222
229
  # Check if a template class is already present
@@ -234,12 +241,6 @@ module Tilt
234
241
  choices.each do |class_name, file|
235
242
  begin
236
243
  require file
237
-
238
- if Thread.list.size > 1
239
- warn "WARN: tilt autoloading '#{file}' in a non thread-safe way; " +
240
- "explicit require '#{file}' suggested."
241
- end
242
-
243
244
  # It's safe to eval() here because constant_defined? will
244
245
  # raise NameError on invalid constant names
245
246
  template_class = eval(class_name)
@@ -252,6 +253,8 @@ module Tilt
252
253
  end
253
254
 
254
255
  raise first_failure if first_failure
256
+ ensure
257
+ LOCK.exit if entered
255
258
  end
256
259
 
257
260
  # This is due to a bug in JRuby (see GH issue jruby/jruby#3585)
@@ -5,45 +5,41 @@ module Tilt
5
5
  # Pandoc markdown implementation. See:
6
6
  # http://pandoc.org/
7
7
  class PandocTemplate < Template
8
- def prepare
9
- @output = PandocRuby.convert(data, options_hash, *options_array).strip
10
- end
8
+ self.default_mime_type = 'text/html'
11
9
 
12
10
  def tilt_to_pandoc_mapping
13
- { :smartypants => [:smart, true],
14
- :escape_html => [:f, 'markdown-raw_html']
11
+ { :smartypants => :smart,
12
+ :escape_html => { :f => 'markdown-raw_html' },
13
+ :commonmark => { :f => 'commonmark' },
14
+ :markdown_strict => { :f => 'markdown_strict' }
15
15
  }
16
16
  end
17
17
 
18
- def pandoc_optimised_options
19
- options.inject({}) do |hash, option|
20
- if tilt_to_pandoc_mapping.has_key?(option[0]) && option[1] === true
21
- hash[tilt_to_pandoc_mapping[option[0]][0]] = tilt_to_pandoc_mapping[option[0]][1]
18
+ # turn options hash into an array
19
+ # Map tilt options to pandoc options
20
+ # Replace hash keys with value true with symbol for key
21
+ # Remove hash keys with value false
22
+ # Leave other hash keys untouched
23
+ def pandoc_options
24
+ options.reduce([]) do |sum, (k,v)|
25
+ case v
26
+ when true
27
+ sum << (tilt_to_pandoc_mapping[k] || k)
28
+ when false
29
+ sum
22
30
  else
23
- hash[option[0]] = option[1]
31
+ sum << { k => v }
24
32
  end
25
-
26
- hash
27
- end.merge({:to => :html})
28
- end
29
-
30
- def options_array
31
- pandoc_optimised_options.map do |option|
32
- option[0] if option[1] === true
33
- end.compact
33
+ end
34
34
  end
35
35
 
36
- def options_hash
37
- pandoc_optimised_options.inject({}) do |hash, option|
38
- # next if option[1] === true
39
- # next if option[1] === false
40
- hash[option[0]] = option[1] unless option[1] === true or option[1] === false
41
- hash
42
- end
36
+ def prepare
37
+ @engine = PandocRuby.new(data, *pandoc_options)
38
+ @output = nil
43
39
  end
44
40
 
45
41
  def evaluate(scope, locals, &block)
46
- @output
42
+ @output ||= @engine.to_html.strip
47
43
  end
48
44
 
49
45
  def allows_script?
@@ -0,0 +1,18 @@
1
+ require 'tilt/template'
2
+ require 'tilt/pandoc'
3
+
4
+ module Tilt
5
+ # Pandoc reStructuredText implementation. See:
6
+ # http://pandoc.org/
7
+ # Use PandocTemplate and specify input format
8
+ class RstPandocTemplate < PandocTemplate
9
+ def tilt_to_pandoc_mapping
10
+ { :smartypants => :smart }
11
+ end
12
+
13
+ def pandoc_options
14
+ options.merge!(f: 'rst')
15
+ super
16
+ end
17
+ end
18
+ end
@@ -125,20 +125,6 @@ module Tilt
125
125
  end
126
126
  end
127
127
  end
128
-
129
- test "warns when there's multiple threads" do
130
- Thread.new do
131
- req = proc do |file|
132
- class ::MyTemplate; end
133
- end
134
-
135
- @mapping.stub :require, req do
136
- assert_output '', /autoloading 'my_template'/ do
137
- @mapping['hello.mt']
138
- end
139
- end
140
- end.join
141
- end
142
128
  end
143
129
 
144
130
  context "lazy with two template classes" do
@@ -180,9 +180,6 @@ begin
180
180
  class MarkdownPandocTest < Minitest::Test
181
181
  include MarkdownTests
182
182
  template Tilt::PandocTemplate
183
-
184
- # Doesn't support escaping
185
- undef test_escape_html_true
186
183
  end
187
184
  rescue LoadError => boom
188
185
  # It should already be warned in the main tests
@@ -9,12 +9,12 @@ begin
9
9
  class PandocTemplateTest < Minitest::Test
10
10
  test "preparing and evaluating templates on #render" do
11
11
  template = Tilt::PandocTemplate.new { |t| "# Hello World!" }
12
- assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render.strip
12
+ assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render
13
13
  end
14
14
 
15
15
  test "can be rendered more than once" do
16
16
  template = Tilt::PandocTemplate.new { |t| "# Hello World!" }
17
- 3.times { assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render.strip }
17
+ 3.times { assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render }
18
18
  end
19
19
 
20
20
  test "smartypants when :smartypants is set" do
@@ -29,12 +29,23 @@ begin
29
29
 
30
30
  # Pandoc has tons of additional markdown features (see http://pandoc.org/README.html#pandocs-markdown).
31
31
  # The test for footnotes should be seen as a general representation for all of them.
32
- test "generates footnotes" do
33
- template = Tilt::PandocTemplate.new { |t| "Here is an inline note.^[Inlines notes are cool!]" }
34
- assert_equal "<p>Here is an inline note.<a href=\"#fn1\" class=\"footnoteRef\" id=\"fnref1\"><sup>1</sup></a></p>\n<div class=\"footnotes\">\n<hr />\n<ol>\n<li id=\"fn1\"><p>Inlines notes are cool!<a href=\"#fnref1\">↩</a></p></li>\n</ol>\n</div>", template.render.strip
35
- end
36
-
32
+ # use markdown_strict => true to disable additional markdown features
37
33
  describe "passing in Pandoc options" do
34
+ test "generates footnotes" do
35
+ template = Tilt::PandocTemplate.new { |t| "Here is an inline note.^[Inlines notes are cool!]" }
36
+ assert_equal "<p>Here is an inline note.<a href=\"#fn1\" class=\"footnoteRef\" id=\"fnref1\"><sup>1</sup></a></p>\n<div class=\"footnotes\">\n<hr />\n<ol>\n<li id=\"fn1\"><p>Inlines notes are cool!<a href=\"#fnref1\">↩</a></p></li>\n</ol>\n</div>", template.render
37
+ end
38
+
39
+ test "doesn't generate footnotes with markdown_strict option" do
40
+ template = Tilt::PandocTemplate.new(:markdown_strict => true) { |t| "Here is an inline note.^[Inlines notes are cool!]" }
41
+ assert_equal "<p>Here is an inline note.^[Inlines notes are cool!]</p>", template.render
42
+ end
43
+
44
+ test "doesn't generate footnotes with commonmark option" do
45
+ template = Tilt::PandocTemplate.new(:commonmark => true) { |t| "Here is an inline note.^[Inlines notes are cool!]" }
46
+ assert_equal "<p>Here is an inline note.^[Inlines notes are cool!]</p>", template.render
47
+ end
48
+
38
49
  test "accepts arguments with values (e.g. :id_prefix => 'xyz')" do
39
50
  # Table of contents isn't on by default
40
51
  template = Tilt::PandocTemplate.new { |t| "# This is a heading" }
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+ require 'tilt'
3
+
4
+ begin
5
+ require 'tilt/rst-pandoc'
6
+
7
+ class RstPandocTemplateTest < Minitest::Test
8
+ test "is registered for '.rst' files" do
9
+ assert_equal Tilt::RstPandocTemplate, Tilt['test.rst']
10
+ end
11
+
12
+ test "compiles and evaluates the template on #render" do
13
+ template = Tilt::RstPandocTemplate.new { |t| "Hello World!\n============" }
14
+ assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render
15
+ end
16
+
17
+ test "can be rendered more than once" do
18
+ template = Tilt::RstPandocTemplate.new { |t| "Hello World!\n============" }
19
+ 3.times do
20
+ assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render
21
+ end
22
+ end
23
+
24
+ test "doens't use markdown options" do
25
+ template = Tilt::RstPandocTemplate.new(:escape_html => true) { |t| "HELLO <blink>WORLD</blink>" }
26
+ err = assert_raises(RuntimeError) { template.render }
27
+ assert_match /pandoc: unrecognized option `--escape-html/, err.message
28
+ end
29
+ end
30
+ rescue LoadError => boom
31
+ warn "Tilt::RstPandocTemplate (disabled) [#{boom}]"
32
+ end
@@ -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 = '2.0.4'
7
- s.date = '2016-05-16'
6
+ s.version = '2.0.5'
7
+ s.date = '2016-06-02'
8
8
 
9
9
  s.description = "Generic interface to multiple Ruby template engines"
10
10
  s.summary = s.description
@@ -53,6 +53,7 @@ Gem::Specification.new do |s|
53
53
  lib/tilt/rdoc.rb
54
54
  lib/tilt/redcarpet.rb
55
55
  lib/tilt/redcloth.rb
56
+ lib/tilt/rst-pandoc.rb
56
57
  lib/tilt/sass.rb
57
58
  lib/tilt/string.rb
58
59
  lib/tilt/template.rb
@@ -101,6 +102,7 @@ Gem::Specification.new do |s|
101
102
  test/tilt_rdoctemplate_test.rb
102
103
  test/tilt_redcarpettemplate_test.rb
103
104
  test/tilt_redclothtemplate_test.rb
105
+ test/tilt_rstpandoctemplate_test.rb
104
106
  test/tilt_sasstemplate_test.rb
105
107
  test/tilt_stringtemplate_test.rb
106
108
  test/tilt_template_test.rb
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tilt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-16 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generic interface to multiple Ruby template engines
14
14
  email: r@tomayko.com
@@ -55,6 +55,7 @@ files:
55
55
  - lib/tilt/rdoc.rb
56
56
  - lib/tilt/redcarpet.rb
57
57
  - lib/tilt/redcloth.rb
58
+ - lib/tilt/rst-pandoc.rb
58
59
  - lib/tilt/sass.rb
59
60
  - lib/tilt/string.rb
60
61
  - lib/tilt/template.rb
@@ -103,6 +104,7 @@ files:
103
104
  - test/tilt_rdoctemplate_test.rb
104
105
  - test/tilt_redcarpettemplate_test.rb
105
106
  - test/tilt_redclothtemplate_test.rb
107
+ - test/tilt_rstpandoctemplate_test.rb
106
108
  - test/tilt_sasstemplate_test.rb
107
109
  - test/tilt_stringtemplate_test.rb
108
110
  - test/tilt_template_test.rb
@@ -137,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
139
  version: '0'
138
140
  requirements: []
139
141
  rubyforge_project:
140
- rubygems_version: 2.2.2
142
+ rubygems_version: 2.5.1
141
143
  signing_key:
142
144
  specification_version: 2
143
145
  summary: Generic interface to multiple Ruby template engines
@@ -171,6 +173,7 @@ test_files:
171
173
  - test/tilt_rdoctemplate_test.rb
172
174
  - test/tilt_redcarpettemplate_test.rb
173
175
  - test/tilt_redclothtemplate_test.rb
176
+ - test/tilt_rstpandoctemplate_test.rb
174
177
  - test/tilt_sasstemplate_test.rb
175
178
  - test/tilt_stringtemplate_test.rb
176
179
  - test/tilt_template_test.rb