tilt 2.1.0 → 2.2.0

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +1 -0
  3. data/bin/tilt +2 -120
  4. data/lib/tilt/_emacs_org.rb +2 -0
  5. data/lib/tilt/_handlebars.rb +2 -0
  6. data/lib/tilt/_jbuilder.rb +2 -0
  7. data/lib/tilt/_org.rb +2 -0
  8. data/lib/tilt/asciidoc.rb +11 -23
  9. data/lib/tilt/babel.rb +5 -13
  10. data/lib/tilt/builder.rb +18 -13
  11. data/lib/tilt/cli.rb +134 -0
  12. data/lib/tilt/coffee.rb +18 -25
  13. data/lib/tilt/commonmarker.rb +47 -81
  14. data/lib/tilt/creole.rb +9 -20
  15. data/lib/tilt/csv.rb +5 -4
  16. data/lib/tilt/erb.rb +18 -12
  17. data/lib/tilt/erubi.rb +7 -6
  18. data/lib/tilt/erubis.rb +12 -6
  19. data/lib/tilt/etanni.rb +3 -2
  20. data/lib/tilt/haml.rb +12 -9
  21. data/lib/tilt/kramdown.rb +8 -20
  22. data/lib/tilt/liquid.rb +10 -14
  23. data/lib/tilt/livescript.rb +8 -20
  24. data/lib/tilt/mapping.rb +180 -104
  25. data/lib/tilt/markaby.rb +5 -7
  26. data/lib/tilt/maruku.rb +5 -19
  27. data/lib/tilt/nokogiri.rb +11 -10
  28. data/lib/tilt/pandoc.rb +33 -51
  29. data/lib/tilt/pipeline.rb +1 -0
  30. data/lib/tilt/plain.rb +4 -15
  31. data/lib/tilt/prawn.rb +15 -23
  32. data/lib/tilt/radius.rb +15 -22
  33. data/lib/tilt/rdiscount.rb +17 -33
  34. data/lib/tilt/rdoc.rb +14 -35
  35. data/lib/tilt/redcarpet.rb +25 -67
  36. data/lib/tilt/redcloth.rb +9 -19
  37. data/lib/tilt/rst-pandoc.rb +6 -19
  38. data/lib/tilt/sass.rb +34 -43
  39. data/lib/tilt/slim.rb +5 -0
  40. data/lib/tilt/string.rb +4 -3
  41. data/lib/tilt/template.rb +146 -56
  42. data/lib/tilt/typescript.rb +11 -18
  43. data/lib/tilt/wikicloth.rb +7 -19
  44. data/lib/tilt/yajl.rb +5 -11
  45. data/lib/tilt.rb +57 -30
  46. metadata +10 -7
  47. data/lib/tilt/bluecloth.rb +0 -26
  48. data/lib/tilt/less.rb +0 -32
  49. data/lib/tilt/sigil.rb +0 -36
data/lib/tilt.rb CHANGED
@@ -1,66 +1,83 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'tilt/mapping'
2
3
  require_relative 'tilt/template'
3
4
 
4
5
  # Namespace for Tilt. This module is not intended to be included anywhere.
5
6
  module Tilt
6
7
  # Current version.
7
- VERSION = '2.1.0'
8
+ VERSION = '2.2.0'
9
+
10
+ EMPTY_HASH = {}.freeze
11
+ private_constant :EMPTY_HASH
8
12
 
9
13
  @default_mapping = Mapping.new
10
14
 
11
- class << self
12
- # @return [Tilt::Mapping] the main mapping object
13
- attr_reader :default_mapping
15
+ # Replace the default mapping with a finalized version of the default
16
+ # mapping. This can be done to improve performance after the template
17
+ # libraries you desire to use have already been loaded. Once this is
18
+ # is called, all attempts to modify the default mapping will fail.
19
+ # This also freezes Tilt itself.
20
+ def self.finalize!
21
+ class << self
22
+ prepend(Module.new do
23
+ def lazy_map(*)
24
+ raise "Tilt.#{__callee__} not supported after Tilt.finalize! has been called"
25
+ end
26
+ alias register lazy_map
27
+ alias register_lazy lazy_map
28
+ alias register_pipeline lazy_map
29
+ alias prefer lazy_map
30
+ end)
31
+ end
32
+
33
+ @default_mapping = @default_mapping.finalized
34
+
35
+ freeze
14
36
  end
