tilt 2.0.11 → 2.3.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 (50) 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 +12 -31
  13. data/lib/tilt/commonmarker.rb +47 -81
  14. data/lib/tilt/creole.rb +9 -20
  15. data/lib/tilt/csv.rb +6 -18
  16. data/lib/tilt/erb.rb +23 -21
  17. data/lib/tilt/erubi.rb +29 -6
  18. data/lib/tilt/erubis.rb +17 -11
  19. data/lib/tilt/etanni.rb +3 -2
  20. data/lib/tilt/haml.rb +73 -65
  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 +228 -109
  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 +19 -0
  30. data/lib/tilt/plain.rb +4 -15
  31. data/lib/tilt/prawn.rb +10 -25
  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 +20 -75
  36. data/lib/tilt/redcloth.rb +9 -19
  37. data/lib/tilt/rst-pandoc.rb +7 -20
  38. data/lib/tilt/sass.rb +34 -43
  39. data/lib/tilt/slim.rb +5 -0
  40. data/lib/tilt/string.rb +9 -3
  41. data/lib/tilt/template.rb +229 -82
  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 +60 -40
  46. metadata +21 -12
  47. data/lib/tilt/bluecloth.rb +0 -24
  48. data/lib/tilt/dummy.rb +0 -3
  49. data/lib/tilt/less.rb +0 -30
  50. data/lib/tilt/sigil.rb +0 -34
data/lib/tilt.rb CHANGED
@@ -1,73 +1,93 @@
1
- require 'tilt/mapping'
2
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+ require_relative 'tilt/mapping'
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.0.11'
8
+ VERSION = '2.3.0'
9
+
10
+ EMPTY_HASH = {}.freeze
11
+ private_constant :EMPTY_HASH
8
12
 
9
13
  @default_mapping = Mapping.new
10
14
 
11
- # @return [Tilt::Mapping] the main mapping object
12
- def self.default_mapping
13
- @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
+ return self if @default_mapping.is_a?(FinalizedMapping)
22
+
23
+ class << self
24
+ prepend(Module.new do
25
+ def lazy_map(*)
26
+ raise "Tilt.#{__callee__} not supported after Tilt.finalize! has been called"
27
+ end
28
+ alias register lazy_map
29
+ alias register_lazy lazy_map
30
+ alias register_pipeline lazy_map
31
+ alias prefer lazy_map
32
+ end)
33
+ end
34
+
35
+ @default_mapping = @default_mapping.finalized
36
+
37
+ freeze
14
38
  end
15
39
 
16
40
  # @private
17
41
  def self.lazy_map
18
- default_mapping.lazy_map
42
+ @default_mapping.lazy_map
19
43
  end
20
44
 
21
45
  # @see Tilt::Mapping#register
22
46
  def self.register(template_class, *extensions)
23
- default_mapping.register(template_class, *extensions)
47
+ @default_mapping.register(template_class, *extensions)
24
48
  end
25
49
 
26
50
  # @see Tilt::Mapping#register_lazy
27
51
  def self.register_lazy(class_name, file, *extensions)
28
- default_mapping.register_lazy(class_name, file, *extensions)
52
+ @default_mapping.register_lazy(class_name, file, *extensions)
29
53
  end
30
54
 
31
- # @deprecated Use {register} instead.
32
- def self.prefer(template_class, *extensions)
33
- register(template_class, *extensions)
55
+ # @see Tilt::Mapping#register_pipeline
56
+ def self.register_pipeline(ext, options=EMPTY_HASH)
57
+ @default_mapping.register_pipeline(ext, options)
34
58
  end
35
59
 
36
60
  # @see Tilt::Mapping#registered?
37
61
  def self.registered?(ext)
38
- default_mapping.registered?(ext)
62
+ @default_mapping.registered?(ext)
39
63
  end
40
64
 
41
65
  # @see Tilt::Mapping#new
42
- def self.new(file, line=nil, options={}, &block)
43
- default_mapping.new(file, line, options, &block)
66
+ def self.new(file, line=nil, options=nil, &block)
67
+ @default_mapping.new(file, line, options, &block)
44
68
  end
