tilt 1.4.1 → 2.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +1 -1
- data/bin/tilt +18 -8
- data/lib/tilt/asciidoc.rb +1 -8
- data/lib/tilt/babel.rb +16 -0
- data/lib/tilt/bluecloth.rb +24 -0
- data/lib/tilt/builder.rb +12 -15
- data/lib/tilt/coffee.rb +10 -6
- data/lib/tilt/commonmarker.rb +88 -0
- data/lib/tilt/creole.rb +25 -0
- data/lib/tilt/csv.rb +12 -18
- data/lib/tilt/dummy.rb +3 -0
- data/lib/tilt/erb.rb +9 -56
- data/lib/tilt/erubi.rb +32 -0
- data/lib/tilt/erubis.rb +43 -0
- data/lib/tilt/haml.rb +66 -44
- data/lib/tilt/kramdown.rb +25 -0
- data/lib/tilt/less.rb +30 -0
- data/lib/tilt/liquid.rb +9 -10
- data/lib/tilt/livescript.rb +23 -0
- data/lib/tilt/mapping.rb +293 -0
- data/lib/tilt/markaby.rb +1 -8
- data/lib/tilt/maruku.rb +22 -0
- data/lib/tilt/nokogiri.rb +1 -8
- data/lib/tilt/pandoc.rb +57 -0
- data/lib/tilt/plain.rb +0 -4
- data/lib/tilt/prawn.rb +43 -0
- data/lib/tilt/radius.rb +1 -8
- data/lib/tilt/rdiscount.rb +39 -0
- data/lib/tilt/rdoc.rb +3 -10
- data/lib/tilt/redcarpet.rb +86 -0
- data/lib/tilt/{textile.rb → redcloth.rb} +1 -8
- data/lib/tilt/rst-pandoc.rb +23 -0
- data/lib/tilt/sass.rb +78 -0
- data/lib/tilt/sigil.rb +34 -0
- data/lib/tilt/string.rb +1 -1
- data/lib/tilt/template.rb +121 -105
- data/lib/tilt/typescript.rb +26 -0
- data/lib/tilt/wikicloth.rb +22 -0
- data/lib/tilt/yajl.rb +1 -8
- data/lib/tilt.rb +118 -155
- metadata +38 -469
- data/CHANGELOG.md +0 -44
- data/Gemfile +0 -32
- data/HACKING +0 -16
- data/README.md +0 -232
- data/Rakefile +0 -104
- data/TEMPLATES.md +0 -516
- data/lib/tilt/css.rb +0 -80
- data/lib/tilt/markdown.rb +0 -214
- data/lib/tilt/wiki.rb +0 -58
- data/test/contest.rb +0 -68
- data/test/markaby/locals.mab +0 -1
- data/test/markaby/markaby.mab +0 -1
- data/test/markaby/markaby_other_static.mab +0 -1
- data/test/markaby/render_twice.mab +0 -1
- data/test/markaby/scope.mab +0 -1
- data/test/markaby/yielding.mab +0 -2
- data/test/tilt_asciidoctor_test.rb +0 -44
- data/test/tilt_blueclothtemplate_test.rb +0 -45
- data/test/tilt_buildertemplate_test.rb +0 -59
- data/test/tilt_cache_test.rb +0 -32
- data/test/tilt_coffeescripttemplate_test.rb +0 -114
- data/test/tilt_compilesite_test.rb +0 -51
- data/test/tilt_creoletemplate_test.rb +0 -28
- data/test/tilt_csv_test.rb +0 -69
- data/test/tilt_erbtemplate_test.rb +0 -239
- data/test/tilt_erubistemplate_test.rb +0 -151
- data/test/tilt_etannitemplate_test.rb +0 -173
- data/test/tilt_fallback_test.rb +0 -122
- data/test/tilt_hamltemplate_test.rb +0 -144
- data/test/tilt_kramdown_test.rb +0 -42
- data/test/tilt_lesstemplate_test.less +0 -1
- data/test/tilt_lesstemplate_test.rb +0 -42
- data/test/tilt_liquidtemplate_test.rb +0 -78
- data/test/tilt_markaby_test.rb +0 -88
- data/test/tilt_markdown_test.rb +0 -172
- data/test/tilt_marukutemplate_test.rb +0 -48
- data/test/tilt_nokogiritemplate_test.rb +0 -87
- data/test/tilt_radiustemplate_test.rb +0 -75
- data/test/tilt_rdiscounttemplate_test.rb +0 -55
- data/test/tilt_rdoctemplate_test.rb +0 -31
- data/test/tilt_redcarpettemplate_test.rb +0 -71
- data/test/tilt_redclothtemplate_test.rb +0 -36
- data/test/tilt_sasstemplate_test.rb +0 -41
- data/test/tilt_stringtemplate_test.rb +0 -170
- data/test/tilt_template_test.rb +0 -323
- data/test/tilt_test.rb +0 -65
- data/test/tilt_wikiclothtemplate_test.rb +0 -32
- data/test/tilt_yajltemplate_test.rb +0 -101
- data/tilt.gemspec +0 -120
data/lib/tilt.rb
CHANGED
@@ -1,132 +1,111 @@
|
|
1
|
+
require 'tilt/mapping'
|
2
|
+
require 'tilt/template'
|
3
|
+
|
4
|
+
# Namespace for Tilt. This module is not intended to be included anywhere.
|
1
5
|
module Tilt
|
2
|
-
|
6
|
+
# Current version.
|
7
|
+
VERSION = '2.0.11'
|
3
8
|
|
4
|
-
@
|
5
|
-
@template_mappings = Hash.new { |h, k| h[k] = [] }
|
9
|
+
@default_mapping = Mapping.new
|
6
10
|
|
7
|
-
#
|
8
|
-
def self.
|
9
|
-
@
|
11
|
+
# @return [Tilt::Mapping] the main mapping object
|
12
|
+
def self.default_mapping
|
13
|
+
@default_mapping
|
10
14
|
end
|
11
15
|
|
12
|
-
|
13
|
-
|
16
|
+
# @private
|
17
|
+
def self.lazy_map
|
18
|
+
default_mapping.lazy_map
|
14
19
|
end
|
15
20
|
|
16
|
-
#
|
21
|
+
# @see Tilt::Mapping#register
|
17
22
|
def self.register(template_class, *extensions)
|
18
|
-
|
19
|
-
|
20
|
-
extensions, template_class = [template_class], extensions[0]
|
21
|
-
end
|
23
|
+
default_mapping.register(template_class, *extensions)
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
26
|
+
# @see Tilt::Mapping#register_lazy
|
27
|
+
def self.register_lazy(class_name, file, *extensions)
|
28
|
+
default_mapping.register_lazy(class_name, file, *extensions)
|
27
29
|
end
|
28
30
|
|
29
|
-
#
|
30
|
-
# don't provide any extensions, it will be preferred for all its already
|
31
|
-
# registered extensions:
|
32
|
-
#
|
33
|
-
# # Prefer RDiscount for its registered file extensions:
|
34
|
-
# Tilt.prefer(Tilt::RDiscountTemplate)
|
35
|
-
#
|
36
|
-
# # Prefer RDiscount only for the .md extensions:
|
37
|
-
# Tilt.prefer(Tilt::RDiscountTemplate, '.md')
|
31
|
+
# @deprecated Use {register} instead.
|
38
32
|
def self.prefer(template_class, *extensions)
|
39
|
-
|
40
|
-
mappings.each do |ext, klasses|
|
41
|
-
@preferred_mappings[ext] = template_class if klasses.include? template_class
|
42
|
-
end
|
43
|
-
else
|
44
|
-
extensions.each do |ext|
|
45
|
-
ext = normalize(ext)
|
46
|
-
register(template_class, ext)
|
47
|
-
@preferred_mappings[ext] = template_class
|
48
|
-
end
|
49
|
-
end
|
33
|
+
register(template_class, *extensions)
|
50
34
|
end
|
51
35
|
|
52
|
-
#
|
36
|
+
# @see Tilt::Mapping#registered?
|
53
37
|
def self.registered?(ext)
|
54
|
-
|
38
|
+
default_mapping.registered?(ext)
|
55
39
|
end
|
56
40
|
|
57
|
-
#
|
58
|
-
# to determine the the template mapping.
|
41
|
+
# @see Tilt::Mapping#new
|
59
42
|
def self.new(file, line=nil, options={}, &block)
|
60
|
-
|
61
|
-
template_class.new(file, line, options, &block)
|
62
|
-
else
|
63
|
-
fail "No template engine registered for #{File.basename(file)}"
|
64
|
-
end
|
43
|
+
default_mapping.new(file, line, options, &block)
|
65
44
|
end
|
66
45
|
|
67
|
-
#
|
68
|
-
# extension. Return nil when no implementation is found.
|
46
|
+
# @see Tilt::Mapping#[]
|
69
47
|
def self.[](file)
|
70
|
-
|
71
|
-
|
72
|
-
pattern = File.basename(pattern)
|
73
|
-
pattern.sub!(/^[^.]*\.?/, '')
|
74
|
-
end
|
75
|
-
|
76
|
-
# Try to find a preferred engine.
|
77
|
-
preferred_klass = @preferred_mappings[pattern]
|
78
|
-
return preferred_klass if preferred_klass
|
79
|
-
|
80
|
-
# Fall back to the general list of mappings.
|
81
|
-
klasses = @template_mappings[pattern]
|
82
|
-
|
83
|
-
# Try to find an engine which is already loaded.
|
84
|
-
template = klasses.detect do |klass|
|
85
|
-
if klass.respond_to?(:engine_initialized?)
|
86
|
-
klass.engine_initialized?
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
return template if template
|
91
|
-
|
92
|
-
# Try each of the classes until one succeeds. If all of them fails,
|
93
|
-
# we'll raise the error of the first class.
|
94
|
-
first_failure = nil
|
48
|
+
default_mapping[file]
|
49
|
+
end
|
95
50
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
first_failure ||= ex
|
101
|
-
next
|
102
|
-
else
|
103
|
-
return klass
|
104
|
-
end
|
105
|
-
end
|
51
|
+
# @see Tilt::Mapping#template_for
|
52
|
+
def self.template_for(file)
|
53
|
+
default_mapping.template_for(file)
|
54
|
+
end
|
106
55
|
|
107
|
-
|
56
|
+
# @see Tilt::Mapping#templates_for
|
57
|
+
def self.templates_for(file)
|
58
|
+
default_mapping.templates_for(file)
|
108
59
|
end
|
109
60
|
|
110
|
-
#
|
111
|
-
|
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]
|
112
71
|
end
|
113
72
|
|
114
73
|
# Extremely simple template cache implementation. Calling applications
|
115
74
|
# create a Tilt::Cache instance and use #fetch with any set of hashable
|
116
75
|
# arguments (such as those to Tilt.new):
|
117
|
-
#
|
118
|
-
#
|
76
|
+
#
|
77
|
+
# cache = Tilt::Cache.new
|
78
|
+
# cache.fetch(path, line, options) { Tilt.new(path, line, options) }
|
119
79
|
#
|
120
80
|
# Subsequent invocations return the already loaded template object.
|
81
|
+
#
|
82
|
+
# @note
|
83
|
+
# Tilt::Cache is a thin wrapper around Hash. It has the following
|
84
|
+
# limitations:
|
85
|
+
# * Not thread-safe.
|
86
|
+
# * Size is unbounded.
|
87
|
+
# * Keys are not copied defensively, and should not be modified after
|
88
|
+
# being passed to #fetch. More specifically, the values returned by
|
89
|
+
# key#hash and key#eql? should not change.
|
90
|
+
# If this is too limiting for you, use a different cache implementation.
|
121
91
|
class Cache
|
122
92
|
def initialize
|
123
93
|
@cache = {}
|
124
94
|
end
|
125
95
|
|
96
|
+
# Caches a value for key, or returns the previously cached value.
|
97
|
+
# If a value has been previously cached for key then it is
|
98
|
+
# returned. Otherwise, block is yielded to and its return value
|
99
|
+
# which may be nil, is cached under key and returned.
|
100
|
+
# @yield
|
101
|
+
# @yieldreturn the value to cache for key
|
126
102
|
def fetch(*key)
|
127
|
-
@cache
|
103
|
+
@cache.fetch(key) do
|
104
|
+
@cache[key] = yield
|
105
|
+
end
|
128
106
|
end
|
129
107
|
|
108
|
+
# Clears the cache.
|
130
109
|
def clear
|
131
110
|
@cache = {}
|
132
111
|
end
|
@@ -135,70 +114,54 @@ module Tilt
|
|
135
114
|
|
136
115
|
# Template Implementations ================================================
|
137
116
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
require 'tilt/rdoc'
|
190
|
-
register RDocTemplate, 'rdoc'
|
191
|
-
|
192
|
-
require 'tilt/wiki'
|
193
|
-
register CreoleTemplate, 'wiki', 'creole'
|
194
|
-
register WikiClothTemplate, 'wiki', 'mediawiki', 'mw'
|
195
|
-
|
196
|
-
require 'tilt/yajl'
|
197
|
-
register YajlTemplate, 'yajl'
|
198
|
-
|
199
|
-
require 'tilt/asciidoc'
|
200
|
-
register AsciidoctorTemplate, 'ad', 'adoc', 'asciidoc'
|
201
|
-
|
202
|
-
require 'tilt/plain'
|
203
|
-
register PlainTemplate, 'html'
|
117
|
+
# ERB
|
118
|
+
register_lazy :ERBTemplate, 'tilt/erb', 'erb', 'rhtml'
|
119
|
+
register_lazy :ErubisTemplate, 'tilt/erubis', 'erb', 'rhtml', 'erubis'
|
120
|
+
register_lazy :ErubiTemplate, 'tilt/erubi', 'erb', 'rhtml', 'erubi'
|
121
|
+
|
122
|
+
# Markdown
|
123
|
+
register_lazy :BlueClothTemplate, 'tilt/bluecloth', 'markdown', 'mkd', 'md'
|
124
|
+
register_lazy :MarukuTemplate, 'tilt/maruku', 'markdown', 'mkd', 'md'
|
125
|
+
register_lazy :KramdownTemplate, 'tilt/kramdown', 'markdown', 'mkd', 'md'
|
126
|
+
register_lazy :RDiscountTemplate, 'tilt/rdiscount', 'markdown', 'mkd', 'md'
|
127
|
+
register_lazy :RedcarpetTemplate, 'tilt/redcarpet', 'markdown', 'mkd', 'md'
|
128
|
+
register_lazy :CommonMarkerTemplate, 'tilt/commonmarker', 'markdown', 'mkd', 'md'
|
129
|
+
register_lazy :PandocTemplate, 'tilt/pandoc', 'markdown', 'mkd', 'md'
|
130
|
+
|
131
|
+
# Rest (sorted by name)
|
132
|
+
register_lazy :AsciidoctorTemplate, 'tilt/asciidoc', 'ad', 'adoc', 'asciidoc'
|
133
|
+
register_lazy :BabelTemplate, 'tilt/babel', 'es6', 'babel', 'jsx'
|
134
|
+
register_lazy :BuilderTemplate, 'tilt/builder', 'builder'
|
135
|
+
register_lazy :CSVTemplate, 'tilt/csv', 'rcsv'
|
136
|
+
register_lazy :CoffeeScriptTemplate, 'tilt/coffee', 'coffee'
|
137
|
+
register_lazy :CoffeeScriptLiterateTemplate, 'tilt/coffee', 'litcoffee'
|
138
|
+
register_lazy :CreoleTemplate, 'tilt/creole', 'wiki', 'creole'
|
139
|
+
register_lazy :EtanniTemplate, 'tilt/etanni', 'etn', 'etanni'
|
140
|
+
register_lazy :HamlTemplate, 'tilt/haml', 'haml'
|
141
|
+
register_lazy :LessTemplate, 'tilt/less', 'less'
|
142
|
+
register_lazy :LiquidTemplate, 'tilt/liquid', 'liquid'
|
143
|
+
register_lazy :LiveScriptTemplate, 'tilt/livescript','ls'
|
144
|
+
register_lazy :MarkabyTemplate, 'tilt/markaby', 'mab'
|
145
|
+
register_lazy :NokogiriTemplate, 'tilt/nokogiri', 'nokogiri'
|
146
|
+
register_lazy :PlainTemplate, 'tilt/plain', 'html'
|
147
|
+
register_lazy :PrawnTemplate, 'tilt/prawn', 'prawn'
|
148
|
+
register_lazy :RDocTemplate, 'tilt/rdoc', 'rdoc'
|
149
|
+
register_lazy :RadiusTemplate, 'tilt/radius', 'radius'
|
150
|
+
register_lazy :RedClothTemplate, 'tilt/redcloth', 'textile'
|
151
|
+
register_lazy :RstPandocTemplate, 'tilt/rst-pandoc', 'rst'
|
152
|
+
register_lazy :SassTemplate, 'tilt/sass', 'sass'
|
153
|
+
register_lazy :ScssTemplate, 'tilt/sass', 'scss'
|
154
|
+
register_lazy :SigilTemplate, 'tilt/sigil', 'sigil'
|
155
|
+
register_lazy :StringTemplate, 'tilt/string', 'str'
|
156
|
+
register_lazy :TypeScriptTemplate, 'tilt/typescript', 'ts', 'tsx'
|
157
|
+
register_lazy :WikiClothTemplate, 'tilt/wikicloth', 'wiki', 'mediawiki', 'mw'
|
158
|
+
register_lazy :YajlTemplate, 'tilt/yajl', 'yajl'
|
159
|
+
|
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'
|
204
167
|
end
|