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,43 +2,52 @@ require 'malt/engines/abstract'
2
2
 
3
3
  module Malt::Engine
4
4
 
5
- # RagTag
5
+ # RagTag XML/HTML templates.
6
6
  #
7
- # http://github.com/rubyworks/ragtag
7
+ # @see http://github.com/rubyworks/ragtag
8
8
  #
9
9
  class RagTag < Abstract
10
10
 
11
11
  default :ragtag, :rt
12
12
 
13
13
  #
14
- def render(params, &yld)
15
- text = params[:text]
16
- file = params[:file]
17
- data = params[:data]
18
- into = params[:to]
14
+ def render(params={}, &content)
15
+ into = parameters(params, :to) || :html
19
16
 
20
17
  case into
21
- when :html, nil
22
- data = make_binding(data, &yld)
23
- intermediate(params).compile(data).to_xhtml
18
+ when :html
19
+ prepare_engine(params,&content).to_html
20
+ when :xhtml
21
+ prepare_engine(params,&content).to_xhtml
24
22
  when :xml
25
- data = make_binding(data, &yld)
26
- intermediate(params).compile(data).to_xml
23
+ prepare_engine(params,&content).to_xml
27
24
  else
28
- super(params, &yld)
25
+ super(params, &content)
29
26
  end
30
27
  end
31
28
 
29
+ #
30
+ def prepare_engine(params={}, &content)
31
+ text, file, scope, locals = parameters(params, :text, :file, :scope, :locals)
32
+
33
+ binding = make_binding(scope, locals, &content)
34
+
35
+ create_engine(params).compile(binding)
36
+ end
37
+
32
38
  #
33
- def intermediate(params)
34
- text = params[:text]
35
- ::RagTag.new(text)
39
+ def create_engine(params={})
40
+ text = parameters(params, :text)
41
+
42
+ cached(text) do
43
+ ::RagTag.new(text)
44
+ end
36
45
  end
37
46
 
38
47
  private
39
48
 
40
49
  # Load Haml library if not already loaded.
41
- def initialize_engine
50
+ def require_engine
42
51
  return if defined? ::RagTag
43
52
  require_library 'ragtag'
44
53
  end
@@ -46,4 +55,3 @@ module Malt::Engine
46
55
  end
47
56
 
48
57
  end
49
-
@@ -6,7 +6,7 @@ module Malt::Engine
6
6
 
7
7
  # Discount Markdown implementation.
8
8
  #
9
- # http://github.com/rtomayko/rdiscount
9
+ # @see http://github.com/rtomayko/rdiscount
10
10
  #
11
11
  # The +:smart+ and +:filter_html+ options can be set true
12
12
  # to enable those flags on the underlying RDiscount object.
@@ -15,31 +15,38 @@ module Malt::Engine
15
15
  default :markdown, :md
16
16
 
17
17
  # Convert Markdown text to HTML text.
18
- def render(params)
19
- case params[:to]
18
+ def render(params={})
19
+ into = parameters(params, :to)
20
+
21
+ case into
20
22
  when :html, nil
21
- intermediate(params).to_html
23
+ prepare_engine(params).to_html
22
24
  else
23
25
  super(params)
24
26
  end
25
27
  end
26
28
 
27
- # Convert Markdown text to intermediate engine object.
28
- def intermediate(params)
29
- text = params[:text]
30
- ::RDiscount.new(text, *flags)
29
+ # Convert Markdown text to create_engine engine object.
30
+ def create_engine(params={})
31
+ text = parameters(params, :text)
32
+
33
+ flags = engine_options(params)
34
+
35
+ cached(text, flags) do
36
+ ::RDiscount.new(text, *flags)
37
+ end
31
38
  end
32
39
 
33
- private
40
+ private
34
41
 
35
42
  # Load rdoc makup library if not already loaded.
36
- def initialize_engine
43
+ def require_engine
37
44
  return if defined? ::RDiscount
