tilt 2.0.0 → 2.4.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.
- checksums.yaml +5 -5
- data/COPYING +2 -1
- data/bin/tilt +2 -110
- data/lib/tilt/_emacs_org.rb +2 -0
- data/lib/tilt/_handlebars.rb +2 -0
- data/lib/tilt/_jbuilder.rb +2 -0
- data/lib/tilt/_org.rb +2 -0
- data/lib/tilt/asciidoc.rb +11 -23
- data/lib/tilt/babel.rb +8 -0
- data/lib/tilt/builder.rb +23 -14
- data/lib/tilt/cli.rb +134 -0
- data/lib/tilt/coffee.rb +17 -25
- data/lib/tilt/commonmarker.rb +95 -0
- data/lib/tilt/creole.rb +9 -20
- data/lib/tilt/csv.rb +9 -21
- data/lib/tilt/erb.rb +27 -19
- data/lib/tilt/erubi.rb +55 -0
- data/lib/tilt/erubis.rb +20 -12
- data/lib/tilt/etanni.rb +5 -4
- data/lib/tilt/haml.rb +79 -42
- data/lib/tilt/kramdown.rb +8 -28
- data/lib/tilt/liquid.rb +11 -9
- data/lib/tilt/livescript.rb +11 -0
- data/lib/tilt/mapping.rb +242 -95
- data/lib/tilt/markaby.rb +5 -7
- data/lib/tilt/maruku.rb +6 -18
- data/lib/tilt/nokogiri.rb +11 -10
- data/lib/tilt/pandoc.rb +39 -0
- data/lib/tilt/pipeline.rb +19 -0
- data/lib/tilt/plain.rb +4 -19
- data/lib/tilt/prawn.rb +28 -0
- data/lib/tilt/radius.rb +15 -22
- data/lib/tilt/rdiscount.rb +17 -33
- data/lib/tilt/rdoc.rb +14 -35
- data/lib/tilt/redcarpet.rb +20 -93
- data/lib/tilt/redcloth.rb +9 -19
- data/lib/tilt/rst-pandoc.rb +10 -0
- data/lib/tilt/sass.rb +59 -22
- data/lib/tilt/slim.rb +5 -0
- data/lib/tilt/string.rb +9 -3
- data/lib/tilt/template.rb +246 -78
- data/lib/tilt/typescript.rb +19 -0
- data/lib/tilt/wikicloth.rb +8 -18
- data/lib/tilt/yajl.rb +5 -11
- data/lib/tilt.rb +91 -41
- metadata +39 -102
- data/CHANGELOG.md +0 -61
- data/Gemfile +0 -39
- data/HACKING +0 -16
- data/README.md +0 -206
- data/Rakefile +0 -95
- data/docs/TEMPLATES.md +0 -523
- data/docs/common.css +0 -14
- data/lib/tilt/bluecloth.rb +0 -24
- data/lib/tilt/less.rb +0 -38
- 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/test_helper.rb +0 -64
- data/test/tilt_asciidoctor_test.rb +0 -44
- data/test/tilt_blueclothtemplate_test.rb +0 -33
- data/test/tilt_buildertemplate_test.rb +0 -59
- data/test/tilt_cache_test.rb +0 -32
- data/test/tilt_coffeescripttemplate_test.rb +0 -104
- data/test/tilt_compilesite_test.rb +0 -51
- data/test/tilt_creoletemplate_test.rb +0 -24
- data/test/tilt_csv_test.rb +0 -65
- data/test/tilt_erbtemplate_test.rb +0 -239
- data/test/tilt_erubistemplate_test.rb +0 -151
- data/test/tilt_etannitemplate_test.rb +0 -174
- data/test/tilt_hamltemplate_test.rb +0 -144
- data/test/tilt_kramdown_test.rb +0 -20
- 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_mapping_test.rb +0 -229
- data/test/tilt_markaby_test.rb +0 -88
- data/test/tilt_markdown_test.rb +0 -174
- data/test/tilt_marukutemplate_test.rb +0 -36
- data/test/tilt_metadata_test.rb +0 -42
- data/test/tilt_nokogiritemplate_test.rb +0 -87
- data/test/tilt_radiustemplate_test.rb +0 -75
- data/test/tilt_rdiscounttemplate_test.rb +0 -43
- data/test/tilt_rdoctemplate_test.rb +0 -29
- data/test/tilt_redcarpettemplate_test.rb +0 -59
- data/test/tilt_redclothtemplate_test.rb +0 -36
- data/test/tilt_sasstemplate_test.rb +0 -41
- data/test/tilt_stringtemplate_test.rb +0 -171
- data/test/tilt_template_test.rb +0 -316
- data/test/tilt_test.rb +0 -60
- data/test/tilt_wikiclothtemplate_test.rb +0 -32
- data/test/tilt_yajltemplate_test.rb +0 -101
- data/tilt.gemspec +0 -107
data/README.md
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
Tilt [](http://travis-ci.org/rtomayko/tilt) [](https://gemnasium.com/rtomayko/tilt)
|
2
|
-
====
|
3
|
-
|
4
|
-
**NOTE** The follow file documents the upcoming release of Tilt (2.0). See
|
5
|
-
https://github.com/rtomayko/tilt/tree/tilt-1 for the current version.
|
6
|
-
|
7
|
-
Tilt is a thin interface over a bunch of different Ruby template engines in
|
8
|
-
an attempt to make their usage as generic as possible. This is useful for web
|
9
|
-
frameworks, static site generators, and other systems that support multiple
|
10
|
-
template engines but don't want to code for each of them individually.
|
11
|
-
|
12
|
-
The following features are supported for all template engines (assuming the
|
13
|
-
feature is relevant to the engine):
|
14
|
-
|
15
|
-
* Custom template evaluation scopes / bindings
|
16
|
-
* Ability to pass locals to template evaluation
|
17
|
-
* Support for passing a block to template evaluation for "yield"
|
18
|
-
* Backtraces with correct filenames and line numbers
|
19
|
-
* Template file caching and reloading
|
20
|
-
* Fast, method-based template source compilation
|
21
|
-
|
22
|
-
The primary goal is to get all of the things listed above right for all
|
23
|
-
template engines included in the distribution.
|
24
|
-
|
25
|
-
Support for these template engines is included with the package:
|
26
|
-
|
27
|
-
ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
|
28
|
-
-------------------------- ----------------------- ----------------------------
|
29
|
-
Asciidoctor .ad, .adoc, .asciidoc asciidoctor (>= 0.1.0)
|
30
|
-
ERB .erb, .rhtml none (included ruby stdlib)
|
31
|
-
Interpolated String .str none (included ruby core)
|
32
|
-
Erubis .erb, .rhtml, .erubis erubis
|
33
|
-
Haml .haml haml
|
34
|
-
Sass .sass haml (< 3.1) or sass (>= 3.1)
|
35
|
-
Scss .scss haml (< 3.1) or sass (>= 3.1)
|
36
|
-
Less CSS .less less
|
37
|
-
Builder .builder builder
|
38
|
-
Liquid .liquid liquid
|
39
|
-
RDiscount .markdown, .mkd, .md rdiscount
|
40
|
-
Redcarpet .markdown, .mkd, .md redcarpet
|
41
|
-
BlueCloth .markdown, .mkd, .md bluecloth
|
42
|
-
Kramdown .markdown, .mkd, .md kramdown
|
43
|
-
Maruku .markdown, .mkd, .md maruku
|
44
|
-
RedCloth .textile redcloth
|
45
|
-
RDoc .rdoc rdoc
|
46
|
-
Radius .radius radius
|
47
|
-
Markaby .mab markaby
|
48
|
-
Nokogiri .nokogiri nokogiri
|
49
|
-
CoffeeScript .coffee coffee-script (+ javascript)
|
50
|
-
Creole (Wiki markup) .wiki, .creole creole
|
51
|
-
WikiCloth (Wiki markup) .wiki, .mediawiki, .mw wikicloth
|
52
|
-
Yajl .yajl yajl-ruby
|
53
|
-
CSV .rcsv none (Ruby >= 1.9), fastercsv (Ruby < 1.9)
|
54
|
-
|
55
|
-
These template engines ship with their own Tilt integration:
|
56
|
-
|
57
|
-
ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
|
58
|
-
-------------------------- ----------------- ----------------------------
|
59
|
-
Slim .slim slim (>= 0.7)
|
60
|
-
Embedded JavaScript sprockets
|
61
|
-
Embedded CoffeeScript sprockets
|
62
|
-
JST sprockets
|
63
|
-
Org-mode .org org-ruby (>= 0.6.2)
|
64
|
-
Handlebars .hbs, .handlebars tilt-handlebars
|
65
|
-
|
66
|
-
See [TEMPLATES.md][t] for detailed information on template engine
|
67
|
-
options and supported features.
|
68
|
-
|
69
|
-
[t]: http://github.com/rtomayko/tilt/blob/master/docs/TEMPLATES.md
|
70
|
-
"Tilt Template Engine Documentation"
|
71
|
-
|
72
|
-
Basic Usage
|
73
|
-
-----------
|
74
|
-
|
75
|
-
Instant gratification:
|
76
|
-
|
77
|
-
require 'erb'
|
78
|
-
require 'tilt'
|
79
|
-
template = Tilt.new('templates/foo.erb')
|
80
|
-
=> #<Tilt::ERBTemplate @file="templates/foo.rb" ...>
|
81
|
-
output = template.render
|
82
|
-
=> "Hello world!"
|
83
|
-
|
84
|
-
It's recommended that calling programs explicitly require template engine
|
85
|
-
libraries (like 'erb' above) at load time. Tilt attempts to lazy require the
|
86
|
-
template engine library the first time a template is created but this is
|
87
|
-
prone to error in threaded environments.
|
88
|
-
|
89
|
-
The {Tilt} module contains generic implementation classes for all supported
|
90
|
-
template engines. Each template class adheres to the same interface for
|
91
|
-
creation and rendering. In the instant gratification example, we let Tilt
|
92
|
-
determine the template implementation class based on the filename, but
|
93
|
-
{Tilt::Template} implementations can also be used directly:
|
94
|
-
|
95
|
-
require 'tilt/haml'
|
96
|
-
template = Tilt::HamlTemplate.new('templates/foo.haml')
|
97
|
-
output = template.render
|
98
|
-
|
99
|
-
The `render` method takes an optional evaluation scope and locals hash
|
100
|
-
arguments. Here, the template is evaluated within the context of the
|
101
|
-
`Person` object with locals `x` and `y`:
|
102
|
-
|
103
|
-
require 'tilt/erb'
|
104
|
-
template = Tilt::ERBTemplate.new('templates/foo.erb')
|
105
|
-
joe = Person.find('joe')
|
106
|
-
output = template.render(joe, :x => 35, :y => 42)
|
107
|
-
|
108
|
-
If no scope is provided, the template is evaluated within the context of an
|
109
|
-
object created with `Object.new`.
|
110
|
-
|
111
|
-
A single `Template` instance's `render` method may be called multiple times
|
112
|
-
with different scope and locals arguments. Continuing the previous example,
|
113
|
-
we render the same compiled template but this time in jane's scope:
|
114
|
-
|
115
|
-
jane = Person.find('jane')
|
116
|
-
output = template.render(jane, :x => 22, :y => nil)
|
117
|
-
|
118
|
-
Blocks can be passed to `render` for templates that support running
|
119
|
-
arbitrary ruby code (usually with some form of `yield`). For instance,
|
120
|
-
assuming the following in `foo.erb`:
|
121
|
-
|
122
|
-
Hey <%= yield %>!
|
123
|
-
|
124
|
-
The block passed to `render` is called on `yield`:
|
125
|
-
|
126
|
-
template = Tilt::ERBTemplate.new('foo.erb')
|
127
|
-
template.render { 'Joe' }
|
128
|
-
# => "Hey Joe!"
|
129
|
-
|
130
|
-
Template Mappings
|
131
|
-
-----------------
|
132
|
-
|
133
|
-
The {Tilt::Mapping} class includes methods for associating template
|
134
|
-
implementation classes with filename patterns and for locating/instantiating
|
135
|
-
template classes based on those associations.
|
136
|
-
|
137
|
-
The {Tilt} module has a global instance of `Mapping` that is populated with the
|
138
|
-
table of template engines above.
|
139
|
-
|
140
|
-
The {Tilt.register} method associates a filename pattern with a specific
|
141
|
-
template implementation. To use ERB for files ending in a `.bar` extension:
|
142
|
-
|
143
|
-
>> Tilt.register Tilt::ERBTemplate, 'bar'
|
144
|
-
>> Tilt.new('views/foo.bar')
|
145
|
-
=> #<Tilt::ERBTemplate @file="views/foo.bar" ...>
|
146
|
-
|
147
|
-
Retrieving the template class for a file or file extension:
|
148
|
-
|
149
|
-
>> Tilt['foo.bar']
|
150
|
-
=> Tilt::ERBTemplate
|
151
|
-
>> Tilt['haml']
|
152
|
-
=> Tilt::HamlTemplate
|
153
|
-
|
154
|
-
Retrieving a list of template classes for a file:
|
155
|
-
|
156
|
-
>> Tilt.templates_for('foo.bar')
|
157
|
-
=> [Tilt::ERBTemplate]
|
158
|
-
>> Tilt.templates_for('foo.haml.bar')
|
159
|
-
=> [Tilt::ERBTemplate, Tilt::HamlTemplate]
|
160
|
-
|
161
|
-
The template class is determined by searching for a series of decreasingly
|
162
|
-
specific name patterns. When creating a new template with
|
163
|
-
`Tilt.new('views/foo.html.erb')`, we check for the following template
|
164
|
-
mappings:
|
165
|
-
|
166
|
-
1. `views/foo.html.erb`
|
167
|
-
2. `foo.html.erb`
|
168
|
-
3. `html.erb`
|
169
|
-
4. `erb`
|
170
|
-
|
171
|
-
Encodings
|
172
|
-
---------
|
173
|
-
|
174
|
-
Tilt needs to know the encoding of the template in order to work properly:
|
175
|
-
|
176
|
-
Tilt will use `Encoding.default_external` as the encoding when reading external
|
177
|
-
files. If you're mostly working with one encoding (e.g. UTF-8) we *highly*
|
178
|
-
recommend setting this option. When providing a custom reader block (`Tilt.new
|
179
|
-
{ custom_string }`) you'll have ensure the string is properly encoded yourself.
|
180
|
-
|
181
|
-
Most of the template engines in Tilt also allows you to override the encoding
|
182
|
-
using the `:default_encoding`-option:
|
183
|
-
|
184
|
-
```ruby
|
185
|
-
tmpl = Tilt.new('hello.erb', :default_encoding => 'Big5')
|
186
|
-
```
|
187
|
-
|
188
|
-
Ultimately it's up to the template engine how to handle the encoding: It might
|
189
|
-
respect `:default_encoding`, it might always assume it's UTF-8 (like
|
190
|
-
CoffeeScript), or it can do its own encoding detection.
|
191
|
-
|
192
|
-
Template Compilation
|
193
|
-
--------------------
|
194
|
-
|
195
|
-
Tilt compiles generated Ruby source code produced by template engines and reuses
|
196
|
-
it on subsequent template invocations. Benchmarks show this yields a 5x-10x
|
197
|
-
performance increase over evaluating the Ruby source on each invocation.
|
198
|
-
|
199
|
-
Template compilation is currently supported for these template engines:
|
200
|
-
StringTemplate, ERB, Erubis, Haml, Nokogiri, Builder and Yajl.
|
201
|
-
|
202
|
-
LICENSE
|
203
|
-
-------
|
204
|
-
|
205
|
-
Tilt is Copyright (c) 2010 [Ryan Tomayko](http://tomayko.com/about) and
|
206
|
-
distributed under the MIT license. See the `COPYING` file for more info.
|
data/Rakefile
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler.setup
|
3
|
-
|
4
|
-
require 'rake/testtask'
|
5
|
-
task :default => [:test]
|
6
|
-
|
7
|
-
# SPECS =====================================================================
|
8
|
-
|
9
|
-
desc 'Run tests (default)'
|
10
|
-
Rake::TestTask.new(:test) do |t|
|
11
|
-
t.test_files = FileList['test/*_test.rb']
|
12
|
-
t.ruby_opts = ['-Itest']
|
13
|
-
t.ruby_opts << '-rubygems' if defined? Gem
|
14
|
-
end
|
15
|
-
|
16
|
-
# DOCUMENTATION =============================================================
|
17
|
-
|
18
|
-
require 'yard'
|
19
|
-
YARD::Rake::YardocTask.new do |t|
|
20
|
-
t.files = [
|
21
|
-
'lib/tilt.rb', 'lib/tilt/mapping.rb', 'lib/tilt/template.rb',
|
22
|
-
'-',
|
23
|
-
'*.md', 'docs/*.md',
|
24
|
-
]
|
25
|
-
|
26
|
-
t.options <<
|
27
|
-
'--no-private' <<
|
28
|
-
'--protected' <<
|
29
|
-
'-m' << 'markdown' <<
|
30
|
-
'--asset' << 'docs/common.css:css/common.css'
|
31
|
-
end
|
32
|
-
|
33
|
-
# PACKAGING =================================================================
|
34
|
-
|
35
|
-
begin
|
36
|
-
require 'rubygems'
|
37
|
-
rescue LoadError
|
38
|
-
end
|
39
|
-
|
40
|
-
if defined?(Gem)
|
41
|
-
SPEC = eval(File.read('tilt.gemspec'))
|
42
|
-
|
43
|
-
def package(ext='')
|
44
|
-
"pkg/tilt-#{SPEC.version}" + ext
|
45
|
-
end
|
46
|
-
|
47
|
-
desc 'Build packages'
|
48
|
-
task :package => %w[.gem .tar.gz].map {|e| package(e)}
|
49
|
-
|
50
|
-
desc 'Build and install as local gem'
|
51
|
-
task :install => package('.gem') do
|
52
|
-
sh "gem install #{package('.gem')}"
|
53
|
-
end
|
54
|
-
|
55
|
-
directory 'pkg/'
|
56
|
-
|
57
|
-
file package('.gem') => %w[pkg/ tilt.gemspec] + SPEC.files do |f|
|
58
|
-
sh "gem build tilt.gemspec"
|
59
|
-
mv File.basename(f.name), f.name
|
60
|
-
end
|
61
|
-
|
62
|
-
file package('.tar.gz') => %w[pkg/] + SPEC.files do |f|
|
63
|
-
sh "git archive --format=tar HEAD | gzip > #{f.name}"
|
64
|
-
end
|
65
|
-
|
66
|
-
desc 'Upload gem and tar.gz distributables to rubyforge'
|
67
|
-
task :release => [package('.gem'), package('.tar.gz')] do |t|
|
68
|
-
sh <<-SH
|
69
|
-
rubyforge add_release sinatra tilt #{SPEC.version} #{package('.gem')} &&
|
70
|
-
rubyforge add_file sinatra tilt #{SPEC.version} #{package('.tar.gz')}
|
71
|
-
SH
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# GEMSPEC ===================================================================
|
76
|
-
|
77
|
-
file 'tilt.gemspec' => FileList['{lib,test}/**','Rakefile'] do |f|
|
78
|
-
# read version from tilt.rb
|
79
|
-
version = File.read('lib/tilt.rb')[/VERSION = '(.*)'/] && $1
|
80
|
-
# read spec file and split out manifest section
|
81
|
-
spec = File.
|
82
|
-
read(f.name).
|
83
|
-
sub(/s\.version\s*=\s*'.*'/, "s.version = '#{version}'")
|
84
|
-
parts = spec.split(" # = MANIFEST =\n")
|
85
|
-
# determine file list from git ls-files
|
86
|
-
files = `git ls-files`.
|
87
|
-
split("\n").sort.reject{ |file| file =~ /^\./ }.
|
88
|
-
map{ |file| " #{file}" }.join("\n")
|
89
|
-
# piece file back together and write...
|
90
|
-
parts[1] = " s.files = %w[\n#{files}\n ]\n"
|
91
|
-
spec = parts.join(" # = MANIFEST =\n")
|
92
|
-
spec.sub!(/s.date = '.*'/, "s.date = '#{Time.now.strftime("%Y-%m-%d")}'")
|
93
|
-
File.open(f.name, 'w') { |io| io.write(spec) }
|
94
|
-
puts "updated #{f.name}"
|
95
|
-
end
|