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,70 +1,36 @@
1
1
  require 'malt/formats/abstract'
2
- require 'malt/formats/html'
3
2
  require 'malt/engines/erb'
4
3
 
5
4
  module Malt::Format
6
5
 
7
6
  # Yes, pure Ruby as a template format.
8
7
  #
9
- # The ruby code is run through eval and whatever is returned is given
8
+ # The ruby code is run through eval and whatever it returns is given
10
9
  # as the rendering.
11
10
  #
12
11
  # The Ruby format is a *polyglot* format --it accepts all conversion
13
12
  # types and assumes the end-user knows it will be the result.
14
13
  #
15
- # The Ruby type is also used for "precompiling" other formats such
16
- # as ERB.
14
+ # In the future, the Ruby type might also used for "precompiling" other
15
+ # formats such as ERB.
17
16
  #
18
- class Ruby < Abstract
17
+ class Ruby < AbstractTemplate
19
18
 
20
- register 'rb'
19
+ file_extension 'rb'
21
20
 
22
21
  #
23
- def rb(*) ; text ; end
24
- alias_method :ruby, :rb
25
-
26
- #
27
- def to_rb(*) ; self ; end
28
- alias_method :to_ruby, :to_rb
29
-
30
- #
31
- def to(type, data=nil, &yld)
32
- new_class = Malt::Format.registry[type.to_sym] # TODO: Malt.machine.format?
33
- new_text = render(data, &yld)
34
- new_file = refile(type)
35
- new_options = options.merge(:text=>new_text, :file=>new_file)
36
- new_class.new(new_options)
22
+ def rb(*)
23
+ text
37
24
  end
38
25
 
39
- # Ruby templates can be any type.
40
- def method_missing(sym, *args, &yld)
41
- if Malt::Format.registry.key?(sym)
42
- return to(sym, *args, &yld).to_s
43
- elsif md = /^to_/.match(sym.to_s)
44
- type = md.post_match.to_sym
45
- if Malt::Format.registry.key?(type) # TODO: Malt.machine.format?
46
- return to(type, *args, &yld)
47
- end
48
- end
49
- super(sym, *args, &yld)
50
- end
26
+ alias_method :ruby, :rb
51
27
 
52
28
  #
53
- #def render_to(to, db, &yld)
54
- # malt_engine.render(text, file, db, &yld)
55
- #end
56
-
57
- def render(*type_and_data, &yld)
58
- type, data = parse_type_and_data(type_and_data)
59
- render_engine.render(:text=>text, :file=>file, :data=>data, &yld)
29
+ def to_rb(*)
30
+ self
60
31
  end
61
32
 
62
- private
63
-
64
- #
65
- def render_engine
66
- @render_engine ||= Malt::Engine::Ruby.new(options)
67
- end
33
+ alias_method :to_ruby, :to_rb
68
34
 
69
35
  end
70
36
 
@@ -6,9 +6,10 @@ module Malt::Format
6
6
 
7
7
  # Sass Format
8
8
  #
9
+ #
9
10
  class Sass < Abstract
10
11
 
11
- register 'sass'
12
+ file_extension 'sass'
12
13
 
13
14
  #
14
15
  def sass(*)
@@ -21,13 +22,14 @@ module Malt::Format
21
22
  end
22
23
 
23
24
  #
24
- def css(data=nil, &yld)
25
- render_engine.render(:format=>:css, :text=>text, :file=>file, :type=>type)
25
+ def css(*data, &content)
26
+ render_into(:css, *data, &content)
27
+ #render_engine.render(:format=>:css, :text=>text, :file=>file, :data=>data, :type=>type, &yld)
26
28
  end
27
29
 
28
30
  #
29
- def to_css(data=nil, &yld)
30
- result = css(data, &yld)
31
+ def to_css(*data, &content)
32
+ result = css(*data, &content)
31
33
  CSS.new(:text=>result, :file=>refile(:css), :type=>:css)
32
34
  end
33
35
 
@@ -38,27 +40,17 @@ module Malt::Format
38
40
  # CSS.new(opts)
39
41
  #end
40
42
 
41
- #
42
- #def render_to(to, db, &yld)
43
- # case to
44
- # when :css
45
- # malt_engine.render_css(text, file, db, &yld)
46
- # else
47
- # raise UnspportedConversion.new(type, to)
48
- # end
49
- #end
50
-
51
- private
43
+ private
52
44
 