38
45
  require_library 'rdiscount'
39
46
  end
40
47
 
41
48
  #
42
- def flags(params={})
49
+ def engine_options(params={})
43
50
  [:smart, :filter_html].select{ |flag| params[flag] || settings[flag] }
44
51
  end
45
52
 
@@ -14,31 +14,37 @@ module Malt::Engine
14
14
  default :rdoc
15
15
 
16
16
  # Convert rdoc text to html.
17
- def render(params)
18
- text = params[:text]
19
- into = params[:to]
17
+ def render(params={})
18
+ into, text = parameters(params, :to, :text)
19
+
20
20
  case into
21
21
  when :html, nil
22
- html_engine.convert(text).to_s
22
+ prepare_engine(params).convert(text).to_s
23
23
  else
24
24
  super(params)
25
25
  end
26
26
  end
27
27
 
28
- private
28
+ #
29
+ def create_engine(params={})
30
+ into = parameters(params, :to)
29
31
 
30
- # Load rdoc makup library if not already loaded.
31
- def initialize_engine
32
- return if defined?(::RDoc::Markup)
33
- require 'rubygems' # hack
34
- require_library 'rdoc/markup'
35
- require_library 'rdoc/markup/to_html'
32
+ cached(into) do
33
+ ::RDoc::Markup::ToHtml.new
36
34
  end
35
+ end
37
36
 
38
- #
39
- def html_engine
40
- @html_engine ||= ::RDoc::Markup::ToHtml.new
41
- end
37
+ private
38
+
39
+ # Load rdoc makup library if not already loaded.
40
+ def require_engine
41
+ return if defined?(::RDoc::Markup)
42
+ require 'rubygems' # hack
43
+ gem 'rdoc', '> 3'
44
+ require_library 'rdoc'
45
+ #require_library 'rdoc/markup'
46
+ #require_library 'rdoc/markup/to_html'
47
+ end
42
48
 
43
49
  end
44
50
 
