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
@@ -1,66 +0,0 @@
|
|
1
|
-
== Markdown
|
2
|
-
|
3
|
-
Malt supports Markdown via either the RDiscount, BlueCloth or Kramdown backends.
|
4
|
-
|
5
|
-
Lets say we have a Markdown document called 'test.md' containing ...
|
6
|
-
|
7
|
-
# Example
|
8
|
-
|
9
|
-
This is an example of Markdown rendering.
|
10
|
-
|
11
|
-
Markdown documents are recognized by the +.markdown+ or +.md+ file extensions.
|
12
|
-
|
13
|
-
html = Malt.render(:file=>'tmp/test.md')
|
14
|
-
|
15
|
-
html.assert.include?('<h1>Example</h1>')
|
16
|
-
|
17
|
-
By default teh RDiscount library is used to render markdown documents, but
|
18
|
-
Malt supports BlueCloth and Kramdown as well. These case be used by setting
|
19
|
-
the :engine option.
|
20
|
-
|
21
|
-
html = Malt.render(:file=>'tmp/test.md', :engine=>:bluecloth)
|
22
|
-
|
23
|
-
And as we can see the document rendered as expected.
|
24
|
-
|
25
|
-
html.assert.include?('<h1>Example</h1>')
|
26
|
-
|
27
|
-
And using the Kramdown library,
|
28
|
-
|
29
|
-
html = Malt.render(:file=>'tmp/test.md', :engine=>:kramdown)
|
30
|
-
|
31
|
-
We can see the document rendered as well, though notice that Kramdown provides
|
32
|
-
some bonus features compared to the other rendering engines.
|
33
|
-
|
34
|
-
html.assert.include?('<h1 id="example">Example</h1>')
|
35
|
-
|
36
|
-
Malt supports Markdown via either the RDiscount, BlueCloth or Kramdown backends.
|
37
|
-
|
38
|
-
Lets say we have an Markdown document called 'test.md' containing ...
|
39
|
-
|
40
|
-
# Example
|
41
|
-
|
42
|
-
This is an example of Markdown rendering.
|
43
|
-
|
44
|
-
We can access the file via the +Malt.file+ method. Markdown documents are
|
45
|
-
recognized by the +.markdown+ or +.md+ file extensions.
|
46
|
-
|
47
|
-
mark = Malt.file('tmp/test.md')
|
48
|
-
|
49
|
-
We can the convert the document to a Malt Html object via the #to_html method.
|
50
|
-
|
51
|
-
html = mark.to_html
|
52
|
-
|
53
|
-
Notice that the output is an instance of Malt::Format::HTML.
|
54
|
-
|
55
|
-
html.class.assert == Malt::Format::HTML
|
56
|
-
|
57
|
-
And that by calling #to_s we can get the rendered HTML document.
|
58
|
-
|
59
|
-
html.to_s.assert.include?('<h1>Example</h1>')
|
60
|
-
|
61
|
-
Or we can convert the document directly to HTML via the #html method.
|
62
|
-
|
63
|
-
out = mark.html
|
64
|
-
|
65
|
-
out.assert.include?('<h1>Example</h1>')
|
66
|
-
|
data/qed/03_formats/05_erb.rdoc
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
== ERB
|
2
|
-
|
3
|
-
Malt supports ERB via the ERB and Erubis engines.
|
4
|
-
|
5
|
-
Lets say we have a ERB document called 'test.erb' containing ...
|
6
|
-
|
7
|
-
<h1>Example <%= title %></h1>
|
8
|
-
|
9
|
-
<p>This is an example of ERB template.</p>
|
10
|
-
|
11
|
-
We can render erb documents via the +render+ method, as we can any format.
|
12
|
-
However, becuase ERB if a template format and not just a markup syntax,
|
13
|
-
we need to also provide the +render+ methods with data for interpolation
|
14
|
-
into the ERB document.
|
15
|
-
|
16
|
-
data = { :title=>"Document" }
|
17
|
-
|
18
|
-
html = Malt.render(:file=>'tmp/test.erb', :data=>data)
|
19
|
-
|
20
|
-
And as we can see the document rendered as expected.
|
21
|
-
|
22
|
-
html.assert.include?('<h1>Example Document</h1>')
|
23
|
-
|
24
|
-
ERB doesn't actually care what format the document is rendered as. The
|
25
|
-
template could have been any text file what so ever, so using the `:format`
|
26
|
-
option would have no effect here.
|
27
|
-
|
28
|
-
By default the common ERB library is used to render erb documents. By setting
|
29
|
-
the :engine option, Erubis can be used instead.
|
30
|
-
|
31
|
-
html = Malt.render(:file=>'tmp/test.erb', :data=>data, :engine=>:erubis)
|
32
|
-
|
33
|
-
And as we can see the document rendered as expected.
|
34
|
-
|
35
|
-
html.assert.include?('<h1>Example Document</h1>')
|
36
|
-
|
37
|
-
Malt supports template engines as well as formats.
|
38
|
-
|
39
|
-
Lets say we have an ERB document called 'test.erb' containing ...
|
40
|
-
|
41
|
-
<h1>Example <%= title %></h1>
|
42
|
-
|
43
|
-
<p>This is an example of ERB template.</p>
|
44
|
-
|
45
|
-
We can render erb documents to any format we wish.
|
46
|
-
|
47
|
-
erb = Malt.file('tmp/test.erb')
|
48
|
-
|
49
|
-
html = erb.to_html(:title=>"Document")
|
50
|
-
|
51
|
-
We will notice that the output is an instance of Malt::Format::HTML.
|
52
|
-
|
53
|
-
html.class.assert == Malt::Format::HTML
|
54
|
-
|
55
|
-
And that by calling #to_s we can get the rendered HTML document.
|
56
|
-
|
57
|
-
html.to_s.assert.include?('<h1>Example Document</h1>')
|
58
|
-
|
59
|
-
Or we can convert the document directly to HTML via the #html method.
|
60
|
-
|
61
|
-
out = erb.html(:title=>"Alternate")
|
62
|
-
|
63
|
-
out.assert.include?('<h1>Example Alternate</h1>')
|
64
|
-
|
65
|
-
ERB doesn't actually care what format the document is rendered as.
|
@@ -1,54 +0,0 @@
|
|
1
|
-
== Liquid
|
2
|
-
|
3
|
-
Lets say we have a Liquid document called 'test.liquid' containing:
|
4
|
-
|
5
|
-
<h1>Example {{ title }}</h1>
|
6
|
-
|
7
|
-
<p>This is an example of a Liquid template.</p>
|
8
|
-
|
9
|
-
We can render liquid documents via the +render+ method, as we can any format.
|
10
|
-
However, becuase Liquid is a template format and not just a markup syntax,
|
11
|
-
we need to also provide the +render+ function with data for interpolation
|
12
|
-
into the liquid document.
|
13
|
-
|
14
|
-
data = { :title=>"Document" }
|
15
|
-
|
16
|
-
html = Malt.render(:file=>'tmp/test.liquid', :data=>data)
|
17
|
-
|
18
|
-
html.assert.include?('<h1>Example Document</h1>')
|
19
|
-
|
20
|
-
Liquid doesn't actually care what format the document is rendered as, since it
|
21
|
-
is purely a template engine that can be applied to any other format.
|
22
|
-
Lets say we have a Liquid document called 'test.liquid' containing ...
|
23
|
-
|
24
|
-
<h1>Example {{ title }}</h1>
|
25
|
-
|
26
|
-
<p>This is an example of a Liquid template.</p>
|
27
|
-
|
28
|
-
We can render erb documents to any format we wish.
|
29
|
-
|
30
|
-
liq = Malt.file('tmp/test.liquid')
|
31
|
-
|
32
|
-
html = liq.to_html(:title=>"Document")
|
33
|
-
|
34
|
-
We will notice that the output is an instance of Malt::Format::HTML.
|
35
|
-
|
36
|
-
html.class.assert == Malt::Format::HTML
|
37
|
-
|
38
|
-
We will notice that the output is an instance of Malt::Format::HTML.
|
39
|
-
|
40
|
-
html.class.assert == Malt::Format::HTML
|
41
|
-
|
42
|
-
Then by calling #to_s we can get the rendered HTML document.
|
43
|
-
|
44
|
-
html.to_s.assert.include?('<h1>Example Document</h1>')
|
45
|
-
|
46
|
-
Or we can convert the document directly to HTML via the #html method.
|
47
|
-
|
48
|
-
out = liq.html(:title=>"Alternate")
|
49
|
-
|
50
|
-
out.assert.include?('<h1>Example Alternate</h1>')
|
51
|
-
|
52
|
-
Liquid doesn't actually care what format the document is rendered as, since it
|
53
|
-
is purely a template engine that can be applied to any format.
|
54
|
-
|
data/qed/03_formats/07_haml.rdoc
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
== Haml
|
2
|
-
|
3
|
-
Lets say we have a Haml document called 'test.haml' containing:
|
4
|
-
|
5
|
-
%h1== Example #{title}
|
6
|
-
%p This is an example of a Haml template.
|
7
|
-
|
8
|
-
We can render Haml documents via the +render+ method, as we can any format.
|
9
|
-
While it might not appear as such on first glance, Haml is actually a template
|
10
|
-
format and not just a markup language, so we need to also provide the +render+
|
11
|
-
function with data for interpolation into the Haml document.
|
12
|
-
|
13
|
-
data = { :title=>"Document" }
|
14
|
-
|
15
|
-
html = Malt.render(:file=>'tmp/test.haml', :data=>data)
|
16
|
-
|
17
|
-
html.assert.include?('<h1>Example Document</h1>')
|
18
|
-
|
19
|
-
We can get a hold of the Haml document via the Malt.file function.
|
20
|
-
|
21
|
-
haml = Malt.file('tmp/test.haml')
|
22
|
-
|
23
|
-
haml.class.assert == Malt::Format::Haml
|
24
|
-
|
25
|
-
We can convert Haml documents to html very easily.
|
26
|
-
|
27
|
-
data = {:title => "Document"}
|
28
|
-
|
29
|
-
html = haml.to_html(data)
|
30
|
-
|
31
|
-
First we will notice that the output is an instance of Malt::Format::HTML.
|
32
|
-
|
33
|
-
html.class.assert == Malt::Format::HTML
|
34
|
-
|
35
|
-
And that by calling #to_s we can get the rendered HTML document.
|
36
|
-
|
37
|
-
html.to_s.assert.include?('<h1>Example Document</h1>')
|
38
|
-
|
39
|
-
Or we can convert the Haml document directly to HTML via the #html method.
|
40
|
-
|
41
|
-
out = haml.html(data)
|
42
|
-
|
43
|
-
out.assert.include?('<h1>Example Document</h1>')
|
44
|
-
|
@@ -1,19 +0,0 @@
|
|
1
|
-
== RagTag
|
2
|
-
|
3
|
-
Lets say we have a Rtals document called 'test.rt' containing:
|
4
|
-
|
5
|
-
<html>
|
6
|
-
<body>
|
7
|
-
<h1>Example <span replace="title">DUMMY</span></h1>
|
8
|
-
<p>This is an example of a RagTag template.</p>
|
9
|
-
</body>
|
10
|
-
</html>
|
11
|
-
|
12
|
-
We can render Rtal documents via the +render+ method, as we can any format.
|
13
|
-
|
14
|
-
data = { :title=>"Document" }
|
15
|
-
|
16
|
-
html = Malt.render(:file=>'tmp/test.rt', :data=>data)
|
17
|
-
|
18
|
-
html.assert.include?('<h1>Example Document</h1>')
|
19
|
-
|
@@ -1,43 +0,0 @@
|
|
1
|
-
== Radius
|
2
|
-
|
3
|
-
Lets say we have a Radius document called 'test.radius' containing:
|
4
|
-
|
5
|
-
<h1>Example <r:title /></h1>
|
6
|
-
<p>This is an example of a Radius template.</p>
|
7
|
-
|
8
|
-
We can render Radius documents via the +render+ method, as we can any format.
|
9
|
-
|
10
|
-
data = {:title=>"Document"}
|
11
|
-
|
12
|
-
html = Malt.render(:file=>'tmp/test.radius', :data=>data, :tag_prefix=>'r')
|
13
|
-
|
14
|
-
html.assert.include?('<h1>Example Document</h1>')
|
15
|
-
|
16
|
-
We can get a hold of the Radius document via the Malt.file function.
|
17
|
-
|
18
|
-
radi = Malt.file('tmp/test.radius', :tag_prefix=>'r')
|
19
|
-
|
20
|
-
radi.class.assert == Malt::Format::Radius
|
21
|
-
|
22
|
-
Notice here we have passed an option to the file constructor. This option
|
23
|
-
is passed on the underlying Radius.new method. Now we can convert Radius
|
24
|
-
documents to HTML documents via #to_html.
|
25
|
-
|
26
|
-
data = {:title => "Document"}
|
27
|
-
|
28
|
-
html = radi.to_html(data)
|
29
|
-
|
30
|
-
First we will notice that the output is an instance of Malt::Format::HTML.
|
31
|
-
|
32
|
-
html.class.assert == Malt::Format::HTML
|
33
|
-
|
34
|
-
And that by calling #to_s we can get the rendered HTML document.
|
35
|
-
|
36
|
-
html.to_s.assert.include?('<h1>Example Document</h1>')
|
37
|
-
|
38
|
-
Or we can convert the Radius document directly to HTML via the #html method.
|
39
|
-
|
40
|
-
out = radi.html(data)
|
41
|
-
|
42
|
-
out.assert.include?('<h1>Example Document</h1>')
|
43
|
-
|
@@ -1,47 +0,0 @@
|
|
1
|
-
== Tenjin
|
2
|
-
|
3
|
-
While Tenjin is generally intended to be used to render HTML documents, it is
|
4
|
-
a general purpose template format that can be used for any type of document.
|
5
|
-
For these uses, the Tenjin file extension is '.tenjin'.
|
6
|
-
|
7
|
-
Lets say we have a Tenjin document called 'test.tenjin' containing:
|
8
|
-
|
9
|
-
Hello #{@name}!
|
10
|
-
|
11
|
-
We can render the document via #render.
|
12
|
-
|
13
|
-
data = { :name=>'World', :items=>['A','B','C'] }
|
14
|
-
|
15
|
-
@text = Malt.render(:file=>'tmp/test.tenjin', :data=>data)
|
16
|
-
|
17
|
-
And we can verify that @text is:
|
18
|
-
|
19
|
-
Hello World!
|
20
|
-
|
21
|
-
We can get a OOP interface tothe Tenjin document via the Malt.file function.
|
22
|
-
|
23
|
-
tenjin = Malt.file('tmp/test.tenjin')
|
24
|
-
|
25
|
-
tenjin.class.assert == Malt::Format::Tenjin
|
26
|
-
|
27
|
-
Since Tenjin is aa general pupose template foramt, we can convert Tenjin
|
28
|
-
documents to any format we wish. For instance we can convert our example
|
29
|
-
to a Text documents via #to_txt.
|
30
|
-
|
31
|
-
data = { :name=>'World', :items=>['<AAA>', 'B&B', '"CCC"'] }
|
32
|
-
|
33
|
-
text = tenjin.to_txt(data)
|
34
|
-
|
35
|
-
First we will notice that the output is an instance of `Malt::Format::Text`.
|
36
|
-
|
37
|
-
text.class.assert == Malt::Format::Text
|
38
|
-
|
39
|
-
And that by calling #to_s we can get the rendered Text document.
|
40
|
-
|
41
|
-
text.to_s.assert.include?('Hello World!')
|
42
|
-
|
43
|
-
Or we can convert the Tenjin document directly to text via the #txt method.
|
44
|
-
|
45
|
-
out = tenjin.txt(data)
|
46
|
-
|
47
|
-
out.assert.include?('Hello World!')
|
@@ -1,55 +0,0 @@
|
|
1
|
-
== RBHTML
|
2
|
-
|
3
|
-
Tenjin is a general purpose template language with support for multiple
|
4
|
-
languages including Ruby. The variation of Tenjin for Ruby, called rbTenjin,
|
5
|
-
defines a document format with an extension of `.rbhtml`.
|
6
|
-
|
7
|
-
Lets say we have a Tenjin document called 'test.rbhtml' containing:
|
8
|
-
|
9
|
-
Hello #{@name}!
|
10
|
-
<ul>
|
11
|
-
<?rb for item in @items ?>
|
12
|
-
<li>${item}</li>
|
13
|
-
<?rb end ?>
|
14
|
-
</ul>
|
15
|
-
|
16
|
-
We can render the document via #render.
|
17
|
-
|
18
|
-
data = { :name=>'World', :items=>['<AAA>', 'B&B', '"CCC"'] }
|
19
|
-
|
20
|
-
@html = Malt.render(:file=>'tmp/test.rbhtml', :data=>data)
|
21
|
-
|
22
|
-
And we can verify that @html is:
|
23
|
-
|
24
|
-
Hello World!
|
25
|
-
<ul>
|
26
|
-
<li><AAA></li>
|
27
|
-
<li>B&B</li>
|
28
|
-
<li>"CCC"</li>
|
29
|
-
</ul>
|
30
|
-
|
31
|
-
We can get a hold of the RBHTML document via the Malt.file function.
|
32
|
-
|
33
|
-
rbhtml = Malt.file('tmp/test.rbhtml')
|
34
|
-
|
35
|
-
rbhtml.class.assert == Malt::Format::RBHTML
|
36
|
-
|
37
|
-
We can convert RBHTML documents to HTML documents via #to_html.
|
38
|
-
|
39
|
-
data = { :name=>'World', :items=>['<AAA>', 'B&B', '"CCC"'] }
|
40
|
-
|
41
|
-
html = rbhtml.to_html(data)
|
42
|
-
|
43
|
-
First we will notice that the output is an instance of Malt::Format::HTML.
|
44
|
-
|
45
|
-
html.class.assert == Malt::Format::HTML
|
46
|
-
|
47
|
-
And that by calling #to_s we can get the rendered HTML document.
|
48
|
-
|
49
|
-
html.to_s.assert.include?('Hello World!')
|
50
|
-
|
51
|
-
Or we can convert the RBHTML document directly to HTML via the #html method.
|
52
|
-
|
53
|
-
out = rbhtml.html(data)
|
54
|
-
|
55
|
-
out.assert.include?('Hello World!')
|
data/qed/03_formats/13_sass.rdoc
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
== Sass
|
2
|
-
|
3
|
-
Lets say we have a Sass document called 'test.sass' containing:
|
4
|
-
|
5
|
-
$blue: #3bbfce
|
6
|
-
$margin: 16px
|
7
|
-
|
8
|
-
.content-navigation
|
9
|
-
border-color: $blue
|
10
|
-
color: darken($blue, 9%)
|
11
|
-
|
12
|
-
.border
|
13
|
-
padding: $margin / 2
|
14
|
-
margin: $margin / 2
|
15
|
-
border-color: $blue
|
16
|
-
|
17
|
-
We can render the Sass document via #render.
|
18
|
-
|
19
|
-
@css = Malt.render(:file=>'tmp/test.sass')
|
20
|
-
|
21
|
-
And we can verify that @css is the expected CSS:
|
22
|
-
|
23
|
-
.content-navigation {
|
24
|
-
border-color: #3bbfce;
|
25
|
-
color: #2ca2af; }
|
26
|
-
|
27
|
-
.border {
|
28
|
-
padding: 8px;
|
29
|
-
margin: 8px;
|
30
|
-
border-color: #3bbfce; }
|
31
|
-
|
32
|
-
We can also get a hold of the Sass document via the Malt.file function.
|
33
|
-
|
34
|
-
sass = Malt.file('tmp/test.sass')
|
35
|
-
|
36
|
-
sass.class.assert == Malt::Format::Sass
|
37
|
-
|
38
|
-
We can convert the Sass document to a CSS document via the #to_css method.
|
39
|
-
|
40
|
-
css = sass.to_css
|
41
|
-
|
42
|
-
We can see that the output is an instance of Malt::Format::HTML.
|
43
|
-
|
44
|
-
css.class.assert == Malt::Format::CSS
|
45
|
-
|
46
|
-
And that by calling #to_s we can get the rendered CSS document.
|
47
|
-
|
48
|
-
css.to_s.assert.include?('border-color: #3bbfce;')
|
49
|
-
|
50
|
-
Or we can convert the Sass document directly to CSS via the #css method.
|
51
|
-
|
52
|
-
out = sass.css
|
53
|
-
|
54
|
-
out.assert.include?('border-color: #3bbfce;')
|
55
|
-
|