tilt 2.1.0 → 2.2.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 +4 -4
- data/COPYING +1 -0
- data/bin/tilt +2 -120
- 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 +5 -13
- data/lib/tilt/builder.rb +18 -13
- data/lib/tilt/cli.rb +134 -0
- data/lib/tilt/coffee.rb +18 -25
- data/lib/tilt/commonmarker.rb +47 -81
- data/lib/tilt/creole.rb +9 -20
- data/lib/tilt/csv.rb +5 -4
- data/lib/tilt/erb.rb +18 -12
- data/lib/tilt/erubi.rb +7 -6
- data/lib/tilt/erubis.rb +12 -6
- data/lib/tilt/etanni.rb +3 -2
- data/lib/tilt/haml.rb +12 -9
- data/lib/tilt/kramdown.rb +8 -20
- data/lib/tilt/liquid.rb +10 -14
- data/lib/tilt/livescript.rb +8 -20
- data/lib/tilt/mapping.rb +180 -104
- data/lib/tilt/markaby.rb +5 -7
- data/lib/tilt/maruku.rb +5 -19
- data/lib/tilt/nokogiri.rb +11 -10
- data/lib/tilt/pandoc.rb +33 -51
- data/lib/tilt/pipeline.rb +1 -0
- data/lib/tilt/plain.rb +4 -15
- data/lib/tilt/prawn.rb +15 -23
- 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 +25 -67
- data/lib/tilt/redcloth.rb +9 -19
- data/lib/tilt/rst-pandoc.rb +6 -19
- data/lib/tilt/sass.rb +34 -43
- data/lib/tilt/slim.rb +5 -0
- data/lib/tilt/string.rb +4 -3
- data/lib/tilt/template.rb +146 -56
- data/lib/tilt/typescript.rb +11 -18
- data/lib/tilt/wikicloth.rb +7 -19
- data/lib/tilt/yajl.rb +5 -11
- data/lib/tilt.rb +57 -30
- metadata +10 -7
- data/lib/tilt/bluecloth.rb +0 -26
- data/lib/tilt/less.rb +0 -32
- data/lib/tilt/sigil.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b933744ac3dc007d759af22c61ea725d84e6d83a689c07e384792d08f330f60
|
4
|
+
data.tar.gz: b07ad772a645934f3c0f912d2864eb9b47964b423a83d3cbc7978e6c90385229
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17e9ff63c011271c8fceb20c08f1c3d36f85c6674608690575ffc08b79b5d9704c0d63e456c00a2a0207295f54ef8c5df9f59c5de71680b1bf018faee93cba26
|
7
|
+
data.tar.gz: fcffaeed7fba1e7f2bd9ec25f57426d544281cd434f8138253f5046f47e73a871770b4e8be1cb08349462b988a6101bbbca1f7ecc273bd74f457271eb3a84aa9
|
data/COPYING
CHANGED
data/bin/tilt
CHANGED
@@ -1,122 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
require 'tilt'
|
2
|
+
require_relative '../lib/tilt/cli'
|
5
3
|
|
6
|
-
|
7
|
-
Usage: tilt <options> <file>
|
8
|
-
Process template <file> and write output to stdout. With no <file> or
|
9
|
-
when <file> is '-', read template from stdin and use the --type option
|
10
|
-
to determine the template's type.
|
11
|
-
|
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
|
16
|
-
|
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
|
20
|
-
|
21
|
-
-h, --help Show this help message
|
22
|
-
|
23
|
-
Convert markdown to HTML:
|
24
|
-
$ tilt foo.markdown > foo.html
|
25
|
-
|
26
|
-
Process ERB template:
|
27
|
-
$ echo "Answer: <%= 2 + 2 %>" | tilt -t erb
|
28
|
-
Answer: 4
|
29
|
-
|
30
|
-
Define variables:
|
31
|
-
$ echo "Answer: <%= 2 + n %>" | tilt -t erb --vars="{:n=>40}"
|
32
|
-
Answer: 42
|
33
|
-
$ echo "Answer: <%= 2 + n.to_i %>" | tilt -t erb -Dn=40
|
34
|
-
Answer: 42
|
35
|
-
USAGE
|
36
|
-
|
37
|
-
script_name = File.basename($0)
|
38
|
-
pattern = nil
|
39
|
-
layout = nil
|
40
|
-
locals = {}
|
41
|
-
|
42
|
-
ARGV.options do |o|
|
43
|
-
o.program_name = script_name
|
44
|
-
|
45
|
-
# list all available template engines
|
46
|
-
o.on("-l", "--list") do
|
47
|
-
groups = {}
|
48
|
-
Tilt.lazy_map.each do |pattern,engines|
|
49
|
-
engines.each do |engine|
|
50
|
-
key = engine[0].split('::').last.sub(/Template$/, '')
|
51
|
-
(groups[key] ||= []) << pattern
|
52
|
-
end
|
53
|
-
end
|
54
|
-
groups.sort { |(k1,v1),(k2,v2)| k1 <=> k2 }.each do |engine,files|
|
55
|
-
printf "%-15s %s\n", engine, files.sort.join(', ')
|
56
|
-
end
|
57
|
-
exit
|
58
|
-
end
|
59
|
-
|
60
|
-
# the template type / pattern
|
61
|
-
o.on("-t", "--type=PATTERN", String) do |val|
|
62
|
-
abort "unknown template type: #{val}" if Tilt[val].nil?
|
63
|
-
pattern = val
|
64
|
-
end
|
65
|
-
|
66
|
-
# pass template output into the specified layout template
|
67
|
-
o.on("-y", "--layout=FILE", String) do |file|
|
68
|
-
paths = [file, "~/.tilt/#{file}", "/etc/tilt/#{file}"]
|
69
|
-
layout = paths.
|
70
|
-
map { |p| File.expand_path(p) }.
|
71
|
-
find { |p| File.exist?(p) }
|
72
|
-
abort "no such layout: #{file}" if layout.nil?
|
73
|
-
end
|
74
|
-
|
75
|
-
# define a local variable
|
76
|
-
o.on("-D", "--define=PAIR", String) do |pair|
|
77
|
-
key, value = pair.split(/[=:]/, 2)
|
78
|
-
locals[key.to_sym] = value
|
79
|
-
end
|
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
|
-
|
90
|
-
# define local variables using a Ruby hash
|
91
|
-
o.on("--vars=RUBY") do |ruby|
|
92
|
-
hash = eval(ruby)
|
93
|
-
abort "vars must be a Hash, not #{hash.inspect}" if !hash.is_a?(Hash)
|
94
|
-
hash.each { |key, value| locals[key.to_sym] = value }
|
95
|
-
end
|
96
|
-
|
97
|
-
o.on_tail("-h", "--help") { puts usage; exit }
|
98
|
-
|
99
|
-
o.parse!
|
100
|
-
end
|
101
|
-
|
102
|
-
file = ARGV.first || '-'
|
103
|
-
pattern = file if pattern.nil?
|
104
|
-
abort "template type not given. see: #{$0} --help" if ['-', ''].include?(pattern)
|
105
|
-
|
106
|
-
engine = Tilt[pattern]
|
107
|
-
abort "template engine not found for: #{pattern}" if engine.nil?
|
108
|
-
|
109
|
-
template =
|
110
|
-
engine.new(file) {
|
111
|
-
if file == '-'
|
112
|
-
$stdin.read
|
113
|
-
else
|
114
|
-
File.read(file)
|
115
|
-
end
|
116
|
-
}
|
117
|
-
output = template.render(self, locals)
|
118
|
-
|
119
|
-
# process layout
|
120
|
-
output = Tilt.new(layout).render(self, locals) { output } if layout
|
121
|
-
|
122
|
-
$stdout.write(output)
|
4
|
+
exit Tilt::CLI.run
|
data/lib/tilt/_org.rb
ADDED
data/lib/tilt/asciidoc.rb
CHANGED
@@ -1,27 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'asciidoctor'
|
3
|
-
|
4
4
|
# AsciiDoc see: http://asciidoc.org/
|
5
|
-
module Tilt
|
6
|
-
# Asciidoctor implementation for AsciiDoc see:
|
7
|
-
# http://asciidoctor.github.com/
|
8
|
-
#
|
9
|
-
# Asciidoctor is an open source, pure-Ruby processor for
|
10
|
-
# converting AsciiDoc documents or strings into HTML 5,
|
11
|
-
# DocBook 4.5 and other formats.
|
12
|
-
class AsciidoctorTemplate < Template
|
13
|
-
self.default_mime_type = 'text/html'
|
14
|
-
|
15
|
-
def prepare
|
16
|
-
options[:header_footer] = false if options[:header_footer].nil?
|
17
|
-
end
|
18
|
-
|
19
|
-
def evaluate(scope, locals, &block)
|
20
|
-
@output ||= Asciidoctor.render(data, options, &block)
|
21
|
-
end
|
22
5
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
6
|
+
# Asciidoctor implementation for AsciiDoc see:
|
7
|
+
# http://asciidoctor.github.com/
|
8
|
+
#
|
9
|
+
# Asciidoctor is an open source, pure-Ruby processor for
|
10
|
+
# converting AsciiDoc documents or strings into HTML 5,
|
11
|
+
# DocBook 4.5 and other formats.
|
12
|
+
Tilt::AsciidoctorTemplate = Tilt::StaticTemplate.subclass do
|
13
|
+
@options[:header_footer] = false if @options[:header_footer].nil?
|
14
|
+
Asciidoctor.render(@data, @options)
|
27
15
|
end
|
data/lib/tilt/babel.rb
CHANGED
@@ -1,16 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'babel/transpiler'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def prepare
|
9
|
-
options[:filename] ||= file
|
10
|
-
end
|
11
|
-
|
12
|
-
def evaluate(scope, locals, &block)
|
13
|
-
@output ||= Babel::Transpiler.transform(data)["code"]
|
14
|
-
end
|
15
|
-
end
|
5
|
+
Tilt::BabelTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do
|
6
|
+
@options[:filename] ||= @file
|
7
|
+
Babel::Transpiler.transform(@data)["code"]
|
16
8
|
end
|
data/lib/tilt/builder.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'builder'
|
3
4
|
|
4
5
|
module Tilt
|
5
|
-
# Builder template implementation.
|
6
|
-
# http://builder.rubyforge.org/
|
6
|
+
# Builder template implementation.
|
7
7
|
class BuilderTemplate < Template
|
8
8
|
self.default_mime_type = 'text/xml'
|
9
9
|
|
10
10
|
def prepare
|
11
|
-
options[:indent] ||= 2
|
11
|
+
@options[:indent] ||= 2
|
12
12
|
end
|
13
13
|
|
14
14
|
def evaluate(scope, locals, &block)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
locals = locals.merge(:xml => xml)
|
15
|
+
if @data.respond_to?(:to_str)
|
16
|
+
unless locals[:xml]
|
17
|
+
locals = Hash[locals]
|
18
|
+
locals[:xml] = xml_builder
|
20
19
|
end
|
21
|
-
return super
|
20
|
+
return super
|
22
21
|
end
|
23
22
|
|
24
|
-
|
23
|
+
xml = locals[:xml] || xml_builder
|
24
|
+
@data.call(xml)
|
25
25
|
xml.target!
|
26
26
|
end
|
27
27
|
|
@@ -30,8 +30,13 @@ module Tilt
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def precompiled_template(locals)
|
33
|
-
data.to_str
|
33
|
+
@data.to_str
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def xml_builder
|
39
|
+
::Builder::XmlMarkup.new(options)
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
37
|
-
|
data/lib/tilt/cli.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative '../tilt'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module Tilt::CLI
|
6
|
+
USAGE = (<<USAGE).freeze
|
7
|
+
Usage: tilt <options> <file>
|
8
|
+
Process template <file> and write output to stdout. With no <file> or
|
9
|
+
when <file> is '-', read template from stdin and use the --type option
|
10
|
+
to determine the template's type.
|
11
|
+
|
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
|
16
|
+
|
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
|
20
|
+
|
21
|
+
-h, --help Show this help message
|
22
|
+
|
23
|
+
Convert markdown to HTML:
|
24
|
+
$ tilt foo.markdown > foo.html
|
25
|
+
|
26
|
+
Process ERB template:
|
27
|
+
$ echo "Answer: <%= 2 + 2 %>" | tilt -t erb
|
28
|
+
Answer: 4
|
29
|
+
|
30
|
+
Define variables:
|
31
|
+
$ echo "Answer: <%= 2 + n %>" | tilt -t erb --vars="{:n=>40}"
|
32
|
+
Answer: 42
|
33
|
+
$ echo "Answer: <%= 2 + n.to_i %>" | tilt -t erb -Dn=40
|
34
|
+
Answer: 42
|
35
|
+
USAGE
|
36
|
+
private_constant :USAGE
|
37
|
+
|
38
|
+
# Backbone of the tilt command line utility. Allows mocking input/output
|
39
|
+
# for simple testing. Returns program exit code.
|
40
|
+
def self.run(argv: ARGV, stdout: $stdout, stdin: $stdin, stderr: $stderr, script_name: File.basename($0))
|
41
|
+
pattern = nil
|
42
|
+
layout = nil
|
43
|
+
locals = {}
|
44
|
+
abort = proc do |msg|
|
45
|
+
stderr.puts msg
|
46
|
+
return 1
|
47
|
+
end
|
48
|
+
|
49
|
+
OptionParser.new do |o|
|
50
|
+
o.program_name = script_name
|
51
|
+
|
52
|
+
# list all available template engines
|
53
|
+
o.on("-l", "--list") do
|
54
|
+
groups = {}
|
55
|
+
Tilt.lazy_map.each do |pattern,engines|
|
56
|
+
engines.each do |engine,|
|
57
|
+
engine = engine.split('::').last.sub(/Template\z/, '')
|
58
|
+
(groups[engine] ||= []) << pattern
|
59
|
+
end
|
60
|
+
end
|
61
|
+
groups.sort { |(k1,v1),(k2,v2)| k1 <=> k2 }.each do |engine,files|
|
62
|
+
stdout.printf "%-20s %s\n", engine, files.sort.join(', ')
|
63
|
+
end
|
64
|
+
return 0
|
65
|
+
end
|
66
|
+
|
67
|
+
# the template type / pattern
|
68
|
+
o.on("-t", "--type=PATTERN", String) do |val|
|
69
|
+
abort.("unknown template type: #{val}") unless Tilt[val]
|
70
|
+
pattern = val
|
71
|
+
end
|
72
|
+
|
73
|
+
# pass template output into the specified layout template
|
74
|
+
o.on("-y", "--layout=FILE", String) do |file|
|
75
|
+
paths = [file, "~/.tilt/#{file}", "/etc/tilt/#{file}"]
|
76
|
+
layout = paths.
|
77
|
+
map { |p| File.expand_path(p) }.
|
78
|
+
find { |p| File.exist?(p) }
|
79
|
+
abort.("no such layout: #{file}") if layout.nil?
|
80
|
+
end
|
81
|
+
|
82
|
+
# define a local variable
|
83
|
+
o.on("-D", "--define=PAIR", String) do |pair|
|
84
|
+
key, value = pair.split(/[=:]/, 2)
|
85
|
+
locals[key.to_sym] = value
|
86
|
+
end
|
87
|
+
|
88
|
+
# define local variables from YAML or JSON
|
89
|
+
o.on("-d", "--define-file=FILE", String) do |file|
|
90
|
+
require 'yaml'
|
91
|
+
abort.("no such define file: #{file}") unless File.exist? file
|
92
|
+
hash = File.open(file, 'r:bom|utf-8') { |f| YAML.load(f.read) }
|
93
|
+
abort.("vars must be a Hash, not instance of #{hash.class}") unless hash.is_a?(Hash)
|
94
|
+
hash.each { |key, value| locals[key.to_sym] = value }
|
95
|
+
end
|
96
|
+
|
97
|
+
# define local variables using a Ruby hash
|
98
|
+
o.on("--vars=RUBY") do |ruby|
|
99
|
+
hash = eval(ruby)
|
100
|
+
abort.("vars must be a Hash, not instance of #{hash.class}") unless hash.is_a?(Hash)
|
101
|
+
hash.each { |key, value| locals[key.to_sym] = value }
|
102
|
+
end
|
103
|
+
|
104
|
+
o.on_tail("-h", "--help") do
|
105
|
+
stdout.puts USAGE
|
106
|
+
return 0
|
107
|
+
end
|
108
|
+
end.parse!(argv)
|
109
|
+
|
110
|
+
file = argv.first || '-'
|
111
|
+
pattern = file if pattern.nil?
|
112
|
+
abort.("template type not given. see: #{script_name} --help") if ['-', ''].include?(pattern)
|
113
|
+
|
114
|
+
engine = Tilt[pattern]
|
115
|
+
abort.("template engine not found for: #{pattern}") unless engine
|
116
|
+
|
117
|
+
template =
|
118
|
+
engine.new(file) {
|
119
|
+
if file == '-'
|
120
|
+
stdin.read
|
121
|
+
else
|
122
|
+
File.read(file)
|
123
|
+
end
|
124
|
+
}
|
125
|
+
output = template.render(self, locals)
|
126
|
+
|
127
|
+
# process layout
|
128
|
+
output = Tilt.new(layout).render(self, locals) { output } if layout
|
129
|
+
|
130
|
+
stdout.write(output)
|
131
|
+
|
132
|
+
0
|
133
|
+
end
|
134
|
+
end
|
data/lib/tilt/coffee.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'coffee_script'
|
3
4
|
|
4
5
|
module Tilt
|
@@ -6,50 +7,42 @@ module Tilt
|
|
6
7
|
# http://coffeescript.org/
|
7
8
|
#
|
8
9
|
# CoffeeScript templates do not support object scopes, locals, or yield.
|
9
|
-
class CoffeeScriptTemplate <
|
10
|
+
class CoffeeScriptTemplate < StaticTemplate
|
10
11
|
self.default_mime_type = 'application/javascript'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@@default_bare
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.default_bare=(value)
|
19
|
-
@@default_bare = value
|
13
|
+
@default_bare = false
|
14
|
+
class << self
|
15
|
+
attr_accessor :default_bare
|
20
16
|
end
|
21
17
|
|
22
|
-
#
|
18
|
+
# :nocov:
|
23
19
|
def self.default_no_wrap
|
24
|
-
|
20
|
+
warn "#{self.class}.default_no_wrap is deprecated and will be removed in Tilt 2.3. Switch to #{self.class}.default_bare."
|
21
|
+
default_bare
|
25
22
|
end
|
26
23
|
|
27
|
-
# DEPRECATED
|
28
24
|
def self.default_no_wrap=(value)
|
29
|
-
|
25
|
+
warn "#{self.class}.default_no_wrap= is deprecated and will be removed in Tilt 2.3. Switch to #{self.class}.default_bare=."
|
26
|
+
self.default_bare = value
|
30
27
|
end
|
28
|
+
# :nocov:
|
31
29
|
|
32
30
|
def self.literate?
|
33
31
|
false
|
34
32
|
end
|
35
33
|
|
36
34
|
def prepare
|
37
|
-
if
|
38
|
-
options[:bare] = self.class.default_bare
|
35
|
+
if !@options.key?(:bare) and !@options.key?(:no_wrap)
|
36
|
+
@options[:bare] = self.class.default_bare
|
39
37
|
end
|
40
|
-
options[:literate] ||= self.class.literate?
|
41
|
-
|
42
|
-
|
43
|
-
def evaluate(scope, locals, &block)
|
44
|
-
@output ||= CoffeeScript.compile(data, options)
|
45
|
-
end
|
46
|
-
|
47
|
-
def allows_script?
|
48
|
-
false
|
38
|
+
@options[:literate] ||= self.class.literate?
|
39
|
+
@output = CoffeeScript.compile(@data, @options)
|
49
40
|
end
|
50
41
|
end
|
51
42
|
|
52
43
|
class CoffeeScriptLiterateTemplate < CoffeeScriptTemplate
|
44
|
+
@default_bare = false
|
45
|
+
|
53
46
|
def self.literate?
|
54
47
|
true
|
55
48
|
end
|
data/lib/tilt/commonmarker.rb
CHANGED
@@ -1,88 +1,54 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'commonmarker'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
EXTENSIONS.select do |extension|
|
41
|
-
options[extension]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def parse_options
|
46
|
-
raw_options = PARSE_OPTIONS.select do |option|
|
47
|
-
options[option]
|
48
|
-
end
|
49
|
-
actual_options = raw_options.map do |option|
|
50
|
-
OPTION_ALIAS[option] || option
|
51
|
-
end
|
52
|
-
|
53
|
-
if actual_options.any?
|
54
|
-
actual_options
|
55
|
-
else
|
56
|
-
:DEFAULT
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def render_options
|
61
|
-
raw_options = RENDER_OPTIONS.select do |option|
|
62
|
-
options[option]
|
63
|
-
end
|
64
|
-
actual_options = raw_options.map do |option|
|
65
|
-
OPTION_ALIAS[option] || option
|
66
|
-
end
|
67
|
-
if actual_options.any?
|
68
|
-
actual_options
|
69
|
-
else
|
70
|
-
:DEFAULT
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def prepare
|
75
|
-
@engine = nil
|
76
|
-
@output = nil
|
77
|
-
end
|
5
|
+
aliases = {
|
6
|
+
:smartypants => :SMART
|
7
|
+
}.freeze
|
8
|
+
parse_opts = [
|
9
|
+
:FOOTNOTES,
|
10
|
+
:LIBERAL_HTML_TAG,
|
11
|
+
:SMART,
|
12
|
+
:smartypants,
|
13
|
+
:STRIKETHROUGH_DOUBLE_TILDE,
|
14
|
+
:UNSAFE,
|
15
|
+
:VALIDATE_UTF8,
|
16
|
+
].freeze
|
17
|
+
render_opts = [
|
18
|
+
:FOOTNOTES,
|
19
|
+
:FULL_INFO_STRING,
|
20
|
+
:GITHUB_PRE_LANG,
|
21
|
+
:HARDBREAKS,
|
22
|
+
:NOBREAKS,
|
23
|
+
:SAFE, # Removed in v0.18.0 (2018-10-17)
|
24
|
+
:SOURCEPOS,
|
25
|
+
:TABLE_PREFER_STYLE_ATTRIBUTES,
|
26
|
+
:UNSAFE,
|
27
|
+
].freeze
|
28
|
+
exts = [
|
29
|
+
:autolink,
|
30
|
+
:strikethrough,
|
31
|
+
:table,
|
32
|
+
:tagfilter,
|
33
|
+
:tasklist,
|
34
|
+
].freeze
|
35
|
+
|
36
|
+
|
37
|
+
Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do
|
38
|
+
extensions = exts.select do |extension|
|
39
|
+
@options[extension]
|
40
|
+
end
|
78
41
|
|
79
|
-
|
80
|
-
|
81
|
-
|
42
|
+
parse_options, render_options = [parse_opts, render_opts].map do |opts|
|
43
|
+
opts = opts.select do |option|
|
44
|
+
@options[option]
|
45
|
+
end.map! do |option|
|
46
|
+
aliases[option] || option
|
82
47
|
end
|
83
48
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
49
|
+
opts = :DEFAULT unless opts.any?
|
50
|
+
opts
|
87
51
|
end
|
52
|
+
|
53
|
+
CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions)
|
88
54
|
end
|
data/lib/tilt/creole.rb
CHANGED
@@ -1,25 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'creole'
|
3
4
|
|
4
|
-
|
5
|
-
# Creole implementation. See:
|
6
|
-
# http://www.wikicreole.org/
|
7
|
-
class CreoleTemplate < Template
|
8
|
-
def prepare
|
9
|
-
opts = {}
|
10
|
-
[:allowed_schemes, :extensions, :no_escape].each do |k|
|
11
|
-
opts[k] = options[k] if options[k]
|
12
|
-
end
|
13
|
-
@engine = Creole::Parser.new(data, opts)
|
14
|
-
@output = nil
|
15
|
-
end
|
5
|
+
allowed_opts = [:allowed_schemes, :extensions, :no_escape].freeze
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
false
|
23
|
-
end
|
7
|
+
# Creole implementation. See: http://www.wikicreole.org/
|
8
|
+
Tilt::CreoleTemplate = Tilt::StaticTemplate.subclass do
|
9
|
+
opts = {}
|
10
|
+
allowed_opts.each do |k|
|
11
|
+
opts[k] = @options[k] if @options[k]
|
24
12
|
end
|
13
|
+
Creole::Parser.new(@data, opts).to_html
|
25
14
|
end
|
data/lib/tilt/csv.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'csv'
|
3
4
|
|
4
5
|
module Tilt
|
@@ -32,13 +33,13 @@ module Tilt
|
|
32
33
|
self.default_mime_type = 'text/csv'
|
33
34
|
|
34
35
|
def prepare
|
35
|
-
@outvar = options.delete(:outvar) || '_csvout'
|
36
|
+
@outvar = @options.delete(:outvar) || '_csvout'
|
36
37
|
end
|
37
38
|
|
38
39
|
def precompiled_template(locals)
|
39
40
|
<<-RUBY
|
40
|
-
#{@outvar} = CSV.generate(**#{options}) do |csv|
|
41
|
-
#{data}
|
41
|
+
#{@outvar} = CSV.generate(**#{@options}) do |csv|
|
42
|
+
#{@data}
|
42
43
|
end
|
43
44
|
RUBY
|
44
45
|
end
|