malt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/History.rdoc +13 -0
  2. data/License.txt +204 -0
  3. data/README.rdoc +68 -0
  4. data/bin/malt +4 -0
  5. data/features/consistent_rendering.feature +36 -0
  6. data/features/samples/sample.erb +1 -0
  7. data/features/samples/sample.erubis +1 -0
  8. data/features/samples/sample.liquid +1 -0
  9. data/features/samples/sample.mustache +1 -0
  10. data/features/samples/sample.radius +1 -0
  11. data/features/step_definitions/engine_steps.rb +49 -0
  12. data/features/support/loadpath.rb +1 -0
  13. data/features/support/sample_class.rb +8 -0
  14. data/lib/malt.rb +79 -0
  15. data/lib/malt/core_ext.rb +31 -0
  16. data/lib/malt/engines.rb +10 -0
  17. data/lib/malt/engines/abstract.rb +151 -0
  18. data/lib/malt/engines/bluecloth.rb +39 -0
  19. data/lib/malt/engines/erb.rb +84 -0
  20. data/lib/malt/engines/erubis.rb +65 -0
  21. data/lib/malt/engines/haml.rb +68 -0
  22. data/lib/malt/engines/kramdown.rb +48 -0
  23. data/lib/malt/engines/less.rb +49 -0
  24. data/lib/malt/engines/liquid.rb +40 -0
  25. data/lib/malt/engines/radius.rb +90 -0
  26. data/lib/malt/engines/rdiscount.rb +49 -0
  27. data/lib/malt/engines/rdoc.rb +46 -0
  28. data/lib/malt/engines/redcloth.rb +42 -0
  29. data/lib/malt/engines/rtals.rb +46 -0
  30. data/lib/malt/engines/ruby.rb +36 -0
  31. data/lib/malt/engines/sass.rb +50 -0
  32. data/lib/malt/engines/tenjin.rb +61 -0
  33. data/lib/malt/formats.rb +10 -0
  34. data/lib/malt/formats/abstract.rb +195 -0
  35. data/lib/malt/formats/css.rb +34 -0
  36. data/lib/malt/formats/erb.rb +102 -0
  37. data/lib/malt/formats/haml.rb +53 -0
  38. data/lib/malt/formats/html.rb +29 -0
  39. data/lib/malt/formats/latex.rb +47 -0
  40. data/lib/malt/formats/less.rb +51 -0
  41. data/lib/malt/formats/liquid.rb +53 -0
  42. data/lib/malt/formats/markdown.rb +83 -0
  43. data/lib/malt/formats/pdf.rb +29 -0
  44. data/lib/malt/formats/radius.rb +47 -0
  45. data/lib/malt/formats/rdoc.rb +43 -0
  46. data/lib/malt/formats/rtals.rb +46 -0
  47. data/lib/malt/formats/ruby.rb +71 -0
  48. data/lib/malt/formats/sass.rb +56 -0
  49. data/lib/malt/formats/tenjin.rb +50 -0
  50. data/lib/malt/formats/text.rb +54 -0
  51. data/lib/malt/formats/textile.rb +59 -0
  52. data/lib/malt/formats/yaml.rb +50 -0
  53. data/lib/malt/kernel.rb +31 -0
  54. data/lib/malt/meta/data.rb +26 -0
  55. data/lib/malt/meta/gemfile +17 -0
  56. data/lib/malt/meta/profile +21 -0
  57. data/meta/data.rb +26 -0
  58. data/meta/gemfile +17 -0
  59. data/meta/profile +21 -0
  60. data/qed/01_overview.rdoc +44 -0
  61. data/qed/applique/malt.rb +12 -0
  62. metadata +283 -0
