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
@@ -2,58 +2,89 @@ require 'malt/engines/abstract'
2
2
 
3
3
  module Malt::Engine
4
4
 
5
- # Erector
5
+ # The Erector template engine handles a builder-style template format.
6
6
  #
7
- # http://erector.rubyforge.org/userguide.html
7
+ # @see http://erector.rubyforge.org/userguide.html
8
+ #
9
+ # For Erector templates the data is passed in as attribute variables.
10
+ #
11
+ # A simple example template:
12
+ #
13
+ # div do
14
+ # h1 @name
15
+ # div @state, :id=>'state'
16
+ # div @content, :id=>'yield'
17
+ # end
18
+ #
19
+ # IMPORTANT! Erecotor templates do not currently support scope.
8
20
  #
9
21
  class Erector < Abstract
10
22
 
11
- default :erector
23
+ default :erector
24
+ register :rbml, :builder
12
25
 
13
26
  #
14
- def intermediate(params)
15
- text = params[:text]
16
- Class.new(::Erector::Widget) do
17
- module_eval %{ def content; #{text}; end }
18
- end
19
- end
27
+ def render(params={}, &content)
28
+ into = params[:to] || :html
20
29
 
21
- #
22
- def render(params, &yld)
23
- into = params[:to]
24
30
  case into
25
- when :html, nil
26
- render_html(params, &yld)
31
+ when :html, :xhtml
32
+ prepare_engine(params, &content).to_html
27
33
  else
28
- super(params, &yld)
34
+ super(params, &content)
35
+ end
36
+ end
37
+
38
+ # Return Erector parser, ready to render results.
39
+ def prepare_engine(params={}, &content)
40
+ file, scope, locals = parameters(params, :file, :scope, :locals)
41
+
42
+ scope, locals = make_external(scope, locals, &content)
43
+
44
+ unless scope.respond_to?(:to_struct)
45
+ scope_locals = {}
46
+ scope.instance_variables.each do |k|
47
+ next if k == "@target"
48
+ name = k.to_s.sub('@','').to_sym
49
+ v = scope.instance_variable_get(k)
50
+ scope_locals[name] = v
51
+ end
52
+ locals = scope_locals.merge(locals)
29
53
  end
54
+
55
+ create_engine(params).new(locals)
30
56
  end
31
57
 
58
+ # TODO: how to support scope ?
59
+
60
+ # Erector constructor support caching.
32
61
  #
33
- def render_html(params={}, &yld)
34
- #text = params[:text]
35
- file = params[:file]
36
- data = params[:data]
37
- data = make_hash(data, &yld)
62
+ def create_engine(params={})
63
+ text, prefix = parameters(params, :text, :prefix)
64
+
65
+ cached(prefix, text) do
66
+ Class.new(::Erector::Widget) do
67
+ module_eval %{
68
+ def #{prefix}; self; end
69
+ } if prefix
38
70
 
39
- intermediate(params).new(data).to_html
71
+ module_eval %{
72
+ def content
73
+ #{text}
74
+ end
75
+ }
76
+ end
77
+ end
40
78
  end
41
79
 
42
- private
80
+ private
43
81
 
44
82
  # Load Erector library if not already loaded.
45
- def initialize_engine
83
+ def require_engine
46
84
  return if defined? ::Erector
47
85
  require_library 'erector'
48
86
  end
49
87
 
50
- #
51
- def engine_options(params)
52
- opts = {}
53
- opts
54
- end
55
-
56
88
  end
57
89
 
58
90
  end
59
-
@@ -10,54 +10,64 @@ module Malt::Engine
10
10
  #
11
11
  class Erubis < Abstract
12
12
 
13
- register :erb, :rhtml
13
+ register :erb, :rhtml, :eruby
14
14
 
15
15
  # Render template.
16
- def render(params, &yld)
17
- text = params[:text]
18
- data = params[:data]
19
- data = make_binding(data, &yld)
20
- intermediate(params).result(data)
21
- end
22
-
23
- # Compile template into Ruby source code.
24
- def compile(params)
25
- text = params[:text]
26
- file = params[:file]
27
- intermediate(text, file).src
28
- end
16
+ def render(params, &content)
17
+ text, file, scope, locals = parameters(params, :text, :file, :scope, :locals)
29
18
 
30
- #
31
- def intermediate(params)
32
- text = params[:text]
33
- file = params[:file]
19
+ # NOTE: Erubis can handle hash data via result(:list=>data).
20
+ # Would it be better to use that?
34
21
 
35
- opts = {}
22
+ bind = make_binding(scope, locals, &content)
36
23
 
37
- if params[:escape_html] || settings[:escape_html]
38
- ::Erubis::EscapedEruby.new(text, settings)
39
- else
40
- ::Erubis::Eruby.new(text, settings)
41
- end
24
+ prepare_engine(params).result(bind)
42
25
  end
43
26
 
44
27
  #
45
- def safe
46
- options[:safe]
47
- end
28
+ #def prepare_eninge(params={})
29
+ # create_engine(params)
30
+ #end
48
31
 
49
32
  #
50
- def trim
51
- options[:trim]
33
+ def create_engine(params={})
34
+ text, file, esc = parameters(params, :text, :file, :escape_html)
35
+
36
+ opts = engine_options(params)
37
+
38
+ cached(text, file, esc, opts) do
39
+ if esc
40
+ ::Erubis::EscapedEruby.new(text, opts)
41
+ else
42
+ ::Erubis::Eruby.new(text, opts)
43
+ end
44
+ end
52
45
  end
53
46
 
54
- ;;;; private ;;;;
47
+ # Compile template into Ruby source code.
48
+ #def compile(params)
49
+ # if cache?
50
+ # @source[params] ||= intermediate(params).src
51
+ # else
52
+ # intermediate(params).src
53
+ # end
54
+ #end
55
+
56
+ private
55
57
 
56
58
  # Load ERB library if not already loaded.
57
- def initialize_engine
59
+ def require_engine
58
60
  return if defined? ::Erubius
59
61
  require_library('erubis')
60
62
  end
63
+
64
+ #
65
+ ENGINE_OPTION_NAMES = %w{safe trim pattern preamble postable}
66
+
67
+ #
68
+ def engine_option_names
69
+ ENGINE_OPTION_NAMES
70
+ end
61
71
 
62
72
  end
63
73
 
@@ -9,55 +9,31 @@ module Malt::Engine
9
9
  default :haml
10
10
 
11
11
  #
12
- def render(params, &yld)
13
- into = params[:to]
12
+ def render(params={}, &content)
13
+ into, scope, locals = parameters(params, :to, :scope, :locals)
14
+
15
+ scope, locals = make_ready(scope, locals, &content)
16
+
14
17
  case into
15
18
  when :html, nil
16
- render_html(params, &yld)
19
+ prepare_engine(params, &content).render(scope, locals, &content)
17
20
  else
18
- super(params, &yld)
21
+ super(params, &content)
19
22
  end
20
23
  end
21
24
 
22
25
  #
23
- def render_html(params, &yld)
24
- text = params[:text]
25
- file = params[:file]
26
- data = params[:data]
27
-
28
- engine = intermediate(params)
29
- case data
30
- when Binding
31
- html = engine.render(make_object(data), &yld)
32
- when Hash
33
- html = engine.render(Object.new, data, &yld)
34
- else
35
- if data.respond_to?(:to_hash)
36
- data = data.to_hash
37
- html = engine.render(Object.new, data, &yld)
38
- else
39
- html = engine.render(data || Object.new, &yld)
40
- end
26
+ def create_engine(params={})
27
+ text, file = parameters(params, :text, :file)
28
+ cached(text, file) do
29
+ ::Haml::Engine.new(text, :filename=>file)
41
30
  end
42
- html
43
- end
44
-
45
- #
46
- #def compile(text, file)
47
- # intermediate # ??
48
- #end
49
-
50
- #
51
- def intermediate(params)
52
- text = params[:text]
53
- file = params[:file]
54
- ::Haml::Engine.new(text, :filename=>file)
55
31
  end
56
32
 
57
- private
33
+ private
58
34
 
59
35
  # Load Haml library if not already loaded.
60
- def initialize_engine
36
+ def require_engine
61
37
  return if defined? ::Haml::Engine
62
38
  require_library 'haml'
63
39
  end
@@ -2,47 +2,72 @@ require 'malt/engines/abstract'
2
2
 
3
3
  module Malt::Engine
4
4
 
5
- # Discount Markdown implementation.
5
+ # Kramdown Markdown implementation.
6
6
  #
7
- # http://github.com/rtomayko/rdiscount
7
+ # http://kramdown.rubyforge.org/
8
8
  #
9
- # The +:smart+ and +:filter_html+ options can be set true
10
- # to enable those flags on the underlying RDiscount object.
11
9
  class Kramdown < Abstract
12
10
 
13
11
  register :markdown, :md
14
12
 
15
13
  # Convert Markdown text to HTML text.
16
14
  #
17
- # @option params [String] :text Template text
18
- # @option params [String,Symbol] :to ('html') Type or file extension to convert template into.
19
- def render(params)
20
- text = params[:text]
21
- into = params[:to]
15
+ # @param [Hash] params
16
+ # A hash containing the Markdown extensions which the parser
17
+ # will identify. The following extensions are accepted.
18
+ #
19
+ # @option params [String] :text
20
+ # Template text.
21
+ #
22
+ # @option params [String,Symbol] :to ('html')
23
+ # Type or file extension to convert template into.
24
+ #
25
+ # @see http://kramdown.rubyforge.org/rdoc/Kramdown/Options.html
26
+ #
27
+ def render(params={})
28
+ into, text = parameters(params, :to, :text)
29
+
22
30
  case into
23
31
  when :html, nil
24
- intermediate(params).to_html
32
+ prepare_engine(params).to_html
25
33
  when :latex
26
- intermediate(params).to_latex
34
+ prepare_engine(params).to_latex
27
35
  else
28
36
  super(params)
29
37
  end
30
38
  end
31
39
 
32
40
  # Convert Markdown text to intermediate object.
33
- def intermediate(params)
34
- text = params[:text]
35
- ::Kramdown::Document.new(text)
41
+ def create_engine(params={})
42
+ text = parameters(params, :text)
43
+ cached(text) do
44
+ ::Kramdown::Document.new(text)
45
+ end
36
46
  end
37
47
 
38
48
  private
39
49
 
40
50
  # Load rdoc makup library if not already loaded.
41
- def initialize_engine
51
+ def require_engine
42
52
  return if defined? ::Kramdown
43
53
  require_library 'kramdown'
44
54
  end
45
55
 
56
+ # Kramdown has lots of options!
57
+ ENGINE_OPTION_NAMES = %w{
58
+ auto_id_prefix auto_ids
59
+ coderay_bold_every coderay_css coderay_line_number_start
60
+ coderay_line_numbers coderay_tab_width coderay_wrap
61
+ entity_output footnote_nr html_to_native latex_headers
62
+ line_width parse_block_html parse_span_html smart_quotes
63
+ template toc_levels
64
+ }
65
+
66
+ #
67
+ def engine_option_names
68
+ ENGINE_OPTION_NAMES
69
+ end
70
+
46
71
  end
47
72
 
48
73
  end
@@ -2,32 +2,33 @@ require 'malt/engines/abstract'
2
2
 
3
3
  module Malt::Engine
4
4
 
5
- # LESS
5
+ # LESS is an extension of CSS. You can write LESS code just like you
6
+ # would write CSS, except you need to compile it to CSS.
6
7
  #
7
- # http://lesscss.org/
8
+ # @see http://lesscss.org/
8
9
  #
9
- # LESS is an extension of CSS. You can write LESS code just like you would write CSS,
10
- # except you need to compile it to CSS. That's what this class is for.
11
10
  class Less < Abstract
12
11
 
13
12
  default :less
14
13
 
15
14
  #
16
- def render(params)
17
- text = params[:text]
18
- into = params[:to]
15
+ def render(params={})
16
+ into, text, compress = parameters(params, :to, :text, :compress)
17
+
19
18
  case into
20
19
  when :css, nil
21
- intermediate(params).to_css
20
+ prepare_engine(params).to_css(:compress=>compress)
22
21
  else
23
22
  super(params)
24
23
  end
25
24
  end
26
25
 
27
26
  #
28
- def intermediate(params)
29
- text = params[:text]
30
- ::Less::Engine.new(text)
27
+ def create_engine(params={})
28
+ text, file = parameters(params, :text, :file)
29
+ cached(text, file) do
30
+ ::Less::Parser.new(:filename=>file).parse(text)
31
+ end
31
32
  end
32
33
 
33
34
  #
@@ -35,11 +36,11 @@ module Malt::Engine
35
36
  # intermediate # ??
36
37
  #end
37
38
 
38
- private
39
+ private
39
40
 
40
41
  # Load Less library if not already loaded.
41
- def initialize_engine
42
- return if defined? ::Less::Engine
42
+ def require_engine
43
+ return if defined? ::Less::Parser
43
44
  require_library 'less'
44
45
  end
45
46
 
@@ -2,34 +2,44 @@ require 'malt/engines/abstract'
2
2
 
3
3
  module Malt::Engine
4
4
 
5
- # Liquid
5
+ # Liquid templates.
6
6
  #
7
- # http://liquid.rubyforge.org/
7
+ # @see http://liquid.rubyforge.org/
8
8
  #
9
9
  class Liquid < Abstract
10
10
 
11
11
  default :liquid
12
12
 
13
13
  #
14
- def intermediate(params)
15
- text = params[:text]
16
- ::Liquid::Template.parse(text)
14
+ def render(params={}, &content) #file, db, &content)
15
+ text, scope, locals = parameters(params, :text, :scope, :locals)
16
+
17
+ data = make_hash(scope, locals, &content)
18
+
19
+ # convert symbol keys to strings w/o rewriting the hash
20
+ symbol_keys = data.keys.select{ |k| Symbol === k }
21
+ symbol_keys.each do |k|
22
+ data[k.to_s] = data[k]
23
+ data.delete(k)
24
+ end
25
+
26
+ engine = prepare_engine(params)
27
+
28
+ engine.render(data)
17
29
  end
18
30
 
19
31
  #
20
- def render(params={}, &yld) #file, db, &yld)
21
- text = params[:text]
22
- data = params[:data]
23
- data = make_hash(data, &yld)
24
- data = data.rekey{ |k| k.to_s }
25
- engine = intermediate(params)
26
- engine.render(data)
32
+ def create_engine(params={})
33
+ text = parameters(params, :text)
34
+ cached(text) do
35
+ ::Liquid::Template.parse(text)
36
+ end
27
37
  end
28
38
 
29
- private
39
+ private
30
40
 
31
41
  # Load Liquid library if not already loaded.
32
- def initialize_engine
42
+ def require_engine
33
43
  return if defined? ::Liquid::Template
34
44
  require_library 'liquid'
35
45
  end