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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +1 -0
  3. data/bin/tilt +2 -120
  4. data/lib/tilt/_emacs_org.rb +2 -0
  5. data/lib/tilt/_handlebars.rb +2 -0
  6. data/lib/tilt/_jbuilder.rb +2 -0
  7. data/lib/tilt/_org.rb +2 -0
  8. data/lib/tilt/asciidoc.rb +11 -23
  9. data/lib/tilt/babel.rb +5 -13
  10. data/lib/tilt/builder.rb +18 -13
  11. data/lib/tilt/cli.rb +134 -0
  12. data/lib/tilt/coffee.rb +18 -25
  13. data/lib/tilt/commonmarker.rb +47 -81
  14. data/lib/tilt/creole.rb +9 -20
  15. data/lib/tilt/csv.rb +5 -4
  16. data/lib/tilt/erb.rb +18 -12
  17. data/lib/tilt/erubi.rb +7 -6
  18. data/lib/tilt/erubis.rb +12 -6
  19. data/lib/tilt/etanni.rb +3 -2
  20. data/lib/tilt/haml.rb +12 -9
  21. data/lib/tilt/kramdown.rb +8 -20
  22. data/lib/tilt/liquid.rb +10 -14
  23. data/lib/tilt/livescript.rb +8 -20
  24. data/lib/tilt/mapping.rb +180 -104
  25. data/lib/tilt/markaby.rb +5 -7
  26. data/lib/tilt/maruku.rb +5 -19
  27. data/lib/tilt/nokogiri.rb +11 -10
  28. data/lib/tilt/pandoc.rb +33 -51
  29. data/lib/tilt/pipeline.rb +1 -0
  30. data/lib/tilt/plain.rb +4 -15
  31. data/lib/tilt/prawn.rb +15 -23
  32. data/lib/tilt/radius.rb +15 -22
  33. data/lib/tilt/rdiscount.rb +17 -33
  34. data/lib/tilt/rdoc.rb +14 -35
  35. data/lib/tilt/redcarpet.rb +25 -67
  36. data/lib/tilt/redcloth.rb +9 -19
  37. data/lib/tilt/rst-pandoc.rb +6 -19
  38. data/lib/tilt/sass.rb +34 -43
  39. data/lib/tilt/slim.rb +5 -0
  40. data/lib/tilt/string.rb +4 -3
  41. data/lib/tilt/template.rb +146 -56
  42. data/lib/tilt/typescript.rb +11 -18
  43. data/lib/tilt/wikicloth.rb +7 -19
  44. data/lib/tilt/yajl.rb +5 -11
  45. data/lib/tilt.rb +57 -30
  46. metadata +10 -7
  47. data/lib/tilt/bluecloth.rb +0 -26
  48. data/lib/tilt/less.rb +0 -32
  49. data/lib/tilt/sigil.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 837e8836cd6aacedb861823faead2fd72549f1c750e2f0350471303c1ca5cab3
4
- data.tar.gz: 578c1873d63eb0e2426e2c86199f414f516952562c85ee9e91e0907a936603b9
3
+ metadata.gz: 0b933744ac3dc007d759af22c61ea725d84e6d83a689c07e384792d08f330f60
4
+ data.tar.gz: b07ad772a645934f3c0f912d2864eb9b47964b423a83d3cbc7978e6c90385229
5
5
  SHA512:
6
- metadata.gz: a63e7b55aacbe374f70317cddd821c065ae512622be8f20bc25aeb2aabd5455d91cb7d97894de420f3bfb4f7c571c5f832047db182bb35107fd6d566879c04d7
7
- data.tar.gz: 2c2785a08edb15f9e593a1b717682212f5a50f1f6694c02256179ee15c9a1e73429a5c6ae804e83611cc645209330c36ea117c6d38698f0021e2a7d748c59919
6
+ metadata.gz: 17e9ff63c011271c8fceb20c08f1c3d36f85c6674608690575ffc08b79b5d9704c0d63e456c00a2a0207295f54ef8c5df9f59c5de71680b1bf018faee93cba26
7
+ data.tar.gz: fcffaeed7fba1e7f2bd9ec25f57426d544281cd434f8138253f5046f47e73a871770b4e8be1cb08349462b988a6101bbbca1f7ecc273bd74f457271eb3a84aa9
data/COPYING CHANGED
@@ -1,4 +1,5 @@
1
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,122 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'ostruct'
3
- require 'optparse'
4
- require 'tilt'
2
+ require_relative '../lib/tilt/cli'
5
3
 
