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,71 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+ require 'malt/engines/erb'
4
+
5
+ module Malt::Formats
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 Ruby < Abstract
19
+
20
+ register 'rb'
21
+
22
+ #
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.registry[type.to_sym]
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)
37
+ end
38
+
39
+ # Ruby templates can be any type.
40
+ def method_missing(sym, *args, &yld)
41
+ if Malt.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.registry.key?(type)
46
+ return to(type, *args, &yld)
47
+ end
48
+ end
49
+ super(sym, *args, &yld)
50
+ end
51
+
52
+ #
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)
60
+ end
61
+
62
+ private
63
+
64
+ #
65
+ def render_engine
66
+ @render_engine ||= Malt::Engines::Ruby.new(options)
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,56 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/css'
3
+ require 'malt/engines/sass'
4
+
5
+ module Malt::Formats
6
+
7
+ # Sass Format
8
+ #
9
+ class Sass < Abstract
10
+
11
+ register 'sass'
12
+
13
+ #
14
+ def css(data=nil, &yld)
15
+ render_engine.render(:format=>:css, :text=>text, :file=>file, :type=>type)
16
+ end
17
+
18
+ #
19
+ def to_css(data=nil, &yld)
20
+ result = css(data, &yld)
21
+ CSS.new(:text=>result, :file=>refile(:css), :type=>:css)
22
+ end
23
+
24
+ #
25
+ #def compile(db, &yld)
26
+ # result = render_engine.render(text, db, &yld)
27
+ # opts = options.merge(:text=>result, file=>refile(:css))
28
+ # CSS.new(opts)
29
+ #end
30
+
31
+ #
32
+ #def render_to(to, db, &yld)
33
+ # case to
34
+ # when :css
35
+ # malt_engine.render_css(text, file, db, &yld)
36
+ # else
37
+ # raise UnspportedConversion.new(type, to)
38
+ # end
39
+ #end
40
+
41
+ private
42
+
43
+ #
44
+ def render_engine
45
+ @render_engine ||= Malt::Engines::Sass.new(options)
46
+ end
47
+
48
+ # Sass default output type is CSS.
49
+ def default
50
+ :css
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,50 @@
1
+ require 'malt/formats/abstract_template'
2
+ require 'malt/formats/html'
3
+ require 'malt/engines/tenjin'
4
+
5
+ module Malt::Formats
6
+
7
+ # Tenjin
8
+ #
9
+ # http://www.kuwata-lab.com/tenjin/
10
+ #
11
+ class Tenjin < AbstractTemplate
12
+
13
+ register 'tenjin'
14
+
15
+ def rb
16
+ render_engine.compile(text, file)
17
+ end
18
+
19
+ # Erb templates can be "precompiled" into Ruby templates.
20
+ def to_rb
21
+ text = rb
22
+ Ruby.new(:text=>text, :file=>refile(:rb), :type=>:rb)
23
+ end
24
+
25
+ alias_method(:to_ruby, :to_rb)
26
+
27
+ #
28
+ def html
29
+ render(:html, data, &yld)
30
+ end
31
+
32
+ #
33
+ def to_html(data, &yld)
34
+ new_text = render(:html, data, &yld)
35
+ new_file = refile(:html)
36
+ new_options = options.merge(:text=>new_text, :file=>new_file, :type=>:html)
37
+ HTML.new(new_options)
38
+ end
39
+
40
+ private
41
+
42
+ #
43
+ def render_engine
44
+ @render_engine ||= Malt::Engines::Tenjin.new(options)
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,54 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+ require 'malt/formats/pdf'
4
+
5
+ module Malt::Formats
6
+
7
+ # Plain text format. Plain text documents are uniqu in that they can
8
+ # be transformed into any other type of document. For example, applying
9
+ # to_html in text doesn't actually transform the source text in any way.
10
+ # Rather it simply "informs" Malt to treat the text as HTML.
11
+ #
12
+ class Text < Abstract
13
+
14
+ register('txt')
15
+
16
+ #
17
+ def txt(*)
18
+ text
19
+ end
20
+
21
+ #
22
+ def to_txt(*)
23
+ self
24
+ end
25
+
26
+ #
27
+ def method_missing(sym, *args, &block)
28
+ if md = /^to_/.match(sym.to_s)
29
+ type = md.post_match.to_sym
30
+ opts = options.merge(:type=>type, :file=>refile(type))
31
+ return Malt.text(text, opts)
32
+ end
33
+ super(sym, *args, &block)
34
+ end
35
+
36
+ # Returns an HTML object.
37
+ #def to_html
38
+ # HTML.new(:text=>text,:file=>refile(:html))
39
+ #end
40
+
41
+ # Returns a PDF object.
42
+ #def to_pdf
43
+ # PDF.new(:text=>text,:file=>refile(:pdf))
44
+ #end
45
+
46
+ private
47
+
48
+ def render_engine
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
@@ -0,0 +1,59 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/engines/redcloth'
3
+
4
+ module Malt::Formats
5
+
6
+ #
7
+ class Textile < Abstract
8
+
9
+ register('textile', 'tt')
10
+
11
+ #
12
+ def html
13
+ render_engine.render(:format=>:html, :text=>text, :file=>file)
14
+ end
15
+
16
+ #
17
+ def textile
18
+ text
19
+ end
20
+
21
+ #
22
+ alias_method :tt, :textile
23
+
24
+ #
25
+ def to_html
26
+ opts = options.merge(:text=>html, :file=>refile(:html), :type=>:html)
27
+ HTML.new(opts)
28
+ end
29
+
30
+ #
31
+ def to_textile
32
+ self
33
+ end
34
+
35
+ alias_method :to_tt, :to_textile
36
+
37
+ #
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
47
+ #end
48
+
49
+ private
50
+
51
+ #
52
+ def render_engine
53
+ @render_engine ||= Malt::Engines::RedCloth.new(options)
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,50 @@
1
+ require 'malt/formats/abstract'
2
+ require 'malt/formats/html'
3
+
4
+ module Malt::Formats
5
+
6
+ # = YAML format
7
+ #
8
+ # TODO: hmm... maybe use data to update yaml?
9
+ class YAML < Abstract
10
+
11
+ register 'yaml', 'yml'
12
+
13
+ #
14
+ def yaml(*)
15
+ text
16
+ end
17
+
18
+ alias_method :yml, :yaml
19
+
20
+ #
21
+ def to_yaml(*)
22
+ self
23
+ end
24
+
25
+ alias_method :to_yml, :to_yaml
26
+
27
+ # Converting a plan YAML file to HTML makes no sense so we
28
+ # just wrap it in +pre+ tags.
29
+ def html
30
+ "<pre>\n#{h text}\n</pre>"
31
+ end
32
+
33
+ #
34
+ def to_html
35
+ text = html
36
+ opts = options.merge(:text=>text, :file=>refile(:html), :type=>:html)
37
+ HTML.new(opts)
38
+ end
39
+
40
+ private
41
+
42
+ # TODO: HTML escaping
43
+ def h(text)
44
+ text
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,31 @@
1
+ require 'malt/core_ext'
2
+
3
+ module Malt
4
+
5
+ module Kernel
6
+ private
7
+
8
+ #
9
+ def make_ostruct(hash)
10
+ case hash
11
+ when OpenStruct
12
+ hash
13
+ else
14
+ OpenStruct.new(hash)
15
+ end
16
+ end
17
+
18
+ #
19
+ def ext_to_type(ext)
20
+ ext = ext.to_s.downcase
21
+ return nil if ext.empty?
22
+ if ext[0,1] == '.'
23
+ ext[1..-1].to_sym
24
+ else
25
+ ext.to_sym
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,26 @@
1
+ Object.__send__(:remove_const, :VERSION) if Object.const_defined?(:VERSION) # becuase Ruby 1.8~ gets in the way
2
+
3
+ module Malt
4
+
5
+ DIRECTORY = File.dirname(__FILE__)
6
+
7
+ def self.gemfile
8
+ @gemfile ||= (
9
+ require 'yaml'
10
+ YAML.load(File.new(DIRECTORY + '/gemfile'))
11
+ )
12
+ end
13
+
14
+ def self.profile
15
+ @profile ||= (
16
+ require 'yaml'
17
+ YAML.load(File.new(DIRECTORY + '/profile'))
18
+ )
19
+ end
20
+
21
+ def self.const_missing(name)
22
+ key = name.to_s.downcase
23
+ gemfile[key] || profile[key] || super(name)
24
+ end
25
+
26
+ end
@@ -0,0 +1,17 @@
1
+ name : malt
2
+ date : 2010-09-07
3
+ version : 0.1.0
4
+
5
+ requires:
6
+ - syckle (build)
7
+ - qed (test)
8
+ - rdoc (test)
9
+ - redcloth (test)
10
+ - bluecloth (test)
11
+ - kramdown (test)
12
+ - haml (test)
13
+ - tenjin (test)
14
+ - rtals (test)
15
+ - liquid (test)
16
+ - erubis (test)
17
+
@@ -0,0 +1,21 @@
1
+ title : Malt
2
+ summary: Multi-template/multi-markup rendering engine
3
+ contact: trans <transfire@gmail.com>
4
+ created: 2010-06-22
5
+
6
+ authors:
7
+ - Thomas Sawyer
8
+
9
+ description:
10
+ Malt provides a factory framework for rendering
11
+ a variety of template and markup document formats.
12
+
13
+ resources:
14
+ home: http://rubyworks.github.com/malt
15
+ code: http://github.com/rubyworks/malt
16
+ wiki: http://wiki.github.com/rubyworks/malt
17
+ docs: http://rubyworks.github.com/malt/docs/api
18
+ bugs: http://github.com/rubyworks/malt/issues
19
+
20
+ copyright:
21
+ Copyright (c) 2010 Thomas Sawyer