45
69
 
46
70
  # @see Tilt::Mapping#[]
47
71
  def self.[](file)
48
- default_mapping[file]
72
+ @default_mapping[file]
49
73
  end
50
74
 
51
75
  # @see Tilt::Mapping#template_for
52
76
  def self.template_for(file)
53
- default_mapping.template_for(file)
77
+ @default_mapping.template_for(file)
54
78
  end
55
79
 
56
80
  # @see Tilt::Mapping#templates_for
57
81
  def self.templates_for(file)
58
- default_mapping.templates_for(file)
82
+ @default_mapping.templates_for(file)
59
83
  end
60
84
 
61
- # @return the template object that is currently rendering.
62
- #
63
- # @example
64
- # tmpl = Tilt['index.erb'].new { '<%= Tilt.current_template %>' }
65
- # tmpl.render == tmpl.to_s
66
- #
67
- # @note This is currently an experimental feature and might return nil
68
- # in the future.
69
- def self.current_template
70
- Thread.current[:tilt_current_template]
85
+ class << self
86
+ # @return [Tilt::Mapping] the main mapping object
87
+ attr_reader :default_mapping
88
+
89
+ # Alias register as prefer for Tilt 1.x compatibility.
90
+ alias prefer register
71
91
  end
72
92
 
73
93
  # Extremely simple template cache implementation. Calling applications
@@ -110,7 +130,10 @@ module Tilt
110
130
  @cache = {}
111
131
  end
112
132
  end
113
-
133
+ # :nocov:
134
+ # TILT3: Remove Tilt::Cache
135
+ deprecate_constant :Cache if respond_to?(:deprecate_constant, true)
136
+ # :nocov:
114
137
 
115
138
  # Template Implementations ================================================
116
139
 
@@ -120,7 +143,6 @@ module Tilt
120
143
  register_lazy :ErubiTemplate, 'tilt/erubi', 'erb', 'rhtml', 'erubi'
121
144
 
122
145
  # Markdown
123
- register_lazy :BlueClothTemplate, 'tilt/bluecloth', 'markdown', 'mkd', 'md'
124
146
  register_lazy :MarukuTemplate, 'tilt/maruku', 'markdown', 'mkd', 'md'
125
147
  register_lazy :KramdownTemplate, 'tilt/kramdown', 'markdown', 'mkd', 'md'
126
148
  register_lazy :RDiscountTemplate, 'tilt/rdiscount', 'markdown', 'mkd', 'md'
@@ -138,9 +160,8 @@ module Tilt
138
160
  register_lazy :CreoleTemplate, 'tilt/creole', 'wiki', 'creole'
139
161
  register_lazy :EtanniTemplate, 'tilt/etanni', 'etn', 'etanni'
140
162
  register_lazy :HamlTemplate, 'tilt/haml', 'haml'
141
- register_lazy :LessTemplate, 'tilt/less', 'less'
142
163
  register_lazy :LiquidTemplate, 'tilt/liquid', 'liquid'
143
- register_lazy :LiveScriptTemplate, 'tilt/livescript','ls'
164
+ register_lazy :LiveScriptTemplate, 'tilt/livescript','ls', 'livescript'
144
165
  register_lazy :MarkabyTemplate, 'tilt/markaby', 'mab'
145
166
  register_lazy :NokogiriTemplate, 'tilt/nokogiri', 'nokogiri'
146
167
  register_lazy :PlainTemplate, 'tilt/plain', 'html'
@@ -151,17 +172,16 @@ module Tilt
151
172
  register_lazy :RstPandocTemplate, 'tilt/rst-pandoc', 'rst'
152
173
  register_lazy :SassTemplate, 'tilt/sass', 'sass'
153
174
  register_lazy :ScssTemplate, 'tilt/sass', 'scss'
154
- register_lazy :SigilTemplate, 'tilt/sigil', 'sigil'
175
+ register_lazy :SlimTemplate, 'tilt/slim', 'slim'
155
176
  register_lazy :StringTemplate, 'tilt/string', 'str'
