tilt 2.0.1 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fceb7a7101d7fee0f5a3d64a4b554c0a0526b028
4
- data.tar.gz: 4cfc354aebbcf7d22a7fc85d34cfdc74e17245e3
3
+ metadata.gz: 647ea82bd6b21c9160337188c95afa692d468048
4
+ data.tar.gz: fe4a38e1124fc88439048033b73ac69c9e26dabc
5
5
  SHA512:
6
- metadata.gz: 1ca1be3a71d372a712708730fc265b293da204309fcfc577229b96190f84bbea4f5dfb12d2ce3dbdb93f0adf2330da2ee8f97b07676fb826b61e42560e5c09c6
7
- data.tar.gz: ce739c19f41b2dcff91ed9d6827839123407a471d644743ec7c292de4c24185b6b66adeacd968fd065a84d18277ee2b49308bf993af5a98d8f1121218dd1e50f
6
+ metadata.gz: 7eeb600f8917fef64a15ae0e595afc9e6a99558be4118ca7b96ce81701159061835fe0103d0320a0f82419b553d215fc1961543abb59789273be9514e43b5ae6
7
+ data.tar.gz: a75cb1d660582518e2512a01da3b9c3ed917b48cea59680752570be482f6db17e79d1d6e2b2225e25c0f96977c5c37acab2e11eda8941883bebd5d20192c67f2
@@ -1,4 +1,16 @@
1
- ## master
1
+ ## 2.0.2 (2016-01-06)
2
+
3
+ * Pass options to Redcarpet (#250, hughbien)
4
+ * Haml: Improve error message on frozen self (judofyr)
5
+ * Add basic support for Babel (judofyr)
6
+ * Add support for .litcoffee (#243, judofyr, mr-vinn)
7
+ * Document Tilt::Cache (#266, tommay)
8
+ * Sort local keys for better caching (#257, jeremyevans)
9
+ * Add more CSV options (#256, Juanmcuello)
10
+ * Add Prawn template (kematzy)
11
+ * Improve cache-miss performance in Tilt::Cache (#251, tommay)
12
+ * Add man page (#241, josephholsten)
13
+ * Support YAML/JSON data in bin/tilt (#241, josephholsten)
2
14
 
3
15
  ## 2.0.1 (2014-03-21)
4
16
 
data/Gemfile CHANGED
@@ -1,27 +1,48 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'yard', '~> 0.8.6'
3
+ gem 'rake'
4
4
  gem 'minitest', '~> 5.0'
5
5
 
6
- gem 'rake'
6
+ group :development do
7
+ gem 'yard', '~> 0.8.6'
8
+ gem 'ronn', '~> 0.7.3'
9
+ end
7
10
 
8
- group :engines do
9
- gem 'asciidoctor', '>= 0.1.0'
11
+ can_execjs = (RUBY_VERSION >= '1.9.3')
12
+
13
+ group :primary do
10
14
  gem 'builder'
11
- gem 'coffee-script'
12
- gem 'contest'
13
- gem 'creole'
14
- gem 'erubis'
15
15
  gem 'haml', '>= 2.2.11', '< 4'
16
+ gem 'erubis'
17
+ gem 'markaby'
18
+ gem 'sass'
19
+
20
+ if can_execjs
21
+ gem 'less'
22
+ gem 'coffee-script'
23
+ gem 'babel-transpiler'
24
+ end
25
+ end
26
+
27
+ platform :mri do
28
+ gem 'duktape', '~> 1.2.1.0' if can_execjs
29
+ end
30
+
31
+ group :secondary do
32
+ gem 'creole'
16
33
  gem 'kramdown'
17
- gem 'less'
34
+ gem 'rdoc'
35
+ gem 'radius'
36
+ gem 'asciidoctor', '>= 0.1.0'
18
37
  gem 'liquid'
19
- gem 'markaby'
20
38
  gem 'maruku'
39
+
40
+ if RUBY_VERSION > '1.9.3'
41
+ gem 'prawn', '>= 2.0.0'
42
+ gem 'pdf-reader', '~> 1.3.3'
43
+ end
44
+
21
45
  gem 'nokogiri' if RUBY_VERSION > '1.9.2'
22
- gem 'radius'
23
- gem 'sass'
24
- gem 'rdoc', (ENV['RDOC_VERSION'] || '> 0')
25
46
 
26
47
  platform :ruby do
27
48
  gem 'wikicloth'
@@ -32,8 +53,7 @@ group :engines do
32
53
  end
33
54
 
34
55
  platform :mri do
35
- gem 'therubyracer'
36
- gem 'bluecloth' if ENV['BLUECLOTH']
56
+ gem 'bluecloth'
37
57
  end
38
58
  end
39
59
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
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)
1
+ Tilt [![Build Status](https://secure.travis-ci.org/rtomayko/tilt.svg)](http://travis-ci.org/rtomayko/tilt) [![Dependency Status](https://gemnasium.com/rtomayko/tilt.png)](https://gemnasium.com/rtomayko/tilt) [![Inline docs](http://inch-ci.org/github/rtomayko/tilt.png)](http://inch-ci.org/github/rtomayko/tilt)
2
2
  ====
3
3
 
4
4
  **NOTE** The following file documents the current release of Tilt (2.0). See
@@ -24,44 +24,64 @@ template engines included in the distribution.
24
24
 
25
25
  Support for these template engines is included with the package:
26
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)
27
+ | Engine | File Extensions | Required Libraries | Maintainer |
28
+ | ----------------------- | ---------------------- | ------------------------------------------ | ----------- |
29
+ | Asciidoctor | .ad, .adoc, .asciidoc | asciidoctor (>= 0.1.0) | Community |
30
+ | ERB | .erb, .rhtml | none (included ruby stdlib) | Tilt team |
31
+ | InterpolatedString | .str | none (included ruby core) | Tilt team |
32
+ | Erubis | .erb, .rhtml, .erubis | erubis | Tilt team |
33
+ | Haml | .haml | haml | Tilt team |
34
+ | Sass | .sass | haml (< 3.1) or sass (>= 3.1) | Tilt team |
35
+ | Scss | .scss | haml (< 3.1) or sass (>= 3.1) | Tilt team |
36
+ | Less CSS | .less | less | Tilt team |
37
+ | Builder | .builder | builder | Tilt team |
38
+ | Liquid | .liquid | liquid | Community |
39
+ | RDiscount | .markdown, .mkd, .md | rdiscount | Community |
40
+ | Redcarpet | .markdown, .mkd, .md | redcarpet | Community |
41
+ | BlueCloth | .markdown, .mkd, .md | bluecloth | Community |
42
+ | Kramdown | .markdown, .mkd, .md | kramdown | Community |
43
+ | Maruku | .markdown, .mkd, .md | maruku | Community |
44
+ | RedCloth | .textile | redcloth | Community |
45
+ | RDoc | .rdoc | rdoc | Tilt team |
46
+ | Radius | .radius | radius | Community |
47
+ | Markaby | .mab | markaby | Tilt team |
48
+ | Nokogiri | .nokogiri | nokogiri | Community |
49
+ | CoffeeScript | .coffee | coffee-script (+ javascript) | Tilt team |
50
+ | CoffeeScript (literate) | .litcoffee | coffee-script (>= 1.5.0) (+ javascript) | Tilt team |
51
+ | Creole (Wiki markup) | .wiki, .creole | creole | Community |
52
+ | WikiCloth (Wiki markup) | .wiki, .mediawiki, .mw | wikicloth | Community |
53
+ | Yajl | .yajl | yajl-ruby | Community |
54
+ | CSV | .rcsv | none (Ruby >= 1.9), fastercsv (Ruby < 1.9) | Tilt team |
55
+ | Prawn | .prawn | prawn (>= 2.0.0) | Community |
56
+ | Babel | .es6, .babel, .jsx | babel-transpiler | Tilt team |
57
+ | Opal | .rb | opal | Community |
58
+
59
+ Every supported template engine has a *maintainer*. Note that this is the
60
+ maintainer of the Tilt integration, not the maintainer of the template engine
61
+ itself. The maintainer is responsible for providing an adequate integration and
62
+ keeping backwards compatibility across Tilt version. Some integrations are
63
+ maintained by the *community*, which is handled in the following way:
64
+
65
+ - The Tilt team will liberally accept pull requests against the template
66
+ integration. It's up the community as a whole to make sure the integration
67
+ stays consistent and backwards compatible over time.
68
+ - Test failures in community-maintained integrations will not be prioritized by
69
+ the Tilt team and a new version of Tilt might be released even though these
70
+ tests are failing.
71
+ - Anyone can become a maintainer for a template engine integration they care
72
+ about. Just open an issue and we'll figure it out.
54
73
 
55
74
  These template engines ship with their own Tilt integration:
56
75
 
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
76
+ | Engine | File Extensions | Required Libraries |
77
+ | ------------------- | ---------------- | ------------------- |
78
+ | Slim | .slim | slim (>= 0.7) |
79
+ | Embedded JavaScript | | sprockets |
80
+ | Embedded CoffeeScript | | sprockets |
81
+ | JST | | sprockets |
82
+ | Org-mode | .org | org-ruby (>= 0.6.2) |
83
+ | Handlebars | .hbs, handlebars | tilt-handlebars |
84
+ | Jbuilder | .jbuilder | tilt-jbuilder |
65
85
 
66
86
  See [TEMPLATES.md][t] for detailed information on template engine
67
87
  options and supported features.
@@ -77,7 +97,7 @@ Instant gratification:
77
97
  require 'erb'
78
98
  require 'tilt'
79
99
  template = Tilt.new('templates/foo.erb')
80
- => #<Tilt::ERBTemplate @file="templates/foo.rb" ...>
100
+ => #<Tilt::ERBTemplate @file="templates/foo.erb" ...>
81
101
  output = template.render
82
102
  => "Hello world!"
83
103
 
data/Rakefile CHANGED
@@ -15,19 +15,29 @@ end
15
15
 
16
16
  # DOCUMENTATION =============================================================
17
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'
18
+ begin
19
+ require 'yard'
20
+ YARD::Rake::YardocTask.new do |t|
21
+ t.files = [
22
+ 'lib/tilt.rb', 'lib/tilt/mapping.rb', 'lib/tilt/template.rb',
23
+ '-',
24
+ '*.md', 'docs/*.md',
25
+ ]
26
+
27
+ t.options <<
28
+ '--no-private' <<
29
+ '--protected' <<
30
+ '-m' << 'markdown' <<
31
+ '--asset' << 'docs/common.css:css/common.css'
32
+ end
33
+ rescue LoadError
34
+ end
35
+
36
+ task :man do
37
+ require 'ronn'
38
+ ENV['RONN_MANUAL'] = "Tilt Manual"
39
+ ENV['RONN_ORGANIZATION'] = "Tilt #{SPEC.version}"
40
+ sh "ronn -w -s toc -r5 --markdown man/*.ronn"
31
41
  end
32
42
 
33
43
  # PACKAGING =================================================================
data/bin/tilt CHANGED
@@ -10,14 +10,15 @@ when <file> is '-', read template from stdin and use the --type option
10
10
  to determine the template's type.
11
11
 
12
12
  Options
13
- -l, --list List template engines + file patterns and exit
14
- -t, --type=<pattern> Use this template engine; required if no <file>
15
- -y, --layout=<file> Use <file> as a layout template
13
+ -l, --list List template engines + file patterns and exit
14
+ -t, --type=<pattern> Use this template engine; required if no <file>
15
+ -y, --layout=<file> Use <file> as a layout template
16
16
 
17
- -D<name>=<value> Define variable <name> as <value>
18
- --vars=<ruby> Evaluate <ruby> to Hash and use for variables
17
+ -D<name>=<value> Define variable <name> as <value>
18
+ -d, --define-file=<file> Load YAML from <file> and use for variables
19
+ --vars=<ruby> Evaluate <ruby> to Hash and use for variables
19
20
 
20
- -h, --help Show this help message
21
+ -h, --help Show this help message
21
22
 
22
23
  Convert markdown to HTML:
23
24
  $ tilt foo.markdown > foo.html
@@ -77,6 +78,15 @@ ARGV.options do |o|
77
78
  locals[key.to_sym] = value
78
79
  end
79
80
 
81
+ # define local variables from YAML or JSON
82
+ o.on("-d", "--define-file=FILE", String) do |file|
83
+ require 'yaml'
84
+ abort "no such define file: #{file}" unless File.exist? file
85
+ hash = File.open(file, 'r:bom|utf-8') { |f| YAML.load f, file }
86
+ abort "vars must be a Hash, not #{hash.inspect}" if !hash.is_a?(Hash)
87
+ hash.each { |key, value| locals[key.to_sym] = value }
88
+ end
89
+
80
90
  # define local variables using a Ruby hash
81
91
  o.on("--vars=RUBY") do |ruby|
82
92
  hash = eval(ruby)
@@ -31,6 +31,7 @@ Tilt also includes support for CSS processors like [LessCSS][lesscss] and
31
31
  * Sass - `Tilt::SassTemplate`
32
32
  * Scss - `Tilt::ScssTemplate`
33
33
  * CoffeeScript - `Tilt::CoffeeScriptTemplate`
34
+ * Literate CoffeeScript - `Tilt::CoffeeScriptLiterateTemplate`
34
35
  * [Textile](#redcloth) - `Tilt::RedClothTemplate`
35
36
  * Creole - `Tilt::CreoleTemplate`
36
37
  * [RDoc](#rdoc) - `Tilt::RDocTemplate`
@@ -4,7 +4,7 @@ require 'tilt/template'
4
4
  # Namespace for Tilt. This module is not intended to be included anywhere.
5
5
  module Tilt
6
6
  # Current version.
7
- VERSION = '2.0.1'
7
+ VERSION = '2.0.2'
8
8
 
9
9
  @default_mapping = Mapping.new
10
10
 
@@ -78,14 +78,31 @@ module Tilt
78
78
  # cache.fetch(path, line, options) { Tilt.new(path, line, options) }
79
79
  #
80
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.
81
91
  class Cache
82
92
  def initialize
83
93
  @cache = {}
84
94
  end
85
95
 
86
- # @see Cache
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
87
102
  def fetch(*key)
88
- @cache[key] ||= yield
103
+ @cache.fetch(key) do
104
+ @cache[key] = yield
105
+ end
89
106
  end
90
107
 
91
108
  # Clears the cache.
@@ -110,9 +127,11 @@ module Tilt
110
127
 
111
128
  # Rest (sorted by name)
112
129
  register_lazy :AsciidoctorTemplate, 'tilt/asciidoc', 'ad', 'adoc', 'asciidoc'
130
+ register_lazy :BabelTemplate, 'tilt/babel', 'es6', 'babel', 'jsx'
113
131
  register_lazy :BuilderTemplate, 'tilt/builder', 'builder'
114
132
  register_lazy :CSVTemplate, 'tilt/csv', 'rcsv'
115
133
  register_lazy :CoffeeScriptTemplate, 'tilt/coffee', 'coffee'
134
+ register_lazy :CoffeeScriptLiterateTemplate, 'tilt/coffee', 'litcoffee'
116
135
  register_lazy :CreoleTemplate, 'tilt/creole', 'wiki', 'creole'
117
136
  register_lazy :EtanniTemplate, 'tilt/etanni', 'etn', 'etanni'
118
137
  register_lazy :HamlTemplate, 'tilt/haml', 'haml'
@@ -121,6 +140,7 @@ module Tilt
121
140
  register_lazy :MarkabyTemplate, 'tilt/markaby', 'mab'
122
141
  register_lazy :NokogiriTemplate, 'tilt/nokogiri', 'nokogiri'
123
142
  register_lazy :PlainTemplate, 'tilt/plain', 'html'
143
+ register_lazy :PrawnTemplate, 'tilt/prawn', 'prawn'
124
144
  register_lazy :RDocTemplate, 'tilt/rdoc', 'rdoc'
125
145
  register_lazy :RadiusTemplate, 'tilt/radius', 'radius'
126
146
  register_lazy :RedClothTemplate, 'tilt/redcloth', 'textile'
@@ -134,4 +154,6 @@ module Tilt
134
154
  register_lazy 'Slim::Template', 'slim', 'slim'
135
155
  register_lazy 'Tilt::HandlebarsTemplate', 'tilt/handlebars', 'handlebars', 'hbs'
136
156
  register_lazy 'Tilt::OrgTemplate', 'org-ruby', 'org'
157
+ register_lazy 'Opal::Processor', 'opal', 'opal', 'rb'
158
+ register_lazy 'Tilt::JbuilderTemplate', 'tilt/jbuilder', 'jbuilder'
137
159
  end
@@ -0,0 +1,15 @@
1
+ require 'tilt/template'
2
+ require 'babel/transpiler'
3
+
4
+ module Tilt
5
+ class BabelTemplate < Template
6
+ def prepare
7
+ options[:filename] ||= file
8
+ end
9
+
10
+ def evaluate(scope, locals, &block)
11
+ @output ||= Babel::Transpiler.transform(data)["code"]
12
+ end
13
+ end
14
+ end
15
+
@@ -29,10 +29,15 @@ module Tilt
29
29
  @@default_bare = value
30
30
  end
31
31
 
32
+ def self.literate?
33
+ false
34
+ end
35
+
32
36
  def prepare
33
37
  if !options.key?(:bare) and !options.key?(:no_wrap)
34
38
  options[:bare] = self.class.default_bare
35
39
  end
40
+ options[:literate] ||= self.class.literate?
36
41
  end
37
42
 
38
43
  def evaluate(scope, locals, &block)
@@ -43,5 +48,11 @@ module Tilt
43
48
  false
44
49
  end
45
50
  end
51
+
52
+ class CoffeeScriptLiterateTemplate < CoffeeScriptTemplate
53
+ def self.literate?
54
+ true
55
+ end
56
+ end
46
57
  end
47
58
 
@@ -45,15 +45,15 @@ module Tilt
45
45
  end
46
46
 
47
47
  def prepare
48
- @code =<<-RUBY
49
- #{self.class.engine}.generate do |csv|
50
- #{data}
51
- end
52
- RUBY
48
+ @outvar = options.delete(:outvar) || '_csvout'
53
49
  end
54
50
 
55
51
  def precompiled_template(locals)
56
- @code
52
+ <<-RUBY
53
+ #{@outvar} = #{self.class.engine}.generate(#{options}) do |csv|
54
+ #{data}
55
+ end
56
+ RUBY
57
57
  end
58
58
 
59
59
  def precompiled(locals)
@@ -13,6 +13,8 @@ module Tilt
13
13
  end
14
14
 
15
15
  def evaluate(scope, locals, &block)
16
+ raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
17
+
16
18
  if @engine.respond_to?(:precompiled_method_return_value, true)
17
19
  super
18
20
  else
@@ -47,11 +49,10 @@ module Tilt
47
49
  <<-RUBY
48
50
  #{precompiled_method_return_value}
49
51
  ensure
50
- @haml_buffer = @haml_buffer.upper
52
+ @haml_buffer = @haml_buffer.upper if @haml_buffer
51
53
  end
52
54
  RUBY
53
55
  end
54
56
  end
55
57
  end
56
58
  end
57
-