15
37
 
16
38
  # @private
17
39
  def self.lazy_map
18
- default_mapping.lazy_map
40
+ @default_mapping.lazy_map
19
41
  end
20
42
 
21
43
  # @see Tilt::Mapping#register
22
44
  def self.register(template_class, *extensions)
23
- default_mapping.register(template_class, *extensions)
45
+ @default_mapping.register(template_class, *extensions)
24
46
  end
25
47
 
26
48
  # @see Tilt::Mapping#register_lazy
27
49
  def self.register_lazy(class_name, file, *extensions)
28
- default_mapping.register_lazy(class_name, file, *extensions)
50
+ @default_mapping.register_lazy(class_name, file, *extensions)
29
51
  end
30
52
 
31
53
  # @see Tilt::Mapping#register_pipeline
32
- def self.register_pipeline(ext, options={})
33
- default_mapping.register_pipeline(ext, options)
34
- end
35
-
36
- # @deprecated Use {register} instead.
37
- def self.prefer(template_class, *extensions)
38
- register(template_class, *extensions)
54
+ def self.register_pipeline(ext, options=EMPTY_HASH)
55
+ @default_mapping.register_pipeline(ext, options)
39
56
  end
40
57
 
41
58
  # @see Tilt::Mapping#registered?
42
59
  def self.registered?(ext)
43
- default_mapping.registered?(ext)
60
+ @default_mapping.registered?(ext)
44
61
  end
45
62
 
46
63
  # @see Tilt::Mapping#new
47
- def self.new(file, line=nil, options={}, &block)
48
- default_mapping.new(file, line, options, &block)
64
+ def self.new(file, line=nil, options=nil, &block)
65
+ @default_mapping.new(file, line, options, &block)
49
66
  end
50
67
 
51
68
  # @see Tilt::Mapping#[]
52
69
  def self.[](file)
53
- default_mapping[file]
70
+ @default_mapping[file]
54
71
  end
55
72
 
56
73
  # @see Tilt::Mapping#template_for
57
74
  def self.template_for(file)
58
- default_mapping.template_for(file)
75
+ @default_mapping.template_for(file)
59
76
  end
60
77
 
61
78
  # @see Tilt::Mapping#templates_for
62
79
  def self.templates_for(file)
63
- default_mapping.templates_for(file)
80
+ @default_mapping.templates_for(file)
64
81
  end
65
82
 
66
83
  # @return the template object that is currently rendering.
@@ -72,9 +89,18 @@ module Tilt
72
89
  # @note This is currently an experimental feature and might return nil
73
90
  # in the future.
74
91
  def self.current_template
92
+ warn "Tilt.current_template is deprecated and will be removed in Tilt 2.3", uplevel: 1
75
93
  Thread.current[:tilt_current_template]
76
94
  end
77
95
 
96
+ class << self
97
+ # @return [Tilt::Mapping] the main mapping object
98
+ attr_reader :default_mapping
99
+
100
+ # Alias register as prefer for Tilt 1.x compatibility.
101
+ alias prefer register
102
+ end
103
+
78
104
  # Extremely simple template cache implementation. Calling applications
79
105
  # create a Tilt::Cache instance and use #fetch with any set of hashable
80
106
  # arguments (such as those to Tilt.new):
@@ -115,7 +141,10 @@ module Tilt
115
141
  @cache = {}
116
142
  end
117
143
  end
118
-
144
+ # :nocov:
145
+ # TILT3: Remove Tilt::Cache
146
+ deprecate_constant :Cache if respond_to?(:deprecate_constant, true)
147
+ # :nocov:
119
148
 
120
149
  # Template Implementations ================================================
121
150
 
@@ -125,7 +154,6 @@ module Tilt
125
154
  register_lazy :ErubiTemplate, 'tilt/erubi', 'erb', 'rhtml', 'erubi'
126
155
 
127
156
  # Markdown
