malt 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/History.rdoc +18 -0
  2. data/README.rdoc +6 -2
  3. data/lib/malt.rb +9 -0
  4. data/lib/malt/engines/abstract.rb +7 -7
  5. data/lib/malt/engines/bluecloth.rb +3 -3
  6. data/lib/malt/engines/builder.rb +72 -0
  7. data/lib/malt/engines/erb.rb +2 -0
  8. data/lib/malt/engines/erector.rb +59 -0
  9. data/lib/malt/engines/haml.rb +2 -2
  10. data/lib/malt/engines/kramdown.rb +6 -4
  11. data/lib/malt/engines/less.rb +8 -8
  12. data/lib/malt/engines/markaby.rb +51 -0
  13. data/lib/malt/engines/mustache.rb +44 -0
  14. data/lib/malt/engines/radius.rb +4 -4
  15. data/lib/malt/engines/ragtag.rb +49 -0
  16. data/lib/malt/engines/rdiscount.rb +1 -1
  17. data/lib/malt/engines/rdoc.rb +3 -3
  18. data/lib/malt/engines/redcloth.rb +1 -1
  19. data/lib/malt/engines/sass.rb +8 -8
  20. data/lib/malt/engines/tenjin.rb +6 -6
  21. data/lib/malt/formats/abstract.rb +8 -2
  22. data/lib/malt/formats/builder.rb +56 -0
  23. data/lib/malt/formats/css.rb +8 -8
  24. data/lib/malt/formats/erector.rb +53 -0
  25. data/lib/malt/formats/haml.rb +2 -2
  26. data/lib/malt/formats/html.rb +3 -3
  27. data/lib/malt/formats/latex.rb +4 -4
  28. data/lib/malt/formats/less.rb +5 -5
  29. data/lib/malt/formats/liquid.rb +11 -1
  30. data/lib/malt/formats/markaby.rb +53 -0
  31. data/lib/malt/formats/markdown.rb +6 -6
  32. data/lib/malt/formats/mustache.rb +34 -0
  33. data/lib/malt/formats/pdf.rb +2 -2
  34. data/lib/malt/formats/radius.rb +4 -4
  35. data/lib/malt/formats/{rtals.rb → ragtag.rb} +13 -9
  36. data/lib/malt/formats/rdoc.rb +4 -4
  37. data/lib/malt/formats/ruby.rb +2 -2
  38. data/lib/malt/formats/sass.rb +10 -0
  39. data/lib/malt/formats/scss.rb +10 -0
  40. data/lib/malt/formats/tenjin.rb +4 -4
  41. data/lib/malt/formats/textile.rb +12 -12
  42. data/lib/malt/formats/xml.rb +29 -0
  43. data/lib/malt/formats/yaml.rb +2 -2
  44. data/lib/malt/meta/data.rb +4 -4
  45. data/lib/malt/meta/{gemfile → package} +6 -2
  46. data/lib/malt/render.rb +37 -9
  47. data/meta/data.rb +4 -4
  48. data/meta/{gemfile → package} +6 -2
  49. data/qed/03_formats/08_ragtag.rdoc +19 -0
  50. data/qed/03_formats/17_markaby.rdoc +50 -0
  51. data/qed/03_formats/18_builder.rb +50 -0
  52. data/qed/03_formats/19_erector.rb +50 -0
  53. data/qed/03_formats/20_mustache.rdoc +54 -0
  54. data/{test/samples/sample.md → qed/samples/sample.markdown} +0 -0
  55. data/{test → qed}/samples/sample.rdoc +0 -0
  56. metadata +81 -12
  57. data/lib/malt/engines/rtals.rb +0 -46
  58. data/qed/03_formats/08_rtal.rdoc +0 -15
@@ -1,5 +1,23 @@
1
1
  = Release History
2
2
 
3
+ == 0.2.0 | 2010-10-22
4
+
5
+ Malt now support Erector, Markaby, Builder and Mustache templates.
6
+ Erector, Markaby and Builder are Ruby-based formats --templates
7
+ are simply Ruby code. This requires them to use instance variables
8
+ in templates rather than local variables/methods. Somethinfg to keep
9
+ in mind.
10
+
11
+ Changes:
12
+
13
+ * Add support for Erector templates.
14
+ * Add support for Markaby templates.
15
+ * Add support for Builder templates.
16
+ * Add support for Mustache templates.
17
+ * Add `:pass` option to render method.
18
+ * Rename `:format` option to `:to` for render method.
19
+
20
+
3
21
  == 0.1.1 | 2010-09-21