6
- usage = <<USAGE
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
@@ -0,0 +1,2 @@
1
+ warn "Lazy loading of emacs org templates is deprecated and will be removed in Tilt 3. Require tilt/emacs_org manually.", uplevel: 1
2
+ require "tilt/emacs_org"
@@ -0,0 +1,2 @@
1
+ warn "Lazy loading of handlebars templates is deprecated and will be removed in Tilt 3. Require tilt/handlebars manually.", uplevel: 1
2
+ require "tilt/handlebars"
@@ -0,0 +1,2 @@
1
+ warn "Lazy loading of jbuilder templates is deprecated and will be removed in Tilt 3. Require tilt/jbuilder manually.", uplevel: 1
2
+ require "tilt/jbuilder"
data/lib/tilt/_org.rb ADDED
@@ -0,0 +1,2 @@
1
+ warn "Lazy loading of org templates is deprecated and will be removed in Tilt 3. Require org-ruby manually.", uplevel: 1
2
+ require "org-ruby"
data/lib/tilt/asciidoc.rb CHANGED
@@ -1,27 +1,15 @@
1
- require 'tilt/template'
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
- def allows_script?
24
- false
25
- end
26
- end
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
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+ require_relative 'template'
2
3
  require 'babel/transpiler'
3
4
 
4
- module Tilt
5
- class BabelTemplate < Template
6
- self.default_mime_type = 'application/javascript'
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
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+ require_relative 'template'
2
3
  require 'builder'
3
4
 
4
5
  module Tilt
5
- # Builder template implementation. See:
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
- xml = (locals[:xml] || ::Builder::XmlMarkup.new(options))
16
-
17
- if data.respond_to?(:to_str)
18
- if !locals[:xml]
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(scope, locals, &block)
20
+ return super
22
21
  end
23
22
 
24
- data.call(xml)
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
- require 'tilt/template'
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 < Template
10
+ class CoffeeScriptTemplate < StaticTemplate
10
11
  self.default_mime_type = 'application/javascript'
11
12
 
12
- @@default_bare = false
13
-
14
- def self.default_bare
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
- # DEPRECATED
18
+ # :nocov:
23
19
  def self.default_no_wrap
24
- @@default_bare
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
- @@default_bare = value
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 !options.key?(:bare) and !options.key?(:no_wrap)
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
- end
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
@@ -1,88 +1,54 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+ require_relative 'template'
2
3
  require 'commonmarker'
3
4
 
4
- module Tilt
5
- class CommonMarkerTemplate < Template
6
- self.default_mime_type = 'text/html'
7
-
8
- OPTION_ALIAS = {
9
- :smartypants => :SMART
10
- }
11
- PARSE_OPTIONS = [
12
- :FOOTNOTES,
13
- :LIBERAL_HTML_TAG,
14
- :SMART,
15
- :smartypants,
16
- :STRIKETHROUGH_DOUBLE_TILDE,
17
- :UNSAFE,
18
- :VALIDATE_UTF8,
19
- ].freeze
20
- RENDER_OPTIONS = [
21
- :FOOTNOTES,
22
- :FULL_INFO_STRING,
23
- :GITHUB_PRE_LANG,
24
- :HARDBREAKS,
25
- :NOBREAKS,
26
- :SAFE, # Removed in v0.18.0 (2018-10-17)
27
- :SOURCEPOS,
28
- :TABLE_PREFER_STYLE_ATTRIBUTES,
29
- :UNSAFE,
30
- ].freeze
31
- EXTENSIONS = [
32
- :autolink,
33
- :strikethrough,
34
- :table,
35
- :tagfilter,
36
- :tasklist,
37
- ].freeze
38
-
39
- def extensions
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
- def evaluate(scope, locals, &block)
80
- doc = CommonMarker.render_doc(data, parse_options, extensions)
81
- doc.to_html(render_options, extensions)
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
- def allows_script?
85
- false
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
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+ require_relative 'template'
2
3
  require 'creole'
3
4
 
4
- module Tilt
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
- def evaluate(scope, locals, &block)
18
- @output ||= @engine.to_html
19
- end
20
-
21
- def allows_script?
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
- require 'tilt/template'
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