53
- #
54
- def render_engine
55
- @render_engine ||= Malt::Engine::Sass.new(options)
56
- end
45
+ ##
46
+ #def render_engine
47
+ # @render_engine ||= Malt::Engine::Sass.new(options)
48
+ #end
57
49
 
58
- # Sass default output type is CSS.
59
- def default
60
- :css
61
- end
50
+ # Sass default output type is CSS.
51
+ def default
52
+ :css
53
+ end
62
54
 
63
55
  end
64
56
 
@@ -9,7 +9,7 @@ module Malt::Format
9
9
  # This uses the same engine as Sass.
10
10
  class SCSS < Abstract
11
11
 
12
- register 'scss'
12
+ file_extension 'scss'
13
13
 
14
14
  #
15
15
  def scss(*)
@@ -22,44 +22,27 @@ module Malt::Format
22
22
  end
23
23
 
24
24
  #
25
- def css(data=nil, &yld)
26
- render_engine.render(:format=>:css, :text=>text, :file=>file, :type=>type)
25
+ def css(*data, &content)
26
+ render_into(:css, *data, &content)
27
27
  end
28
28
 
29
29
  #
30
- def to_css(data=nil, &yld)
31
- result = css(data, &yld)
30
+ def to_css(*data, &content)
31
+ result = css(*data, &content)
32
32
  CSS.new(:text=>result, :file=>refile(:css), :type=>:css)
33
33
  end
34
34
 
35
- #
36
- #def compile(db, &yld)
37
- # result = render_engine.render(text, db, &yld)
38
- # opts = options.merge(:text=>result, file=>refile(:css))
39
- # CSS.new(opts)
40
- #end
35
+ private
41
36
 
42
- #
43
- #def render_to(to, db, &yld)
44
- # case to
45
- # when :css
46
- # malt_engine.render_css(text, file, db, &yld)
47
- # else
48
- # raise UnspportedConversion.new(type, to)
49
- # end
37
+ ##
38
+ #def render_engine
39
+ # @render_engine ||= Malt::Engine::Sass.new(options)
50
40
  #end
51
41
 
52
- private
53
-
54
- #
55
- def render_engine
56
- @render_engine ||= Malt::Engine::Sass.new(options)
57
- end
58
-
59
- # Sass default output type is CSS.
60
- def default
61
- :css
62
- end
42
+ # Sass default output type is CSS.
43
+ def default
44
+ :css
45
+ end
63
46
 
64
47
  end
65
48
 
@@ -0,0 +1,61 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+ require 'malt/engines/erb'
4
+
5
+ module Malt::Format
6
+
7
+ # Yes, pure Ruby as a template format.
8
+ #
9
+ # The ruby code is run through eval and whatever is returned is given
10
+ # as the rendering.
11
+ #
12
+ # The Ruby format is a *polyglot* format --it accepts all conversion
13
+ # types and assumes the end-user knows it will be the result.
14
+ #
15
+ # The Ruby type is also used for "precompiling" other formats such
16
+ # as ERB.
17
+ #
18
+ class String < AbstractTemplate
19
+
20
+ file_extension 'str'
21
+
22
+ #
23
+ def string(*) ; text ; end
24
+
25
+ #
26
+ def to_string(*) ; self ; end
27
+
28
+ =begin
29
+ #
30
+ def to(type, *data, &yld)
31
+ new_class = Malt::Format.registry[type.to_sym] # TODO: Malt.machine.format?
32
+ new_text = render(*data, &yld)
33
+ new_file = refile(type)
34
+ new_options = options.merge(:text=>new_text, :file=>new_file)
35
+ new_class.new(new_options)
36
+ end
37
+ =end
38
+
39
+ # # Ruby templates can be any type.
40
+ # def method_missing(sym, *args, &yld)
41
+ # if Malt::Format.registry.key?(sym)
42
+ # return to(sym, *args, &yld).to_s
43
+ # elsif md = /^to_/.match(sym.to_s)
44
+ # type = md.post_match.to_sym
45
+ # if Malt::Format.registry.key?(type) # TODO: Malt.machine.format?
46
+ # return to(type, *args, &yld)
47
+ # end
48
+ # end
49
+ # super(sym, *args, &yld)
50
+ # end
51
+
52
+ #private
53
+
54
+ ##
55
+ #def render_engine
56
+ # @render_engine ||= Malt::Engine::String.new(options)
57
+ #end
58
+
59
+ end
60
+
61
+ end
@@ -25,13 +25,13 @@ module Malt::Format
25
25
  alias_method(:to_ruby, :to_rb)