4
22
 
5
23
  This release simple fixes two bugs. One to handle variant arity
@@ -6,8 +6,12 @@
6
6
 
7
7
  == DESCRIPTION
8
8
 
9
- Malt provides a factory framework for rendering
10
- a variety of template and markup document formats.
9
+ Malt provides a factory framework for rendering a variety of template and
10
+ markup document formats. Malt has a very object-oriented design
11
+ utilizing separate engine adapter classes and format classes. This makes
12
+ Malt easy to maintain, debug and extend, and thus more robust. In fact,
13
+ Malt supports template caching and ERB compilation by default, which was
14
+ very easy to implement thanks to it's clean design.
11
15
 
12
16
 
13
17
  == SYNOPSIS
@@ -20,6 +20,15 @@ module Malt
20
20
  @registry ||= {}
21
21
  end
22
22
 
23
+ #
24
+ def self.support?(ext)
25
+ ext = ext.to_s
26
+ type = ext.sub(/^\./, '').strip
27
+ return false if type.empty?
28
+ #@registry.key?(ext.to_sym)
29
+ #Engine.registry[type.to_sym]
30
+ Engine.registry.key?(type.to_sym)
31
+ end
23
32
 
24
33
  #
25
34
  def self.file(file, options={})
@@ -42,7 +42,7 @@ module Engine
42
42
  end
43
43
  end
44
44
 
45
- # Override this method to load rendering engine library.
45
+ #
46
46
  def initialize(settings={})
47
47
  @settings = settings.rekey
48
48
 
@@ -53,7 +53,6 @@ module Engine
53
53
  end
54
54
 
55
55
  # Access to the options given to the initializer.
56
- # Returns an OpenStruct object.
57
56
  attr :settings
58
57
 
59
58
  #
@@ -90,27 +89,28 @@ module Engine
90
89
  # Convert a data source into a Binding.
91
90
  # TODO: handle yld.
92
91
  def make_binding(db, &yld)
93
- return db if Binding === db
92
+ return db if Binding === db # FIXME: no yld
94
93
 
95
94
  if db.respond_to?(:to_binding)
96
- return db.to_binding
95
+ return db.to_binding(&yld)
97
96
  end
98
97
 
99
- db = make_object(db)
98
+ db = make_object(db, &yld)
100
99
 
101
100
  return db.instance_eval{ binding }
102
101
  end
103
102
 
104
103
  # Convert a data source into an Object (aka a "scope").
105
- def make_object(db)
104
+ def make_object(db, &yld)
106
105
  if db.respond_to?(:to_hash)
107
106
  hash = db.to_hash
107
+ hash[:yield] = yld.call if yld
108
108
  attrs = hash.keys.map{ |k| k.to_sym }
109
109
  return Struct.new(*attrs).new(*hash.values)
110
110
  end
111
111
 
112
112
  if Binding === db
113
- eval('self', binding)
113
+ eval('self', binding) # FIXME: no yld
114
114
  end
115
115
 
116
116
  return db
@@ -9,9 +9,9 @@ module Malt::Engine
9
9
 
10
10
  # Convert Markdown text to HTML text.
11
11
  def render(params)
12
- text = params[:text]
13
- format = params[:format]
14
- case format
12
+ text = params[:text]
13
+ into = params[:to]
14
+ case into
15
15
  when :html, nil
16
16
  intermediate(params).to_html
17
17
  else