128
- register_lazy :BlueClothTemplate, 'tilt/bluecloth', 'markdown', 'mkd', 'md'
129
157
  register_lazy :MarukuTemplate, 'tilt/maruku', 'markdown', 'mkd', 'md'
130
158
  register_lazy :KramdownTemplate, 'tilt/kramdown', 'markdown', 'mkd', 'md'
131
159
  register_lazy :RDiscountTemplate, 'tilt/rdiscount', 'markdown', 'mkd', 'md'
@@ -143,7 +171,6 @@ module Tilt
143
171
  register_lazy :CreoleTemplate, 'tilt/creole', 'wiki', 'creole'
144
172
  register_lazy :EtanniTemplate, 'tilt/etanni', 'etn', 'etanni'
145
173
  register_lazy :HamlTemplate, 'tilt/haml', 'haml'
146
- register_lazy :LessTemplate, 'tilt/less', 'less'
147
174
  register_lazy :LiquidTemplate, 'tilt/liquid', 'liquid'
148
175
  register_lazy :LiveScriptTemplate, 'tilt/livescript','ls', 'livescript'
149
176
  register_lazy :MarkabyTemplate, 'tilt/markaby', 'mab'
@@ -156,16 +183,16 @@ module Tilt
156
183
  register_lazy :RstPandocTemplate, 'tilt/rst-pandoc', 'rst'
157
184
  register_lazy :SassTemplate, 'tilt/sass', 'sass'
158
185
  register_lazy :ScssTemplate, 'tilt/sass', 'scss'
159
- register_lazy :SigilTemplate, 'tilt/sigil', 'sigil'
186
+ register_lazy :SlimTemplate, 'tilt/slim', 'slim'
160
187
  register_lazy :StringTemplate, 'tilt/string', 'str'
161
188
  register_lazy :TypeScriptTemplate, 'tilt/typescript', 'ts', 'tsx'
162
189
  register_lazy :WikiClothTemplate, 'tilt/wikicloth', 'wiki', 'mediawiki', 'mw'
163
190
  register_lazy :YajlTemplate, 'tilt/yajl', 'yajl'
164
191
 
165
- # External template engines
166
- register_lazy 'Slim::Template', 'slim', 'slim'
167
- register_lazy 'Tilt::HandlebarsTemplate', 'tilt/handlebars', 'handlebars', 'hbs'
168
- register_lazy 'Tilt::OrgTemplate', 'org-ruby', 'org'
169
- register_lazy 'Tilt::EmacsOrgTemplate', 'tilt/emacs_org', 'org'
170
- register_lazy 'Tilt::JbuilderTemplate', 'tilt/jbuilder', 'jbuilder'
192
+ # TILT3: Remove
193
+ # Deprecated lazy loading of external template engines
194
+ register_lazy 'Tilt::HandlebarsTemplate', 'tilt/_handlebars', 'handlebars', 'hbs'
195
+ register_lazy 'Tilt::OrgTemplate', 'tilt/_org', 'org'
196
+ register_lazy 'Tilt::OrgTemplate', 'tilt/_emacs_org', 'org'
197
+ register_lazy 'Tilt::JbuilderTemplate', 'tilt/_jbuilder', 'jbuilder'
171
198
  end
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: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -10,10 +10,10 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-02-17 00:00:00.000000000 Z
13
+ date: 2023-06-05 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Generic interface to multiple Ruby template engines
16
- email: r@tomayko.com
16
+ email: code@jeremyevans.net
17
17
  executables:
18
18
  - tilt
19
19
  extensions: []
@@ -22,10 +22,14 @@ files:
22
22
  - COPYING
23
23
  - bin/tilt
24
24
  - lib/tilt.rb
25
+ - lib/tilt/_emacs_org.rb
26
+ - lib/tilt/_handlebars.rb
27
+ - lib/tilt/_jbuilder.rb
28
+ - lib/tilt/_org.rb
25
29
  - lib/tilt/asciidoc.rb
26
30
  - lib/tilt/babel.rb
27
- - lib/tilt/bluecloth.rb
28
31
  - lib/tilt/builder.rb
