malt 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/.ruby +156 -0
  2. data/Assembly +28 -0
  3. data/COPYING.rdoc +33 -0
  4. data/Gemfile +10 -0
  5. data/HISTORY.rdoc +102 -0
  6. data/README.rdoc +16 -10
  7. data/Reapfile +4 -0
  8. data/lib/malt.rb +36 -8
  9. data/lib/malt.yml +156 -0
  10. data/lib/malt/conversions.rb +42 -0
  11. data/lib/malt/core_ext.rb +81 -3
  12. data/lib/malt/engines/abstract.rb +259 -50
  13. data/lib/malt/engines/bluecloth.rb +19 -9
  14. data/lib/malt/engines/builder.rb +93 -32
  15. data/lib/malt/engines/coffee.rb +46 -0
  16. data/lib/malt/engines/creole.rb +60 -0
  17. data/lib/malt/engines/erb.rb +69 -44
  18. data/lib/malt/engines/erector.rb +61 -30
  19. data/lib/malt/engines/erubis.rb +41 -31
  20. data/lib/malt/engines/haml.rb +13 -37
  21. data/lib/malt/engines/kramdown.rb +40 -15
  22. data/lib/malt/engines/less.rb +15 -14
  23. data/lib/malt/engines/liquid.rb +24 -14
  24. data/lib/malt/engines/markaby.rb +44 -22
  25. data/lib/malt/engines/maruku.rb +89 -0
  26. data/lib/malt/engines/mustache.rb +20 -14
  27. data/lib/malt/engines/nokogiri.rb +89 -0
  28. data/lib/malt/engines/radius.rb +72 -34
  29. data/lib/malt/engines/ragtag.rb +26 -18
  30. data/lib/malt/engines/rdiscount.rb +18 -11
  31. data/lib/malt/engines/rdoc.rb +21 -15
  32. data/lib/malt/engines/redcarpet.rb +137 -0
  33. data/lib/malt/engines/redcloth.rb +15 -7
  34. data/lib/malt/engines/ruby.rb +13 -12
  35. data/lib/malt/engines/sass.rb +30 -17
  36. data/lib/malt/engines/string.rb +36 -0
  37. data/lib/malt/engines/tenjin.rb +70 -27
  38. data/lib/malt/engines/wikicloth.rb +48 -0
  39. data/lib/malt/formats/abstract.rb +90 -29
  40. data/lib/malt/formats/abstract_template.rb +10 -8
  41. data/lib/malt/formats/builder.rb +39 -13
  42. data/lib/malt/formats/coffee.rb +54 -0
  43. data/lib/malt/formats/css.rb +3 -3
  44. data/lib/malt/formats/erb.rb +31 -66
  45. data/lib/malt/formats/haml.rb +8 -8
  46. data/lib/malt/formats/html.rb +1 -7
  47. data/lib/malt/formats/javascript.rb +27 -0
  48. data/lib/malt/formats/latex.rb +1 -1
  49. data/lib/malt/formats/less.rb +13 -11
  50. data/lib/malt/formats/liquid.rb +7 -7
  51. data/lib/malt/formats/markdown.rb +43 -44
  52. data/lib/malt/formats/mediawiki.rb +70 -0
  53. data/lib/malt/formats/mustache.rb +5 -5
  54. data/lib/malt/formats/pdf.rb +1 -7
  55. data/lib/malt/formats/radius.rb +5 -4
  56. data/lib/malt/formats/ragtag.rb +14 -13
  57. data/lib/malt/formats/rbhtml.rb +28 -20
  58. data/lib/malt/formats/rdoc.rb +5 -4
  59. data/lib/malt/formats/rhtml.rb +19 -43
  60. data/lib/malt/formats/ruby.rb +11 -45
  61. data/lib/malt/formats/sass.rb +16 -24
  62. data/lib/malt/formats/scss.rb +13 -30
  63. data/lib/malt/formats/string.rb +61 -0
  64. data/lib/malt/formats/tenjin.rb +4 -4
  65. data/lib/malt/formats/text.rb +1 -1
  66. data/lib/malt/formats/textile.rb +7 -19
  67. data/lib/malt/kernel.rb +1 -2
  68. data/lib/malt/machine.rb +83 -13
  69. data/lib/malt/tilted.rb +216 -0
  70. data/lib/malt/version.rb +21 -0
  71. data/test/helper.rb +15 -0
  72. data/test/unit/engines/case_engine_bluecloth.rb +40 -0
  73. data/test/unit/engines/case_engine_builder.rb +30 -0
  74. data/test/unit/engines/case_engine_coffee.rb +30 -0
  75. data/test/unit/engines/case_engine_creole.rb +35 -0
  76. data/test/unit/engines/case_engine_erb.rb +28 -0
  77. data/test/unit/engines/case_engine_erector.rb +36 -0
  78. data/test/unit/engines/case_engine_erubis.rb +28 -0
  79. data/test/unit/engines/case_engine_haml.rb +30 -0
  80. data/test/unit/engines/case_engine_kramdown.rb +30 -0
  81. data/test/unit/engines/case_engine_less.rb +40 -0
  82. data/test/unit/engines/case_engine_liquid.rb +28 -0
  83. data/test/unit/engines/case_engine_markaby.rb +20 -0
  84. data/test/unit/engines/case_engine_maruku.rb +30 -0
  85. data/test/unit/engines/case_engine_mustache.rb +28 -0
  86. data/test/unit/engines/case_engine_nokogiri.rb +30 -0
  87. data/test/unit/engines/case_engine_radius.rb +30 -0
  88. data/test/unit/engines/case_engine_ragtag.rb +40 -0
  89. data/test/unit/engines/case_engine_rdiscount.rb +30 -0
  90. data/test/unit/engines/case_engine_rdoc.rb +31 -0
  91. data/test/unit/engines/case_engine_redcarpet.rb +30 -0
  92. data/test/unit/engines/case_engine_redcloth.rb +31 -0
  93. data/test/unit/engines/case_engine_ruby.rb +28 -0
  94. data/test/unit/engines/case_engine_sass.rb +36 -0
  95. data/test/unit/engines/case_engine_string.rb +28 -0
  96. data/test/unit/engines/case_engine_tenjin.rb +28 -0
  97. data/test/unit/engines/case_engine_wikicloth.rb +25 -0
  98. data/test/unit/machine.rb +27 -0
  99. data/test/unit/malt.rb +12 -0
  100. metadata +364 -266
  101. data/History.rdoc +0 -64
  102. data/License.txt +0 -205
  103. data/Syckfile +0 -80
  104. data/features/consistent_rendering.feature +0 -36
  105. data/features/samples/sample.erb +0 -1
  106. data/features/samples/sample.erubis +0 -1
  107. data/features/samples/sample.liquid +0 -1
  108. data/features/samples/sample.mustache +0 -1
  109. data/features/samples/sample.radius +0 -1
  110. data/features/step_definitions/engine_steps.rb +0 -49
  111. data/features/support/loadpath.rb +0 -1
  112. data/features/support/sample_class.rb +0 -8
  113. data/lib/malt/formats/erector.rb +0 -53
  114. data/lib/malt/formats/markaby.rb +0 -53
  115. data/lib/malt/meta/data.rb +0 -26
  116. data/lib/malt/meta/package +0 -21
  117. data/lib/malt/meta/profile +0 -21
  118. data/meta/data.rb +0 -26
  119. data/meta/package +0 -21
  120. data/meta/profile +0 -21
  121. data/qed/01_overview.rdoc +0 -8
  122. data/qed/02_formats.rdoc +0 -39
  123. data/qed/03_formats/01_overview.rdoc +0 -7
  124. data/qed/03_formats/02_rdoc.rdoc +0 -83
  125. data/qed/03_formats/03_textile.rdoc +0 -48
  126. data/qed/03_formats/04_markdown.rdoc +0 -66
  127. data/qed/03_formats/05_erb.rdoc +0 -65
  128. data/qed/03_formats/06_liquid.rdoc +0 -54
  129. data/qed/03_formats/07_haml.rdoc +0 -44
  130. data/qed/03_formats/08_ragtag.rdoc +0 -19
  131. data/qed/03_formats/09_radius.rdoc +0 -43
  132. data/qed/03_formats/11_tenjin.rdoc +0 -47
  133. data/qed/03_formats/12_rbhtml.rdoc +0 -55
  134. data/qed/03_formats/13_sass.rdoc +0 -55
  135. data/qed/03_formats/14_scss.rdoc +0 -58
  136. data/qed/03_formats/15_less.rdoc +0 -46
  137. data/qed/03_formats/16_ruby.rdoc +0 -48
  138. data/qed/03_formats/17_markaby.rdoc +0 -50
  139. data/qed/03_formats/18_builder.rb +0 -50
  140. data/qed/03_formats/19_erector.rb +0 -50
  141. data/qed/03_formats/20_mustache.rdoc +0 -54
  142. data/qed/05_machine/01_limited_formats.rdoc +0 -29
  143. data/qed/05_machine/02_prioritized_engines.rdoc +0 -34
  144. data/qed/applique/malt.rb +0 -13
  145. data/qed/samples/data.yml +0 -4
  146. data/qed/samples/output-erb.txt +0 -1
  147. data/qed/samples/output-liquid.txt +0 -1
  148. data/qed/samples/output-mustache.txt +0 -1
  149. data/qed/samples/output-radius.txt +0 -1
  150. data/qed/samples/sample.erb +0 -1
  151. data/qed/samples/sample.liquid +0 -1
  152. data/qed/samples/sample.markdown +0 -308
  153. data/qed/samples/sample.mustache +0 -1
  154. data/qed/samples/sample.radius +0 -1
  155. data/qed/samples/sample.rdoc +0 -8
