tilt 1.4.1 → 2.0.11

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