@@ -0,0 +1,137 @@
1
+ require 'malt/engines/abstract'
2
+
3
+ module Malt::Engine
4
+
5
+ # Redcarpet Markdown implementation.
6
+ #
7
+ # @see https://github.com/tanoku/redcarpet
8
+ #
9
+ class Redcarpet < Abstract
10
+
11
+ register :markdown, :md
12
+
13
+ # Convert Markdown text to HTML text.
14
+ #
15
+ # @param [Hash] params
16
+ #
17
+ # @option params [String] :text
18
+ # Template text
19
+ #
20
+ # @option params [String,Symbol] :to ('html')
21
+ # Type or file extension to convert template into.
22
+ #
23
+ def render(params={})
24
+ into, text = parameters(params, :to, :text)
25
+
26
+ case into
27
+ when :html, nil # :man, :manpage
28
+ if ::Redcarpet::VERSION < '2'
29
+ prepare_engine(params).to_html
30
+ else
31
+ prepare_engine(params).render(text)
32
+ end
33
+ else
34
+ super(params)
35
+ end
36
+ end
37
+
38
+ # Convert Markdown text to intermediate object.
39
+ #
40
+ # @param [Hash] params
41
+ # A hash containing the Markdown extensions which the parser
42
+ # will identify. The following extensions are accepted.
43
+ #
44
+ # @option params [Boolean] :no_intra_emphasis
45
+ # Do not parse emphasis inside of words. Strings such as `foo_bar_baz`
46
+ # will not generate `<em>` tags.
47
+ #
48
+ # @option params [Boolean] :tables
49
+ # Parse tables, PHP-Markdown style.
50
+ #
51
+ # @option params [Boolean] :fenced_code_blocks
52
+ # Parse fenced code blocks, PHP-Markdown style. Blocks delimited with
53
+ # three or more `~` or backticks will be considered as code, without
54
+ # the need to be indented. An optional language name may be added at
55
+ # the end of the opening fence for the code block
56
+ #
57
+ # @option params [Boolean] :autolink
58
+ # parse links even when they are not enclosed in
59
+ # `<>` characters. Autolinks for the http, https and ftp
60
+ # protocols will be automatically detected. Email addresses
61
+ # are also handled, and http links without protocol, but
62
+ # starting with `www.`
63
+ #
64
+ # @option params [Boolean] :strikethrough
65
+ # parse strikethrough, PHP-Markdown style
66
+ # Two `~` characters mark the start of a strikethrough,
67
+ # e.g. `this is ~~good~~ bad`
68
+ #
69
+ # @option params [Boolean] :lax_html_blocks
70
+ # HTML blocks do not require to be surrounded
71
+ # by an empty line as in the Markdown standard.
72
+ #
73
+ # @option params [Boolean] :space_after_headers
74
+ # A space is always required between the
75
+ # hash at the beginning of a header and its name, e.g.
76
+ # `#this is my header` would not be a valid header.
77
+ #
78
+ # @option params [Boolean] :superscript
79
+ # parse superscripts after the `^` character;
80
+ # contiguous superscripts are nested together, and complex
81
+ # values can be enclosed in parenthesis, e.g. `this is the 2^(nd) time`
82
+ #
83
+ def create_engine(params={})
84
+ return create_engine_1x(params) if ::Redcarpet::VERSION < '2'
85
+
86
+ into, toc = parameters(params, :to, :toc)
87
+
88
+ opts = engine_options(params)
89
+
90
+ case into
91
+ when :man, :manpage
92
+ renderer = ::Redcarpet::Render::ManPage
93
+ else
94
+ if toc
95
+ renderer = ::Redcarpet::Render::HTML_TOC
96
+ else
97
+ renderer = ::Redcarpet::Render::HTML
98
+ end
99
+ end
100
+
101
+ cached(into, toc, opts) do
102
+ ::Redcarpet::Markdown.new(renderer)
103
+ end
104
+ end
105
+
106
+ # For Recarpet v1.x.
107
+ def create_engine_1x(params={})
108
+ text = parameters(params, :text)
109
+
110
+ cached(text) do
111
+ ::Redcarpet.new(text) #, engine_options(params))
112
+ end
113
+ end
114
+
115
+ private
116
+
117
+ ENGINE_OPTION_NAMES = %w{
118
+ no_intra_emphasis tables fenced_code_blocks autolink strikethrough
119
+ lax_html_blocks space_after_headers superscript
120
+ }
121
+
122
+ # Load rdoc makup library if not already loaded.
123
+ def require_engine
124
+ return if defined? ::Redcarpet
125
+ require_library 'redcarpet'
126
+ end
127
+
128
+ #
129
+ def engine_option_names
130
+ ENGINE_OPTION_NAMES
131
+ end
132
+
133
+ end
134
+
135
+ end
136
+
137
+
@@ -2,7 +2,10 @@ require 'malt/engines/abstract'
2
2
 
3
3
  module Malt::Engine
4
4
 
5
+ # Redcloth handles textile markup.
5
6
  #
7
+ # @see http://redcloth.org/
8
+
6
9
  class RedCloth < Abstract
7
10
 
8
11
  default :tt, :textile
@@ -14,24 +17,29 @@ module Malt::Engine
14
17
  # :format => Symbol of the format to render [:html]
15
18
  #
16
19
  def render(params={})
17
- case params[:to]
20
+ into, text = parameters(params, :to, :text)
21
+
22
+ case into
18
23
  when :html, nil
19
- intermediate(params).to_html
24
+ prepare_engine(params).to_html
20
25
  else
21
26
  super(params)
22
27
  end
23
28
  end
24
29
 
25
30
  #