@@ -1,36 +1,50 @@
1
1
  require 'malt/formats/abstract'
2
2
  require 'malt/formats/html'
3
3
  require 'malt/engines/builder'
4
+ require 'malt/engines/markaby'
5
+ require 'malt/engines/nokogiri'
6
+ require 'malt/engines/erector'
4
7
 
5
8
  module Malt::Format
6
9
 
7
- # Builder looks like a Markup format, but it is a template format
8
- # as Ruby code.
10
+ # Builder is the format common to Builder, Markaby, Erector and Nokogiri's Builder.
11
+ # Although there are some variant features between them, they all support the
12
+ # same general format. The format looks like a Markup format, but is in fact a
13
+ # templating system built out of Ruby code for creating XML/HTML documents.
9
14
  #
10
- # http://builder.rubyforge.org/
15
+ # @see http://builder.rubyforge.org/
16
+ # @see http://markaby.rubyforge.org/
17
+ # @see http://erector.rubyforge.org/
18
+ # @see http://nokogiri.org/
11
19
  #
20
+ # To unite these different engines I have designated them a common file
21
+ # extension of `.rbml`.
22
+ #
12
23
  class Builder < Abstract
13
24
 
14
- register 'builder'
25
+ file_extension 'rbml', 'builder', 'nokogiri', 'mab', 'markaby', 'erector'
15
26
 
