tilt 2.0.10 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  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 +12 -31
  13. data/lib/tilt/commonmarker.rb +47 -71
  14. data/lib/tilt/creole.rb +9 -20
  15. data/lib/tilt/csv.rb +6 -18
  16. data/lib/tilt/erb.rb +23 -21
  17. data/lib/tilt/erubi.rb +29 -6
  18. data/lib/tilt/erubis.rb +17 -11
  19. data/lib/tilt/etanni.rb +3 -2
  20. data/lib/tilt/haml.rb +73 -65
  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 +228 -109
  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 -43
  29. data/lib/tilt/pipeline.rb +19 -0
  30. data/lib/tilt/plain.rb +4 -15
  31. data/lib/tilt/prawn.rb +10 -25
  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 +20 -72
  36. data/lib/tilt/redcloth.rb +9 -19
  37. data/lib/tilt/rst-pandoc.rb +7 -15
  38. data/lib/tilt/sass.rb +45 -28
  39. data/lib/tilt/slim.rb +5 -0
  40. data/lib/tilt/string.rb +9 -3
  41. data/lib/tilt/template.rb +235 -77
  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 +60 -39
  46. metadata +24 -16
  47. data/lib/tilt/bluecloth.rb +0 -24
  48. data/lib/tilt/dummy.rb +0 -3
  49. data/lib/tilt/less.rb +0 -30
  50. data/lib/tilt/sigil.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 65edfb577c11890055c06be1af7c6cd1692d6bb1
4
- data.tar.gz: 025cb576450017fe953040a197522416e98c7835
2
+ SHA256:
3
+ metadata.gz: 42821dda310628574e4e1c99c69751d463bee48887c8f90c82768b80bb17231b
4
+ data.tar.gz: eb67c15726743517bf14d6db8b0034f7cbb7bd6c3c96d72ce24623430df03202
5
5
  SHA512:
6
- metadata.gz: f1bbd4f61540f418aed012bd34cca939a7a208f0dc73ec5283041a0611fb629d5941bf24ab2976e2038774599b5d5e8f29c7beb0fababdf91c6f2d4eb9628a0b
7
- data.tar.gz: 32cb517066dc3550f33b201980884479dbd387864133267ac1563fcfa8500386bbcf204ca0fbb9c98bac8f910cc1af647ff9464839806b1d32a088865c0d6e52
6
+ metadata.gz: 832ae277c35c2bb4fb36f93d2aaa411ec5ac948eb7d1eec956d70a1a54d27a2c4d326ae02bc5a75d06177aebb29d22cec4437ada71691ca25aba050fcad78236
7
+ data.tar.gz: ecc19aa399a14acc5c3d4f5adfc2d0bb70bf8d7552fd90ae7e4165cbad45b8f149e6cd808c49c0808762b6b9c68945dc6009a94c2910056a49f9e702637a8391
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,27 +7,12 @@ 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
20
- end
21
-
22
- # DEPRECATED
23
- def self.default_no_wrap
24
- @@default_bare
25
- end
26
-
27
- # DEPRECATED
28
- def self.default_no_wrap=(value)
29
- @@default_bare = value
13
+ @default_bare = false
14
+ class << self
15
+ attr_accessor :default_bare
30
16
  end
31
17
 
32
18
  def self.literate?
@@ -34,22 +20,17 @@ module Tilt
34
20
  end
35
21
 
36
22
  def prepare
37
- if !options.key?(:bare) and !options.key?(:no_wrap)
38
- options[:bare] = self.class.default_bare
23
+ if !@options.key?(:bare) and !@options.key?(:no_wrap)
24
+ @options[:bare] = self.class.default_bare
39
25
  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
26
+ @options[:literate] ||= self.class.literate?
27
+ @output = CoffeeScript.compile(@data, @options)
49
28
  end
50
29
  end
51
30
 
52
31
  class CoffeeScriptLiterateTemplate < CoffeeScriptTemplate
32
+ @default_bare = false
33
+
53
34
  def self.literate?
54
35
  true
55
36
  end
@@ -1,78 +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
- :SMART,
13
- :smartypants,
14
- ].freeze
15
- RENDER_OPTIONS = [
16
- :GITHUB_PRE_LANG,
17
- :HARDBREAKS,
18
- :NOBREAKS,
19
- :SAFE,
20
- :SOURCEPOS,
21
- ].freeze
22
- EXTENSIONS = [
23
- :autolink,
24
- :strikethrough,
25
- :table,
26
- :tagfilter,
27
- ].freeze
28
-
29
- def extensions
30
- EXTENSIONS.select do |extension|
31
- options[extension]
32
- end
33
- end
34
-
35
- def parse_options
36
- raw_options = PARSE_OPTIONS.select do |option|
37
- options[option]
38
- end
39
- actual_options = raw_options.map do |option|
40
- OPTION_ALIAS[option] || option
41
- end
42
-
43
- if actual_options.any?
44
- actual_options
45
- else
46
- :DEFAULT
47
- end
48
- end
49
-
50
- def render_options
51
- raw_options = RENDER_OPTIONS.select do |option|
52
- options[option]
53
- end
54
- actual_options = raw_options.map do |option|
55
- OPTION_ALIAS[option] || option
56
- end
57
- if actual_options.any?
58
- actual_options
59
- else
60
- :DEFAULT
61
- end
62
- end
63
-
64
- def prepare
65
- @engine = nil
66
- @output = nil
67
- 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
68
41
 
69
- def evaluate(scope, locals, &block)
70
- doc = CommonMarker.render_doc(data, parse_options, extensions)
71
- 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
72
47
  end
73
48
 
74
- def allows_script?
75
- false
76
- end
49
+ opts = :DEFAULT unless opts.any?
50
+ opts
77
51
  end
52
+
53
+ CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions)
78
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,10 +1,6 @@
1
- require 'tilt/template'
2
-
3
- if RUBY_VERSION >= '1.9.0'
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,22 +32,14 @@ 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
- @outvar = options.delete(:outvar) || '_csvout'
36
+ @outvar = @options.delete(:outvar) || '_csvout'
49
37
  end
50
38
 
51
39
  def precompiled_template(locals)
52
40
  <<-RUBY
53
- #{@outvar} = #{self.class.engine}.generate(#{options}) do |csv|
54
- #{data}
41
+ #{@outvar} = CSV.generate(**#{@options}) do |csv|
42
+ #{@data}
55
43
  end
56
44
  RUBY
57
45
  end