26
26
 
27
27
  #
28
- def html(data=nil, &yld)
29
- render(:html, data, &yld)
28
+ def html(*data, &content)
29
+ render_into(:html, *data, &content)
30
30
  end
31
31
 
32
32
  #
33
- def to_html(data=nil, &yld)
34
- new_text = render(:html, data, &yld)
33
+ def to_html(*data, &yld)
34
+ new_text = render(:html, *data, &yld)
35
35
  new_file = refile(:html)
36
36
  new_options = options.merge(:text=>new_text, :file=>new_file, :type=>:html)
37
37
  HTML.new(new_options)
@@ -11,7 +11,7 @@ module Malt::Format
11
11
  #
12
12
  class Text < Abstract
13
13
 
14
- register('txt')
14
+ file_extension 'txt'
15
15
 
16
16
  #
17
17
  def txt(*)
@@ -6,7 +6,7 @@ module Malt::Format
6
6
  #
7
7
  class Textile < Abstract
8
8
 
9
- register('textile', 'tt')
9
+ file_extension 'textile', 'tt'
10
10
 
11
11
  #
12
12
  def textile(*)
@@ -24,8 +24,8 @@ module Malt::Format
24
24
  alias_method :to_tt, :to_textile
25
25
 
26
26
  #
27
- def html(*)
28
- render_engine.render(:format=>:html, :text=>text, :file=>file)
27
+ def html(*data, &content)
28
+ render_into(:html, *data, &content)
29
29
  end
30
30
 
31
31
  #
@@ -34,25 +34,13 @@ module Malt::Format
34
34
  HTML.new(opts)
35
35
  end
36
36
 
37
+ #private
37
38
  #
38
- #def render_to(to, *)
39
- # case to
40
- # when :textile, :tt
41
- # self
42
- # when :html
43
- # malt_engine.render_html(text, file)
44
- # else
45
- # raise "can't render textile to #{to} type" #?
46
- # end
39
+ ##
40
+ #def render_engine
41
+ # @render_engine ||= Malt::Engine::RedCloth.new(options)
47
42
  #end
48
43
 
49
- private
50
-
51
- #
52
- def render_engine
53
- @render_engine ||= Malt::Engine::RedCloth.new(options)
54
- end
55
-
56
44
  end
57
45
 
58
46
  end
@@ -1,7 +1,6 @@
1
- require 'malt/core_ext'
2
-
3
1
  module Malt
4
2
 
3
+ # Common methods that can be used through-out Malt classes.
5
4
  module Kernel
6
5
  private
7
6
 
@@ -5,19 +5,19 @@ module Malt
5
5
  # which engines and formats are used for rendering.
6
6
  #--
7
7
  # TODO: Can we dynamically generate the MARKUP and TEMPLATE constants
8
- # from the format classes? In anycase, the still need tweaking.
8
+ # from the format classes? In anycase, the still needs tweaking.
9
9
  #++
10
10
  class Machine
11
11
 
12
12
  # List of markup types. These are formats that just allow markup transformations
13
13
  # and do not provide for data injection.
14
- MARKUP = [:rdoc, :markdown, :textile, :scss, :sass, :less, :css, :html, :xml]
14
+ MARKUP = [:rdoc, :markdown, :textile, :scss, :sass, :less, :css, :html, :xml, :wikicloth]
15
15
 
16
16
  # List of template types. These are template formats that provide data injection.
17
- TEMPLATES = [:ruby, :erb, :liquid, :mustache, :tenjin, :ragtag, :radius, :erector, :builder, :markaby]
17
+ TEMPLATE = [:erb, :liquid, :mustache, :tenjin, :ragtag, :radius, :erector, :builder, :ruby, :string]
18
18
 
19
19
  # Template types that prevent arbitrary Ruby code execution.
20
- TEMPLATES_SAFE = [:liquid, :mustache]
20
+ TEMPLATE_SAFE = [:liquid, :mustache]
21
21
 
22
22
  # New Malt Machine.
23
23
  #
@@ -26,7 +26,7 @@ module Malt
26
26
  #
27
27
  def initialize(config={})
28
28
  if priority = config[:priority]
29
- priority.map!{ |e| e.to_sym }
29
+ priority = priority.map{ |e| e.to_sym }
30
30
  else
31
31
  priority = []
32
32
  end
@@ -68,6 +68,7 @@ module Malt
68
68
  end
69
69
  @priority
70
70
  end
71
+ alias_method :prefer, :priority
71
72
 