26
- def intermediate(params={})
27
- text = params[:text]
28
- ::RedCloth.new(text)
31
+ def create_engine(params={})
32
+ text = parameters(params, :text)
33
+
34
+ cached(text) do
35
+ ::RedCloth.new(text)
36
+ end
29
37
  end
30
38
 
31
- private
39
+ private
32
40
 
33
41
  # Load redcloth library if not already loaded.
34
- def initialize_engine
42
+ def require_engine
35
43
  return if defined? ::RedCloth
36
44
  require_library 'redcloth'
37
45
  end
@@ -2,32 +2,33 @@ require 'malt/engines/abstract'
2
2
 
3
3
  module Malt::Engine
4
4
 
5
- # Ruby as a template engine.
5
+ # Ruby return reuslt as template engine.
6
6
  #
7
- # http://
7
+ # @todo deprecate ?
8
+ #
9
+ # @see http://ruby-lang.org
8
10
  #
9
11
  class Ruby < Abstract
10
12
 
11
13
  default :rb
12
14
 
13
15
  #
14
- def render(params={}, &yld)
15
- text = params[:text]
16
- file = params[:file]
17
- data = params[:data]
18
- data = make_binding(data, &yld)
19
- eval(text, data, file)
16
+ def render(params={}, &content)
17
+ text, file, scope, locals = parameters(params, :text, :file, :scope, :locals)
18
+
19
+ bind = make_binding(scope, locals, &content)
20
+ eval(text, bind, file || 'eval')
20
21
  end
21
22
 
22
23
  # Ruby compiles to Ruby. How odd. ;)
23
- def compile(text, file)
24
- text
24
+ def compile(params)
25
+ params[:text] #file
25
26
  end
26
27
 
27
- private
28
+ private
28
29
 
29
30
  #
30
- def initialize_engine
31
+ def require_engine
31
32
  end
32
33
 
33
34
  end
@@ -9,40 +9,53 @@ module Malt::Engine
9
9
  default :sass, :scss
10
10
 
11
11
  #
12
- def render(params, &yld)
13
- text = params[:text]
14
- file = params[:file]
15
- into = params[:to]
12
+ def render(params={}, &content)
13
+ into = parameters(params, :to)
16
14
 
17
15
  case into
18
16
  when :css, nil
19
- engine = intermediate(params)
17
+ engine = prepare_engine(params)
20
18
  engine.render
21
19
  else
22
- super(params, &yld)
20
+ super(params, &content)
23
21
  end
24
22
  end
25
23
 
26
24
  #
27
- def intermediate(params)
28
- text = params[:text]
29
- file = params[:file]
30
- type = params[:type]
31
- ::Sass::Engine.new(text, :filename=>file, :syntax=>type)
25
+ def create_engine(params={})
26
+ text, file, type = parameters(params, :text, :file, :type)
27
+
28
+ opts = engine_options(params)
29
+
30
+ opts[:filename] = file
31
+ opts[:syntax] = type
32
+
33
+ cached(text, file, type) do
34
+ ::Sass::Engine.new(text, opts)
35
+ end
32
36
  end
33
37
 
34
- private
38
+ private
35
39
 
36
40
  # Load Sass library if not already loaded.
37
- def initialize_engine
41
+ def require_engine
38
42
  return if defined? ::Sass::Engine
39
43
  require_library 'sass'
40
44
  end
41
45
 
42
- #def engine_options
43
- # opts = {}
44
- # opts
45
- #end
46
+ # List of Sass/Scss engine options. Note that not all options are supported.
47
+ # Also use `:type` instead of `:syntax` and `:file` instead of `:filename`.
48
+ #
49
+ # @see http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options
50
+ ENGINE_OPTION_NAMES = %w{
51
+ syntax filename line style unix_newlines
52
+ line_numbers trace_selectors debug_info quiet
53
+ }
54
+
55
+ #
56
+ def engine_option_names
57
+ ENGINE_OPTION_NAMES
58
+ end
46
59
 
47
60
  end
48
61