tilt 2.4.0 → 2.9.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.
- checksums.yaml +4 -4
- data/COPYING +1 -1
- data/lib/tilt/asciidoc.rb +12 -5
- data/lib/tilt/babel.rb +5 -0
- data/lib/tilt/builder.rb +4 -0
- data/lib/tilt/coffee.rb +14 -4
- data/lib/tilt/commonmarker.rb +65 -0
- data/lib/tilt/csv.rb +35 -25
- data/lib/tilt/erb.rb +67 -2
- data/lib/tilt/erubi.rb +41 -8
- data/lib/tilt/etanni.rb +7 -0
- data/lib/tilt/haml.rb +67 -1
- data/lib/tilt/herb.rb +110 -0
- data/lib/tilt/kramdown.rb +47 -1
- data/lib/tilt/liquid.rb +66 -13
- data/lib/tilt/livescript.rb +11 -4
- data/lib/tilt/mapping.rb +9 -9
- data/lib/tilt/markaby.rb +11 -2
- data/lib/tilt/nokogiri.rb +13 -2
- data/lib/tilt/pandoc.rb +43 -1
- data/lib/tilt/pipeline.rb +6 -1
- data/lib/tilt/plain.rb +5 -1
- data/lib/tilt/prawn.rb +17 -6
- data/lib/tilt/radius.rb +55 -0
- data/lib/tilt/rdiscount.rb +65 -6
- data/lib/tilt/rdoc.rb +33 -11
- data/lib/tilt/redcarpet.rb +42 -0
- data/lib/tilt/redcloth.rb +28 -1
- data/lib/tilt/rst-pandoc.rb +24 -1
- data/lib/tilt/sass.rb +16 -3
- data/lib/tilt/slim.rb +13 -0
- data/lib/tilt/string.rb +10 -2
- data/lib/tilt/template.rb +189 -33
- data/lib/tilt/typescript.rb +5 -0
- data/lib/tilt/yajl.rb +46 -36
- data/lib/tilt.rb +12 -7
- metadata +5 -10
- data/lib/tilt/creole.rb +0 -14
- data/lib/tilt/erubis.rb +0 -51
- data/lib/tilt/maruku.rb +0 -10
- data/lib/tilt/wikicloth.rb +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 07376d5da37cfc37ba1364a962859139ab42e2c6453aea4bd5610c2daccee019
|
|
4
|
+
data.tar.gz: dc64be5c7fbf26c8f6def8e40c143a61de7e46ed69157d0b0a0c1a558b9e4d93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20bc55f1b6cdceb99068e2a40ac0df35006b6f61c27a66f31606ee79e32df7431bef7e2d37ca6ecef5cc30ef131f7f19f340258d12a1836ce4aee2a1ad0a4b23
|
|
7
|
+
data.tar.gz: 409ef4a5ba49ec95425d810987b892d694aa3794ce937256c7673caea67dc9ef93f64fb1b5b399de0a0ada44d13424d305d63f3e9b96a6f346739f8a7491c2b3
|
data/COPYING
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Copyright (c) 2010-2016 Ryan Tomayko <http://tomayko.com/about>
|
|
2
|
-
Copyright (c) 2015-
|
|
2
|
+
Copyright (c) 2015-2026 Jeremy Evans and contributors
|
|
3
3
|
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to
|
data/lib/tilt/asciidoc.rb
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
require_relative 'template'
|
|
3
|
-
require 'asciidoctor'
|
|
4
|
-
# AsciiDoc see: http://asciidoc.org/
|
|
5
2
|
|
|
6
|
-
#
|
|
7
|
-
#
|
|
3
|
+
# = AsciiDoc
|
|
4
|
+
#
|
|
5
|
+
# Asciidoctor implementation for AsciiDoc
|
|
8
6
|
#
|
|
9
7
|
# Asciidoctor is an open source, pure-Ruby processor for
|
|
10
8
|
# converting AsciiDoc documents or strings into HTML 5,
|
|
11
9
|
# DocBook 4.5 and other formats.
|
|
10
|
+
#
|
|
11
|
+
# === See also
|
|
12
|
+
#
|
|
13
|
+
# * http://asciidoc.org
|
|
14
|
+
# * http://asciidoctor.github.com
|
|
15
|
+
|
|
16
|
+
require_relative 'template'
|
|
17
|
+
require 'asciidoctor'
|
|
18
|
+
|
|
12
19
|
Tilt::AsciidoctorTemplate = Tilt::StaticTemplate.subclass do
|
|
13
20
|
@options[:header_footer] = false if @options[:header_footer].nil?
|
|
14
21
|
Asciidoctor.render(@data, @options)
|
data/lib/tilt/babel.rb
CHANGED
data/lib/tilt/builder.rb
CHANGED
data/lib/tilt/coffee.rb
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
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
|
+
|
|
2
16
|
require_relative 'template'
|
|
3
17
|
require 'coffee_script'
|
|
4
18
|
|
|
5
19
|
module Tilt
|
|
6
|
-
# CoffeeScript template implementation. See:
|
|
7
|
-
# http://coffeescript.org/
|
|
8
|
-
#
|
|
9
|
-
# CoffeeScript templates do not support object scopes, locals, or yield.
|
|
10
20
|
class CoffeeScriptTemplate < StaticTemplate
|
|
11
21
|
self.default_mime_type = 'application/javascript'
|
|
12
22
|
|
data/lib/tilt/commonmarker.rb
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
#
|
|
3
|
+
# = Markdown (<tt>markdown</tt>, <tt>md</tt>, <tt>mkd</tt>)
|
|
4
|
+
#
|
|
5
|
+
# Markdown is a lightweight markup language, created by John Gruber
|
|
6
|
+
# and Aaron Swartz. For any markup that is not covered by Markdown’s syntax, HTML
|
|
7
|
+
# is used. Marking up plain text with Markdown markup is easy and Markdown
|
|
8
|
+
# formatted texts are readable.
|
|
9
|
+
#
|
|
10
|
+
# === Example
|
|
11
|
+
#
|
|
12
|
+
# Hello Markdown Templates
|
|
13
|
+
# ========================
|
|
14
|
+
#
|
|
15
|
+
# Hello World. This is a paragraph.
|
|
16
|
+
#
|
|
17
|
+
# === Usage
|
|
18
|
+
#
|
|
19
|
+
# To wrap a Markdown formatted document with a layout:
|
|
20
|
+
#
|
|
21
|
+
# layout = Tilt['erb'].new do
|
|
22
|
+
# "<!doctype html><title></title><%= yield %>"
|
|
23
|
+
# end
|
|
24
|
+
# data = Tilt['md'].new { "# hello tilt" }
|
|
25
|
+
# layout.render { data.render }
|
|
26
|
+
# # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
|
|
27
|
+
#
|
|
28
|
+
# === Options
|
|
29
|
+
#
|
|
30
|
+
# ==== <tt>:smartypants => true|false</tt>
|
|
31
|
+
#
|
|
32
|
+
# Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
|
|
33
|
+
#
|
|
34
|
+
# ==== <tt>:escape_html => true|false</tt>
|
|
35
|
+
#
|
|
36
|
+
# Set <tt>true</tt> disallow raw HTML in Markdown contents. HTML is converted to
|
|
37
|
+
# literal text by escaping <tt><</tt> characters.
|
|
38
|
+
#
|
|
39
|
+
# === See also
|
|
40
|
+
#
|
|
41
|
+
# * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
|
|
42
|
+
|
|
2
43
|
require_relative 'template'
|
|
3
44
|
require 'commonmarker'
|
|
4
45
|
|
|
@@ -9,14 +50,24 @@ if defined?(::Commonmarker)
|
|
|
9
50
|
parse_opts = [
|
|
10
51
|
:smart,
|
|
11
52
|
:default_info_string,
|
|
53
|
+
:relaxed_tasklist_matching,
|
|
54
|
+
:relaxed_autolinks,
|
|
55
|
+
:leave_footnote_definitions,
|
|
56
|
+
:ignore_setext,
|
|
12
57
|
].freeze
|
|
13
58
|
render_opts = [
|
|
14
59
|
:hardbreaks,
|
|
15
60
|
:github_pre_lang,
|
|
61
|
+
:full_info_string,
|
|
16
62
|
:width,
|
|
17
63
|
:unsafe,
|
|
18
64
|
:escape,
|
|
19
65
|
:sourcepos,
|
|
66
|
+
:escaped_char_spans,
|
|
67
|
+
:ignore_empty_links,
|
|
68
|
+
:gfm_quirks,
|
|
69
|
+
:prefer_fenced,
|
|
70
|
+
:tasklist_classes,
|
|
20
71
|
].freeze
|
|
21
72
|
exts = [
|
|
22
73
|
:strikethrough,
|
|
@@ -27,9 +78,23 @@ if defined?(::Commonmarker)
|
|
|
27
78
|
:superscript,
|
|
28
79
|
:header_ids,
|
|
29
80
|
:footnotes,
|
|
81
|
+
:inline_footnotes,
|
|
30
82
|
:description_lists,
|
|
31
83
|
:front_matter_delimiter,
|
|
84
|
+
:multiline_block_quotes,
|
|
85
|
+
:math_dollars,
|
|
86
|
+
:math_code,
|
|
32
87
|
:shortcodes,
|
|
88
|
+
:wikilinks_title_before_pipe,
|
|
89
|
+
:wikilinks_title_after_pipe,
|
|
90
|
+
:underline,
|
|
91
|
+
:spoiler,
|
|
92
|
+
:greentext,
|
|
93
|
+
:subscript,
|
|
94
|
+
:subtext,
|
|
95
|
+
:alerts,
|
|
96
|
+
:cjk_friendly_emphasis,
|
|
97
|
+
:highlight,
|
|
33
98
|
].freeze
|
|
34
99
|
|
|
35
100
|
Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do
|
data/lib/tilt/csv.rb
CHANGED
|
@@ -1,34 +1,44 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = CSV
|
|
4
|
+
#
|
|
5
|
+
# CSV Template implementation.
|
|
6
|
+
#
|
|
7
|
+
# === Example
|
|
8
|
+
#
|
|
9
|
+
# # Example of csv template
|
|
10
|
+
# tpl = <<-EOS
|
|
11
|
+
# # header
|
|
12
|
+
# csv << ['NAME', 'ID']
|
|
13
|
+
#
|
|
14
|
+
# # data rows
|
|
15
|
+
# @people.each do |person|
|
|
16
|
+
# csv << [person[:name], person[:id]]
|
|
17
|
+
# end
|
|
18
|
+
# EOS
|
|
19
|
+
#
|
|
20
|
+
# @people = [
|
|
21
|
+
# {:name => "Joshua Peek", :id => 1},
|
|
22
|
+
# {:name => "Ryan Tomayko", :id => 2},
|
|
23
|
+
# {:name => "Simone Carletti", :id => 3}
|
|
24
|
+
# ]
|
|
25
|
+
#
|
|
26
|
+
# template = Tilt::CSVTemplate.new { tpl }
|
|
27
|
+
# template.render(self)
|
|
28
|
+
#
|
|
29
|
+
# === See also
|
|
30
|
+
#
|
|
31
|
+
# * http://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html
|
|
32
|
+
#
|
|
33
|
+
# === Related module
|
|
34
|
+
#
|
|
35
|
+
# * Tilt::CSVTemplate
|
|
36
|
+
|
|
2
37
|
require_relative 'template'
|
|
3
38
|
require 'csv'
|
|
4
39
|
|
|
5
40
|
module Tilt
|
|
6
41
|
|
|
7
|
-
# CSV Template implementation. See:
|
|
8
|
-
# http://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html
|
|
9
|
-
#
|
|
10
|
-
# == Example
|
|
11
|
-
#
|
|
12
|
-
# # Example of csv template
|
|
13
|
-
# tpl = <<-EOS
|
|
14
|
-
# # header
|
|
15
|
-
# csv << ['NAME', 'ID']
|
|
16
|
-
#
|
|
17
|
-
# # data rows
|
|
18
|
-
# @people.each do |person|
|
|
19
|
-
# csv << [person[:name], person[:id]]
|
|
20
|
-
# end
|
|
21
|
-
# EOS
|
|
22
|
-
#
|
|
23
|
-
# @people = [
|
|
24
|
-
# {:name => "Joshua Peek", :id => 1},
|
|
25
|
-
# {:name => "Ryan Tomayko", :id => 2},
|
|
26
|
-
# {:name => "Simone Carletti", :id => 3}
|
|
27
|
-
# ]
|
|
28
|
-
#
|
|
29
|
-
# template = Tilt::CSVTemplate.new { tpl }
|
|
30
|
-
# template.render(self)
|
|
31
|
-
#
|
|
32
42
|
class CSVTemplate < Template
|
|
33
43
|
self.default_mime_type = 'text/csv'
|
|
34
44
|
|
data/lib/tilt/erb.rb
CHANGED
|
@@ -1,10 +1,75 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = ERB (<tt>erb</tt>, <tt>rhtml</tt>)
|
|
4
|
+
#
|
|
5
|
+
# ERB is a simple but powerful template languge for Ruby. In Tilt it's
|
|
6
|
+
# backed by {Erubi}[rdoc-ref:lib/tilt/erubi.rb] (if installed on your system] or by
|
|
7
|
+
# {erb.rb}[rdoc-ref:lib/tilt/erb.rb] (which is included in Ruby's standard library]. This
|
|
8
|
+
# documentation applies to both implementations.
|
|
9
|
+
#
|
|
10
|
+
# === Example
|
|
11
|
+
#
|
|
12
|
+
# Hello <%= world %>!
|
|
13
|
+
#
|
|
14
|
+
# === Usage
|
|
15
|
+
#
|
|
16
|
+
# ERB templates support custom evaluation scopes and locals:
|
|
17
|
+
#
|
|
18
|
+
# >> require 'erb'
|
|
19
|
+
# >> template = Tilt.new('hello.html.erb')
|
|
20
|
+
# >> template.render(self, :world => 'World!')
|
|
21
|
+
# => "Hello World!"
|
|
22
|
+
#
|
|
23
|
+
# Or, use <tt>Tilt['erb']</tt> directly to process strings:
|
|
24
|
+
#
|
|
25
|
+
# template = Tilt['erb'].new { "Hello <%= world %>!" }
|
|
26
|
+
# template.render(self, :world => 'World!')
|
|
27
|
+
#
|
|
28
|
+
# The <tt>Tilt::ERBTemplate</tt> class is registered for all files ending in <tt>.erb</tt> or
|
|
29
|
+
# <tt>.rhtml</tt> by default, but with a *lower* priority than ErubiTemplate.
|
|
30
|
+
# If you specifically want to use ERB, it's recommended to use
|
|
31
|
+
# <tt>#prefer</tt>:
|
|
32
|
+
#
|
|
33
|
+
# Tilt.prefer Tilt::ERBTemplate
|
|
34
|
+
#
|
|
35
|
+
# __NOTE:__ It's suggested that your program <tt>require 'erb'</tt> at load time when
|
|
36
|
+
# using this template engine within a threaded environment.
|
|
37
|
+
#
|
|
38
|
+
# === Options
|
|
39
|
+
#
|
|
40
|
+
# ==== <tt>:trim => trim</tt>
|
|
41
|
+
#
|
|
42
|
+
# The ERB trim mode flags. This is a string consisting of any combination of the
|
|
43
|
+
# following characters:
|
|
44
|
+
#
|
|
45
|
+
# * <tt>'>'</tt> omits newlines for lines ending in <tt>></tt>
|
|
46
|
+
# * <tt>'<>'</tt> omits newlines for lines starting with <tt><%</tt> and ending in <tt>%></tt>
|
|
47
|
+
# * <tt>'%'</tt> enables processing of lines beginning with <tt>%</tt>
|
|
48
|
+
# * <tt>true</tt> is an alias of <tt><></tt>
|
|
49
|
+
#
|
|
50
|
+
# ==== <tt>:outvar => '_erbout'</tt>
|
|
51
|
+
#
|
|
52
|
+
# The name of the variable used to accumulate template output. This can be
|
|
53
|
+
# any valid Ruby expression but must be assignable. By default a local
|
|
54
|
+
# variable named <tt>_erbout</tt> is used.
|
|
55
|
+
#
|
|
56
|
+
# ==== <tt>:freeze => false</tt>
|
|
57
|
+
#
|
|
58
|
+
# If set to true, will set the <tt>frozen_string_literal</tt> flag in the compiled
|
|
59
|
+
# template code, so that string literals inside the templates will be frozen.
|
|
60
|
+
#
|
|
61
|
+
# === See also
|
|
62
|
+
#
|
|
63
|
+
# * http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html
|
|
64
|
+
#
|
|
65
|
+
# === Related module
|
|
66
|
+
#
|
|
67
|
+
# * Tilt::ERBTemplate
|
|
68
|
+
|
|
2
69
|
require_relative 'template'
|
|
3
70
|
require 'erb'
|
|
4
71
|
|
|
5
72
|
module Tilt
|
|
6
|
-
# ERB template implementation. See:
|
|
7
|
-
# http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html
|
|
8
73
|
class ERBTemplate < Template
|
|
9
74
|
SUPPORTS_KVARGS = ::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false
|
|
10
75
|
|
data/lib/tilt/erubi.rb
CHANGED
|
@@ -1,16 +1,49 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = Erubi (<tt>erb</tt>, <tt>rhtml</tt>, <tt>erubi</tt>)
|
|
4
|
+
#
|
|
5
|
+
# {Erubi}[https://github.com/jeremyevans/erubi] is an ERB implementation that uses the same algorithm as
|
|
6
|
+
# the erubis gem, but is maintained and offers numerous improvements.
|
|
7
|
+
#
|
|
8
|
+
# All the documentation of {ERB}[rdoc-ref:lib/tilt/erb.rb] applies in addition to the following:
|
|
9
|
+
#
|
|
10
|
+
# === Usage
|
|
11
|
+
#
|
|
12
|
+
# The <tt>Tilt::ErubiTemplate</tt> class is registered for all files ending in <tt>.erb</tt> or
|
|
13
|
+
# <tt>.rhtml</tt> by default, with the *highest* priority.
|
|
14
|
+
#
|
|
15
|
+
# __NOTE:__ It's suggested that your program <tt>require 'erubi'</tt> at load time when
|
|
16
|
+
# using this template engine within a threaded environment.
|
|
17
|
+
#
|
|
18
|
+
# === Options
|
|
19
|
+
#
|
|
20
|
+
# ==== <tt>:engine_class => Erubi::Engine</tt>
|
|
21
|
+
#
|
|
22
|
+
# Allows you to specify a custom engine class to use instead of the
|
|
23
|
+
# default which is <tt>Erubi::Engine</tt>.
|
|
24
|
+
#
|
|
25
|
+
# ==== Other
|
|
26
|
+
#
|
|
27
|
+
# Other options are passed to the constructor of the engine class.
|
|
28
|
+
#
|
|
29
|
+
# ErubiTemplate supports the following additional options, in addition
|
|
30
|
+
# to the options supported by the Erubi engine:
|
|
31
|
+
#
|
|
32
|
+
# :engine_class :: allows you to specify a custom engine class to use
|
|
33
|
+
# instead of the default (which is ::Erubi::Engine).
|
|
34
|
+
#
|
|
35
|
+
# === See also
|
|
36
|
+
#
|
|
37
|
+
# * {Erubi Home}[https://github.com/jeremyevans/erubi]
|
|
38
|
+
#
|
|
39
|
+
# === Related module
|
|
40
|
+
#
|
|
41
|
+
# * Tilt::ErubiTemplate
|
|
42
|
+
|
|
2
43
|
require_relative 'template'
|
|
3
44
|
require 'erubi'
|
|
4
45
|
|
|
5
46
|
module Tilt
|
|
6
|
-
# Erubi (a simplified version of Erubis) template implementation.
|
|
7
|
-
# See https://github.com/jeremyevans/erubi
|
|
8
|
-
#
|
|
9
|
-
# ErubiTemplate supports the following additional options, in addition
|
|
10
|
-
# to the options supported by the Erubi engine:
|
|
11
|
-
#
|
|
12
|
-
# :engine_class :: allows you to specify a custom engine class to use
|
|
13
|
-
# instead of the default (which is ::Erubi::Engine).
|
|
14
47
|
class ErubiTemplate < Template
|
|
15
48
|
def prepare
|
|
16
49
|
@options[:preamble] = false
|
data/lib/tilt/etanni.rb
CHANGED
data/lib/tilt/haml.rb
CHANGED
|
@@ -1,4 +1,70 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = Haml (<tt>haml</tt>)
|
|
4
|
+
#
|
|
5
|
+
# {Haml}[https://haml.info] is a markup language that’s used to cleanly and simply describe
|
|
6
|
+
# the HTML of any web document without the use of inline code. Haml functions as
|
|
7
|
+
# a replacement for inline page templating systems such as PHP, ASP, and ERB, the
|
|
8
|
+
# templating language used in most Ruby on Rails applications. However, Haml
|
|
9
|
+
# avoids the need for explicitly coding HTML into the template, because it itself
|
|
10
|
+
# is a description of the HTML, with some code to generate dynamic content.
|
|
11
|
+
# ({more}[http://haml.info/about.html)]
|
|
12
|
+
#
|
|
13
|
+
# === Example
|
|
14
|
+
#
|
|
15
|
+
# %html
|
|
16
|
+
# %head
|
|
17
|
+
# %title= @title
|
|
18
|
+
# %body
|
|
19
|
+
# %h1
|
|
20
|
+
# Hello
|
|
21
|
+
# = world + '!'
|
|
22
|
+
#
|
|
23
|
+
# === Usage
|
|
24
|
+
#
|
|
25
|
+
# The <tt>Tilt::HamlTemplate</tt> class is registered for all files ending in <tt>.haml</tt>
|
|
26
|
+
# by default. Haml templates support custom evaluation scopes and locals:
|
|
27
|
+
#
|
|
28
|
+
# >> require 'haml'
|
|
29
|
+
# >> template = Tilt.new('hello.haml')
|
|
30
|
+
# => #<Tilt::HamlTemplate @file='hello.haml'>
|
|
31
|
+
# >> @title = "Hello Haml!"
|
|
32
|
+
# >> template.render(self, :world => 'Haml!')
|
|
33
|
+
# => "
|
|
34
|
+
# <html>
|
|
35
|
+
# <head>
|
|
36
|
+
# <title>Hello Haml!</title>
|
|
37
|
+
# </head>
|
|
38
|
+
# <body>
|
|
39
|
+
# <h1>Hello Haml!</h1>
|
|
40
|
+
# </body>
|
|
41
|
+
# </html>"
|
|
42
|
+
#
|
|
43
|
+
# Or, use the <tt>Tilt::HamlTemplate</tt> class directly to process strings:
|
|
44
|
+
#
|
|
45
|
+
# >> require 'haml'
|
|
46
|
+
# >> template = Tilt::HamlTemplate.new { "%h1= 'Hello Haml!'" }
|
|
47
|
+
# => #<Tilt::HamlTemplate @file=nil ...>
|
|
48
|
+
# >> template.render
|
|
49
|
+
# => "<h1>Hello Haml!</h1>"
|
|
50
|
+
#
|
|
51
|
+
# __NOTE:__ It's suggested that your program <tt>require 'haml'</tt> at load time when
|
|
52
|
+
# using this template engine within a threaded environment.
|
|
53
|
+
#
|
|
54
|
+
# === Options
|
|
55
|
+
#
|
|
56
|
+
# Please see the {Haml Reference}[http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options] for all available options.
|
|
57
|
+
#
|
|
58
|
+
# === See also
|
|
59
|
+
#
|
|
60
|
+
# * {#haml.docs}[http://haml.info/docs.html]
|
|
61
|
+
# * {Haml Tutorial}[http://haml.info/tutorial.html]
|
|
62
|
+
# * {Haml Reference}[http://haml.info/docs/yardoc/file.HAML_REFERENCE.html]
|
|
63
|
+
#
|
|
64
|
+
# === Related module
|
|
65
|
+
#
|
|
66
|
+
# * Tilt::HamlTemplate
|
|
67
|
+
|
|
2
68
|
require_relative 'template'
|
|
3
69
|
require 'haml'
|
|
4
70
|
|
|
@@ -12,7 +78,7 @@ module Tilt
|
|
|
12
78
|
class HamlTemplate < Template
|
|
13
79
|
self.default_mime_type = 'text/html'
|
|
14
80
|
|
|
15
|
-
#
|
|
81
|
+
# <tt>Gem::Version.correct?</tt> may return false because of Haml::VERSION #=> "3.1.8 (Separated Sally)". After Haml 4, it's always correct.
|
|
16
82
|
if Gem::Version.correct?(Haml::VERSION) && Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5.0.0.beta.2')
|
|
17
83
|
def prepare
|
|
18
84
|
@options[:filename] = eval_file
|
data/lib/tilt/herb.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = Herb (<tt>herb</tt>, <tt>html.erb</tt>)
|
|
4
|
+
#
|
|
5
|
+
# {Herb}[https://herb-tools.dev] is an HTML-aware ERB implementation, which parses the
|
|
6
|
+
# HTML in the template in addition to the embedded Ruby.
|
|
7
|
+
#
|
|
8
|
+
# Herb's engine is API compatible with the Erubi engine, so all the documentation of
|
|
9
|
+
# {Erubi}[rdoc-ref:lib/tilt/erubi.rb] applies in addition to the following:
|
|
10
|
+
#
|
|
11
|
+
# === Differences from Erubi
|
|
12
|
+
#
|
|
13
|
+
# Herb parses the HTML in the template, and raises <tt>Herb::Engine::CompilationError</tt>
|
|
14
|
+
# when creating the template if the HTML is invalid (such as unclosed or mismatched tags),
|
|
15
|
+
# or if the embedded Ruby has invalid syntax. Erubi inspects neither the HTML nor the Ruby;
|
|
16
|
+
# with Erubi, invalid Ruby syntax instead raises a SyntaxError when Tilt compiles the
|
|
17
|
+
# template, which by default does not happen until the template is first rendered.
|
|
18
|
+
#
|
|
19
|
+
# Herb escapes interpolated values based on where they appear in the document, using a
|
|
20
|
+
# separate escape function for attribute values, <tt><script></tt> content, and
|
|
21
|
+
# <tt><style></tt> content. Erubi uses a single escape function everywhere.
|
|
22
|
+
#
|
|
23
|
+
# Herb accepts additional engine options. As with the Erubi engine options, these are
|
|
24
|
+
# passed through to the engine class. See
|
|
25
|
+
# {Herb::Engine}[https://herb-tools.dev/projects/engine] for the full list.
|
|
26
|
+
#
|
|
27
|
+
# === Usage
|
|
28
|
+
#
|
|
29
|
+
# The <tt>Tilt::HerbTemplate</tt> class is registered for all files ending in <tt>.herb</tt> or
|
|
30
|
+
# <tt>.html.erb</tt> by default. Unlike {Erubi}[rdoc-ref:lib/tilt/erubi.rb], it is not
|
|
31
|
+
# registered for <tt>.erb</tt> or <tt>.rhtml</tt>, since that would change which engine is
|
|
32
|
+
# used for existing templates. To use Herb for those as well, use:
|
|
33
|
+
#
|
|
34
|
+
# Tilt.register Tilt::HerbTemplate, 'erb', 'rhtml'
|
|
35
|
+
#
|
|
36
|
+
# __NOTE:__ It's suggested that your program <tt>require 'herb'</tt> at load time when
|
|
37
|
+
# using this template engine within a threaded environment.
|
|
38
|
+
#
|
|
39
|
+
# === Options
|
|
40
|
+
#
|
|
41
|
+
# ==== <tt>:engine_class => Herb::Engine</tt>
|
|
42
|
+
#
|
|
43
|
+
# Allows you to specify a custom engine class to use instead of the
|
|
44
|
+
# default which is <tt>Herb::Engine</tt>.
|
|
45
|
+
#
|
|
46
|
+
# ==== Other
|
|
47
|
+
#
|
|
48
|
+
# Other options are passed to the constructor of the engine class.
|
|
49
|
+
#
|
|
50
|
+
# === See also
|
|
51
|
+
#
|
|
52
|
+
# * {Herb Home}[https://herb-tools.dev]
|
|
53
|
+
# * {Herb::Engine}[https://herb-tools.dev/projects/engine]
|
|
54
|
+
# * {Herb Source}[https://github.com/marcoroth/herb]
|
|
55
|
+
#
|
|
56
|
+
# === Related module
|
|
57
|
+
#
|
|
58
|
+
# * Tilt::HerbTemplate
|
|
59
|
+
|
|
60
|
+
require_relative 'template'
|
|
61
|
+
require 'herb'
|
|
62
|
+
require 'herb/engine'
|
|
63
|
+
|
|
64
|
+
module Tilt
|
|
65
|
+
class HerbTemplate < Template
|
|
66
|
+
def prepare
|
|
67
|
+
@options[:preamble] = false
|
|
68
|
+
@options[:postamble] = false
|
|
69
|
+
@options[:ensure] = true
|
|
70
|
+
|
|
71
|
+
# Unlike Erubi, Herb uses the filename when reporting errors, so pass
|
|
72
|
+
# the file Tilt loaded the template from if the caller did not set one.
|
|
73
|
+
@options[:filename] ||= file
|
|
74
|
+
|
|
75
|
+
engine_class = @options[:engine_class] || Herb::Engine
|
|
76
|
+
|
|
77
|
+
# If :freeze option is given, the intent is to setup frozen string
|
|
78
|
+
# literals in the template. So enable frozen string literals in the
|
|
79
|
+
# code Tilt generates if the :freeze option is given.
|
|
80
|
+
if @freeze_string_literals = !!@options[:freeze]
|
|
81
|
+
# Passing the :freeze option to Herb sets the
|
|
82
|
+
# frozen-string-literal magic comment, which doesn't have an effect
|
|
83
|
+
# with Tilt as Tilt wraps the resulting code. Worse, the magic
|
|
84
|
+
# comment appearing not at the top of the file can cause a warning.
|
|
85
|
+
# So remove the :freeze option before passing to Herb.
|
|
86
|
+
@options.delete(:freeze)
|
|
87
|
+
|
|
88
|
+
# Herb by default appends .freeze to template literals, but that is
|
|
89
|
+
# not necessary and slows down code when Tilt is using frozen string
|
|
90
|
+
# literals, so pass the :freeze_template_literals option to not
|
|
91
|
+
# append .freeze.
|
|
92
|
+
@options[:freeze_template_literals] = false
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
@engine = engine_class.new(@data, @options)
|
|
96
|
+
@outvar = @engine.bufvar
|
|
97
|
+
@src = @engine.src
|
|
98
|
+
|
|
99
|
+
@engine
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def precompiled_template(locals)
|
|
103
|
+
@src
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def freeze_string_literals?
|
|
107
|
+
@freeze_string_literals
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
data/lib/tilt/kramdown.rb
CHANGED
|
@@ -1,10 +1,56 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# = Markdown (<tt>markdown</tt>, <tt>md</tt>, <tt>mkd</tt>)
|
|
4
|
+
#
|
|
5
|
+
# Markdown is a lightweight markup language, created by John Gruber
|
|
6
|
+
# and Aaron Swartz. For any markup that is not covered by Markdown’s syntax, HTML
|
|
7
|
+
# is used. Marking up plain text with Markdown markup is easy and Markdown
|
|
8
|
+
# formatted texts are readable.
|
|
9
|
+
#
|
|
10
|
+
# === Example
|
|
11
|
+
#
|
|
12
|
+
# Hello Markdown Templates
|
|
13
|
+
# ========================
|
|
14
|
+
#
|
|
15
|
+
# Hello World. This is a paragraph.
|
|
16
|
+
#
|
|
17
|
+
# === Usage
|
|
18
|
+
#
|
|
19
|
+
# To wrap a Markdown formatted document with a layout:
|
|
20
|
+
#
|
|
21
|
+
# layout = Tilt['erb'].new do
|
|
22
|
+
# "<!doctype html><title></title><%= yield %>"
|
|
23
|
+
# end
|
|
24
|
+
# data = Tilt['md'].new { "# hello tilt" }
|
|
25
|
+
# layout.render { data.render }
|
|
26
|
+
# # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
|
|
27
|
+
#
|
|
28
|
+
# === Options
|
|
29
|
+
#
|
|
30
|
+
# Every implementation of Markdown *should* support these options, but there are
|
|
31
|
+
# some known problems with the Kramdown engine.
|
|
32
|
+
#
|
|
33
|
+
# ==== <tt>:smartypants => true|false</tt>
|
|
34
|
+
#
|
|
35
|
+
# Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
|
|
36
|
+
#
|
|
37
|
+
# In Kramdown this option only applies to smart quotes. It will apply a
|
|
38
|
+
# subset of Smarty Pants (e.g. <tt>...</tt> to <tt>…</tt>) regardless of any option.
|
|
39
|
+
#
|
|
40
|
+
# ==== <tt>:escape_html => true|false</tt>
|
|
41
|
+
#
|
|
42
|
+
# Kramdown doesn't support this option.
|
|
43
|
+
#
|
|
44
|
+
# === See also
|
|
45
|
+
#
|
|
46
|
+
# * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
|
|
47
|
+
# * {Kramdown Markdown implementation}[https://kramdown.gettalong.org]
|
|
48
|
+
|
|
2
49
|
require_relative 'template'
|
|
3
50
|
require 'kramdown'
|
|
4
51
|
|
|
5
52
|
dumb_quotes = [39, 39, 34, 34].freeze
|
|
6
53
|
|
|
7
|
-
# Kramdown Markdown implementation. See: https://kramdown.gettalong.org/
|
|
8
54
|
Tilt::KramdownTemplate = Tilt::StaticTemplate.subclass do
|
|
9
55
|
# dup as Krawmdown modifies the passed option with map!
|
|
10
56
|
@options[:smart_quotes] = dumb_quotes.dup unless @options[:smartypants]
|