72
73
  #
73
74
  def engine?(ext)
@@ -92,7 +93,7 @@ module Malt
92
93
  type = options[:type] || options[:format] || File.extname(file)
93
94
  type = ext_to_type(type)
94
95
  malt_class = formats[type]
95
- raise "unkown type -- #{type}" unless malt_class
96
+ raise "unknown type -- #{type}" unless malt_class
96
97
  malt_class.new(options.merge(:file=>file,:type=>type))
97
98
  end
98
99
 
@@ -110,11 +111,14 @@ module Malt
110
111
  end
111
112
 
112
113
  # Open a URL as a Malt Format object.
114
+ #
115
+ # @return [Malt::Format]
113
116
  def open(url, options={})
114
117
  require 'open-uri'
115
118
  text = open(url).read
116
119
  file = File.basename(url) # parse better with URI.parse
117
- text(text, :file=>file)
120
+ options[:file] = file
121
+ text(text, options)
118
122
  end
119
123
 
120
124
  # Render template directly.
@@ -126,14 +130,67 @@ module Malt
126
130
  # parameters[:engine] - Force the use of a this specific engine.
127
131
  # parameters[:to] - Format to convert to (usual default is `html`).
128
132
  #
129
- def render(parameters={}, &body)
133
+ def render(parameters={}, &content)
134
+ parameters = normalize_parameters(parameters)
135
+
136
+ if parameters[:multi]
137
+ multi_render(parameters, &content)
138
+ else
139
+ single_render(parameters, &content)
140
+ end
141
+ end
142
+
143
+ private
144
+
145
+ # Normalize parameters.
146
+ def normalize_parameters(parameters)
147
+ params = parameters.rekey
148
+
149
+ if data = params.delete(:data)
150
+ scope, locals = split_data(data)
151
+ params[:scope] ||= scope
152
+ params[:locals] ||= locals
153
+ end
154
+
155
+ file = params[:file]
156
+ text = params[:text]
157
+
158
+ unless text
159
+ params[:text] = file_read(file)
160
+ end
161
+
162
+ params
163
+ end
164
+
165
+ #
166
+ def multi_render(parameters={}, &content)
167
+ type = parameters[:type]
168
+ #file = parameters[:file]
169
+ text = parameters[:text]
170
+
171
+ if type = parameters[:type]
172
+ types = [type].flatten
173
+ else
174
+ types = file.split('.')[1..-1]
175
+ end
176
+
177
+ types.reverse_each do |t|
178
+ parameters[:type] = t
179
+ parameters[:text] = single_render(parameters, &content)
180
+ end
181
+
182
+ parameters[:text]
183
+ end
184
+
185
+ #
186
+ def single_render(parameters={}, &content)
130
187
  type = parameters[:type]
131
188
  file = parameters[:file]
132
189
  text = parameters[:text]
133
190
  engine = parameters[:engine]
134
191
 
135
192
  type = file_type(file, type)
136
- text = file_read(file) unless text
193
+ #text = file_read(file) unless text
137
194
 
138
195
  engine_class = engine(type, engine)
139
196
 
@@ -142,22 +199,22 @@ module Malt
142
199
  parameters[:text] = text
143
200
 
144
201
  engine = engine_class.new
145
- engine.render(parameters, &body)
202
+
203
+ engine.render(parameters, &content)
146
204
  else
147
205
  if parameters[:pass]
148
206
  text
149
207
  else
150
208
  raise NoEngineError, "no engine to handle `#{type}' format"
151
209
  end
152
- end
210
+ end
153
211
  end
154
212
 
155
- private
156
-
157
213
  #
158
214
  def engine(type, engine=nil)
159
215
  type = ext_to_type(type)
160
216
  #engine = engine || Malt.config.engine[type] # FIXME
217
+
161
218
  case engine
162
219
  when Class
163
220
  #raise unless Engine.registry[type].include?(engine)
@@ -218,6 +275,19 @@ module Malt
218
275
  end
219
276
  end
220
277
 
278
+ # Unlike +#scope_and_locals+, this method returns +nil+ for missing
279
+ # scope or locals.
280
+ #
281
+ def split_data(data)
282
+ scope, locals = *[data].flatten
283
+ if scope.respond_to?(:to_hash)
284
+ locals ||= {}
285
+ locals = locals.merge(scope.to_hash)
286
+ scope = nil
287
+ end
288
+ return scope, locals
289
+ end
290
+
221
291
  end
222
292
 
223
293
  #