156
177
  register_lazy :TypeScriptTemplate, 'tilt/typescript', 'ts', 'tsx'
157
178
  register_lazy :WikiClothTemplate, 'tilt/wikicloth', 'wiki', 'mediawiki', 'mw'
158
179
  register_lazy :YajlTemplate, 'tilt/yajl', 'yajl'
159
180
 
160
- # External template engines
161
- register_lazy 'Slim::Template', 'slim', 'slim'
162
- register_lazy 'Tilt::HandlebarsTemplate', 'tilt/handlebars', 'handlebars', 'hbs'
163
- register_lazy 'Tilt::OrgTemplate', 'org-ruby', 'org'
164
- register_lazy 'Tilt::EmacsOrgTemplate', 'tilt/emacs_org', 'org'
165
- register_lazy 'Opal::Processor', 'opal', 'opal', 'rb'
166
- register_lazy 'Tilt::JbuilderTemplate', 'tilt/jbuilder', 'jbuilder'
181
+ # TILT3: Remove
182
+ # Deprecated lazy loading of external template engines
183
+ register_lazy 'Tilt::HandlebarsTemplate', 'tilt/_handlebars', 'handlebars', 'hbs'
184
+ register_lazy 'Tilt::OrgTemplate', 'tilt/_org', 'org'
185
+ register_lazy 'Tilt::OrgTemplate', 'tilt/_emacs_org', 'org'
186
+ register_lazy 'Tilt::JbuilderTemplate', 'tilt/_jbuilder', 'jbuilder'
167
187
  end
metadata CHANGED
@@ -1,17 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tilt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
8
+ - Magnus Holm
9
+ - Jeremy Evans
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2022-07-22 00:00:00.000000000 Z
13
+ date: 2023-09-14 00:00:00.000000000 Z
12
14
  dependencies: []
13
15
  description: Generic interface to multiple Ruby template engines
14
- email: r@tomayko.com
16
+ email: code@jeremyevans.net
15
17
  executables:
16
18
  - tilt
17
19
  extensions: []
@@ -20,22 +22,24 @@ files:
20
22
  - COPYING
21
23
  - bin/tilt
22
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
23
29
  - lib/tilt/asciidoc.rb
24
30
  - lib/tilt/babel.rb
25
- - lib/tilt/bluecloth.rb
26
31
  - lib/tilt/builder.rb
32
+ - lib/tilt/cli.rb
27
33
  - lib/tilt/coffee.rb
28
34
  - lib/tilt/commonmarker.rb
29
35
  - lib/tilt/creole.rb
30
36
  - lib/tilt/csv.rb
31
- - lib/tilt/dummy.rb
32
37
  - lib/tilt/erb.rb
33
38
  - lib/tilt/erubi.rb
34
39
  - lib/tilt/erubis.rb
35
40
  - lib/tilt/etanni.rb
36
41
  - lib/tilt/haml.rb
37
42
  - lib/tilt/kramdown.rb
38
- - lib/tilt/less.rb
39
43
  - lib/tilt/liquid.rb
40
44
  - lib/tilt/livescript.rb
41
45
  - lib/tilt/mapping.rb
@@ -43,6 +47,7 @@ files:
43
47
  - lib/tilt/maruku.rb
44
48
  - lib/tilt/nokogiri.rb
45
49
  - lib/tilt/pandoc.rb
50
+ - lib/tilt/pipeline.rb
46
51
  - lib/tilt/plain.rb
47
52
  - lib/tilt/prawn.rb
48
53
  - lib/tilt/radius.rb
@@ -52,16 +57,20 @@ files:
52
57
  - lib/tilt/redcloth.rb
53
58
  - lib/tilt/rst-pandoc.rb
54
59
  - lib/tilt/sass.rb
55
- - lib/tilt/sigil.rb
60
+ - lib/tilt/slim.rb
56
61
  - lib/tilt/string.rb
57
62
  - lib/tilt/template.rb
58
63
  - lib/tilt/typescript.rb
59
64
  - lib/tilt/wikicloth.rb
