tilt 2.0.11 → 2.7.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 (50) 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 +18 -23
  9. data/lib/tilt/babel.rb +9 -12
  10. data/lib/tilt/builder.rb +22 -13
  11. data/lib/tilt/cli.rb +134 -0
  12. data/lib/tilt/coffee.rb +26 -35
  13. data/lib/tilt/commonmarker.rb +123 -75
  14. data/lib/tilt/csv.rb +41 -43
  15. data/lib/tilt/erb.rb +90 -23
  16. data/lib/tilt/erubi.rb +70 -14
  17. data/lib/tilt/etanni.rb +12 -4
  18. data/lib/tilt/haml.rb +139 -65
  19. data/lib/tilt/kramdown.rb +54 -20
  20. data/lib/tilt/liquid.rb +75 -26
  21. data/lib/tilt/livescript.rb +14 -19
  22. data/lib/tilt/mapping.rb +233 -114
  23. data/lib/tilt/markaby.rb +16 -9
  24. data/lib/tilt/nokogiri.rb +24 -12
  25. data/lib/tilt/pandoc.rb +75 -51
  26. data/lib/tilt/pipeline.rb +24 -0
  27. data/lib/tilt/plain.rb +6 -13
  28. data/lib/tilt/prawn.rb +26 -30
  29. data/lib/tilt/radius.rb +70 -22
  30. data/lib/tilt/rdiscount.rb +75 -32
  31. data/lib/tilt/rdoc.rb +28 -35
  32. data/lib/tilt/redcarpet.rb +63 -76
  33. data/lib/tilt/redcloth.rb +35 -18
  34. data/lib/tilt/rst-pandoc.rb +28 -18
  35. data/lib/tilt/sass.rb +58 -45
  36. data/lib/tilt/slim.rb +18 -0
  37. data/lib/tilt/string.rb +19 -5
  38. data/lib/tilt/template.rb +392 -89
  39. data/lib/tilt/typescript.rb +15 -17
  40. data/lib/tilt/yajl.rb +51 -47
  41. data/lib/tilt.rb +68 -44
  42. metadata +22 -19
  43. data/lib/tilt/bluecloth.rb +0 -24
  44. data/lib/tilt/creole.rb +0 -25
  45. data/lib/tilt/dummy.rb +0 -3
  46. data/lib/tilt/erubis.rb +0 -43
  47. data/lib/tilt/less.rb +0 -30
  48. data/lib/tilt/maruku.rb +0 -22
  49. data/lib/tilt/sigil.rb +0 -34
  50. data/lib/tilt/wikicloth.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a552c8551a7093b787234c00bac7ccaaef77e89b1d4835c31ddbaeb8388c74ae
4
- data.tar.gz: 014cff88cd5ec4157d02127576eb788a6b0ae3795e69dc448781093f59153769
3
+ metadata.gz: e425f100107f57bdcf754dde8fcabc9a1d63ad9ee1ad5e2bffe2b5103affc712
4
+ data.tar.gz: 655f9f6617846da59ce0011c4ad15cb20ec01b55045662a4ef6d4537b6ff523c
5
5
  SHA512:
6
- metadata.gz: 9d9da743f0359f10e8486b946132d39ba892482a99e7961c4a62258a680a214030824e92442db2421f35cac7c4378ff3e8e8e0af72bd8af35150aae2cc58555b
7
- data.tar.gz: 2755a44a43e094eb95bffe6ab095f4d8a6cc1b58d1c96d6c20325d8d607ada32da7529758dfed8f8d8f09a3eafe2c7d96f381c314c7cc99f950a36c5eaff3454
6
+ metadata.gz: 18339cfc7b770f714aa272fa5bc8d9d0726b23b0cff8df69c45f2bafa3a341705c50c152bff1c20187b328e46c05b08a0e7a2ab0339352e42afd871559fecf8b
7
+ data.tar.gz: c0d5aee0ec0c2cab1f30aef4bc783432ce945dd446c929b3af370f2f57175718d76ae5f55e0ba1df29de2dc64720d4c911592c9ea0516b8e6abfd06daef656c7
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,22 @@
1
- require 'tilt/template'
2
- require 'asciidoctor'
3
-
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'
1
+ # frozen_string_literal: true
14
2
 
15
- def prepare
16
- options[:header_footer] = false if options[:header_footer].nil?
17
- end
3
+ # = AsciiDoc
4
+ #
5
+ # Asciidoctor implementation for AsciiDoc
6
+ #
7
+ # Asciidoctor is an open source, pure-Ruby processor for
8
+ # converting AsciiDoc documents or strings into HTML 5,
9
+ # DocBook 4.5 and other formats.
10
+ #
11
+ # === See also
12
+ #
13
+ # * http://asciidoc.org
14
+ # * http://asciidoctor.github.com
18
15
 
