malt 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +156 -0
- data/Assembly +28 -0
- data/COPYING.rdoc +33 -0
- data/Gemfile +10 -0
- data/HISTORY.rdoc +102 -0
- data/README.rdoc +16 -10
- data/Reapfile +4 -0
- data/lib/malt.rb +36 -8
- data/lib/malt.yml +156 -0
- data/lib/malt/conversions.rb +42 -0
- data/lib/malt/core_ext.rb +81 -3
- data/lib/malt/engines/abstract.rb +259 -50
- data/lib/malt/engines/bluecloth.rb +19 -9
- data/lib/malt/engines/builder.rb +93 -32
- data/lib/malt/engines/coffee.rb +46 -0
- data/lib/malt/engines/creole.rb +60 -0
- data/lib/malt/engines/erb.rb +69 -44
- data/lib/malt/engines/erector.rb +61 -30
- data/lib/malt/engines/erubis.rb +41 -31
- data/lib/malt/engines/haml.rb +13 -37
- data/lib/malt/engines/kramdown.rb +40 -15
- data/lib/malt/engines/less.rb +15 -14
- data/lib/malt/engines/liquid.rb +24 -14
- data/lib/malt/engines/markaby.rb +44 -22
- data/lib/malt/engines/maruku.rb +89 -0
- data/lib/malt/engines/mustache.rb +20 -14
- data/lib/malt/engines/nokogiri.rb +89 -0
- data/lib/malt/engines/radius.rb +72 -34
- data/lib/malt/engines/ragtag.rb +26 -18
- data/lib/malt/engines/rdiscount.rb +18 -11
- data/lib/malt/engines/rdoc.rb +21 -15
- data/lib/malt/engines/redcarpet.rb +137 -0
- data/lib/malt/engines/redcloth.rb +15 -7
- data/lib/malt/engines/ruby.rb +13 -12
- data/lib/malt/engines/sass.rb +30 -17
- data/lib/malt/engines/string.rb +36 -0
- data/lib/malt/engines/tenjin.rb +70 -27
- data/lib/malt/engines/wikicloth.rb +48 -0
- data/lib/malt/formats/abstract.rb +90 -29
- data/lib/malt/formats/abstract_template.rb +10 -8
- data/lib/malt/formats/builder.rb +39 -13
- data/lib/malt/formats/coffee.rb +54 -0
- data/lib/malt/formats/css.rb +3 -3
- data/lib/malt/formats/erb.rb +31 -66
- data/lib/malt/formats/haml.rb +8 -8
- data/lib/malt/formats/html.rb +1 -7
- data/lib/malt/formats/javascript.rb +27 -0
- data/lib/malt/formats/latex.rb +1 -1
- data/lib/malt/formats/less.rb +13 -11
- data/lib/malt/formats/liquid.rb +7 -7
- data/lib/malt/formats/markdown.rb +43 -44
- data/lib/malt/formats/mediawiki.rb +70 -0
- data/lib/malt/formats/mustache.rb +5 -5
- data/lib/malt/formats/pdf.rb +1 -7
- data/lib/malt/formats/radius.rb +5 -4
- data/lib/malt/formats/ragtag.rb +14 -13
- data/lib/malt/formats/rbhtml.rb +28 -20
- data/lib/malt/formats/rdoc.rb +5 -4
- data/lib/malt/formats/rhtml.rb +19 -43
- data/lib/malt/formats/ruby.rb +11 -45
- data/lib/malt/formats/sass.rb +16 -24
- data/lib/malt/formats/scss.rb +13 -30
- data/lib/malt/formats/string.rb +61 -0
- data/lib/malt/formats/tenjin.rb +4 -4
- data/lib/malt/formats/text.rb +1 -1
- data/lib/malt/formats/textile.rb +7 -19
- data/lib/malt/kernel.rb +1 -2
- data/lib/malt/machine.rb +83 -13
- data/lib/malt/tilted.rb +216 -0
- data/lib/malt/version.rb +21 -0
- data/test/helper.rb +15 -0
- data/test/unit/engines/case_engine_bluecloth.rb +40 -0
- data/test/unit/engines/case_engine_builder.rb +30 -0
- data/test/unit/engines/case_engine_coffee.rb +30 -0
- data/test/unit/engines/case_engine_creole.rb +35 -0
- data/test/unit/engines/case_engine_erb.rb +28 -0
- data/test/unit/engines/case_engine_erector.rb +36 -0
- data/test/unit/engines/case_engine_erubis.rb +28 -0
- data/test/unit/engines/case_engine_haml.rb +30 -0
- data/test/unit/engines/case_engine_kramdown.rb +30 -0
- data/test/unit/engines/case_engine_less.rb +40 -0
- data/test/unit/engines/case_engine_liquid.rb +28 -0
- data/test/unit/engines/case_engine_markaby.rb +20 -0
- data/test/unit/engines/case_engine_maruku.rb +30 -0
- data/test/unit/engines/case_engine_mustache.rb +28 -0
- data/test/unit/engines/case_engine_nokogiri.rb +30 -0
- data/test/unit/engines/case_engine_radius.rb +30 -0
- data/test/unit/engines/case_engine_ragtag.rb +40 -0
- data/test/unit/engines/case_engine_rdiscount.rb +30 -0
- data/test/unit/engines/case_engine_rdoc.rb +31 -0
- data/test/unit/engines/case_engine_redcarpet.rb +30 -0
- data/test/unit/engines/case_engine_redcloth.rb +31 -0
- data/test/unit/engines/case_engine_ruby.rb +28 -0
- data/test/unit/engines/case_engine_sass.rb +36 -0
- data/test/unit/engines/case_engine_string.rb +28 -0
- data/test/unit/engines/case_engine_tenjin.rb +28 -0
- data/test/unit/engines/case_engine_wikicloth.rb +25 -0
- data/test/unit/machine.rb +27 -0
- data/test/unit/malt.rb +12 -0
- metadata +364 -266
- data/History.rdoc +0 -64
- data/License.txt +0 -205
- data/Syckfile +0 -80
- data/features/consistent_rendering.feature +0 -36
- data/features/samples/sample.erb +0 -1
- data/features/samples/sample.erubis +0 -1
- data/features/samples/sample.liquid +0 -1
- data/features/samples/sample.mustache +0 -1
- data/features/samples/sample.radius +0 -1
- data/features/step_definitions/engine_steps.rb +0 -49
- data/features/support/loadpath.rb +0 -1
- data/features/support/sample_class.rb +0 -8
- data/lib/malt/formats/erector.rb +0 -53
- data/lib/malt/formats/markaby.rb +0 -53
- data/lib/malt/meta/data.rb +0 -26
- data/lib/malt/meta/package +0 -21
- data/lib/malt/meta/profile +0 -21
- data/meta/data.rb +0 -26
- data/meta/package +0 -21
- data/meta/profile +0 -21
- data/qed/01_overview.rdoc +0 -8
- data/qed/02_formats.rdoc +0 -39
- data/qed/03_formats/01_overview.rdoc +0 -7
- data/qed/03_formats/02_rdoc.rdoc +0 -83
- data/qed/03_formats/03_textile.rdoc +0 -48
- data/qed/03_formats/04_markdown.rdoc +0 -66
- data/qed/03_formats/05_erb.rdoc +0 -65
- data/qed/03_formats/06_liquid.rdoc +0 -54
- data/qed/03_formats/07_haml.rdoc +0 -44
- data/qed/03_formats/08_ragtag.rdoc +0 -19
- data/qed/03_formats/09_radius.rdoc +0 -43
- data/qed/03_formats/11_tenjin.rdoc +0 -47
- data/qed/03_formats/12_rbhtml.rdoc +0 -55
- data/qed/03_formats/13_sass.rdoc +0 -55
- data/qed/03_formats/14_scss.rdoc +0 -58
- data/qed/03_formats/15_less.rdoc +0 -46
- data/qed/03_formats/16_ruby.rdoc +0 -48
- data/qed/03_formats/17_markaby.rdoc +0 -50
- data/qed/03_formats/18_builder.rb +0 -50
- data/qed/03_formats/19_erector.rb +0 -50
- data/qed/03_formats/20_mustache.rdoc +0 -54
- data/qed/05_machine/01_limited_formats.rdoc +0 -29
- data/qed/05_machine/02_prioritized_engines.rdoc +0 -34
- data/qed/applique/malt.rb +0 -13
- data/qed/samples/data.yml +0 -4
- data/qed/samples/output-erb.txt +0 -1
- data/qed/samples/output-liquid.txt +0 -1
- data/qed/samples/output-mustache.txt +0 -1
- data/qed/samples/output-radius.txt +0 -1
- data/qed/samples/sample.erb +0 -1
- data/qed/samples/sample.liquid +0 -1
- data/qed/samples/sample.markdown +0 -308
- data/qed/samples/sample.mustache +0 -1
- data/qed/samples/sample.radius +0 -1
- data/qed/samples/sample.rdoc +0 -8
data/lib/malt/engines/erector.rb
CHANGED
@@ -2,58 +2,89 @@ require 'malt/engines/abstract'
|
|
2
2
|
|
3
3
|
module Malt::Engine
|
4
4
|
|
5
|
-
# Erector
|
5
|
+
# The Erector template engine handles a builder-style template format.
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# @see http://erector.rubyforge.org/userguide.html
|
8
|
+
#
|
9
|
+
# For Erector templates the data is passed in as attribute variables.
|
10
|
+
#
|
11
|
+
# A simple example template:
|
12
|
+
#
|
13
|
+
# div do
|
14
|
+
# h1 @name
|
15
|
+
# div @state, :id=>'state'
|
16
|
+
# div @content, :id=>'yield'
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# IMPORTANT! Erecotor templates do not currently support scope.
|
8
20
|
#
|
9
21
|
class Erector < Abstract
|
10
22
|
|
11
|
-
default
|
23
|
+
default :erector
|
24
|
+
register :rbml, :builder
|
12
25
|
|
13
26
|
#
|
14
|
-
def
|
15
|
-
|
16
|
-
Class.new(::Erector::Widget) do
|
17
|
-
module_eval %{ def content; #{text}; end }
|
18
|
-
end
|
19
|
-
end
|
27
|
+
def render(params={}, &content)
|
28
|
+
into = params[:to] || :html
|
20
29
|
|
21
|
-
#
|
22
|
-
def render(params, &yld)
|
23
|
-
into = params[:to]
|
24
30
|
case into
|
25
|
-
when :html,
|
26
|
-
|
31
|
+
when :html, :xhtml
|
32
|
+
prepare_engine(params, &content).to_html
|
27
33
|
else
|
28
|
-
super(params, &
|
34
|
+
super(params, &content)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return Erector parser, ready to render results.
|
39
|
+
def prepare_engine(params={}, &content)
|
40
|
+
file, scope, locals = parameters(params, :file, :scope, :locals)
|
41
|
+
|
42
|
+
scope, locals = make_external(scope, locals, &content)
|
43
|
+
|
44
|
+
unless scope.respond_to?(:to_struct)
|
45
|
+
scope_locals = {}
|
46
|
+
scope.instance_variables.each do |k|
|
47
|
+
next if k == "@target"
|
48
|
+
name = k.to_s.sub('@','').to_sym
|
49
|
+
v = scope.instance_variable_get(k)
|
50
|
+
scope_locals[name] = v
|
51
|
+
end
|
52
|
+
locals = scope_locals.merge(locals)
|
29
53
|
end
|
54
|
+
|
55
|
+
create_engine(params).new(locals)
|
30
56
|
end
|
31
57
|
|
58
|
+
# TODO: how to support scope ?
|
59
|
+
|
60
|
+
# Erector constructor support caching.
|
32
61
|
#
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
62
|
+
def create_engine(params={})
|
63
|
+
text, prefix = parameters(params, :text, :prefix)
|
64
|
+
|
65
|
+
cached(prefix, text) do
|
66
|
+
Class.new(::Erector::Widget) do
|
67
|
+
module_eval %{
|
68
|
+
def #{prefix}; self; end
|
69
|
+
} if prefix
|
38
70
|
|
39
|
-
|
71
|
+
module_eval %{
|
72
|
+
def content
|
73
|
+
#{text}
|
74
|
+
end
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
40
78
|
end
|
41
79
|
|
42
|
-
|
80
|
+
private
|
43
81
|
|
44
82
|
# Load Erector library if not already loaded.
|
45
|
-
def
|
83
|
+
def require_engine
|
46
84
|
return if defined? ::Erector
|
47
85
|
require_library 'erector'
|
48
86
|
end
|
49
87
|
|
50
|
-
#
|
51
|
-
def engine_options(params)
|
52
|
-
opts = {}
|
53
|
-
opts
|
54
|
-
end
|
55
|
-
|
56
88
|
end
|
57
89
|
|
58
90
|
end
|
59
|
-
|
data/lib/malt/engines/erubis.rb
CHANGED
@@ -10,54 +10,64 @@ module Malt::Engine
|
|
10
10
|
#
|
11
11
|
class Erubis < Abstract
|
12
12
|
|
13
|
-
register :erb, :rhtml
|
13
|
+
register :erb, :rhtml, :eruby
|
14
14
|
|
15
15
|
# Render template.
|
16
|
-
def render(params, &
|
17
|
-
text = params
|
18
|
-
data = params[:data]
|
19
|
-
data = make_binding(data, &yld)
|
20
|
-
intermediate(params).result(data)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Compile template into Ruby source code.
|
24
|
-
def compile(params)
|
25
|
-
text = params[:text]
|
26
|
-
file = params[:file]
|
27
|
-
intermediate(text, file).src
|
28
|
-
end
|
16
|
+
def render(params, &content)
|
17
|
+
text, file, scope, locals = parameters(params, :text, :file, :scope, :locals)
|
29
18
|
|
30
|
-
|
31
|
-
|
32
|
-
text = params[:text]
|
33
|
-
file = params[:file]
|
19
|
+
# NOTE: Erubis can handle hash data via result(:list=>data).
|
20
|
+
# Would it be better to use that?
|
34
21
|
|
35
|
-
|
22
|
+
bind = make_binding(scope, locals, &content)
|
36
23
|
|
37
|
-
|
38
|
-
::Erubis::EscapedEruby.new(text, settings)
|
39
|
-
else
|
40
|
-
::Erubis::Eruby.new(text, settings)
|
41
|
-
end
|
24
|
+
prepare_engine(params).result(bind)
|
42
25
|
end
|
43
26
|
|
44
27
|
#
|
45
|
-
def
|
46
|
-
|
47
|
-
end
|
28
|
+
#def prepare_eninge(params={})
|
29
|
+
# create_engine(params)
|
30
|
+
#end
|
48
31
|
|
49
32
|
#
|
50
|
-
def
|
51
|
-
|
33
|
+
def create_engine(params={})
|
34
|
+
text, file, esc = parameters(params, :text, :file, :escape_html)
|
35
|
+
|
36
|
+
opts = engine_options(params)
|
37
|
+
|
38
|
+
cached(text, file, esc, opts) do
|
39
|
+
if esc
|
40
|
+
::Erubis::EscapedEruby.new(text, opts)
|
41
|
+
else
|
42
|
+
::Erubis::Eruby.new(text, opts)
|
43
|
+
end
|
44
|
+
end
|
52
45
|
end
|
53
46
|
|
54
|
-
|
47
|
+
# Compile template into Ruby source code.
|
48
|
+
#def compile(params)
|
49
|
+
# if cache?
|
50
|
+
# @source[params] ||= intermediate(params).src
|
51
|
+
# else
|
52
|
+
# intermediate(params).src
|
53
|
+
# end
|
54
|
+
#end
|
55
|
+
|
56
|
+
private
|
55
57
|
|
56
58
|
# Load ERB library if not already loaded.
|
57
|
-
def
|
59
|
+
def require_engine
|
58
60
|
return if defined? ::Erubius
|
59
61
|
require_library('erubis')
|
60
62
|
end
|
63
|
+
|
64
|
+
#
|
65
|
+
ENGINE_OPTION_NAMES = %w{safe trim pattern preamble postable}
|
66
|
+
|
67
|
+
#
|
68
|
+
def engine_option_names
|
69
|
+
ENGINE_OPTION_NAMES
|
70
|
+
end
|
61
71
|
|
62
72
|
end
|
63
73
|
|
data/lib/malt/engines/haml.rb
CHANGED
@@ -9,55 +9,31 @@ module Malt::Engine
|
|
9
9
|
default :haml
|
10
10
|
|
11
11
|
#
|
12
|
-
def render(params, &
|
13
|
-
into = params
|
12
|
+
def render(params={}, &content)
|
13
|
+
into, scope, locals = parameters(params, :to, :scope, :locals)
|
14
|
+
|
15
|
+
scope, locals = make_ready(scope, locals, &content)
|
16
|
+
|
14
17
|
case into
|
15
18
|
when :html, nil
|
16
|
-
|
19
|
+
prepare_engine(params, &content).render(scope, locals, &content)
|
17
20
|
else
|
18
|
-
super(params, &
|
21
|
+
super(params, &content)
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
25
|
#
|
23
|
-
def
|
24
|
-
text = params
|
25
|
-
file
|
26
|
-
|
27
|
-
|
28
|
-
engine = intermediate(params)
|
29
|
-
case data
|
30
|
-
when Binding
|
31
|
-
html = engine.render(make_object(data), &yld)
|
32
|
-
when Hash
|
33
|
-
html = engine.render(Object.new, data, &yld)
|
34
|
-
else
|
35
|
-
if data.respond_to?(:to_hash)
|
36
|
-
data = data.to_hash
|
37
|
-
html = engine.render(Object.new, data, &yld)
|
38
|
-
else
|
39
|
-
html = engine.render(data || Object.new, &yld)
|
40
|
-
end
|
26
|
+
def create_engine(params={})
|
27
|
+
text, file = parameters(params, :text, :file)
|
28
|
+
cached(text, file) do
|
29
|
+
::Haml::Engine.new(text, :filename=>file)
|
41
30
|
end
|
42
|
-
html
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
#def compile(text, file)
|
47
|
-
# intermediate # ??
|
48
|
-
#end
|
49
|
-
|
50
|
-
#
|
51
|
-
def intermediate(params)
|
52
|
-
text = params[:text]
|
53
|
-
file = params[:file]
|
54
|
-
::Haml::Engine.new(text, :filename=>file)
|
55
31
|
end
|
56
32
|
|
57
|
-
|
33
|
+
private
|
58
34
|
|
59
35
|
# Load Haml library if not already loaded.
|
60
|
-
def
|
36
|
+
def require_engine
|
61
37
|
return if defined? ::Haml::Engine
|
62
38
|
require_library 'haml'
|
63
39
|
end
|
@@ -2,47 +2,72 @@ require 'malt/engines/abstract'
|
|
2
2
|
|
3
3
|
module Malt::Engine
|
4
4
|
|
5
|
-
#
|
5
|
+
# Kramdown Markdown implementation.
|
6
6
|
#
|
7
|
-
# http://
|
7
|
+
# http://kramdown.rubyforge.org/
|
8
8
|
#
|
9
|
-
# The +:smart+ and +:filter_html+ options can be set true
|
10
|
-
# to enable those flags on the underlying RDiscount object.
|
11
9
|
class Kramdown < Abstract
|
12
10
|
|
13
11
|
register :markdown, :md
|
14
12
|
|
15
13
|
# Convert Markdown text to HTML text.
|
16
14
|
#
|
17
|
-
# @
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
# @param [Hash] params
|
16
|
+
# A hash containing the Markdown extensions which the parser
|
17
|
+
# will identify. The following extensions are accepted.
|
18
|
+
#
|
19
|
+
# @option params [String] :text
|
20
|
+
# Template text.
|
21
|
+
#
|
22
|
+
# @option params [String,Symbol] :to ('html')
|
23
|
+
# Type or file extension to convert template into.
|
24
|
+
#
|
25
|
+
# @see http://kramdown.rubyforge.org/rdoc/Kramdown/Options.html
|
26
|
+
#
|
27
|
+
def render(params={})
|
28
|
+
into, text = parameters(params, :to, :text)
|
29
|
+
|
22
30
|
case into
|
23
31
|
when :html, nil
|
24
|
-
|
32
|
+
prepare_engine(params).to_html
|
25
33
|
when :latex
|
26
|
-
|
34
|
+
prepare_engine(params).to_latex
|
27
35
|
else
|
28
36
|
super(params)
|
29
37
|
end
|
30
38
|
end
|
31
39
|
|
32
40
|
# Convert Markdown text to intermediate object.
|
33
|
-
def
|
34
|
-
text = params
|
35
|
-
|
41
|
+
def create_engine(params={})
|
42
|
+
text = parameters(params, :text)
|
43
|
+
cached(text) do
|
44
|
+
::Kramdown::Document.new(text)
|
45
|
+
end
|
36
46
|
end
|
37
47
|
|
38
48
|
private
|
39
49
|
|
40
50
|
# Load rdoc makup library if not already loaded.
|
41
|
-
def
|
51
|
+
def require_engine
|
42
52
|
return if defined? ::Kramdown
|
43
53
|
require_library 'kramdown'
|
44
54
|
end
|
45
55
|
|
56
|
+
# Kramdown has lots of options!
|
57
|
+
ENGINE_OPTION_NAMES = %w{
|
58
|
+
auto_id_prefix auto_ids
|
59
|
+
coderay_bold_every coderay_css coderay_line_number_start
|
60
|
+
coderay_line_numbers coderay_tab_width coderay_wrap
|
61
|
+
entity_output footnote_nr html_to_native latex_headers
|
62
|
+
line_width parse_block_html parse_span_html smart_quotes
|
63
|
+
template toc_levels
|
64
|
+
}
|
65
|
+
|
66
|
+
#
|
67
|
+
def engine_option_names
|
68
|
+
ENGINE_OPTION_NAMES
|
69
|
+
end
|
70
|
+
|
46
71
|
end
|
47
72
|
|
48
73
|
end
|
data/lib/malt/engines/less.rb
CHANGED
@@ -2,32 +2,33 @@ require 'malt/engines/abstract'
|
|
2
2
|
|
3
3
|
module Malt::Engine
|
4
4
|
|
5
|
-
# LESS
|
5
|
+
# LESS is an extension of CSS. You can write LESS code just like you
|
6
|
+
# would write CSS, except you need to compile it to CSS.
|
6
7
|
#
|
7
|
-
#
|
8
|
+
# @see http://lesscss.org/
|
8
9
|
#
|
9
|
-
# LESS is an extension of CSS. You can write LESS code just like you would write CSS,
|
10
|
-
# except you need to compile it to CSS. That's what this class is for.
|
11
10
|
class Less < Abstract
|
12
11
|
|
13
12
|
default :less
|
14
13
|
|
15
14
|
#
|
16
|
-
def render(params)
|
17
|
-
text = params
|
18
|
-
|
15
|
+
def render(params={})
|
16
|
+
into, text, compress = parameters(params, :to, :text, :compress)
|
17
|
+
|
19
18
|
case into
|
20
19
|
when :css, nil
|
21
|
-
|
20
|
+
prepare_engine(params).to_css(:compress=>compress)
|
22
21
|
else
|
23
22
|
super(params)
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
26
|
#
|
28
|
-
def
|
29
|
-
text = params
|
30
|
-
|
27
|
+
def create_engine(params={})
|
28
|
+
text, file = parameters(params, :text, :file)
|
29
|
+
cached(text, file) do
|
30
|
+
::Less::Parser.new(:filename=>file).parse(text)
|
31
|
+
end
|
31
32
|
end
|
32
33
|
|
33
34
|
#
|
@@ -35,11 +36,11 @@ module Malt::Engine
|
|
35
36
|
# intermediate # ??
|
36
37
|
#end
|
37
38
|
|
38
|
-
|
39
|
+
private
|
39
40
|
|
40
41
|
# Load Less library if not already loaded.
|
41
|
-
def
|
42
|
-
return if defined? ::Less::
|
42
|
+
def require_engine
|
43
|
+
return if defined? ::Less::Parser
|
43
44
|
require_library 'less'
|
44
45
|
end
|
45
46
|
|
data/lib/malt/engines/liquid.rb
CHANGED
@@ -2,34 +2,44 @@ require 'malt/engines/abstract'
|
|
2
2
|
|
3
3
|
module Malt::Engine
|
4
4
|
|
5
|
-
# Liquid
|
5
|
+
# Liquid templates.
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# @see http://liquid.rubyforge.org/
|
8
8
|
#
|
9
9
|
class Liquid < Abstract
|
10
10
|
|
11
11
|
default :liquid
|
12
12
|
|
13
13
|
#
|
14
|
-
def
|
15
|
-
text = params
|
16
|
-
|
14
|
+
def render(params={}, &content) #file, db, &content)
|
15
|
+
text, scope, locals = parameters(params, :text, :scope, :locals)
|
16
|
+
|
17
|
+
data = make_hash(scope, locals, &content)
|
18
|
+
|
19
|
+
# convert symbol keys to strings w/o rewriting the hash
|
20
|
+
symbol_keys = data.keys.select{ |k| Symbol === k }
|
21
|
+
symbol_keys.each do |k|
|
22
|
+
data[k.to_s] = data[k]
|
23
|
+
data.delete(k)
|
24
|
+
end
|
25
|
+
|
26
|
+
engine = prepare_engine(params)
|
27
|
+
|
28
|
+
engine.render(data)
|
17
29
|
end
|
18
30
|
|
19
31
|
#
|
20
|
-
def
|
21
|
-
text = params
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
engine = intermediate(params)
|
26
|
-
engine.render(data)
|
32
|
+
def create_engine(params={})
|
33
|
+
text = parameters(params, :text)
|
34
|
+
cached(text) do
|
35
|
+
::Liquid::Template.parse(text)
|
36
|
+
end
|
27
37
|
end
|
28
38
|
|
29
|
-
|
39
|
+
private
|
30
40
|
|
31
41
|
# Load Liquid library if not already loaded.
|
32
|
-
def
|
42
|
+
def require_engine
|
33
43
|
return if defined? ::Liquid::Template
|
34
44
|
require_library 'liquid'
|
35
45
|
end
|