@@ -0,0 +1,72 @@
1
+ require 'malt/engines/abstract'
2
+
3
+ module Malt::Engine
4
+
5
+ # Builder
6
+ #
7
+ # http://builder.rubyforge.org/
8
+ #
9
+ class Builder < Abstract
10
+
11
+ default :builder
12
+
13
+ #
14
+ #def intermediate(params)
15
+ #end
16
+
17
+ #
18
+ def render(params, &yld)
19
+ into = params[:to]
20
+ case into
21
+ when :html, nil
22
+ render_html(params, &yld)
23
+ else
24
+ super(params, &yld)
25
+ end
26
+ end
27
+
28
+ # TODO: Do we need a #make_ivar(data, &yld) method to make data into
29
+ # instance variables for some templates like this one?
30
+ def render_html(params={}, &yld)
31
+ text = params[:text]
32
+ file = params[:file]
33
+ data = params[:data]
34
+
35
+ data = make_hash(data, &yld)
36
+ builder = ::Builder::XmlMarkup.new(engine_options(params))
37
+ data.each{ |k,v| builder.instance_eval("@#{k} = v") }
38
+ builder.instance_eval(text, file)
39
+ end
40
+
41
+ private
42
+
43
+ # Load Erector library if not already loaded.
44
+ def initialize_engine
45
+ return if defined? ::Builder
46
+ require_library 'builder'
47
+ end
48
+
49
+ # :target=>target_object: Object receiving the markup. target_object must
50
+ # respond to the <<(a_string) operator and return itself.
51
+ # The default target is a plain string target.
52
+ #
53
+ # :indent=>indentation: Number of spaces used for indentation. The default
54
+ # is no indentation and no line breaks.
55
+ #
56
+ # :margin=>initial_indentation_level: Amount of initial indentation
57
+ # (specified in levels, not spaces).
58
+ def engine_options(params)
59
+ target = params[:target] || settings[:target]
60
+ indent = params[:indent] || settings[:indent]
61
+ margin = params[:margin] || settings[:margin]
62
+ opts = {}
63
+ opts[:target] = target if target
64
+ opts[:indent] = indent if indent
65
+ opts[:margin] = margin if margin
66
+ opts
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
@@ -28,7 +28,9 @@ module Malt::Engine
28
28
  text = params[:text]
29
29
  file = params[:file]
30
30
  data = params[:data]
31
+
31
32
  data = make_binding(data, &yld)
33
+
32
34
  if settings[:precompile] == false
33
35
  intermediate(params).result(data)
34
36
  else
@@ -0,0 +1,59 @@
1
+ require 'malt/engines/abstract'
2
+
3
+ module Malt::Engine
4
+
5
+ # Erector
6
+ #
7
+ # http://erector.rubyforge.org/userguide.html
8
+ #
9
+ class Erector < Abstract
10
+
11
+ default :erector
12
+
13
+ #
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
20
+
21
+ #
22
+ def render(params, &yld)
23
+ into = params[:to]
24
+ case into
25
+ when :html, nil
26
+ render_html(params, &yld)
27
+ else
28
+ super(params, &yld)
29
+ end
30
+ end
31
+
32
+ #
33
+ def render_html(params={}, &yld)
34
+ #text = params[:text]
35
+ file = params[:file]
36
+ data = params[:data]
37
+ data = make_hash(data, &yld)
38
+
39
+ intermediate(params).new(data).to_html
40
+ end
41
+
42
+ private
43
+
44
+ # Load Erector library if not already loaded.
45
+ def initialize_engine
46
+ return if defined? ::Erector
47
+ require_library 'erector'
48
+ end
49
+
50
+ #
51
+ def engine_options(params)
52
+ opts = {}
53
+ opts
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
@@ -10,8 +10,8 @@ module Malt::Engine
10
10
 
11
11
  #
12
12
  def render(params, &yld)
13
- format = params[:format]
14
- case format
13
+ into = params[:to]
14
+ case into
15
15
  when :html, nil
16
16
  render_html(params, &yld)
17
17
  else
@@ -13,10 +13,13 @@ module Malt::Engine
13
13
  register :markdown, :md
14
14
 
15
15
  # Convert Markdown text to HTML text.
16
+ #
17
+ # @option params [String] :text Template text
18
+ # @option params [String,Symbol] :to ('html') Type or file extension to convert template into.
16
19
  def render(params)
17
- text = params[:text]
18
- format = params[:format]
19
- case format
20
+ text = params[:text]
21
+ into = params[:to]
22
+ case into
20
23
  when :html, nil
21
24
  intermediate(params).to_html
22
25
  when :latex
@@ -32,7 +35,6 @@ module Malt::Engine
32
35
  ::Kramdown::Document.new(text)
33
36
  end
34
37
 
35
-
36
38
  private
37
39
 
38
40
  # Load rdoc makup library if not already loaded.
@@ -14,9 +14,9 @@ module Malt::Engine
14
14
 
15
15
  #
16
16
  def render(params)
17
- text = params[:text]
18
- format = params[:format]
19
- case format
17
+ text = params[:text]
18
+ into = params[:to]
19
+ case into
20
20
  when :css, nil
21
21
  intermediate(params).to_css
22
22
  else
@@ -37,11 +37,11 @@ module Malt::Engine
37
37
 
