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
@@ -0,0 +1,216 @@
1
+ require 'malt' unless defined?(Malt)
2
+
3
+ module Malt
4
+
5
+ # Base class for the Tilt-like template classes.
6
+ class Malted
7
+ #
8
+ def self.engine_index
9
+ @@engine_index ||= {}
10
+ end
11
+
12
+ #
13
+ def self.malt_engine(engine_class=nil)
14
+ if engine_class
15
+ @malt_engine = engine_class
16
+ engine_index[@malt_engine] = self
17
+ end
18
+ @malt_engine
19
+ end
20
+
21
+ #
22
+ def malt_engine
23
+ self.class.malt_engine.new(@options)
24
+ end
25
+
26
+ #
27
+ def initialize(file, options={})
28
+ @file = file
29
+ @options = options || {}
30
+ end
31
+
32
+ #
33
+ def render(*data, &yields)
34
+ text = File.read(@file)
35
+ malt_engine.render(:text=>text, :file=>@file, :data=>data, &yields)
36
+ end
37
+ end
38
+
39
+ # Tilt compatability layer. This get included into the toplevel.
40
+ module Tilted
41
+
42
+ #
43
+ module Tilt
44
+ extend Malt::Kernel
45
+
46
+ #
47
+ def self.new(file, options={})
48
+ ext = ext_to_type(File.extname(file))
49
+ malt_engine = Malt::Engine.defaults[ext] || Malt::Engine.registry[ext].first
50
+ tilt_engine = Malted.engine_index[malt_engine]
51
+ tilt_engine.new(file, options)
52
+ end
53
+
54
+
55
+ class StringTemplate < Malted
56
+ malt_engine Malt::Engine::String
57
+ end
58
+
59
+
60
+ # E R U B Y
61
+
62
+ #
63
+ class ERBTemplate < Malted
64
+ malt_engine Malt::Engine::Erb
65
+ end
66
+
67
+ #
68
+ class ErubisTemplate < Malted
69
+ malt_engine Malt::Engine::Erubis
70
+ end
71
+
72
+
73
+ # C U R L E Y B R A C K E T S
74
+
75
+ #
76
+ class LiquidTemplate < Malted
77
+ malt_engine Malt::Engine::Liquid
78
+ end
79
+
80
+
81
+ # H T M L
82
+
83
+ #
84
+ class RadiusTemplate < Malted
85
+ malt_engine Malt::Engine::Radius
86
+ end
87
+
88
+ #
89
+ class HAMLTemplate < Malted
90
+ malt_engine Malt::Engine::Haml
91
+ end
92
+
93
+
94
+ # B U I L D E R
95
+
96
+ #
97
+ class BuilderTemplate < Malted
98
+ malt_engine Malt::Engine::Builder
99
+ end
100
+
101
+ #
102
+ class MarkabyTemplate < Malted
103
+ malt_engine Malt::Engine::Markaby
104
+ end
105
+
106
+ #
107
+ class NokogiriTemplate < Malted
108
+ malt_engine Malt::Engine::Nokogiri
109
+ end
110
+
111
+ #
112
+ class ErectorTemplate < Malted
113
+ malt_engine Malt::Engine::Erector
114
+ end
115
+
116
+
117
+ # R D O C
118
+
119
+ #
120
+ class RDocTemplate < Malted
121
+ malt_engine Malt::Engine::RDoc
122
+ end
123
+
124
+
125
+ # T E X T I L E
126
+
127
+ #
128
+ class RedClothTemplate < Malted
129
+ malt_engine Malt::Engine::RedCloth
130
+ end
131
+
132
+
133
+ # M A R K D O W N
134
+
135
+ #
136
+ class RDiscountTemplate < Malted
137
+ malt_engine Malt::Engine::RDiscount
138
+ end
139
+
140
+ #
141
+ class BlueClothTemplate < Malted
142
+ malt_engine Malt::Engine::BlueCloth
143
+ end
144
+
145
+ #
146
+ class KramdownTemplate < Malted
147
+ malt_engine Malt::Engine::Kramdown
148
+ end
149
+
150
+ #
151
+ class RedcarpetTemplate < Malted
152
+ malt_engine Malt::Engine::Redcarpet
153
+ end
154
+
155
+ #
156
+ class MarukuTemplate < Malted
157
+ malt_engine Malt::Engine::Maruku
158
+ end
159
+
160
+
161
+ # C S S
162
+
163
+ #
164
+ class SassTemplate < Malted
165
+ malt_engine Malt::Engine::Sass
166
+ #
167
+ def malt_engine
168
+ options = @options.merge(:type=>:sass)
169
+ self.class.malt_engine.new(options)
170
+ end
171
+ end
172
+
173
+ #
174
+ class ScssTemplate < Malted
175
+ malt_engine Malt::Engine::Sass
176
+ #
177
+ def malt_engine
178
+ options = @options.merge(:type=>:scss)
179
+ self.class.malt_engine.new(options)
180
+ end
181
+ end
182
+
183
+ class LessTemplate < Malted
184
+ malt_engine Malt::Engine::Less
185
+ end
186
+
187
+
188
+ # S O U R C E C O D E
189
+
190
+ #
191
+ class CoffeeScriptTemplate < Malted
192
+ malt_engine Malt::Engine::Coffee
193
+ end
194
+
195
+
196
+ # W I K I
197
+
198
+ #
199
+ class CreoleTemplate < Malted
200
+ malt_engine Malt::Engine::Creole
201
+ end
202
+
203
+ #
204
+ class WikiClothTemplate < Malted
205
+ malt_engine Malt::Engine::WikiCloth
206
+ end
207
+
208
+ end
209
+
210
+ end
211
+
212
+ end
213
+
214
+ # Include in toplevel space.
215
+ include Malt::Tilted
216
+
@@ -0,0 +1,21 @@
1
+ module Malt
2
+
3
+ # Access to project metadata.
4
+ def self.metadata
5
+ @metadata ||= (
6
+ require 'yaml'
7
+ YAML.load(File.new(File.dirname(__FILE__) + '/../malt.yml'))
8
+ )
9
+ end
10
+
11
+ # Access to project metadata via constants.
12
+ def self.const_missing(name)
13
+ key = name.to_s.downcase
14
+ metadata[key] || super(name)
15
+ end
16
+
17
+ # TODO: Here until bug in 1.8 is fixed.
18
+ VERSION = metadata['version']
19
+
20
+ end
21
+
@@ -0,0 +1,15 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'lemon'
4
+ require 'ae'
5
+ require 'ae/pry'
6
+
7
+ require 'malt'
8
+
9
+ # lets try this for now
10
+ #require 'rr'
11
+
12
+ #class Lemon::World
13
+ # include RR::Adapters::RRMethods
14
+ #end
15
+
@@ -0,0 +1,40 @@
1
+ testcase Malt::Engine::BlueCloth do
2
+
3
+ method :render do
4
+
5
+ test "convert BlueCloth text" do
6
+ e = Malt::Engine::BlueCloth.new(:text=>"# Testing")
7
+ h = e.render
8
+ h.assert.index "<h1>Testing</h1>"
9
+ end
10
+
11
+ test "raises NotImplementedError if converstion format not supported" do
12
+ e = Malt::Engine::BlueCloth.new
13
+ expect NotImplementedError do
14
+ e.render(:to=>:DNE, :text=>"# Testing")
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ method :prepare_engine do
21
+
22
+ test "returns a ::BlueCloth instance" do
23
+ e = Malt::Engine::BlueCloth.new
24
+ r = e.prepare_engine(:text=>"# Testing")
25
+ r.assert.is_a? ::BlueCloth
26
+ end
27
+
28
+ end
29
+
30
+ method :create_engine do
31
+
32
+ test "returns a ::BlueCloth instance" do
33
+ e = Malt::Engine::BlueCloth.new
34
+ r = e.create_engine(:text=>"# Testing")
35
+ r.assert.is_a? ::BlueCloth
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,30 @@
1
+ testcase Malt::Engine::Builder do
2
+
3
+ method :render do
4
+
5
+ test "convert Builder DSL to XML by default" do
6
+ e = Malt::Engine::Builder.new(:text=>%[h1 "Testing"])
7
+ h = e.render
8
+ h.assert.index "<h1>Testing</h1>"
9
+ end
10
+
11
+ test "raises NotImplementedError if converstion format not supported" do
12
+ e = Malt::Engine::Builder.new
13
+ expect NotImplementedError do
14
+ e.render(:to=>:DNE, :text=>%[h1 "Testing"])
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ method :create_engine do
21
+
22
+ test "returns an ::Builder::XmlMarkup instance" do
23
+ e = Malt::Engine::Builder.new
24
+ r = e.create_engine(:text=>%[h1 "Testing"])
25
+ r.assert.is_a? ::Builder::XmlMarkup
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,30 @@
1
+ testcase Malt::Engine::Coffee do
2
+
3
+ method :render do
4
+
5
+ test "convert Coffee text" do
6
+ e = Malt::Engine::Coffee.new(:text=>"square = (x) -> x * x")
7
+ h = e.render
8
+ h.assert.index "square = function(x) {\n return x * x;\n };"
9
+ end
10
+
11
+ test "raises NotImplementedError if converstion format not supported" do
12
+ e = Malt::Engine::Coffee.new
13
+ expect NotImplementedError do
14
+ e.render(:to=>:DNE, :text=>"square = (x) -> x * x")
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ #method :intermediate do
21
+ #
22
+ # test "returns an ::Coffee instance" do
23
+ # e = Malt::Engine::Coffee.new
24
+ # r = e.intermediate(:text=>"square = (x) -> x * x")
25
+ # r.assert.is_a? ::Coffee
26
+ # end
27
+ #
28
+ #end
29
+
30
+ end
@@ -0,0 +1,35 @@
1
+ testcase Malt::Engine::Creole do
2
+
3
+ method :render do
4
+
5
+ test "convert media wiki text to HTML by default" do
6
+ e = Malt::Engine::Creole.new(:text=>"== Testing ==")
7
+ h = e.render
8
+ h.assert.index "<h2>" # so complicated that we're lucky to find it ;)
9
+ h.assert.index "Testing"
10
+ end
11
+
12
+ end
13
+
14
+ method :prepare_engine do
15
+
16
+ test "returns a Creole instance" do
17
+ e = Malt::Engine::Creole.new
18
+ r = e.prepare_engine(:text=>"== Testing ==")
19
+ r.assert.is_a? ::Creole::Parser
20
+ end
21
+
22
+ end
23
+
24
+ method :create_engine do
25
+
26
+ test "returns a Creole instance" do
27
+ e = Malt::Engine::Creole.new
28
+ r = e.create_engine(:text=>"== Testing ==")
29
+ r.assert.is_a? ::Creole::Parser
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
@@ -0,0 +1,28 @@
1
+ testcase Malt::Engine::Erb do
2
+
3
+ method :render do
4
+
5
+ test "convert ERB text" do
6
+ e = Malt::Engine::Erb.new(:text=>"<h1><%= title %></h1>")
7
+ h = e.render(:locals=>{:title=>'Testing'})
8
+ h.assert.index "<h1>Testing</h1>"
9
+ end
10
+
11
+ test "Erb is converstion format agnostic" do
12
+ e = Malt::Engine::Erb.new
13
+ e.render(:to=>:DNE, :text=>"<h1>Testing</h1>")
14
+ end
15
+
16
+ end
17
+
18
+ method :prepare_engine do
19
+
20
+ test "returns an ERB instance" do
21
+ e = Malt::Engine::Erb.new
22
+ r = e.prepare_engine(:text=>"=<h1><%= title %></h1>")
23
+ r.assert.is_a? ::ERB
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,36 @@
1
+ testcase Malt::Engine::Erector do
2
+
3
+ method :render do
4
+
5
+ test "convert Erector template" do
6
+ e = Malt::Engine::Erector.new(:text=>"h1 'Testing'")
7
+ h = e.render
8
+ h.assert.index "<h1>Testing</h1>"
9
+ end
10
+
11
+ end
12
+
13
+ # NOTE: truth is these will probably become private so there isn't
14
+ # really necessary to test them directly.
15
+
16
+ method :prepare_engine do
17
+
18
+ test "returns an instance of a subclass of Erector::Widget" do
19
+ e = Malt::Engine::Erector.new
20
+ r = e.prepare_engine(:text=>"h1 'Testing'")
21
+ assert r.is_a?(::Erector::Widget) # do it this way b/c of odd warning
22
+ end
23
+
24
+ end
25
+
26
+ method :create_engine do
27
+
28
+ test "returns a subclass of Erector::Widget" do
29
+ e = Malt::Engine::Erector.new
30
+ r = e.create_engine(:text=>"h1 'Testing'")
31
+ r.assert < ::Erector::Widget
32
+ end
33
+
34
+ end
35
+
36
+ end