32
+ - lib/tilt/cli.rb
29
33
  - lib/tilt/coffee.rb
30
34
  - lib/tilt/commonmarker.rb
31
35
  - lib/tilt/creole.rb
@@ -36,7 +40,6 @@ files:
36
40
  - lib/tilt/etanni.rb
37
41
  - lib/tilt/haml.rb
38
42
  - lib/tilt/kramdown.rb
39
- - lib/tilt/less.rb
40
43
  - lib/tilt/liquid.rb
41
44
  - lib/tilt/livescript.rb
42
45
  - lib/tilt/mapping.rb
@@ -54,7 +57,7 @@ files:
54
57
  - lib/tilt/redcloth.rb
55
58
  - lib/tilt/rst-pandoc.rb
56
59
  - lib/tilt/sass.rb
57
- - lib/tilt/sigil.rb
60
+ - lib/tilt/slim.rb
58
61
  - lib/tilt/string.rb
59
62
  - lib/tilt/template.rb
60
63
  - lib/tilt/typescript.rb
@@ -89,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
92
  - !ruby/object:Gem::Version
90
93
  version: '0'
91
94
  requirements: []
92
- rubygems_version: 3.4.6
95
+ rubygems_version: 3.4.10
93
96
  signing_key:
94
97
  specification_version: 4
95
98
  summary: Generic interface to multiple Ruby template engines
@@ -1,26 +0,0 @@
1
- require 'tilt/template'
2
- require 'bluecloth'
3
-
4
- warn "Tilt::BlueClothTemplate is deprecated, please switch to a different markdown implementation"
5
-
6
- module Tilt
7
- # BlueCloth Markdown implementation. See:
8
- # http://deveiate.org/projects/BlueCloth/
9
- class BlueClothTemplate < Template
10
- self.default_mime_type = 'text/html'
11
-
12
- def prepare
13
- @engine = BlueCloth.new(data, options)
14
- @output = nil
15
- end
16
-
17
- def evaluate(scope, locals, &block)
18
- @output ||= @engine.to_html
19
- end
20
-
21
- def allows_script?
22
- false
23
- end
24
- end
25
- end
26
-
data/lib/tilt/less.rb DELETED
@@ -1,32 +0,0 @@
1
- require 'tilt/template'
2
- require 'less'
3
-
4
- warn "Tilt::LessTemplate is deprecated, consider switching from LESS to SCSS"
5
-
6
- module Tilt
7
- # Lessscss template implementation. See:
8
- # http://lesscss.org/
9
- #
10
- # Less templates do not support object scopes, locals, or yield.
11
- class LessTemplate < Template
12
- self.default_mime_type = 'text/css'
13
-
14
- def prepare
15
- if ::Less.const_defined? :Engine
16
- @engine = ::Less::Engine.new(data)
17
- else
18
- parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line)
19
- @engine = parser.parse(data)
20
- end
21
- end
22
-
23
- def evaluate(scope, locals, &block)
24
- @output ||= @engine.to_css(options)
25
- end
26
-
27
- def allows_script?
28
- false
29
- end
30
- end
31
- end
32
-
data/lib/tilt/sigil.rb DELETED
@@ -1,36 +0,0 @@
1
- require 'open3'
2
- require 'shellwords'
3
-
4
- warn "Tilt::SigilTemplate is deprecated"
5
-
6
- module Tilt
7
- # Standalone string interpolator and template processor implementation in Go.
8
- # see: https://github.com/gliderlabs/sigil
9
- class SigilTemplate < Template
10
- def prepare
11
- end
12
-
13
- def evaluate(scope, locals, &block)
14
- variables = locals.map {|k, v| "#{k}=#{v}" }
15
-
16
- cmd = ['sigil']
17
-
18
- unless variables.empty?
19
- cmd << '-p'
20
- cmd.concat(variables)
21
- end
22
-
23
- out, err, status = Open3.capture3(*cmd, :stdin_data => data)
24
-
25
- if status.success?
26
- out.chomp
27
- else
28
- raise err.chomp.gsub('<stdin>', file)
29
- end
30
- end
31
-
32
- def allows_script?
33
- false
34
- end
35
- end
36
- end