38
38
  private
39
39
 
40
- # Load Less library if not already loaded.
41
- def initialize_engine
42
- return if defined? ::Less::Engine
43
- require_library 'less'
44
- end
40
+ # Load Less library if not already loaded.
41
+ def initialize_engine
42
+ return if defined? ::Less::Engine
43
+ require_library 'less'
44
+ end
45
45
 
46
46
  end
47
47
 
@@ -0,0 +1,51 @@
1
+ require 'malt/engines/abstract'
2
+
3
+ module Malt::Engine
4
+
5
+ # Markaby
6
+ #
7
+ # http://markaby.rubyforge.org/
8
+ #
9
+ class Markaby < Abstract
10
+
11
+ default :markaby, :mab
12
+
13
+ #
14
+ #def intermediate(params)
15
+ # text = params[:text]
16
+ # eval("lambda{ #{text} }")
17
+ #end
18
+
19
+ #
20
+ def render(params, &yld)
21
+ into = params[:to]
22
+ case into
23
+ when :html, nil
24
+ render_html(params, &yld)
25
+ else
26
+ super(params, &yld)
27
+ end
28
+ end
29
+
30
+ #
31
+ def render_html(params={}, &yld)
32
+ text = params[:text]
33
+ file = params[:file]
34
+ data = params[:data]
35
+ data = make_hash(data, &yld)
36
+ builder = ::Markaby::Builder.new(data)
37
+ builder.instance_eval(text).to_s
38
+ end
39
+
40
+ private
41
+
42
+ # Load Markaby library if not already loaded.
43
+ def initialize_engine
44
+ return if defined? ::Markaby
45
+ require_library 'markaby'
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,44 @@
1
+ require 'malt/engines/abstract'
2
+
3
+ module Malt::Engine
4
+
5
+ # Mustache engine.
6
+ #
7
+ # http://github.com/defunkt/mustache
8
+ #
9
+ class Mustache < Abstract
10
+
11
+ register :mustache
12
+
13
+ ## Convert Markdown text to intermediate object.
14
+ #def intermediate(params)
15
+ # text = params[:text]
16
+ # ???
17
+ #end
18
+
19
+ #
20
+ def render(params={}, &yld) #file, db, &yld)
21
+ text = params[:text]
22
+ data = params[:data]
23
+
24
+ data = make_hash(data, &yld)
25
+
26
+ #engine = intermediate(params)
27
+ #engine.render(data)
28
+ ::Mustache.render(text, data)
29
+ end
30
+
31
+
32
+ private
33
+
34
+ # Load rdoc makup library if not already loaded.
35
+ def initialize_engine
36
+ return if defined? ::Mustache
37
+ require_library 'mustache'
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+
@@ -12,10 +12,10 @@ module Malt::Engine
12
12
 
13
13
  #
14
14
  def render(params, &yld)
15
- text = params[:text]
16
- data = params[:data]
17
- format = params[:format]
18
- case format
15
+ text = params[:text]
16
+ data = params[:data]
17
+ into = params[:to]
18
+ case into
19
19
  when :html, :xml, nil
20
20
  data = make_context(data, &yld)
21
21
  opts = engine_options(params)
@@ -0,0 +1,49 @@
1
+ require 'malt/engines/abstract'
2
+
3
+ module Malt::Engine
4
+
5
+ # RagTag
6
+ #
7
+ # http://github.com/rubyworks/ragtag
8
+ #
9
+ class RagTag < Abstract
10
+
11
+ default :ragtag, :rt
12
+
13
+ #
14
+ def render(params, &yld)
15
+ text = params[:text]
16
+ file = params[:file]
17
+ data = params[:data]
18
+ into = params[:to]
19
+
20
+ case into
21
+ when :html, nil
22
+ data = make_binding(data, &yld)
23
+ intermediate(params).compile(data).to_xhtml
24
+ when :xml
25
+ data = make_binding(data, &yld)
26
+ intermediate(params).compile(data).to_xml
27
+ else
28
+ super(params, &yld)
29
+ end
30
+ end
31
+
32
+ #
33
+ def intermediate(params)
34
+ text = params[:text]
35
+ ::RagTag.new(text)
36
+ end
37
+
38
+ private
39
+
40
+ # Load Haml library if not already loaded.
41
+ def initialize_engine
42
+ return if defined? ::RagTag
43
+ require_library 'ragtag'
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+