malt 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +15 -1
- data/Syckfile +80 -0
- data/lib/malt.rb +1 -1
- data/lib/malt/config.rb +12 -0
- data/lib/malt/engines.rb +1 -1
- data/lib/malt/engines/abstract.rb +2 -2
- data/lib/malt/engines/bluecloth.rb +1 -1
- data/lib/malt/engines/erb.rb +1 -1
- data/lib/malt/engines/erubis.rb +1 -1
- data/lib/malt/engines/haml.rb +1 -1
- data/lib/malt/engines/kramdown.rb +1 -1
- data/lib/malt/engines/less.rb +1 -1
- data/lib/malt/engines/liquid.rb +1 -1
- data/lib/malt/engines/radius.rb +1 -1
- data/lib/malt/engines/rdiscount.rb +1 -1
- data/lib/malt/engines/rdoc.rb +1 -1
- data/lib/malt/engines/redcloth.rb +1 -1
- data/lib/malt/engines/rtals.rb +1 -1
- data/lib/malt/engines/ruby.rb +1 -1
- data/lib/malt/engines/sass.rb +1 -1
- data/lib/malt/engines/tenjin.rb +1 -1
- data/lib/malt/formats.rb +1 -1
- data/lib/malt/formats/abstract.rb +5 -3
- data/lib/malt/formats/abstract_template.rb +45 -0
- data/lib/malt/formats/css.rb +1 -1
- data/lib/malt/formats/erb.rb +3 -3
- data/lib/malt/formats/haml.rb +2 -2
- data/lib/malt/formats/html.rb +1 -1
- data/lib/malt/formats/latex.rb +1 -1
- data/lib/malt/formats/less.rb +2 -2
- data/lib/malt/formats/liquid.rb +2 -2
- data/lib/malt/formats/markdown.rb +4 -4
- data/lib/malt/formats/pdf.rb +1 -1
- data/lib/malt/formats/radius.rb +2 -2
- data/lib/malt/formats/rbhtml.rb +52 -0
- data/lib/malt/formats/rdoc.rb +2 -2
- data/lib/malt/formats/rhtml.rb +86 -0
- data/lib/malt/formats/rtals.rb +2 -2
- data/lib/malt/formats/ruby.rb +2 -2
- data/lib/malt/formats/sass.rb +2 -2
- data/lib/malt/formats/scss.rb +57 -0
- data/lib/malt/formats/tenjin.rb +2 -2
- data/lib/malt/formats/text.rb +1 -1
- data/lib/malt/formats/textile.rb +2 -2
- data/lib/malt/formats/yaml.rb +1 -1
- data/lib/malt/markup.rb +9 -0
- data/lib/malt/meta/gemfile +2 -2
- data/lib/malt/render.rb +65 -0
- data/lib/malt/template.rb +12 -0
- data/meta/gemfile +2 -2
- data/qed/01_overview.rdoc +6 -42
- data/qed/02_formats.rdoc +39 -0
- data/qed/03_formats/01_overview.rdoc +7 -0
- data/qed/03_formats/02_rdoc.rdoc +83 -0
- data/qed/03_formats/03_textile.rdoc +48 -0
- data/qed/03_formats/04_markdown.rdoc +66 -0
- data/qed/03_formats/05_erb.rdoc +65 -0
- data/qed/03_formats/06_liquid.rdoc +54 -0
- data/qed/03_formats/07_haml.rdoc +44 -0
- data/qed/03_formats/08_rtal.rdoc +15 -0
- data/qed/03_formats/09_radius.rdoc +43 -0
- data/qed/03_formats/11_tenjin.rdoc +47 -0
- data/qed/03_formats/12_rbhtml.rdoc +55 -0
- data/qed/03_formats/13_sass.rdoc +55 -0
- data/qed/03_formats/14_scss.rdoc +58 -0
- data/qed/03_formats/15_less.rdoc +46 -0
- data/qed/03_formats/16_ruby.rdoc +48 -0
- data/qed/samples/data.yml +4 -0
- data/qed/samples/output-erb.txt +1 -0
- data/qed/samples/output-liquid.txt +1 -0
- data/qed/samples/output-mustache.txt +1 -0
- data/qed/samples/output-radius.txt +1 -0
- data/qed/samples/sample.erb +1 -0
- data/qed/samples/sample.liquid +1 -0
- data/qed/samples/sample.mustache +1 -0
- data/qed/samples/sample.radius +1 -0
- data/test/samples/sample.md +308 -0
- data/test/samples/sample.rdoc +8 -0
- metadata +40 -4
data/lib/malt/formats/liquid.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'malt/formats/abstract_template'
|
2
2
|
require 'malt/engines/liquid'
|
3
3
|
|
4
|
-
module Malt::
|
4
|
+
module Malt::Format
|
5
5
|
|
6
6
|
# Liquid templates
|
7
7
|
#
|
@@ -44,7 +44,7 @@ module Malt::Formats
|
|
44
44
|
|
45
45
|
#
|
46
46
|
def render_engine
|
47
|
-
@render_engine ||= Malt::
|
47
|
+
@render_engine ||= Malt::Engine::Liquid.new(options)
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -4,7 +4,7 @@ require 'malt/formats/latex'
|
|
4
4
|
require 'malt/engines/rdiscount'
|
5
5
|
require 'malt/engines/bluecloth'
|
6
6
|
|
7
|
-
module Malt::
|
7
|
+
module Malt::Format
|
8
8
|
|
9
9
|
# If using the Kramdown engine, then Latex is also a supported output format.
|
10
10
|
class Markdown < Abstract
|
@@ -68,11 +68,11 @@ module Malt::Formats
|
|
68
68
|
@render_engine ||= (
|
69
69
|
case engine
|
70
70
|
when :bluecloth
|
71
|
-
Malt::
|
71
|
+
Malt::Engine::BlueCloth.new(options)
|
72
72
|
when :kramdown
|
73
|
-
Malt::
|
73
|
+
Malt::Engine::Kramdown.new(options)
|
74
74
|
else
|
75
|
-
Malt::
|
75
|
+
Malt::Engine::RDiscount.new(options)
|
76
76
|
end
|
77
77
|
)
|
78
78
|
end
|
data/lib/malt/formats/pdf.rb
CHANGED
data/lib/malt/formats/radius.rb
CHANGED
@@ -2,7 +2,7 @@ require 'malt/formats/abstract'
|
|
2
2
|
require 'malt/formats/html'
|
3
3
|
require 'malt/engines/radius'
|
4
4
|
|
5
|
-
module Malt::
|
5
|
+
module Malt::Format
|
6
6
|
|
7
7
|
# Radius Template
|
8
8
|
#
|
@@ -38,7 +38,7 @@ module Malt::Formats
|
|
38
38
|
|
39
39
|
#
|
40
40
|
def render_engine
|
41
|
-
@render_engine ||= Malt::
|
41
|
+
@render_engine ||= Malt::Engine::Radius.new(options)
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'malt/formats/abstract'
|
2
|
+
require 'malt/formats/html'
|
3
|
+
require 'malt/engines/erb'
|
4
|
+
require 'malt/engines/erubis'
|
5
|
+
|
6
|
+
module Malt::Format
|
7
|
+
|
8
|
+
# RBHTML is a variant of Tenjin, but limited to HTML conversion.
|
9
|
+
class RBHTML < Abstract
|
10
|
+
|
11
|
+
register 'rbhtml'
|
12
|
+
|
13
|
+
# RHTML templates can be "pre-compiled" into Ruby templates.
|
14
|
+
def rb(*)
|
15
|
+
render_engine.compile(:text=>text, :file=>file)
|
16
|
+
end
|
17
|
+
|
18
|
+
# RHTML templates can be "pre-compiled" into Ruby templates.
|
19
|
+
def to_rb(*)
|
20
|
+
text = rb
|
21
|
+
Ruby.new(:text=>text, :file=>refile(:rb), :type=>:rb)
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
alias_method(:to_ruby, :to_rb)
|
26
|
+
|
27
|
+
#
|
28
|
+
alias_method(:precompile, :to_rb)
|
29
|
+
|
30
|
+
#
|
31
|
+
def html(data=nil, &yld)
|
32
|
+
render_engine.render(:text=>text, :file=>file, :data=>data, :format=>:html, &yld)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
def to_html(data=nil, &yld)
|
37
|
+
text = html(data, &yld)
|
38
|
+
opts = options.merge(:text=>text, :file=>refile(:html), :type=>:html)
|
39
|
+
HTML.new(opts)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
#
|
45
|
+
def render_engine
|
46
|
+
@render_engine ||= Malt::Engine::Tenjin.new(options)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
data/lib/malt/formats/rdoc.rb
CHANGED
@@ -2,7 +2,7 @@ require 'malt/formats/abstract'
|
|
2
2
|
require 'malt/formats/html'
|
3
3
|
require 'malt/engines/rdoc'
|
4
4
|
|
5
|
-
module Malt::
|
5
|
+
module Malt::Format
|
6
6
|
|
7
7
|
#
|
8
8
|
class RDoc < Abstract
|
@@ -34,7 +34,7 @@ module Malt::Formats
|
|
34
34
|
|
35
35
|
#
|
36
36
|
def render_engine
|
37
|
-
@render_engine ||= Malt::
|
37
|
+
@render_engine ||= Malt::Engine::RDoc.new(options)
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'malt/formats/abstract'
|
2
|
+
require 'malt/formats/html'
|
3
|
+
require 'malt/engines/erb'
|
4
|
+
require 'malt/engines/erubis'
|
5
|
+
|
6
|
+
module Malt::Format
|
7
|
+
|
8
|
+
# RHTML is a variant of Erb files which are limited to conversion to HTML.
|
9
|
+
class RHTML < Abstract
|
10
|
+
|
11
|
+
register 'rhtml'
|
12
|
+
|
13
|
+
# RHTML templates can be "pre-compiled" into Ruby templates.
|
14
|
+
def rb(*)
|
15
|
+
render_engine.compile(:text=>text, :file=>file)
|
16
|
+
end
|
17
|
+
|
18
|
+
# RHTML templates can be "pre-compiled" into Ruby templates.
|
19
|
+
def to_rb(*)
|
20
|
+
text = rb
|
21
|
+
Ruby.new(:text=>text, :file=>refile(:rb), :type=>:rb)
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
alias_method(:to_ruby, :to_rb)
|
26
|
+
|
27
|
+
#
|
28
|
+
alias_method(:precompile, :to_rb)
|
29
|
+
|
30
|
+
#
|
31
|
+
def html(data=nil, &yld)
|
32
|
+
render_engine.render(:text=>text, :file=>file, :format=>:html)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
def to_html(data=nil, &yld)
|
37
|
+
text = html(data, &yld)
|
38
|
+
opts = options.merge(:text=>text, :file=>refile(:html), :type=>:html)
|
39
|
+
HTML.new(opts)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
#def render(data, &yld)
|
44
|
+
# if options[:recompile]
|
45
|
+
# result = render_engine.render(db, &yld)
|
46
|
+
# else
|
47
|
+
# result = precompile.compile(db, &yld)
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# HTML.new(:text=>result, :file=>refile(:html))
|
51
|
+
#end
|
52
|
+
|
53
|
+
#
|
54
|
+
#def to_html(db, &yld)
|
55
|
+
# # unless pre-compilation is turned off, convert to ruby
|
56
|
+
# return to_ruby.to_html(db, &yld) unless options[:recompile]
|
57
|
+
# convert(:html, db, &yld)
|
58
|
+
#end
|
59
|
+
|
60
|
+
#
|
61
|
+
#def render_to(to, db, &yld)
|
62
|
+
# #if options[:recompile]
|
63
|
+
# render_engine.render(text, file, db, &yld)
|
64
|
+
# #else
|
65
|
+
# # to_ruby.render(db, &yld)
|
66
|
+
# #end
|
67
|
+
#end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
#
|
72
|
+
def render_engine
|
73
|
+
@render_engine ||= (
|
74
|
+
case engine
|
75
|
+
when :erubis
|
76
|
+
Malt::Engine::Erubis.new(options)
|
77
|
+
else
|
78
|
+
Malt::Engine::Erb.new(options)
|
79
|
+
end
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
data/lib/malt/formats/rtals.rb
CHANGED
@@ -2,7 +2,7 @@ require 'malt/formats/abstract'
|
|
2
2
|
require 'malt/formats/html'
|
3
3
|
require 'malt/engines/rtals'
|
4
4
|
|
5
|
-
module Malt::
|
5
|
+
module Malt::Format
|
6
6
|
|
7
7
|
#
|
8
8
|
class Rtals < Abstract
|
@@ -37,7 +37,7 @@ module Malt::Formats
|
|
37
37
|
|
38
38
|
#
|
39
39
|
def render_engine
|
40
|
-
@render_engine ||= Malt::
|
40
|
+
@render_engine ||= Malt::Engine::RTALS.new(options)
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
data/lib/malt/formats/ruby.rb
CHANGED
@@ -2,7 +2,7 @@ require 'malt/formats/abstract'
|
|
2
2
|
require 'malt/formats/html'
|
3
3
|
require 'malt/engines/erb'
|
4
4
|
|
5
|
-
module Malt::
|
5
|
+
module Malt::Format
|
6
6
|
|
7
7
|
# Yes, pure Ruby as a template format.
|
8
8
|
#
|
@@ -63,7 +63,7 @@ module Malt::Formats
|
|
63
63
|
|
64
64
|
#
|
65
65
|
def render_engine
|
66
|
-
@render_engine ||= Malt::
|
66
|
+
@render_engine ||= Malt::Engine::Ruby.new(options)
|
67
67
|
end
|
68
68
|
|
69
69
|
end
|
data/lib/malt/formats/sass.rb
CHANGED
@@ -2,7 +2,7 @@ require 'malt/formats/abstract'
|
|
2
2
|
require 'malt/formats/css'
|
3
3
|
require 'malt/engines/sass'
|
4
4
|
|
5
|
-
module Malt::
|
5
|
+
module Malt::Format
|
6
6
|
|
7
7
|
# Sass Format
|
8
8
|
#
|
@@ -42,7 +42,7 @@ module Malt::Formats
|
|
42
42
|
|
43
43
|
#
|
44
44
|
def render_engine
|
45
|
-
@render_engine ||= Malt::
|
45
|
+
@render_engine ||= Malt::Engine::Sass.new(options)
|
46
46
|
end
|
47
47
|
|
48
48
|
# Sass default output type is CSS.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'malt/formats/abstract'
|
2
|
+
require 'malt/formats/css'
|
3
|
+
require 'malt/engines/sass'
|
4
|
+
|
5
|
+
module Malt::Format
|
6
|
+
|
7
|
+
# SCSS Format
|
8
|
+
#
|
9
|
+
# This uses the same engine as Sass.
|
10
|
+
class SCSS < Abstract
|
11
|
+
|
12
|
+
register 'scss'
|
13
|
+
|
14
|
+
#
|
15
|
+
def css(data=nil, &yld)
|
16
|
+
render_engine.render(:format=>:css, :text=>text, :file=>file, :type=>type)
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
def to_css(data=nil, &yld)
|
21
|
+
result = css(data, &yld)
|
22
|
+
CSS.new(:text=>result, :file=>refile(:css), :type=>:css)
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
#def compile(db, &yld)
|
27
|
+
# result = render_engine.render(text, db, &yld)
|
28
|
+
# opts = options.merge(:text=>result, file=>refile(:css))
|
29
|
+
# CSS.new(opts)
|
30
|
+
#end
|
31
|
+
|
32
|
+
#
|
33
|
+
#def render_to(to, db, &yld)
|
34
|
+
# case to
|
35
|
+
# when :css
|
36
|
+
# malt_engine.render_css(text, file, db, &yld)
|
37
|
+
# else
|
38
|
+
# raise UnspportedConversion.new(type, to)
|
39
|
+
# end
|
40
|
+
#end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
#
|
45
|
+
def render_engine
|
46
|
+
@render_engine ||= Malt::Engine::Sass.new(options)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Sass default output type is CSS.
|
50
|
+
def default
|
51
|
+
:css
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
data/lib/malt/formats/tenjin.rb
CHANGED
@@ -2,7 +2,7 @@ require 'malt/formats/abstract_template'
|
|
2
2
|
require 'malt/formats/html'
|
3
3
|
require 'malt/engines/tenjin'
|
4
4
|
|
5
|
-
module Malt::
|
5
|
+
module Malt::Format
|
6
6
|
|
7
7
|
# Tenjin
|
8
8
|
#
|
@@ -41,7 +41,7 @@ module Malt::Formats
|
|
41
41
|
|
42
42
|
#
|
43
43
|
def render_engine
|
44
|
-
@render_engine ||= Malt::
|
44
|
+
@render_engine ||= Malt::Engine::Tenjin.new(options)
|
45
45
|
end
|
46
46
|
|
47
47
|
end
|
data/lib/malt/formats/text.rb
CHANGED
@@ -2,7 +2,7 @@ require 'malt/formats/abstract'
|
|
2
2
|
require 'malt/formats/html'
|
3
3
|
require 'malt/formats/pdf'
|
4
4
|
|
5
|
-
module Malt::
|
5
|
+
module Malt::Format
|
6
6
|
|
7
7
|
# Plain text format. Plain text documents are uniqu in that they can
|
8
8
|
# be transformed into any other type of document. For example, applying
|
data/lib/malt/formats/textile.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'malt/formats/abstract'
|
2
2
|
require 'malt/engines/redcloth'
|
3
3
|
|
4
|
-
module Malt::
|
4
|
+
module Malt::Format
|
5
5
|
|
6
6
|
#
|
7
7
|
class Textile < Abstract
|
@@ -50,7 +50,7 @@ module Malt::Formats
|
|
50
50
|
|
51
51
|
#
|
52
52
|
def render_engine
|
53
|
-
@render_engine ||= Malt::
|
53
|
+
@render_engine ||= Malt::Engine::RedCloth.new(options)
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|
data/lib/malt/formats/yaml.rb
CHANGED
data/lib/malt/markup.rb
ADDED
data/lib/malt/meta/gemfile
CHANGED
data/lib/malt/render.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'malt/config'
|
2
|
+
require 'malt/core_ext'
|
3
|
+
|
4
|
+
module Malt
|
5
|
+
|
6
|
+
#
|
7
|
+
def self.config
|
8
|
+
@config ||= Config.new
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
def self.render(parameters={}, &body)
|
13
|
+
type = parameters[:type]
|
14
|
+
file = parameters[:file]
|
15
|
+
engine = parameters[:engine]
|
16
|
+
|
17
|
+
type = file_type(file) unless type
|
18
|
+
text = file_read(file) unless text
|
19
|
+
engine = engine(type, engine).new
|
20
|
+
|
21
|
+
parameters[:type] = type
|
22
|
+
parameters[:text] = text
|
23
|
+
|
24
|
+
engine.render(parameters, &body)
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
def self.engine(type, engine=nil)
|
29
|
+
type = type.to_sym
|
30
|
+
engine = engine || config.engine[type]
|
31
|
+
case engine
|
32
|
+
when Class
|
33
|
+
#raise unless Engine.registry[type].include?(engine)
|
34
|
+
engine
|
35
|
+
when String, Symbol
|
36
|
+
match = engine.to_s.downcase
|
37
|
+
Engine.registry[type].find{ |e| e.basename.downcase == match }
|
38
|
+
else
|
39
|
+
if Engine.registry[type]
|
40
|
+
Engine.registry[type].first
|
41
|
+
else
|
42
|
+
raise "no engine to handle `#{type}' format"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
def self.file_type(file)
|
49
|
+
ext = File.extname(file)
|
50
|
+
ext = ext.to_s.downcase
|
51
|
+
if ext.empty?
|
52
|
+
nil
|
53
|
+
elsif ext[0,1] == '.'
|
54
|
+
ext[1..-1].to_sym
|
55
|
+
else
|
56
|
+
ext.to_sym
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# TODO: Handle File objects and URLs.
|
61
|
+
def self.file_read(file)
|
62
|
+
File.read(file)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|