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/ragtag.rb
CHANGED
@@ -2,43 +2,52 @@ require 'malt/engines/abstract'
|
|
2
2
|
|
3
3
|
module Malt::Engine
|
4
4
|
|
5
|
-
# RagTag
|
5
|
+
# RagTag XML/HTML templates.
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# @see http://github.com/rubyworks/ragtag
|
8
8
|
#
|
9
9
|
class RagTag < Abstract
|
10
10
|
|
11
11
|
default :ragtag, :rt
|
12
12
|
|
13
13
|
#
|
14
|
-
def render(params, &
|
15
|
-
|
16
|
-
file = params[:file]
|
17
|
-
data = params[:data]
|
18
|
-
into = params[:to]
|
14
|
+
def render(params={}, &content)
|
15
|
+
into = parameters(params, :to) || :html
|
19
16
|
|
20
17
|
case into
|
21
|
-
when :html
|
22
|
-
|
23
|
-
|
18
|
+
when :html
|
19
|
+
prepare_engine(params,&content).to_html
|
20
|
+
when :xhtml
|
21
|
+
prepare_engine(params,&content).to_xhtml
|
24
22
|
when :xml
|
25
|
-
|
26
|
-
intermediate(params).compile(data).to_xml
|
23
|
+
prepare_engine(params,&content).to_xml
|
27
24
|
else
|
28
|
-
super(params, &
|
25
|
+
super(params, &content)
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
29
|
+
#
|
30
|
+
def prepare_engine(params={}, &content)
|
31
|
+
text, file, scope, locals = parameters(params, :text, :file, :scope, :locals)
|
32
|
+
|
33
|
+
binding = make_binding(scope, locals, &content)
|
34
|
+
|
35
|
+
create_engine(params).compile(binding)
|
36
|
+
end
|
37
|
+
|
32
38
|
#
|
33
|
-
def
|
34
|
-
text = params
|
35
|
-
|
39
|
+
def create_engine(params={})
|
40
|
+
text = parameters(params, :text)
|
41
|
+
|
42
|
+
cached(text) do
|
43
|
+
::RagTag.new(text)
|
44
|
+
end
|
36
45
|
end
|
37
46
|
|
38
47
|
private
|
39
48
|
|
40
49
|
# Load Haml library if not already loaded.
|
41
|
-
def
|
50
|
+
def require_engine
|
42
51
|
return if defined? ::RagTag
|
43
52
|
require_library 'ragtag'
|
44
53
|
end
|
@@ -46,4 +55,3 @@ module Malt::Engine
|
|
46
55
|
end
|
47
56
|
|
48
57
|
end
|
49
|
-
|
@@ -6,7 +6,7 @@ module Malt::Engine
|
|
6
6
|
|
7
7
|
# Discount Markdown implementation.
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# @see http://github.com/rtomayko/rdiscount
|
10
10
|
#
|
11
11
|
# The +:smart+ and +:filter_html+ options can be set true
|
12
12
|
# to enable those flags on the underlying RDiscount object.
|
@@ -15,31 +15,38 @@ module Malt::Engine
|
|
15
15
|
default :markdown, :md
|
16
16
|
|
17
17
|
# Convert Markdown text to HTML text.
|
18
|
-
def render(params)
|
19
|
-
|
18
|
+
def render(params={})
|
19
|
+
into = parameters(params, :to)
|
20
|
+
|
21
|
+
case into
|
20
22
|
when :html, nil
|
21
|
-
|
23
|
+
prepare_engine(params).to_html
|
22
24
|
else
|
23
25
|
super(params)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
# Convert Markdown text to
|
28
|
-
def
|
29
|
-
text = params
|
30
|
-
|
29
|
+
# Convert Markdown text to create_engine engine object.
|
30
|
+
def create_engine(params={})
|
31
|
+
text = parameters(params, :text)
|
32
|
+
|
33
|
+
flags = engine_options(params)
|
34
|
+
|
35
|
+
cached(text, flags) do
|
36
|
+
::RDiscount.new(text, *flags)
|
37
|
+
end
|
31
38
|
end
|
32
39
|
|
33
|
-
|
40
|
+
private
|
34
41
|
|
35
42
|
# Load rdoc makup library if not already loaded.
|
36
|
-
def
|
43
|
+
def require_engine
|
37
44
|
return if defined? ::RDiscount
|
38
45
|
require_library 'rdiscount'
|
39
46
|
end
|
40
47
|
|
41
48
|
#
|
42
|
-
def
|
49
|
+
def engine_options(params={})
|
43
50
|
[:smart, :filter_html].select{ |flag| params[flag] || settings[flag] }
|
44
51
|
end
|
45
52
|
|
data/lib/malt/engines/rdoc.rb
CHANGED
@@ -14,31 +14,37 @@ module Malt::Engine
|
|
14
14
|
default :rdoc
|
15
15
|
|
16
16
|
# Convert rdoc text to html.
|
17
|
-
def render(params)
|
18
|
-
text = params
|
19
|
-
|
17
|
+
def render(params={})
|
18
|
+
into, text = parameters(params, :to, :text)
|
19
|
+
|
20
20
|
case into
|
21
21
|
when :html, nil
|
22
|
-
|
22
|
+
prepare_engine(params).convert(text).to_s
|
23
23
|
else
|
24
24
|
super(params)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
#
|
29
|
+
def create_engine(params={})
|
30
|
+
into = parameters(params, :to)
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
return if defined?(::RDoc::Markup)
|
33
|
-
require 'rubygems' # hack
|
34
|
-
require_library 'rdoc/markup'
|
35
|
-
require_library 'rdoc/markup/to_html'
|
32
|
+
cached(into) do
|
33
|
+
::RDoc::Markup::ToHtml.new
|
36
34
|
end
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
private
|
38
|
+
|
39
|
+
# Load rdoc makup library if not already loaded.
|
40
|
+
def require_engine
|
41
|
+
return if defined?(::RDoc::Markup)
|
42
|
+
require 'rubygems' # hack
|
43
|
+
gem 'rdoc', '> 3'
|
44
|
+
require_library 'rdoc'
|
45
|
+
#require_library 'rdoc/markup'
|
46
|
+
#require_library 'rdoc/markup/to_html'
|
47
|
+
end
|
42
48
|
|
43
49
|
end
|
44
50
|
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'malt/engines/abstract'
|
2
|
+
|
3
|
+
module Malt::Engine
|
4
|
+
|
5
|
+
# Redcarpet Markdown implementation.
|
6
|
+
#
|
7
|
+
# @see https://github.com/tanoku/redcarpet
|
8
|
+
#
|
9
|
+
class Redcarpet < Abstract
|
10
|
+
|
11
|
+
register :markdown, :md
|
12
|
+
|
13
|
+
# Convert Markdown text to HTML text.
|
14
|
+
#
|
15
|
+
# @param [Hash] params
|
16
|
+
#
|
17
|
+
# @option params [String] :text
|
18
|
+
# Template text
|
19
|
+
#
|
20
|
+
# @option params [String,Symbol] :to ('html')
|
21
|
+
# Type or file extension to convert template into.
|
22
|
+
#
|
23
|
+
def render(params={})
|
24
|
+
into, text = parameters(params, :to, :text)
|
25
|
+
|
26
|
+
case into
|
27
|
+
when :html, nil # :man, :manpage
|
28
|
+
if ::Redcarpet::VERSION < '2'
|
29
|
+
prepare_engine(params).to_html
|
30
|
+
else
|
31
|
+
prepare_engine(params).render(text)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
super(params)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Convert Markdown text to intermediate object.
|
39
|
+
#
|
40
|
+
# @param [Hash] params
|
41
|
+
# A hash containing the Markdown extensions which the parser
|
42
|
+
# will identify. The following extensions are accepted.
|
43
|
+
#
|
44
|
+
# @option params [Boolean] :no_intra_emphasis
|
45
|
+
# Do not parse emphasis inside of words. Strings such as `foo_bar_baz`
|
46
|
+
# will not generate `<em>` tags.
|
47
|
+
#
|
48
|
+
# @option params [Boolean] :tables
|
49
|
+
# Parse tables, PHP-Markdown style.
|
50
|
+
#
|
51
|
+
# @option params [Boolean] :fenced_code_blocks
|
52
|
+
# Parse fenced code blocks, PHP-Markdown style. Blocks delimited with
|
53
|
+
# three or more `~` or backticks will be considered as code, without
|
54
|
+
# the need to be indented. An optional language name may be added at
|
55
|
+
# the end of the opening fence for the code block
|
56
|
+
#
|
57
|
+
# @option params [Boolean] :autolink
|
58
|
+
# parse links even when they are not enclosed in
|
59
|
+
# `<>` characters. Autolinks for the http, https and ftp
|
60
|
+
# protocols will be automatically detected. Email addresses
|
61
|
+
# are also handled, and http links without protocol, but
|
62
|
+
# starting with `www.`
|
63
|
+
#
|
64
|
+
# @option params [Boolean] :strikethrough
|
65
|
+
# parse strikethrough, PHP-Markdown style
|
66
|
+
# Two `~` characters mark the start of a strikethrough,
|
67
|
+
# e.g. `this is ~~good~~ bad`
|
68
|
+
#
|
69
|
+
# @option params [Boolean] :lax_html_blocks
|
70
|
+
# HTML blocks do not require to be surrounded
|
71
|
+
# by an empty line as in the Markdown standard.
|
72
|
+
#
|
73
|
+
# @option params [Boolean] :space_after_headers
|
74
|
+
# A space is always required between the
|
75
|
+
# hash at the beginning of a header and its name, e.g.
|
76
|
+
# `#this is my header` would not be a valid header.
|
77
|
+
#
|
78
|
+
# @option params [Boolean] :superscript
|
79
|
+
# parse superscripts after the `^` character;
|
80
|
+
# contiguous superscripts are nested together, and complex
|
81
|
+
# values can be enclosed in parenthesis, e.g. `this is the 2^(nd) time`
|
82
|
+
#
|
83
|
+
def create_engine(params={})
|
84
|
+
return create_engine_1x(params) if ::Redcarpet::VERSION < '2'
|
85
|
+
|
86
|
+
into, toc = parameters(params, :to, :toc)
|
87
|
+
|
88
|
+
opts = engine_options(params)
|
89
|
+
|
90
|
+
case into
|
91
|
+
when :man, :manpage
|
92
|
+
renderer = ::Redcarpet::Render::ManPage
|
93
|
+
else
|
94
|
+
if toc
|
95
|
+
renderer = ::Redcarpet::Render::HTML_TOC
|
96
|
+
else
|
97
|
+
renderer = ::Redcarpet::Render::HTML
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
cached(into, toc, opts) do
|
102
|
+
::Redcarpet::Markdown.new(renderer)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# For Recarpet v1.x.
|
107
|
+
def create_engine_1x(params={})
|
108
|
+
text = parameters(params, :text)
|
109
|
+
|
110
|
+
cached(text) do
|
111
|
+
::Redcarpet.new(text) #, engine_options(params))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
ENGINE_OPTION_NAMES = %w{
|
118
|
+
no_intra_emphasis tables fenced_code_blocks autolink strikethrough
|
119
|
+
lax_html_blocks space_after_headers superscript
|
120
|
+
}
|
121
|
+
|
122
|
+
# Load rdoc makup library if not already loaded.
|
123
|
+
def require_engine
|
124
|
+
return if defined? ::Redcarpet
|
125
|
+
require_library 'redcarpet'
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
def engine_option_names
|
130
|
+
ENGINE_OPTION_NAMES
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
@@ -2,7 +2,10 @@ require 'malt/engines/abstract'
|
|
2
2
|
|
3
3
|
module Malt::Engine
|
4
4
|
|
5
|
+
# Redcloth handles textile markup.
|
5
6
|
#
|
7
|
+
# @see http://redcloth.org/
|
8
|
+
|
6
9
|
class RedCloth < Abstract
|
7
10
|
|
8
11
|
default :tt, :textile
|
@@ -14,24 +17,29 @@ module Malt::Engine
|
|
14
17
|
# :format => Symbol of the format to render [:html]
|
15
18
|
#
|
16
19
|
def render(params={})
|
17
|
-
|
20
|
+
into, text = parameters(params, :to, :text)
|
21
|
+
|
22
|
+
case into
|
18
23
|
when :html, nil
|
19
|
-
|
24
|
+
prepare_engine(params).to_html
|
20
25
|
else
|
21
26
|
super(params)
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
25
30
|
#
|
26
|
-
def
|
27
|
-
text = params
|
28
|
-
|
31
|
+
def create_engine(params={})
|
32
|
+
text = parameters(params, :text)
|
33
|
+
|
34
|
+
cached(text) do
|
35
|
+
::RedCloth.new(text)
|
36
|
+
end
|
29
37
|
end
|
30
38
|
|
31
|
-
|
39
|
+
private
|
32
40
|
|
33
41
|
# Load redcloth library if not already loaded.
|
34
|
-
def
|
42
|
+
def require_engine
|
35
43
|
return if defined? ::RedCloth
|
36
44
|
require_library 'redcloth'
|
37
45
|
end
|
data/lib/malt/engines/ruby.rb
CHANGED
@@ -2,32 +2,33 @@ require 'malt/engines/abstract'
|
|
2
2
|
|
3
3
|
module Malt::Engine
|
4
4
|
|
5
|
-
# Ruby as
|
5
|
+
# Ruby return reuslt as template engine.
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# @todo deprecate ?
|
8
|
+
#
|
9
|
+
# @see http://ruby-lang.org
|
8
10
|
#
|
9
11
|
class Ruby < Abstract
|
10
12
|
|
11
13
|
default :rb
|
12
14
|
|
13
15
|
#
|
14
|
-
def render(params={}, &
|
15
|
-
text = params
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
eval(text, data, file)
|
16
|
+
def render(params={}, &content)
|
17
|
+
text, file, scope, locals = parameters(params, :text, :file, :scope, :locals)
|
18
|
+
|
19
|
+
bind = make_binding(scope, locals, &content)
|
20
|
+
eval(text, bind, file || 'eval')
|
20
21
|
end
|
21
22
|
|
22
23
|
# Ruby compiles to Ruby. How odd. ;)
|
23
|
-
def compile(
|
24
|
-
text
|
24
|
+
def compile(params)
|
25
|
+
params[:text] #file
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
+
private
|
28
29
|
|
29
30
|
#
|
30
|
-
def
|
31
|
+
def require_engine
|
31
32
|
end
|
32
33
|
|
33
34
|
end
|
data/lib/malt/engines/sass.rb
CHANGED
@@ -9,40 +9,53 @@ module Malt::Engine
|
|
9
9
|
default :sass, :scss
|
10
10
|
|
11
11
|
#
|
12
|
-
def render(params, &
|
13
|
-
|
14
|
-
file = params[:file]
|
15
|
-
into = params[:to]
|
12
|
+
def render(params={}, &content)
|
13
|
+
into = parameters(params, :to)
|
16
14
|
|
17
15
|
case into
|
18
16
|
when :css, nil
|
19
|
-
engine =
|
17
|
+
engine = prepare_engine(params)
|
20
18
|
engine.render
|
21
19
|
else
|
22
|
-
super(params, &
|
20
|
+
super(params, &content)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
24
|
#
|
27
|
-
def
|
28
|
-
text = params
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
def create_engine(params={})
|
26
|
+
text, file, type = parameters(params, :text, :file, :type)
|
27
|
+
|
28
|
+
opts = engine_options(params)
|
29
|
+
|
30
|
+
opts[:filename] = file
|
31
|
+
opts[:syntax] = type
|
32
|
+
|
33
|
+
cached(text, file, type) do
|
34
|
+
::Sass::Engine.new(text, opts)
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
|
-
|
38
|
+
private
|
35
39
|
|
36
40
|
# Load Sass library if not already loaded.
|
37
|
-
def
|
41
|
+
def require_engine
|
38
42
|
return if defined? ::Sass::Engine
|
39
43
|
require_library 'sass'
|
40
44
|
end
|
41
45
|
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
+
# List of Sass/Scss engine options. Note that not all options are supported.
|
47
|
+
# Also use `:type` instead of `:syntax` and `:file` instead of `:filename`.
|
48
|
+
#
|
49
|
+
# @see http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options
|
50
|
+
ENGINE_OPTION_NAMES = %w{
|
51
|
+
syntax filename line style unix_newlines
|
52
|
+
line_numbers trace_selectors debug_info quiet
|
53
|
+
}
|
54
|
+
|
55
|
+
#
|
56
|
+
def engine_option_names
|
57
|
+
ENGINE_OPTION_NAMES
|
58
|
+
end
|
46
59
|
|
47
60
|
end
|
48
61
|
|