milk 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. data/INSTALL +8 -0
  2. data/LICENSE +24 -17
  3. data/README +3 -0
  4. data/Rakefile +21 -56
  5. data/bin/milk +2 -19
  6. data/doc/classes/Milk.html +198 -0
  7. data/doc/classes/Milk.src/M000005.html +17 -0
  8. data/doc/classes/Milk/Application.html +209 -0
  9. data/doc/classes/Milk/Application.src/M000007.html +69 -0
  10. data/doc/classes/Milk/Application.src/M000008.html +38 -0
  11. data/doc/classes/Milk/Component.html +397 -0
  12. data/doc/classes/Milk/Component.src/M000014.html +19 -0
  13. data/doc/classes/Milk/Component.src/M000015.html +16 -0
  14. data/doc/classes/Milk/Component.src/M000016.html +15 -0
  15. data/doc/classes/Milk/Component.src/M000017.html +15 -0
  16. data/doc/classes/Milk/Component.src/M000018.html +15 -0
  17. data/doc/classes/Milk/Component.src/M000019.html +15 -0
  18. data/doc/classes/Milk/Component.src/M000020.html +15 -0
  19. data/doc/classes/Milk/Component.src/M000021.html +15 -0
  20. data/doc/classes/Milk/Component.src/M000022.html +18 -0
  21. data/doc/classes/Milk/Component.src/M000023.html +21 -0
  22. data/doc/classes/Milk/Component.src/M000024.html +15 -0
  23. data/doc/classes/Milk/Component.src/M000025.html +22 -0
  24. data/doc/classes/Milk/ExternalCompilerError.html +117 -0
  25. data/doc/classes/Milk/Field.html +114 -0
  26. data/doc/classes/Milk/Fields.html +173 -0
  27. data/doc/classes/Milk/Fields/ComponentArray.html +114 -0
  28. data/doc/classes/Milk/Fields/ImageChooser.html +114 -0
  29. data/doc/classes/Milk/Fields/MarkdownField.html +114 -0
  30. data/doc/classes/Milk/Fields/PageChooser.html +114 -0
  31. data/doc/classes/Milk/Fields/SpriteChooser.html +114 -0
  32. data/doc/classes/Milk/Fields/TextField.html +114 -0
  33. data/doc/classes/Milk/Haxe.html +208 -0
  34. data/doc/classes/Milk/Haxe.src/M000005.html +40 -0
  35. data/doc/classes/Milk/Haxe.src/M000006.html +15 -0
  36. data/doc/classes/Milk/Page.html +243 -0
  37. data/doc/classes/Milk/Page.src/M000009.html +17 -0
  38. data/doc/classes/Milk/Page.src/M000010.html +17 -0
  39. data/doc/classes/Milk/Page.src/M000011.html +18 -0
  40. data/doc/classes/Milk/Page.src/M000012.html +20 -0
  41. data/doc/classes/Milk/Page.src/M000013.html +21 -0
  42. data/doc/classes/Milk/PageNotFoundError.html +110 -0
  43. data/doc/classes/Object.html +237 -0
  44. data/doc/classes/Object.src/M000001.html +13 -0
  45. data/doc/classes/Object.src/M000002.html +13 -0
  46. data/doc/classes/Object.src/M000003.html +15 -0
  47. data/doc/classes/Object.src/M000004.html +15 -0
  48. data/doc/created.rid +1 -0
  49. data/doc/files/INSTALL.html +106 -0
  50. data/doc/files/LICENSE.html +126 -0
  51. data/doc/files/README.html +100 -0
  52. data/doc/files/Rakefile.html +121 -0
  53. data/doc/files/bin/milk.html +100 -0
  54. data/doc/files/doc/classes/Milk/Application_html.html +302 -0
  55. data/doc/files/doc/classes/Milk/Application_src/M000007_html.html +173 -0
  56. data/doc/files/doc/classes/Milk/Application_src/M000008_html.html +142 -0
  57. data/doc/files/doc/classes/Milk/Component_html.html +477 -0
  58. data/doc/files/doc/classes/Milk/Component_src/M000014_html.html +123 -0
  59. data/doc/files/doc/classes/Milk/Component_src/M000015_html.html +120 -0
  60. data/doc/files/doc/classes/Milk/Component_src/M000016_html.html +119 -0
  61. data/doc/files/doc/classes/Milk/Component_src/M000017_html.html +119 -0
  62. data/doc/files/doc/classes/Milk/Component_src/M000018_html.html +119 -0
  63. data/doc/files/doc/classes/Milk/Component_src/M000019_html.html +119 -0
  64. data/doc/files/doc/classes/Milk/Component_src/M000020_html.html +119 -0
  65. data/doc/files/doc/classes/Milk/Component_src/M000021_html.html +119 -0
  66. data/doc/files/doc/classes/Milk/Component_src/M000022_html.html +122 -0
  67. data/doc/files/doc/classes/Milk/Component_src/M000023_html.html +125 -0
  68. data/doc/files/doc/classes/Milk/Component_src/M000024_html.html +119 -0
  69. data/doc/files/doc/classes/Milk/Component_src/M000025_html.html +126 -0
  70. data/doc/files/doc/classes/Milk/ExternalCompilerError_html.html +214 -0
  71. data/doc/files/doc/classes/Milk/Field_html.html +209 -0
  72. data/doc/files/doc/classes/Milk/Fields/ComponentArray_html.html +209 -0
  73. data/doc/files/doc/classes/Milk/Fields/ImageChooser_html.html +209 -0
  74. data/doc/files/doc/classes/Milk/Fields/MarkdownField_html.html +209 -0
  75. data/doc/files/doc/classes/Milk/Fields/PageChooser_html.html +209 -0
  76. data/doc/files/doc/classes/Milk/Fields/SpriteChooser_html.html +209 -0
  77. data/doc/files/doc/classes/Milk/Fields/TextField_html.html +209 -0
  78. data/doc/files/doc/classes/Milk/Fields_html.html +264 -0
  79. data/doc/files/doc/classes/Milk/Haxe_html.html +298 -0
  80. data/doc/files/doc/classes/Milk/Haxe_src/M000005_html.html +144 -0
  81. data/doc/files/doc/classes/Milk/Haxe_src/M000006_html.html +119 -0
  82. data/doc/files/doc/classes/Milk/PageNotFoundError_html.html +205 -0
  83. data/doc/files/doc/classes/Milk/Page_html.html +330 -0
  84. data/doc/files/doc/classes/Milk/Page_src/M000009_html.html +121 -0
  85. data/doc/files/doc/classes/Milk/Page_src/M000010_html.html +121 -0
  86. data/doc/files/doc/classes/Milk/Page_src/M000011_html.html +122 -0
  87. data/doc/files/doc/classes/Milk/Page_src/M000012_html.html +124 -0
  88. data/doc/files/doc/classes/Milk/Page_src/M000013_html.html +125 -0
  89. data/doc/files/doc/classes/Milk_html.html +321 -0
  90. data/doc/files/doc/classes/Object_html.html +334 -0
  91. data/doc/files/doc/classes/Object_src/M000001_html.html +117 -0
  92. data/doc/files/doc/classes/Object_src/M000002_html.html +117 -0
  93. data/doc/files/doc/classes/Object_src/M000003_html.html +119 -0
  94. data/doc/files/doc/classes/Object_src/M000004_html.html +119 -0
  95. data/doc/files/doc/created_rid.html +97 -0
  96. data/doc/files/doc/files/INSTALL_html.html +206 -0
  97. data/doc/files/doc/files/LICENSE_html.html +226 -0
  98. data/doc/files/doc/files/README_html.html +201 -0
  99. data/doc/files/doc/files/Rakefile_html.html +221 -0
  100. data/doc/files/doc/files/bin/milk_html.html +198 -0
  101. data/doc/files/doc/files/lib/milk/application_rb_html.html +188 -0
  102. data/doc/files/doc/files/lib/milk/component_rb_html.html +188 -0
  103. data/doc/files/doc/files/lib/milk/field_rb_html.html +188 -0
  104. data/doc/files/doc/files/lib/milk/fields/component_array_rb_html.html +188 -0
  105. data/doc/files/doc/files/lib/milk/fields/image_chooser_rb_html.html +188 -0
  106. data/doc/files/doc/files/lib/milk/fields/markdown_field_rb_html.html +188 -0
  107. data/doc/files/doc/files/lib/milk/fields/page_chooser_rb_html.html +188 -0
  108. data/doc/files/doc/files/lib/milk/fields/sprite_chooser_rb_html.html +188 -0
  109. data/doc/files/doc/files/lib/milk/fields/text_field_rb_html.html +188 -0
  110. data/doc/files/doc/files/lib/milk/fields/xhtml_haml_html.html +211 -0
  111. data/doc/files/doc/files/lib/milk/haxe_rb_html.html +188 -0
  112. data/doc/files/doc/files/lib/milk/page_rb_html.html +188 -0
  113. data/doc/files/doc/files/lib/milk/tasks_rb_html.html +202 -0
  114. data/doc/files/doc/files/lib/milk/templates/bzrignore_html.html +197 -0
  115. data/doc/files/doc/files/lib/milk/templates/rackup_html.html +217 -0
  116. data/doc/files/doc/files/lib/milk/templates/rakefile_html.html +198 -0
  117. data/doc/files/doc/files/lib/milk/templates/restart_html.html +197 -0
  118. data/doc/files/doc/files/lib/milk_rb_html.html +197 -0
  119. data/doc/files/doc/fr_class_index_html.html +160 -0
  120. data/doc/files/doc/fr_file_index_html.html +174 -0
  121. data/doc/files/doc/fr_method_index_html.html +178 -0
  122. data/doc/files/doc/index_html.html +128 -0
  123. data/doc/files/doc/rdoc-style_css.html +665 -0
  124. data/doc/files/lib/milk/application_rb.html +90 -0
  125. data/doc/files/lib/milk/component_rb.html +90 -0
  126. data/doc/files/lib/milk/field_rb.html +90 -0
  127. data/doc/files/lib/milk/fields/component_array_rb.html +90 -0
  128. data/doc/files/lib/milk/fields/image_chooser_rb.html +90 -0
  129. data/doc/files/lib/milk/fields/markdown_field_rb.html +90 -0
  130. data/doc/files/lib/milk/fields/page_chooser_rb.html +90 -0
  131. data/doc/files/lib/milk/fields/sprite_chooser_rb.html +90 -0
  132. data/doc/files/lib/milk/fields/text_field_rb.html +90 -0
  133. data/doc/files/lib/milk/fields/xhtml_haml.html +107 -0
  134. data/doc/files/lib/milk/haxe_rb.html +90 -0
  135. data/doc/files/lib/milk/page_rb.html +90 -0
  136. data/doc/files/lib/milk/tasks_rb.html +104 -0
  137. data/doc/files/lib/milk/templates/bzrignore.html +97 -0
  138. data/doc/files/lib/milk/templates/rackup.html +119 -0
  139. data/doc/files/lib/milk/templates/rakefile.html +98 -0
  140. data/doc/files/lib/milk/templates/restart.html +97 -0
  141. data/doc/files/lib/milk_rb.html +97 -0
  142. data/doc/fr_class_index.html +27 -0
  143. data/doc/fr_file_index.html +169 -0
  144. data/doc/fr_method_index.html +33 -0
  145. data/doc/index.html +21 -0
  146. data/doc/rdoc-style.css +299 -0
  147. data/lib/milk.rb +58 -0
  148. data/lib/milk/application.rb +98 -0
  149. data/lib/milk/component.rb +73 -0
  150. data/lib/milk/field.rb +16 -0
  151. data/lib/milk/fields/component_array.rb +4 -0
  152. data/lib/milk/fields/image_chooser.rb +4 -0
  153. data/lib/milk/fields/markdown_field.rb +4 -0
  154. data/lib/milk/fields/page_chooser.rb +4 -0
  155. data/lib/milk/fields/sprite_chooser.rb +4 -0
  156. data/lib/milk/fields/text_field.rb +4 -0
  157. data/lib/milk/fields/xhtml.haml +10 -0
  158. data/lib/milk/haxe.rb +139 -0
  159. data/lib/milk/page.rb +45 -0
  160. data/lib/milk/tasks.rb +89 -0
  161. data/lib/milk/templates/bzrignore +3 -0
  162. data/lib/milk/templates/rackup +16 -0
  163. data/lib/milk/templates/rakefile +4 -0
  164. data/lib/milk/templates/restart +1 -0
  165. metadata +246 -26
  166. data/.document +0 -5
  167. data/.gitignore +0 -5
  168. data/README.rdoc +0 -7
  169. data/test/milk_test.rb +0 -7
  170. data/test/test_helper.rb +0 -10
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <!--
5
+
6
+ Methods [RDoc Documentation]
7
+
8
+ -->
9
+ <head>
10
+ <title>Methods [RDoc Documentation]</title>
11
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
12
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
13
+ <base target="docwin" />
14
+ </head>
15
+ <body>
16
+ <div class="index">
17
+ <h1 class="section-bar">Methods</h1>
18
+ <div id="index-entries">
19
+
20
+ <a href="classes/Object.html#M000004">class_def (Object)</a><br />
21
+
22
+ <a href="classes/Milk.html#M000005">get_milk_root (Milk)</a><br />
23
+
24
+ <a href="classes/Object.html#M000003">meta_def (Object)</a><br />
25
+
26
+ <a href="classes/Object.html#M000002">meta_eval (Object)</a><br />
27
+
28
+ <a href="classes/Object.html#M000001">metaclass (Object)</a><br />
29
+
30
+ </div>
31
+ </div>
32
+ </body>
33
+ </html>
@@ -0,0 +1,21 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <!--
5
+
6
+ RDoc Documentation
7
+
8
+ -->
9
+ <head>
10
+ <title>RDoc Documentation</title>
11
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
12
+ </head>
13
+ <frameset rows="20%, 80%">
14
+ <frameset cols="25%,35%,45%">
15
+ <frame src="fr_file_index.html" title="Files" name="Files" />
16
+ <frame src="fr_class_index.html" name="Classes" />
17
+ <frame src="fr_method_index.html" name="Methods" />
18
+ </frameset>
19
+ <frame src="files/Rakefile.html" name="docwin" />
20
+ </frameset>
21
+ </html>
@@ -0,0 +1,299 @@
1
+ body {
2
+ font-family: Verdana,Arial,Helvetica,sans-serif;
3
+ font-size: 90%;
4
+ margin: 0;
5
+ margin-left: 40px;
6
+ padding: 0;
7
+ background: white;
8
+ color: black;
9
+ }
10
+
11
+ h1, h2, h3, h4 {
12
+ margin: 0;
13
+ background: transparent;
14
+ }
15
+
16
+ h1 {
17
+ font-size: 150%;
18
+ }
19
+
20
+ h2,h3,h4 {
21
+ margin-top: 1em;
22
+ }
23
+
24
+ :link, :visited {
25
+ background: #eef;
26
+ color: #039;
27
+ text-decoration: none;
28
+ }
29
+
30
+ :link:hover, :visited:hover {
31
+ background: #039;
32
+ color: #eef;
33
+ }
34
+
35
+ /* Override the base stylesheet's Anchor inside a table cell */
36
+ td > :link, td > :visited {
37
+ background: transparent;
38
+ color: #039;
39
+ text-decoration: none;
40
+ }
41
+
42
+ /* and inside a section title */
43
+ .section-title > :link, .section-title > :visited {
44
+ background: transparent;
45
+ color: #eee;
46
+ text-decoration: none;
47
+ }
48
+
49
+ /* === Structural elements =================================== */
50
+
51
+ .index {
52
+ margin: 0;
53
+ margin-left: -40px;
54
+ padding: 0;
55
+ font-size: 90%;
56
+ }
57
+
58
+ .index :link, .index :visited {
59
+ margin-left: 0.7em;
60
+ }
61
+
62
+ .index .section-bar {
63
+ margin-left: 0px;
64
+ padding-left: 0.7em;
65
+ background: #ccc;
66
+ font-size: small;
67
+ }
68
+
69
+ #classHeader, #fileHeader {
70
+ width: auto;
71
+ color: white;
72
+ padding: 0.5em 1.5em 0.5em 1.5em;
73
+ margin: 0;
74
+ margin-left: -40px;
75
+ border-bottom: 3px solid #006;
76
+ }
77
+
78
+ #classHeader :link, #fileHeader :link,
79
+ #classHeader :visited, #fileHeader :visited {
80
+ background: inherit;
81
+ color: white;
82
+ }
83
+
84
+ #classHeader td, #fileHeader td {
85
+ background: inherit;
86
+ color: white;
87
+ }
88
+
89
+ #fileHeader {
90
+ background: #057;
91
+ }
92
+
93
+ #classHeader {
94
+ background: #048;
95
+ }
96
+
97
+ .class-name-in-header {
98
+ font-size: 180%;
99
+ font-weight: bold;
100
+ }
101
+
102
+ #bodyContent {
103
+ padding: 0 1.5em 0 1.5em;
104
+ }
105
+
106
+ #description {
107
+ padding: 0.5em 1.5em;
108
+ background: #efefef;
109
+ border: 1px dotted #999;
110
+ }
111
+
112
+ #description h1, #description h2, #description h3,
113
+ #description h4, #description h5, #description h6 {
114
+ color: #125;
115
+ background: transparent;
116
+ }
117
+
118
+ #validator-badges {
119
+ text-align: center;
120
+ }
121
+
122
+ #validator-badges img {
123
+ border: 0;
124
+ }
125
+
126
+ #copyright {
127
+ color: #333;
128
+ background: #efefef;
129
+ font: 0.75em sans-serif;
130
+ margin-top: 5em;
131
+ margin-bottom: 0;
132
+ padding: 0.5em 2em;
133
+ }
134
+
135
+ /* === Classes =================================== */
136
+
137
+ table.header-table {
138
+ color: white;
139
+ font-size: small;
140
+ }
141
+
142
+ .type-note {
143
+ font-size: small;
144
+ color: #dedede;
145
+ }
146
+
147
+ .section-bar {
148
+ color: #333;
149
+ border-bottom: 1px solid #999;
150
+ margin-left: -20px;
151
+ }
152
+
153
+ .section-title {
154
+ background: #79a;
155
+ color: #eee;
156
+ padding: 3px;
157
+ margin-top: 2em;
158
+ margin-left: -30px;
159
+ border: 1px solid #999;
160
+ }
161
+
162
+ .top-aligned-row {
163
+ vertical-align: top
164
+ }
165
+
166
+ .bottom-aligned-row {
167
+ vertical-align: bottom
168
+ }
169
+
170
+ #diagram img {
171
+ border: 0;
172
+ }
173
+
174
+ /* --- Context section classes ----------------------- */
175
+
176
+ .context-row { }
177
+
178
+ .context-item-name {
179
+ font-family: monospace;
180
+ font-weight: bold;
181
+ color: black;
182
+ }
183
+
184
+ .context-item-value {
185
+ font-size: small;
186
+ color: #448;
187
+ }
188
+
189
+ .context-item-desc {
190
+ color: #333;
191
+ padding-left: 2em;
192
+ }
193
+
194
+ /* --- Method classes -------------------------- */
195
+
196
+ .method-detail {
197
+ background: #efefef;
198
+ padding: 0;
199
+ margin-top: 0.5em;
200
+ margin-bottom: 1em;
201
+ border: 1px dotted #ccc;
202
+ }
203
+
204
+ .method-heading {
205
+ color: black;
206
+ background: #ccc;
207
+ border-bottom: 1px solid #666;
208
+ padding: 0.2em 0.5em 0 0.5em;
209
+ }
210
+
211
+ .method-signature {
212
+ color: black;
213
+ background: inherit;
214
+ }
215
+
216
+ .method-name {
217
+ font-weight: bold;
218
+ }
219
+
220
+ .method-args {
221
+ font-style: italic;
222
+ }
223
+
224
+ .method-description {
225
+ padding: 0 0.5em 0 0.5em;
226
+ }
227
+
228
+ /* --- Source code sections -------------------- */
229
+
230
+ :link.source-toggle, :visited.source-toggle {
231
+ font-size: 90%;
232
+ }
233
+
234
+ div.method-source-code {
235
+ background: #262626;
236
+ color: #ffdead;
237
+ margin: 1em;
238
+ padding: 0.5em;
239
+ border: 1px dashed #999;
240
+ overflow: auto;
241
+ }
242
+
243
+ div.method-source-code pre {
244
+ color: #ffdead;
245
+ }
246
+
247
+ /* --- Ruby keyword styles --------------------- */
248
+
249
+ .standalone-code {
250
+ background: #221111;
251
+ color: #ffdead;
252
+ overflow: auto;
253
+ }
254
+
255
+ .ruby-constant {
256
+ color: #7fffd4;
257
+ background: transparent;
258
+ }
259
+
260
+ .ruby-keyword {
261
+ color: #00ffff;
262
+ background: transparent;
263
+ }
264
+
265
+ .ruby-ivar {
266
+ color: #eedd82;
267
+ background: transparent;
268
+ }
269
+
270
+ .ruby-operator {
271
+ color: #00ffee;
272
+ background: transparent;
273
+ }
274
+
275
+ .ruby-identifier {
276
+ color: #ffdead;
277
+ background: transparent;
278
+ }
279
+
280
+ .ruby-node {
281
+ color: #ffa07a;
282
+ background: transparent;
283
+ }
284
+
285
+ .ruby-comment {
286
+ color: #b22222;
287
+ font-weight: bold;
288
+ background: transparent;
289
+ }
290
+
291
+ .ruby-regexp {
292
+ color: #ffa07a;
293
+ background: transparent;
294
+ }
295
+
296
+ .ruby-value {
297
+ color: #7fffd4;
298
+ background: transparent;
299
+ }
@@ -0,0 +1,58 @@
1
+ # Autoload some useful libraries
2
+ autoload 'Haml', 'haml'
3
+ autoload 'Sass', 'sass'
4
+ autoload 'Maruku', 'maruku'
5
+ autoload 'YAML', 'yaml'
6
+ autoload 'FileUtils', 'fileutils'
7
+
8
+ # Set up our main namespace with autoloaded parts
9
+ module Milk
10
+ VERSION = '0.0.1'
11
+
12
+ LIB_DIR = File.dirname(__FILE__)
13
+ BIN_DIR = File.absolute_path(File.dirname(__FILE__)+"/../../local/bin")
14
+ def self.get_milk_root
15
+ c = caller(1).collect { |line| line.split(':').first }
16
+ c = c.select { |line| line !~ /\/gems\// }
17
+ File.absolute_path(File.dirname(c.first))
18
+ end
19
+ MILK_ROOT ||= get_milk_root
20
+ COMPONENTS_DIR = MILK_ROOT + "/design"
21
+ PAGES_DIR = MILK_ROOT + "/pages"
22
+ PUBLIC_DIR = MILK_ROOT + "/public"
23
+
24
+ $LOAD_PATH.unshift(LIB_DIR) unless $LOAD_PATH.include?(LIB_DIR)
25
+ autoload :Application, "milk/application"
26
+ autoload :Component, "milk/component"
27
+ autoload :Page, "milk/page"
28
+ autoload :Haxe, "milk/haxe"
29
+ autoload :Field, "milk/field"
30
+ autoload :Fields, "milk/field"
31
+ end
32
+
33
+ # Autoload the components of the user space app into the root namespace for easy use
34
+ Dir.glob(Milk::COMPONENTS_DIR + "/*.rb").each do |c|
35
+ name = c.split('/').last.gsub(/(.*)\.rb/) { $1 }
36
+ class_name = name.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
37
+ path = c.gsub(/(.*)\.rb/) { $1 }
38
+ autoload class_name.to_sym, path
39
+ end
40
+
41
+ # Include metaid for easy metaclass management
42
+ class Object
43
+ # The hidden singleton lurks behind everyone
44
+ def metaclass; class << self; self; end; end
45
+ def meta_eval &blk; metaclass.instance_eval &blk; end
46
+
47
+ # Adds methods to a metaclass
48
+ def meta_def name, &blk
49
+ meta_eval { define_method name, &blk }
50
+ end
51
+
52
+ # Defines an instance method within a class
53
+ def class_def name, &blk
54
+ class_eval { define_method name, &blk }
55
+ end
56
+ end
57
+
58
+
@@ -0,0 +1,98 @@
1
+ module Milk
2
+ class Application
3
+
4
+ PAGE_PATH_REGEX = /^\/([A-Z][a-zA-Z]+(\/[A-Z][a-zA-Z]+)*)+\/*$/
5
+ EDIT_PATH_REGEX = /^\/([A-Z][a-zA-Z]+(\/[A-Z][a-zA-Z]+)*)+\/edit\/*$/
6
+ HAXE_PATH_REGEX = /^\/(.*).hx$/
7
+
8
+ def route(req)
9
+ path = req.path_info
10
+
11
+ if path == '/'
12
+ # Special case for root
13
+ path = '/Home'
14
+ end
15
+
16
+ # Fallback to match everything
17
+ regex = /(.*)/
18
+
19
+ # Route the request to the right callback
20
+ action = case
21
+ when req.get?
22
+ case
23
+ when path =~ HAXE_PATH_REGEX
24
+ regex = HAXE_PATH_REGEX
25
+ :haxe
26
+ when path =~ PAGE_PATH_REGEX
27
+ regex = PAGE_PATH_REGEX
28
+ :view
29
+ when path =~ EDIT_PATH_REGEX
30
+ regex = EDIT_PATH_REGEX
31
+ :edit
32
+ end
33
+ when req.delete?
34
+ if path =~ PAGE_PATH_REGEX
35
+ regex = PAGE_PATH_REGEX
36
+ :delete
37
+ end
38
+ when req.put?
39
+ if path =~ PAGE_PATH_REGEX
40
+ regex = PAGE_PATH_REGEX
41
+ :save
42
+ end
43
+ end || :not_found
44
+
45
+ page_name = regex.match(path)[1]
46
+
47
+ if (action == :view || action == :edit)
48
+ begin
49
+ page = Milk::Page.find(page_name)
50
+ rescue Milk::PageNotFoundError
51
+ action = :not_found
52
+ end
53
+ end
54
+
55
+ if (action == :haxe)
56
+ begin
57
+ page = Milk::Haxe.new(page_name)
58
+ rescue Milk::PageNotFoundError
59
+ action = :not_found
60
+ end
61
+ end
62
+
63
+ return action, page_name, page
64
+ end
65
+
66
+ # Rack call interface
67
+ def call(env)
68
+ req = Rack::Request.new(env)
69
+
70
+ # Route the request
71
+ action, page_name, page = route(req)
72
+
73
+ # Send proper mime types for browsers that claim to accept it
74
+ if env['HTTP_ACCEPT'].include? "application/xhtml+xml"
75
+ html_type = "application/xhtml+xml"
76
+ else
77
+ html_type = "text/html"
78
+ end
79
+
80
+ case action
81
+ when :haxe
82
+ [200, {"Content-Type"=>"application/x-shockwave-flash"}, [page]]
83
+ when :not_found
84
+ [404, {"Content-Type"=>html_type}, [Milk::Page.find('NotFound').view]]
85
+ when :view
86
+ [200, {"Content-Type"=>html_type}, [page.view]]
87
+ when :edit
88
+ [200, {"Content-Type"=>html_type}, [page.edit]]
89
+ else
90
+ [500, {"Content-Type"=>html_type}, [action.to_s]]
91
+ end
92
+ end
93
+ end
94
+
95
+ class PageNotFoundError < Exception
96
+ end
97
+ end
98
+