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
data/lib/tilt/sass.rb CHANGED
@@ -1,17 +1,53 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = Sass / Scss
4
+ #
5
+ # Sass/Scss template implementation for generating CSS.
6
+ #
7
+ # Sass templates do not support object scopes, locals, or yield.
8
+ #
9
+ # === See also
10
+ #
11
+ # * https://sass-lang.com/
12
+ #
13
+ # === Related modules
14
+ #
15
+ # * Tilt::SassTemplate
16
+ # * Tilt::ScssTemplate
17
+
18
+ require_relative 'template'
2
19
 
3
20
  module Tilt
4
- # Sass template implementation. See:
5
- # http://haml.hamptoncatlin.com/
6
- #
7
- # Sass templates do not support object scopes, locals, or yield.
8
- class SassTemplate < Template
21
+ class SassTemplate < StaticTemplate
9
22
  self.default_mime_type = 'text/css'
10
23
 
11
24
  begin
12
25
  require 'sass-embedded'
26
+ # :nocov:
13
27
  require 'uri'
14
- Engine = nil
28
+
29
+ ALLOWED_KEYS = (defined?(::Sass::Compiler) ? ::Sass::Compiler : ::Sass::Embedded).
30
+ instance_method(:compile_string).
31
+ parameters.
32
+ map{|k, v| v if k == :key}.
33
+ compact rescue nil
34
+ private_constant :ALLOWED_KEYS
35
+
36
+ private
37
+
38
+ def _prepare_output
39
+ ::Sass.compile_string(@data, **sass_options).css
40
+ end
41
+
42
+ def sass_options
43
+ path = File.absolute_path(eval_file)
44
+ path = '/' + path unless path.start_with?('/')
45
+ opts = @options.dup
46
+ opts[:url] = ::URI::File.build([nil, ::URI::DEFAULT_PARSER.escape(path)]).to_s
47
+ opts[:syntax] = :indented
48
+ opts.delete_if{|k| !ALLOWED_KEYS.include?(k)} if ALLOWED_KEYS
49
+ opts
50
+ end
15
51
  rescue LoadError => err
16
52
  begin
17
53
  require 'sassc'
@@ -24,55 +60,32 @@ module Tilt
24
60
  raise err
25
61
  end
26
62
  end
27
- end
28
63
 
29
- def prepare
30
- @engine = unless Engine.nil?
31
- Engine.new(data, sass_options)
32
- end
33
- end
34
-
35
- def evaluate(scope, locals, &block)
36
- @output ||= if @engine.nil?
37
- ::Sass.compile_string(data, **sass_embedded_options).css
38
- else
39
- @engine.render
40
- end
41
- end
64
+ private
42
65
 
43
- def allows_script?
44
- false
45
- end
46
-
47
- private
48
- def eval_file_url
49
- path = File.absolute_path(eval_file)
50
- path = '/' + path unless path.start_with?('/')
51
- ::URI::File.build([nil, ::URI::DEFAULT_PARSER.escape(path)]).to_s
52
- end
53
-
54
- def sass_embedded_options
55
- options.merge(:url => eval_file_url, :syntax => :indented)
56
- end
66
+ def _prepare_output
67
+ Engine.new(@data, sass_options).render
68
+ end
57
69
 
58
- def sass_options
59
- options.merge(:filename => eval_file, :line => line, :syntax => :sass)
70
+ def sass_options
71
+ @options[:filename] = eval_file
72
+ @options[:line] = @line
73
+ @options[:syntax] = :sass
74
+ @options
75
+ end
76
+ # :nocov:
60
77
  end
61
78
  end
62
79
 
63
- # Sass's new .scss type template implementation.
64
80
  class ScssTemplate < SassTemplate
65
81
  self.default_mime_type = 'text/css'
66
82
 
67
- private
68
- def sass_embedded_options
69
- options.merge(:url => eval_file_url, :syntax => :scss)
70
- end
83
+ private
71
84
 
72
85
  def sass_options
73
- options.merge(:filename => eval_file, :line => line, :syntax => :scss)
86
+ opts = super
87
+ opts[:syntax] = :scss
88
+ opts
74
89
  end
75
90
  end
76
-
77
91
  end
78
-
data/lib/tilt/slim.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # = Slim (<tt>slim</tt>)
4
+ #
5
+ # === Embedded locals
6
+ #
7
+ # In slim templates, the comment format looks like this:
8
+ #
9
+ # //# locals: ()
10
+ #
11
+ # === See also
12
+ #
13
+ # * https://slim-template.github.io
14
+
15
+ require_relative 'template'
16
+ require 'slim'
17
+
18
+ Tilt::SlimTemplate = Slim::Template
data/lib/tilt/string.rb CHANGED
@@ -1,12 +1,22 @@
1
- require 'tilt/template'
1
+ # frozen_string_literal: true
2
+
3
+ # = String
4
+ #
5
+ # The template source is evaluated as a Ruby string. The #{} interpolation
6
+ # syntax can be used to generated dynamic output.
7
+ #
8
+ # === Related module
9
+ #
10
+ # * Tilt::StringTemplate
11
+
12
+ require_relative 'template'
2
13
 
3
14
  module Tilt
4
- # The template source is evaluated as a Ruby string. The #{} interpolation
5
- # syntax can be used to generated dynamic output.
6
15
  class StringTemplate < Template
7
16
  def prepare
8
- hash = "TILT#{data.hash.abs}"
9
- @code = String.new("<<#{hash}.chomp\n#{data}\n#{hash}")
17
+ hash = "TILT#{@data.hash.abs}"
18
+ @freeze_string_literals = !!@options[:freeze]
19
+ @code = String.new("<<#{hash}.chomp\n#{@data}\n#{hash}")
10
20
  end
11
21
 
12
22
  def precompiled_template(locals)
@@ -17,5 +27,9 @@ module Tilt
17
27
  source, offset = super
18
28
  [source, offset + 1]
19
29
  end
30
+
31
+ def freeze_string_literals?
32
+ @freeze_string_literals
33
+ end
20
34
  end
21
35
  end