tilt 2.0.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d9bb9bafc29e9442fed0bf862fb442ea6efaa97c2881b7b958361f0ef7095aaa
|
4
|
+
data.tar.gz: f25db1d4c05ef3b20c5fabefa4eb664e702f51f8d9821b0c44f5f5404ade4c3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc69e05565c5b007fbaaddc7636d6298fc9930c42d1e029834b752236309d97024132118bb723817c5c192cad1f1cef01e278ce4fc46629dac706d0ec4fdd6a2
|
7
|
+
data.tar.gz: 702e18b78c3e9b21e1abe86671bbe6f2427db44b05be4941c1693f30070f1de028af5324294d693bdeda130da603ecfd5c98dcefbce7ca21f7e7f6df5a249b97
|
data/COPYING
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Copyright (c) 2010 Ryan Tomayko <http://tomayko.com/about>
|
1
|
+
Copyright (c) 2010-2016 Ryan Tomayko <http://tomayko.com/about>
|
2
|
+
Copyright (c) 2015-2023 Jeremy Evans
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
5
|
of this software and associated documentation files (the "Software"), to
|
data/bin/tilt
CHANGED
@@ -1,112 +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
|
-
--vars=<ruby> Evaluate <ruby> to Hash and use for variables
|
19
|
-
|
20
|
-
-h, --help Show this help message
|
21
|
-
|
22
|
-
Convert markdown to HTML:
|
23
|
-
$ tilt foo.markdown > foo.html
|
24
|
-
|
25
|
-
Process ERB template:
|
26
|
-
$ echo "Answer: <%= 2 + 2 %>" | tilt -t erb
|
27
|
-
Answer: 4
|
28
|
-
|
29
|
-
Define variables:
|
30
|
-
$ echo "Answer: <%= 2 + n %>" | tilt -t erb --vars="{:n=>40}"
|
31
|
-
Answer: 42
|
32
|
-
$ echo "Answer: <%= 2 + n.to_i %>" | tilt -t erb -Dn=40
|
33
|
-
Answer: 42
|
34
|
-
USAGE
|
35
|
-
|
36
|
-
script_name = File.basename($0)
|
37
|
-
pattern = nil
|
38
|
-
layout = nil
|
39
|
-
locals = {}
|
40
|
-
|
41
|
-
ARGV.options do |o|
|
42
|
-
o.program_name = script_name
|
43
|
-
|
44
|
-
# list all available template engines
|
45
|
-
o.on("-l", "--list") do
|
46
|
-
groups = {}
|
47
|
-
Tilt.mappings.each do |pattern,engines|
|
48
|
-
engines.each do |engine|
|
49
|
-
key = engine.name.split('::').last.sub(/Template$/, '')
|
50
|
-
(groups[key] ||= []) << pattern
|
51
|
-
end
|
52
|
-
end
|
53
|
-
groups.sort { |(k1,v1),(k2,v2)| k1 <=> k2 }.each do |engine,files|
|
54
|
-
printf "%-15s %s\n", engine, files.sort.join(', ')
|
55
|
-
end
|
56
|
-
exit
|
57
|
-
end
|
58
|
-
|
59
|
-
# the template type / pattern
|
60
|
-
o.on("-t", "--type=PATTERN", String) do |val|
|
61
|
-
abort "unknown template type: #{val}" if Tilt[val].nil?
|
62
|
-
pattern = val
|
63
|
-
end
|
64
|
-
|
65
|
-
# pass template output into the specified layout template
|
66
|
-
o.on("-y", "--layout=FILE", String) do |file|
|
67
|
-
paths = [file, "~/.tilt/#{file}", "/etc/tilt/#{file}"]
|
68
|
-
layout = paths.
|
69
|
-
map { |p| File.expand_path(p) }.
|
70
|
-
find { |p| File.exist?(p) }
|
71
|
-
abort "no such layout: #{file}" if layout.nil?
|
72
|
-
end
|
73
|
-
|
74
|
-
# define a local variable
|
75
|
-
o.on("-D", "--define=PAIR", String) do |pair|
|
76
|
-
key, value = pair.split(/[=:]/, 2)
|
77
|
-
locals[key.to_sym] = value
|
78
|
-
end
|
79
|
-
|
80
|
-
# define local variables using a Ruby hash
|
81
|
-
o.on("--vars=RUBY") do |ruby|
|
82
|
-
hash = eval(ruby)
|
83
|
-
abort "vars must be a Hash, not #{hash.inspect}" if !hash.is_a?(Hash)
|
84
|
-
hash.each { |key, value| locals[key.to_sym] = value }
|
85
|
-
end
|
86
|
-
|
87
|
-
o.on_tail("-h", "--help") { puts usage; exit }
|
88
|
-
|
89
|
-
o.parse!
|
90
|
-
end
|
91
|
-
|
92
|
-
file = ARGV.first || '-'
|
93
|
-
pattern = file if pattern.nil?
|
94
|
-
abort "template type not given. see: #{$0} --help" if ['-', ''].include?(pattern)
|
95
|
-
|
96
|
-
engine = Tilt[pattern]
|
97
|
-
abort "template engine not found for: #{pattern}" if engine.nil?
|
98
|
-
|
99
|
-
template =
|
100
|
-
engine.new(file) {
|
101
|
-
if file == '-'
|
102
|
-
$stdin.read
|
103
|
-
else
|
104
|
-
File.read(file)
|
105
|
-
end
|
106
|
-
}
|
107
|
-
output = template.render(self, locals)
|
108
|
-
|
109
|
-
# process layout
|
110
|
-
output = Tilt.new(layout).render(self, locals) { output } if layout
|
111
|
-
|
112
|
-
$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
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
3
|
+
require 'babel/transpiler'
|
4
|
+
|
5
|
+
Tilt::BabelTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do
|
6
|
+
@options[:filename] ||= @file
|
7
|
+
Babel::Transpiler.transform(@data)["code"]
|
8
|
+
end
|
data/lib/tilt/builder.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
2
3
|
require 'builder'
|
3
4
|
|
4
5
|
module Tilt
|
5
|
-
|
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
|
-
def prepare
|
10
|
+
def prepare
|
11
|
+
@options[:indent] ||= 2
|
12
|
+
end
|
11
13
|
|
12
14
|
def evaluate(scope, locals, &block)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
if @data.respond_to?(:to_str)
|
16
|
+
unless locals[:xml]
|
17
|
+
locals = Hash[locals]
|
18
|
+
locals[:xml] = xml_builder
|
19
|
+
end
|
20
|
+
return super
|
21
|
+
end
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
xml = locals[:xml] || xml_builder
|
24
|
+
@data.call(xml)
|
25
|
+
xml.target!
|
22
26
|
end
|
23
27
|
|
24
28
|
def precompiled_postamble(locals)
|
@@ -26,8 +30,13 @@ module Tilt
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def precompiled_template(locals)
|
29
|
-
data.to_str
|
33
|
+
@data.to_str
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def xml_builder
|
39
|
+
::Builder::XmlMarkup.new(options)
|
30
40
|
end
|
31
41
|
end
|
32
42
|
end
|
33
|
-
|
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,41 +7,32 @@ 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
|
20
|
-
end
|
21
|
-
|
22
|
-
# DEPRECATED
|
23
|
-
def self.default_no_wrap
|
24
|
-
@@default_bare
|
13
|
+
@default_bare = false
|
14
|
+
class << self
|
15
|
+
attr_accessor :default_bare
|
25
16
|
end
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
@@default_bare = value
|
18
|
+
def self.literate?
|
19
|
+
false
|
30
20
|
end
|
31
21
|
|
32
22
|
def prepare
|
33
|
-
if
|
34
|
-
options[:bare] = self.class.default_bare
|
23
|
+
if !@options.key?(:bare) and !@options.key?(:no_wrap)
|
24
|
+
@options[:bare] = self.class.default_bare
|
35
25
|
end
|
26
|
+
@options[:literate] ||= self.class.literate?
|
27
|
+
@output = CoffeeScript.compile(@data, @options)
|
36
28
|
end
|
29
|
+
end
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
31
|
+
class CoffeeScriptLiterateTemplate < CoffeeScriptTemplate
|
32
|
+
@default_bare = false
|
41
33
|
|
42
|
-
def
|
43
|
-
|
34
|
+
def self.literate?
|
35
|
+
true
|
44
36
|
end
|
45
37
|
end
|
46
38
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
3
|
+
require 'commonmarker'
|
4
|
+
|
5
|
+
if defined?(::Commonmarker)
|
6
|
+
aliases = {
|
7
|
+
:smartypants => :smart
|
8
|
+
}.freeze
|
9
|
+
parse_opts = [
|
10
|
+
:smart,
|
11
|
+
:default_info_string,
|
12
|
+
].freeze
|
13
|
+
render_opts = [
|
14
|
+
:hardbreaks,
|
15
|
+
:github_pre_lang,
|
16
|
+
:width,
|
17
|
+
:unsafe,
|
18
|
+
:escape,
|
19
|
+
:sourcepos,
|
20
|
+
].freeze
|
21
|
+
exts = [
|
22
|
+
:strikethrough,
|
23
|
+
:tagfilter,
|
24
|
+
:table,
|
25
|
+
:autolink,
|
26
|
+
:tasklist,
|
27
|
+
:superscript,
|
28
|
+
:header_ids,
|
29
|
+
:footnotes,
|
30
|
+
:description_lists,
|
31
|
+
:front_matter_delimiter,
|
32
|
+
:shortcodes,
|
33
|
+
].freeze
|
34
|
+
|
35
|
+
Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do
|
36
|
+
parse_options = @options.select { |key, _| parse_opts.include?(key.downcase) }.transform_keys(&:downcase)
|
37
|
+
parse_options.merge!(@options.select { |key, _| aliases.has_key?(key) }.transform_keys { |key| aliases[key] })
|
38
|
+
render_options = @options.select { |key, _| render_opts.include?(key.downcase) }.transform_keys(&:downcase)
|
39
|
+
extensions = @options.select { |key, _| exts.include?(key) }.transform_keys(&:downcase)
|
40
|
+
|
41
|
+
Commonmarker.to_html(@data, options: { parse: parse_options, render: render_options, extension: extensions })
|
42
|
+
end
|
43
|
+
# :nocov:
|
44
|
+
else
|
45
|
+
aliases = {
|
46
|
+
:smartypants => :SMART
|
47
|
+
}.freeze
|
48
|
+
parse_opts = [
|
49
|
+
:FOOTNOTES,
|
50
|
+
:LIBERAL_HTML_TAG,
|
51
|
+
:SMART,
|
52
|
+
:smartypants,
|
53
|
+
:STRIKETHROUGH_DOUBLE_TILDE,
|
54
|
+
:UNSAFE,
|
55
|
+
:VALIDATE_UTF8,
|
56
|
+
].freeze
|
57
|
+
render_opts = [
|
58
|
+
:FOOTNOTES,
|
59
|
+
:FULL_INFO_STRING,
|
60
|
+
:GITHUB_PRE_LANG,
|
61
|
+
:HARDBREAKS,
|
62
|
+
:NOBREAKS,
|
63
|
+
:SAFE, # Removed in v0.18.0 (2018-10-17)
|
64
|
+
:SOURCEPOS,
|
65
|
+
:TABLE_PREFER_STYLE_ATTRIBUTES,
|
66
|
+
:UNSAFE,
|
67
|
+
].freeze
|
68
|
+
exts = [
|
69
|
+
:autolink,
|
70
|
+
:strikethrough,
|
71
|
+
:table,
|
72
|
+
:tagfilter,
|
73
|
+
:tasklist,
|
74
|
+
].freeze
|
75
|
+
|
76
|
+
Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do
|
77
|
+
extensions = exts.select do |extension|
|
78
|
+
@options[extension]
|
79
|
+
end
|
80
|
+
|
81
|
+
parse_options, render_options = [parse_opts, render_opts].map do |opts|
|
82
|
+
opts = opts.select do |option|
|
83
|
+
@options[option]
|
84
|
+
end.map! do |option|
|
85
|
+
aliases[option] || option
|
86
|
+
end
|
87
|
+
|
88
|
+
opts = :DEFAULT unless opts.any?
|
89
|
+
opts
|
90
|
+
end
|
91
|
+
|
92
|
+
CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
# :nocov:
|
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,10 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'csv'
|
5
|
-
else
|
6
|
-
require 'fastercsv'
|
7
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'template'
|
3
|
+
require 'csv'
|
8
4
|
|
9
5
|
module Tilt
|
10
6
|
|
@@ -36,24 +32,16 @@ module Tilt
|
|
36
32
|
class CSVTemplate < Template
|
37
33
|
self.default_mime_type = 'text/csv'
|
38
34
|
|
39
|
-
def self.engine
|
40
|
-
if RUBY_VERSION >= '1.9.0' && defined? ::CSV
|
41
|
-
::CSV
|
42
|
-
elsif defined? ::FasterCSV
|
43
|
-
::FasterCSV
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
35
|
def prepare
|
48
|
-
@
|
49
|
-
#{self.class.engine}.generate do |csv|
|
50
|
-
#{data}
|
51
|
-
end
|
52
|
-
RUBY
|
36
|
+
@outvar = @options.delete(:outvar) || '_csvout'
|
53
37
|
end
|
54
38
|
|
55
39
|
def precompiled_template(locals)
|
56
|
-
|
40
|
+
<<-RUBY
|
41
|
+
#{@outvar} = CSV.generate(**#{@options}) do |csv|
|
42
|
+
#{@data}
|
43
|
+
end
|
44
|
+
RUBY
|
57
45
|
end
|
58
46
|
|
59
47
|
def precompiled(locals)
|