60
65
  - lib/tilt/yajl.rb
61
- homepage: https://github.com/rtomayko/tilt/
66
+ homepage: https://github.com/jeremyevans/tilt
62
67
  licenses:
63
68
  - MIT
64
- metadata: {}
69
+ metadata:
70
+ bug_tracker_uri: https://github.com/jeremyevans/tilt/issues
71
+ changelog_uri: https://github.com/jeremyevans/tilt/blob/master/CHANGELOG.md
72
+ mailing_list_uri: https://github.com/jeremyevans/tilt/discussions
73
+ source_code_uri: https://github.com/jeremyevans/tilt
65
74
  post_install_message:
66
75
  rdoc_options:
67
76
  - "--line-numbers"
@@ -76,15 +85,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
85
  requirements:
77
86
  - - ">="
78
87
  - !ruby/object:Gem::Version
79
- version: '0'
88
+ version: '2.0'
80
89
  required_rubygems_version: !ruby/object:Gem::Requirement
81
90
  requirements:
82
91
  - - ">="
83
92
  - !ruby/object:Gem::Version
84
93
  version: '0'
85
94
  requirements: []
86
- rubygems_version: 3.2.29
95
+ rubygems_version: 3.4.10
87
96
  signing_key:
88
- specification_version: 2
97
+ specification_version: 4
89
98
  summary: Generic interface to multiple Ruby template engines
90
99
  test_files: []
@@ -1,24 +0,0 @@
1
- require 'tilt/template'
2
- require 'bluecloth'
3
-
4
- module Tilt
5
- # BlueCloth Markdown implementation. See:
6
- # http://deveiate.org/projects/BlueCloth/
7
- class BlueClothTemplate < Template
8
- self.default_mime_type = 'text/html'
9
-
10
- def prepare
11
- @engine = BlueCloth.new(data, options)
12
- @output = nil
13
- end
14
-
15
- def evaluate(scope, locals, &block)
16
- @output ||= @engine.to_html
17
- end
18
-
19
- def allows_script?
20
- false
21
- end
22
- end
23
- end
24
-
data/lib/tilt/dummy.rb DELETED
@@ -1,3 +0,0 @@
1
- # Used for detecting autoloading bug in JRuby
2
- class Tilt::Dummy; end
3
-
data/lib/tilt/less.rb DELETED
@@ -1,30 +0,0 @@
1
- require 'tilt/template'
2
- require 'less'
3
-
4
- module Tilt
5
- # Lessscss template implementation. See:
6
- # http://lesscss.org/
7
- #
8
- # Less templates do not support object scopes, locals, or yield.
9
- class LessTemplate < Template
10
- self.default_mime_type = 'text/css'
11
-
12
- def prepare
13
- if ::Less.const_defined? :Engine
14
- @engine = ::Less::Engine.new(data)
15
- else
16
- parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line)
17
- @engine = parser.parse(data)
18
- end
19
- end
20
-
21
- def evaluate(scope, locals, &block)
22
- @output ||= @engine.to_css(options)
23
- end
24
-
25
- def allows_script?
26
- false
27
- end
28
- end
29
- end
30
-
data/lib/tilt/sigil.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'open3'
2
- require 'shellwords'
3
-
4
- module Tilt
5
- # Standalone string interpolator and template processor implementation in Go.
6
- # see: https://github.com/gliderlabs/sigil
7
- class SigilTemplate < Template
8
- def prepare
9
- end
10
-
11
- def evaluate(scope, locals, &block)
12
- variables = locals.map {|k, v| "#{k}=#{v}" }
13
-
14
- cmd = ['sigil']
15
-
16
- unless variables.empty?
17
- cmd << '-p'
18
- cmd.concat(variables)
19
- end
20
-
21
- out, err, status = Open3.capture3(*cmd, :stdin_data => data)
22
-
23
- if status.success?
24
- out.chomp
25
- else
26
- raise err.chomp.gsub('<stdin>', file)
27
- end
28
- end
29
-
30
- def allows_script?
31
- false
32
- end
33
- end
34
- end