16
27
  #
17
28
  def builder(*)
18
29
  text
19
30
  end
31
+ alias_method :rbml, :builder
20
32
 
21
33
  #
22
34
  def to_builder(*)
23
35
  self
24
36
  end
37
+ alias_method :to_rbml, :to_builder
25
38
 
26
39
  #
27
- def html(data=nil, &yld)
28
- render_engine.render(:format=>:html, :text=>text, :file=>file, :data=>data, &yld)
40
+ def html(*data, &content)
41
+ #render_engine.render(:to=>:html, :text=>text, :file=>file, :data=>data, &yld)
42
+ render_into(:html, *data, &content)
29
43
  end
30
44
 
31
45
  #
32
- def to_html(data=nil, &yld)
33
- text = html(data, &yld)
46
+ def to_html(*data, &content)
47
+ text = html(*data, &content)
34
48
  opts = options.merge(:text=>text, :file=>refile(:html), :type=>:html)
35
49
  HTML.new(opts)
36
50
  end
@@ -43,12 +57,24 @@ module Malt::Format
43
57
  # )
44
58
  #end
45
59
 
46
- private
60
+ private
47
61
 
48
- #
49
- def render_engine
50
- @render_engine ||= Malt::Engine::Builder.new(options)
51
- end
62
+ # TODO: allow the type to influence the engine selection
63
+ #
64
+ #def render_engine
65
+ # @render_engine ||= (
66
+ # case engine
67
+ # when :erector
68
+ # Malt::Engine::Erector.new(options)
69
+ # when :builder
70
+ # Malt::Engine::Builder.new(options)
71
+ # when :markaby, :mab
72
+ # Malt::Engine::Markaby.new(options)
73
+ # else
74
+ # Malt::Engine::Nokogiri.new(options)
75
+ # end
76
+ # )
77
+ #end
52
78
 