19
- def evaluate(scope, locals, &block)
20
- @output ||= Asciidoctor.render(data, options, &block)
21
- end
16
+ require_relative 'template'
17
+ require 'asciidoctor'
22
18
 
23
- def allows_script?
24
- false
25
- end
26
- end
19
+ Tilt::AsciidoctorTemplate = Tilt::StaticTemplate.subclass do
20
+ @options[:header_footer] = false if @options[:header_footer].nil?
21
+ Asciidoctor.render(@data, @options)
27
22
  end
data/lib/tilt/babel.rb CHANGED
@@ -1,16 +1,13 @@
1
- require 'tilt/template'
2
- require 'babel/transpiler'
1
+ # frozen_string_literal: true
3
2
 
4
- module Tilt
5
- class BabelTemplate < Template
6
- self.default_mime_type = 'application/javascript'
3
+ # = Babel
4
+ #
5
+ #
7
6
 
8
- def prepare
9
- options[:filename] ||= file
10
- end
7
+ require_relative 'template'
8
+ require 'babel/transpiler'
11
9
 
12
- def evaluate(scope, locals, &block)
13
- @output ||= Babel::Transpiler.transform(data)["code"]
14
- end
15
- end
10
+ Tilt::BabelTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do
11
+ @options[:filename] ||= @file
12
+ Babel::Transpiler.transform(@data)["code"]
16
13
  end
data/lib/tilt/builder.rb CHANGED
@@ -1,27 +1,31 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = Builder
4
+ #
5
+
6
+ require_relative 'template'
2
7
  require 'builder'
3
8
 
4
9
  module Tilt
5
- # Builder template implementation. See:
6
- # http://builder.rubyforge.org/
10
+ # Builder template implementation.
7
11
  class BuilderTemplate < Template
8
12
  self.default_mime_type = 'text/xml'
9
13
 
10
14
  def prepare
11
- options[:indent] ||= 2
15
+ @options[:indent] ||= 2
12
16
  end
13
17
 
14
18
  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)
19
+ if @data.respond_to?(:to_str)
20
+ unless locals[:xml]
21
+ locals = Hash[locals]
22
+ locals[:xml] = xml_builder
20
23
  end
21
- return super(scope, locals, &block)
24
+ return super
22
25
  end
23
26
 
24
- data.call(xml)
27
+ xml = locals[:xml] || xml_builder
28
+ @data.call(xml)
25
29
  xml.target!
26
30
  end
27
31
 
@@ -30,8 +34,13 @@ module Tilt
30
34
  end
31
35
 
32
36
  def precompiled_template(locals)
33
- data.to_str
37
+ @data.to_str
38
+ end
39
+
40
+ private
41
+
42
+ def xml_builder
43
+ ::Builder::XmlMarkup.new(options)
34
44
  end
35
45
  end
36
46
  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,32 +1,28 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # CoffeeScript / Literate CoffeeScript template implementation.
4
+ #
5
+ # CoffeeScript templates do not support object scopes, locals, or yield.
6
+ #
7
+ # === See also
8
+ #
9
+ # * http://coffeescript.org
10
+ #
11
+ # === Related modules
12
+ #
13
+ # * Tilt::CoffeeScriptTemplate
14
+ # * Tilt::CoffeeScriptLiterateTemplate
15
+
16
+ require_relative 'template'
2
17
  require 'coffee_script'
3
18
 
4
19
  module Tilt
5
- # CoffeeScript template implementation. See:
6
- # http://coffeescript.org/
7
- #
8
- # CoffeeScript templates do not support object scopes, locals, or yield.
9
- class CoffeeScriptTemplate < Template
20
+ class CoffeeScriptTemplate < StaticTemplate
10
21
  self.default_mime_type = 'application/javascript'
11
22
 
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
23
+ @default_bare = false
24
+ class << self
25
+ attr_accessor :default_bare
30
26
  end
31
27
 
32
28
  def self.literate?
@@ -34,22 +30,17 @@ module Tilt
34
30
  end
35
31
 
36
32
  def prepare
37
- if !options.key?(:bare) and !options.key?(:no_wrap)
38
- options[:bare] = self.class.default_bare
33
+ if !@options.key?(:bare) and !@options.key?(:no_wrap)
34
+ @options[:bare] = self.class.default_bare
39
35
  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
36
+ @options[:literate] ||= self.class.literate?
37
+ @output = CoffeeScript.compile(@data, @options)
49
38
  end
50
39
  end
51
40
 
52
41
  class CoffeeScriptLiterateTemplate < CoffeeScriptTemplate
42
+ @default_bare = false
43
+
53
44
  def self.literate?
54
45
  true
55
46
  end