@@ -0,0 +1,53 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+ require 'malt/engines/haml'
4
+
5
+ module Malt::Formats
6
+
7
+ # Haml looks like a Markup format, but it turns out to be
8
+ # a template format too.
9
+ class Haml < Abstract
10
+
11
+ register 'haml'
12
+
13
+ #
14
+ def haml
15
+ text
16
+ end
17
+
18
+ #
19
+ def to_haml
20
+ self
21
+ end
22
+
23
+ #
24
+ def html(data=nil, &yld)
25
+ render_engine.render(:format=>:html, :text=>text, :file=>file, :data=>data, &yld)
26
+ end
27
+
28
+ #
29
+ def to_html(data=nil, &yld)
30
+ text = html(data, &yld)
31
+ opts = options.merge(:text=>text, :file=>refile(:html), :type=>:html)
32
+ HTML.new(opts)
33
+ end
34
+
35
+ #
36
+ #def to_ruby(db, &yld)
37
+ # @ruby ||= (
38
+ # source = engine.compile(text, file)
39
+ # Ruby.new(:text=>source, :file=>refile(:rb))
40
+ # )
41
+ #end
42
+
43
+ private
44
+
45
+ #
46
+ def render_engine
47
+ @render_engine ||= Malt::Engines::Haml.new(options)
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
@@ -0,0 +1,29 @@
1
+ require 'malt/formats/abstract'
2
+
3
+ module Malt::Formats
4
+
5
+ #
6
+ class HTML < Abstract
7
+
8
+ register 'html'
9
+
10
+ #
11
+ def html(*)
12
+ text
13
+ end
14
+
15
+ # HTML is HTML ;)
16
+ def to_html(*)
17
+ self
18
+ end
19
+
20
+ private
21
+
22
+ #
23
+ def render_engine
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
@@ -0,0 +1,47 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/pdf'
3
+
4
+ module Malt::Formats
5
+
6
+ #
7
+ class Latex < Abstract
8
+
9
+ register 'latex'
10
+
11
+ #
12
+ def latex
13
+ text
14
+ end
15
+
16
+ #
17
+ def to_latex
18
+ self
19
+ end
20
+
21
+ # TODO
22
+ def pdf
23
+ raise "not implemented yet"
24
+ end
25
+
26
+ # TODO
27
+ def to_pdf
28
+ text = pdf
29
+ opts = options.merge(:text=>text, :file=>refile(:pdf), :type=>:pdf)
30
+ PDF.new(opts)
31
+ end
32
+
33
+ private
34
+
35
+ #
36
+ def render_engine
37
+ end
38
+
39
+ # Latext default output type is PDF.
40
+ def default
41
+ :pdf
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,51 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/engines/less'
3
+
4
+ module Malt::Formats
5
+
6
+ # = LESS
7
+ #
8
+ # See http://lesscss.org/
9
+ #
10
+ class LESS < Abstract
11
+
12
+ register('less')
13
+
14
+ #
15
+ def less
16
+ text
17
+ end
18
+
19
+ #
20
+ def to_less
21
+ self
22
+ end
23
+
24
+ #
25
+ def css
26
+ render_engine.render(:text=>text, :file=>:file, :format=>:css)
27
+ end
28
+
29
+ #
30
+ def to_css
31
+ text = css
32
+ opts = options.merge(:text=>text, file=>refile(:css), :type=>:css)
33
+ CSS.new(opts)
34
+ end
35
+
36
+ private
37
+
38
+ #
39
+ def render_engine
40
+ @render_engine ||= Malt::Engines::Less.new(options)
41
+ end
42
+
43
+ # LESS default output type is CSS.
44
+ def default
45
+ :css
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,53 @@
1
+ require 'malt/formats/abstract_template'
2
+ require 'malt/engines/liquid'
3
+
4
+ module Malt::Formats
5
+
6
+ # Liquid templates
7
+ #
8
+ # http://liquid.rubyforge.org/
9
+ #
10
+ class Liquid < AbstractTemplate
11
+
12
+ register 'liquid'
13
+
14
+ # #
15
+ # def to(type, data=nil, &yld)
16
+ # type = type.to_sym
17
+ # new_class = Malt.registry[type]
18
+ # new_text = render(data, &yld)
19
+ # new_file = refile(type)
20
+ # new_options = options.merge(:text=>new_text, :file=>new_file, :type=>type)
21
+ # new_class.new(new_options)
22
+ # end
23
+
24
+ # #
25
+ # def render(*type_and_data, &yld)
26
+ # type, data = parse_type_and_data(type_and_data)
27
+ # render_engine.render(:text=>text, :file=>file, :data=>data, &yld)
28
+ # end
29
+
30
+ # # Liquid templates can be any type.
31
+ # def method_missing(sym, *args, &yld)
32
+ # if Malt.registry.key?(sym)
33
+ # return render(sym, *args, &yld)
34
+ # elsif md = /^to_/.match(sym.to_s)
35
+ # type = md.post_match.to_sym
36
+ # if Malt.registry.key?(type)
37
+ # return to(type, *args, &yld)
38
+ # end
39
+ # end
40
+ # super(sym, *args, &yld)
41
+ # end
42
+
43
+ private
44
+
45
+ #
46
+ def render_engine
47
+ @render_engine ||= Malt::Engines::Liquid.new(options)
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
@@ -0,0 +1,83 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+ require 'malt/formats/latex'
4
+ require 'malt/engines/rdiscount'
5
+ require 'malt/engines/bluecloth'
6
+
7
+ module Malt::Formats
8
+
9
+ # If using the Kramdown engine, then Latex is also a supported output format.
10
+ class Markdown < Abstract
11
+
12
+ register('markdown', 'md')
13
+
14
+ #
15
+ def html
16
+ render_engine.render(:text=>text, :file=>file, :format=>:html)
17
+ end
18
+
19
+ #
20
+ def latex
21
+ render_engine.render(:text=>text, :file=>file, :format=>:latex)
22
+ end
23
+
24
+ #
25
+ def markdown
26
+ text
27
+ end
28
+
29
+ #
30
+ alias_method :md, :markdown
31
+
32
+ # Convert to HTML.
33
+ def to_html
34
+ opts = options.merge(:text=>html, :file=>refile(:html), :type=>:html)
35
+ HTML.new(opts)
36
+ end
37
+
38
+ # Latex is only supported by the Kramdown engine.
39
+ def to_latex
40
+ opts = options.merge(:text=>html, :file=>refile(:latex), :type=>:latex)
41
+ Latex.new(opts)
42
+ end
43
+
44
+ #
45
+ def to_markdown
46
+ self
47
+ end
48
+
49
+ #
50
+ alias_method :to_md, :to_markdown
51
+
52
+ #
53
+ #def render_to(to, *)
54
+ # case to
55
+ # when :markdown, :md
56
+ # text
57
+ # when :html
58
+ # malt_engine.render_html(text, file)
59
+ # when :txt # THINK: Does this make sense?
60
+ # text
61
+ # end
62
+ #end
63
+
64
+ private
65
+
66
+ #
67
+ def render_engine
68
+ @render_engine ||= (
69
+ case engine
70
+ when :bluecloth
71
+ Malt::Engines::BlueCloth.new(options)
72
+ when :kramdown
73
+ Malt::Engines::Kramdown.new(options)
74
+ else
75
+ Malt::Engines::RDiscount.new(options)
76
+ end
77
+ )
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
@@ -0,0 +1,29 @@
1
+ require 'malt/formats/abstract'
2
+
3
+ module Malt::Formats
4
+
5
+ #
6
+ class PDF < Abstract
7
+
8
+ register 'pdf'
9
+
10
+ #
11
+ def pdf
12
+ text
13
+ end
14
+
15
+ #
16
+ def to_pdf
17
+ self
18
+ end
19
+
20
+ private
21
+
22
+ #
23
+ def render_engine
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
@@ -0,0 +1,47 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+ require 'malt/engines/radius'
4
+
5
+ module Malt::Formats
6
+
7
+ # Radius Template
8
+ #
9
+ # http://github.com/jlong/radius/
10
+ #
11
+ class Radius < Abstract
12
+
13
+ register('radius')
14
+
15
+ #
16
+ def radius
17
+ text
18
+ end
19
+
20
+ #
21
+ def to_radius
22
+ self
23
+ end
24
+
25
+ #
26
+ def html(data, &yld)
27
+ render_engine.render(:text=>text, :file=>file, :data=>data, &yld)
28
+ end
29
+
30
+ #
31
+ def to_html(data, &yld)
32
+ text = html(data, &yld)
33
+ opts = options.merge(:text=>text, :file=>refile(:html), :type=>:html)
34
+ HTML.new(opts)
35
+ end
36
+
37
+ private
38
+
39
+ #
40
+ def render_engine
41
+ @render_engine ||= Malt::Engines::Radius.new(options)
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,43 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+ require 'malt/engines/rdoc'
4
+
5
+ module Malt::Formats
6
+
7
+ #
8
+ class RDoc < Abstract
9
+
10
+ register('rdoc')
11
+
12
+ #
13
+ def rdoc
14
+ text
15
+ end
16
+
17
+ #
18
+ def to_rdoc
19
+ self
20
+ end
21
+
22
+ #
23
+ def html
24
+ render_engine.render(:text=>text, :file=>file, :format=>:html)
25
+ end
26
+
27
+ #
28
+ def to_html
29
+ opts = options.merge(:text=>html, :file=>refile(:html), :type=>:html)
30
+ HTML.new(opts)
31
+ end
32
+
33
+ private
34
+
35
+ #
36
+ def render_engine
37
+ @render_engine ||= Malt::Engines::RDoc.new(options)
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,46 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+ require 'malt/engines/rtals'
4
+
5
+ module Malt::Formats
6
+
7
+ #
8
+ class Rtals < Abstract
9
+
10
+ register('rtal')
11
+
12
+ #
13
+ def html(data, &yld)
14
+ render_engine.render(:text=>text, :data=>data, &yld)
15
+ end
16
+
17
+ #
18
+ def to_html(data, &yld)
19
+ text = html(data, &yld)
20
+ opts = options.merge(:text=>text, :file=>refile(:html), :type=>:html)
21
+ HTML.new(opts)
22
+ end
23
+
24
+ #
25
+ def xml(data, &yld)
26
+ render_engine.render(:text=>text, :data=>data, &yld)
27
+ end
28
+
29
+ #
30
+ def to_xml(data, &yld)
31
+ text = xml(data, &yld)
32
+ opts = options.merge(:text=>text, :file=>refile(:xml), :type=>:xml)
33
+ HTML.new(opts)
34
+ end
35
+
36
+ private
37
+
38
+ #
39
+ def render_engine
40
+ @render_engine ||= Malt::Engines::RTALS.new(options)
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+