53
79
  end
54
80
 
@@ -0,0 +1,54 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/javascript'
3
+ require 'malt/engines/coffee'
4
+
5
+ module Malt::Format
6
+
7
+ # Coffee Format
8
+ #
9
+ class Coffee < Abstract
10
+
11
+ file_extension 'coffee'
12
+
13
+ #
14
+ def coffee(*)
15
+ text
16
+ end
17
+
18
+ #
19
+ def to_coffee(*)
20
+ self
21
+ end
22
+
23
+ #
24
+ def javascript(*data, &content)
25
+ #render_engine.render(:format=>:javascript, :text=>text, :file=>file, :data=>data, :type=>type, &yielding)
26
+ render_into(:javascript, *data, &content)
27
+ end
28
+
29
+ alias :js :javascript
30
+
31
+ #
32
+ def to_javascript(*data, &content)
33
+ result = javascript(*data, &content)
34
+ Javascript.new(:text=>result, :file=>refile(:js), :type=>:javascript)
35
+ end
36
+
37
+ alias :to_js :to_javascript
38
+
39
+ private
40
+
41
+ #
42
+ #def render_engine
43
+ # @render_engine ||= Malt::Engine::Coffee.new(options)
44
+ #end
45
+
46
+ # Coffee default output type is Javascript.
47
+ def default
48
+ :javascript
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
@@ -5,7 +5,7 @@ module Malt::Format
5
5
  #
6
6
  class CSS < Abstract
7
7
 
8
- register('css')
8
+ file_extension 'css'
9
9
 
10
10
  #
11
11
  def css(*)
@@ -20,8 +20,8 @@ module Malt::Format
20
20
  private
21
21
 
22
22
  #
23
- def render_engine
24
- end
23
+ #def render_engine
24
+ #end
25
25
 
26
26
  # CSS default output type is itself.
27
27
  def default
@@ -8,94 +8,59 @@ module Malt::Format
8
8
  #
9
9
  class Erb < AbstractTemplate
10
10
 
11
- register 'erb'
12
-
13
- # TODO: Lookup engine from engine registry.
14
- def rb(*)
15
- render_engine.compile(:text=>text, :file=>file)
16
- end
17
-
18
- # Erb templates can be "pre-compiled" into Ruby templates.
19
- def to_rb(*)
20
- text = rb
21
- Ruby.new(:text=>text, :file=>refile(:rb))
22
- end
23
-
24
- #
25
- alias_method(:to_ruby, :to_rb)
26
-
27
- #
28
- alias_method :precompile, :to_rb
11
+ file_extension 'erb'
29
12
 
30
13
  # Technically #method_missing will pick this up, but since it is likely
31
14
  # to be the most commonly used, adding the method directly will provide
32
15
  # a small speed boost.
33
- def html(data=nil, &yld)
34
- render(:html, data, &yld)
16
+ #
17
+ def html(*data, &content)
18
+ render_into(:html, *data, &content)
35
19
  end
36
20
 
37
21
  # Technically #method_missing will pick this up, but since it is likely
38
22
  # to be the most commonly used, adding the method directly will provide
39
23
  # a small speed boost.
40
- def to_html(data=nil, &yld)
41
- new_text = render(:html, data, &yld)
24
+ def to_html(*data, &yld)
25
+ new_text = render(:html, *data, &yld)
42
26
  new_file = refile(:html)
43
27
  new_options = options.merge(:text=>new_text, :file=>new_file, :type=>:html)
44
28
  HTML.new(new_options)
45
29
  end
46
30
 
47
- # #
48
- # def to(type, data=nil, &yld)
49
- # new_class = Malt.registry[type.to_sym]
50
- # new_text = render(type, data, &yld)
51
- # new_file = refile(type)
52
- # new_options = options.merge(:text=>new_text, :file=>new_file, :type=>type)
53
- # new_class.new(new_options)
54
- # end
55
-
56
- # #
57
- # def render(*type_and_data, &yld)
58
- # type, data = parse_type_and_data(type_and_data)
59
- # opts = options.merge(:format=>type, :text=>text, :file=>file, :data=>data)
60
- # #opts = options.merge(:format=>type, :text=>text, :file=>file, :data=>data, :engine=>engine)
61
- # #Malt.render(opts, &yld)
62
- # #if options[:recompile]
63
- # render_engine.render(opts, &yld)
64
- # #else
65
- # # precompile.render(type, data, &yld)
66
- # #end
67
- # end
31
+ # TODO: compile, if we decide to support
32
+ =begin
33
+ # TODO: Lookup engine from engine registry.
34
+ def rb(*)
35
+ render_engine.compile(:text=>text, :file=>file)
36
+ end
68
37
 
38
+ # Erb templates can be "pre-compiled" into Ruby templates.
39
+ def to_rb(*)
40
+ text = rb
41
+ Ruby.new(:text=>text, :file=>refile(:rb))
42
+ end
69
43
 
70
44
  #
71
- #def to_html(db, &yld)
72
- # # unless pre-compilation is turned off, convert to ruby
73
- # return to_ruby.to_html(db, &yld) unless options[:recompile]
74
- # convert(:html, db, &yld)
75
- #end
45
+ alias_method(:to_ruby, :to_rb)
76
46
 
77
47
  #
78
- #def render_to(to, db, &yld)
79
- # #if options[:recompile]
80
- # render_engine.render(text, file, db, &yld)
81
- # #else
82
- # # to_ruby.render(db, &yld)
83
- # #end
84
- #end
48
+ alias_method :precompile, :to_rb
49
+ =end
85
50
 
86
- private
51
+ #private
87
52
 
88
53
  #
89
- def render_engine
90
- @render_engine ||= (
91
- case engine
92
- when :erubis
93
- Malt::Engine::Erubis.new(options)
94
- else
95
- Malt::Engine::Erb.new(options)
96
- end
97
- )
98
- end
54
+ #def render_engine
55
+ # @render_engine ||= (
56
+ # case engine
57
+ # when :erubis
58
+ # Malt::Engine::Erubis.new(options)
59
+ # else
60
+ # Malt::Engine::Erb.new(options)
61
+ # end
62
+ # )
63
+ #end
99
64
 
100
65
  end
101
66
 
@@ -21,13 +21,13 @@ module Malt::Format
21
21
  end
22
22
 
23
23
  #
24
- def html(data=nil, &yld)
25
- render_engine.render(:format=>:html, :text=>text, :file=>file, :data=>data, &yld)
24
+ def html(*data, &content)
25
+ render_into(:html, *data, &content)
26
26
  end
27
27
 
28
28
  #
29
- def to_html(data=nil, &yld)
30
- text = html(data, &yld)
29
+ def to_html(*data, &content)
30
+ text = html(*data, &content)
31
31
  opts = options.merge(:text=>text, :file=>refile(:html), :type=>:html)
32
32
  HTML.new(opts)
33
33
  end
@@ -40,12 +40,12 @@ module Malt::Format
40
40
  # )
41
41
  #end
42
42
 
43
- private
43
+ #private
44
44
 
45
45
  #
46
- def render_engine
47
- @render_engine ||= Malt::Engine::Haml.new(options)
48
- end
46
+ #def render_engine
47
+ # @render_engine ||= Malt::Engine::Haml.new(options)
48
+ #end
49
49
 
50
50
  end
51
51
 
@@ -5,7 +5,7 @@ module Malt::Format
5
5
  #
6
6
  class HTML < Abstract
7
7
 
8
- register 'html'
8
+ file_extension 'html' #, 'xhtml' ?
9
9
 
10
10
  #
11
11
  def html(*)
@@ -17,12 +17,6 @@ module Malt::Format
17
17
  self
18
18
  end
19
19
 
20
- private
21
-
22
- #
23
- def render_engine
24
- end
25
-
26
20
  end
27
21
 
28
22
  end
@@ -0,0 +1,27 @@
1
+ require 'malt/formats/abstract'
2
+
3
+ module Malt::Format
4
+
5
+ #
6
+ class Javascript < Abstract
7
+
8
+ file_extension 'js'
9
+
10
+ #
11
+ def js(*)
12
+ text
13
+ end
14
+
15
+ alias_method :javascript, :js
16
+
17
+ #
18
+ def to_js(*)
19
+ self
20
+ end
21
+
22
+ alias_method :to_javascript, :to_js
23
+
24
+ end
25
+
26
+ end
27
+
@@ -6,7 +6,7 @@ module Malt::Format
6
6
  #
7
7
  class Latex < Abstract
8
8
 
9
- register 'latex'
9
+ file_extension 'latex'
10
10
 
11
11
  #
12
12
  def latex(*)
@@ -9,7 +9,7 @@ module Malt::Format
9
9
  #
10
10
  class LESS < Abstract
11
11
 
12
- register('less')
12
+ file_extension 'less'
13
13
 
14
14
  #
15
15
  def less(*)
@@ -22,23 +22,25 @@ module Malt::Format
22
22
  end
23
23
 
24
24
  #
25
- def css(*)
26
- render_engine.render(:text=>text, :file=>:file, :format=>:css)
25
+ def css(*data, &content)
26
+ render_into(:css, *data, &content)
27
+ #opts = options.merge(:text=>text, :file=>file, :format=>:css)
28
+ #render_engine.render(opts)
27
29
  end
28
30
 
29
31
  #
30
- def to_css(*)
31
- text = css
32
+ def to_css(*data, &content)
33
+ text = css(*data, &content)
32
34
  opts = options.merge(:text=>text, :file=>refile(:css), :type=>:css)
33
35
  CSS.new(opts)
34
36
  end
35
37
 
36
- private
37
-
38
- #
39
- def render_engine
40
- @render_engine ||= Malt::Engine::Less.new(options)
41
- end
38
+ # private
39
+ #
40
+ # #
41
+ # def render_engine
42
+ # @render_engine ||= Malt::Engine::Less.new(options)
43
+ # end
42
44
 
43
45
  # LESS default output type is CSS.
44
46
  def default
@@ -9,7 +9,7 @@ module Malt::Format
9
9
  #
10
10
  class Liquid < AbstractTemplate
11
11
 
12
- register('liquid')
12
+ file_extension 'liquid'
13
13
 
14
14
  #
15
15
  def liquid(*)
@@ -50,12 +50,12 @@ module Malt::Format
50
50
  # super(sym, *args, &yld)
51
51
  # end
52
52
 
53
- private
54
-
55
- #
56
- def render_engine
57
- @render_engine ||= Malt::Engine::Liquid.new(options)
58
- end
53
+ # private
54
+ #
55
+ # #
56
+ # def render_engine
57
+ # @render_engine ||= Malt::Engine::Liquid.new(options)
58
+ # end
59
59
 
60
60
  end
61
61