orange 0.5.5 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. data/lib/orange.rb +2 -5
  2. data/spec/orange_spec.rb +5 -0
  3. data/spec/{orange-core/spec_helper.rb → spec_helper.rb} +0 -0
  4. metadata +28 -235
  5. data/lib/orange-core.rb +0 -8
  6. data/lib/orange-core/application.rb +0 -132
  7. data/lib/orange-core/assets/css/exceptions.css +0 -50
  8. data/lib/orange-core/assets/js/exceptions.js +0 -44
  9. data/lib/orange-core/carton.rb +0 -178
  10. data/lib/orange-core/core.rb +0 -266
  11. data/lib/orange-core/magick.rb +0 -270
  12. data/lib/orange-core/middleware/base.rb +0 -96
  13. data/lib/orange-core/middleware/database.rb +0 -45
  14. data/lib/orange-core/middleware/four_oh_four.rb +0 -45
  15. data/lib/orange-core/middleware/globals.rb +0 -17
  16. data/lib/orange-core/middleware/loader.rb +0 -13
  17. data/lib/orange-core/middleware/rerouter.rb +0 -53
  18. data/lib/orange-core/middleware/restful_router.rb +0 -99
  19. data/lib/orange-core/middleware/route_context.rb +0 -39
  20. data/lib/orange-core/middleware/route_site.rb +0 -51
  21. data/lib/orange-core/middleware/show_exceptions.rb +0 -80
  22. data/lib/orange-core/middleware/static.rb +0 -67
  23. data/lib/orange-core/middleware/static_file.rb +0 -32
  24. data/lib/orange-core/middleware/template.rb +0 -60
  25. data/lib/orange-core/packet.rb +0 -232
  26. data/lib/orange-core/plugin.rb +0 -172
  27. data/lib/orange-core/resource.rb +0 -96
  28. data/lib/orange-core/resources/mapper.rb +0 -36
  29. data/lib/orange-core/resources/model_resource.rb +0 -228
  30. data/lib/orange-core/resources/not_found.rb +0 -10
  31. data/lib/orange-core/resources/page_parts.rb +0 -68
  32. data/lib/orange-core/resources/parser.rb +0 -113
  33. data/lib/orange-core/resources/routable_resource.rb +0 -16
  34. data/lib/orange-core/resources/scaffold.rb +0 -106
  35. data/lib/orange-core/stack.rb +0 -226
  36. data/lib/orange-core/templates/exceptions.haml +0 -111
  37. data/lib/orange-core/views/default_resource/create.haml +0 -4
  38. data/lib/orange-core/views/default_resource/edit.haml +0 -9
  39. data/lib/orange-core/views/default_resource/list.haml +0 -10
  40. data/lib/orange-core/views/default_resource/show.haml +0 -4
  41. data/lib/orange-core/views/default_resource/table_row.haml +0 -7
  42. data/lib/orange-core/views/not_found/404.haml +0 -2
  43. data/lib/orange-more.rb +0 -23
  44. data/lib/orange-more/administration.rb +0 -1
  45. data/lib/orange-more/administration/assets/css/admin.css +0 -286
  46. data/lib/orange-more/administration/assets/css/blueprint-ie.css +0 -35
  47. data/lib/orange-more/administration/assets/css/blueprint-print.css +0 -29
  48. data/lib/orange-more/administration/assets/css/blueprint.css +0 -257
  49. data/lib/orange-more/administration/assets/js/jquery.js +0 -152
  50. data/lib/orange-more/administration/cartons/site.rb +0 -7
  51. data/lib/orange-more/administration/cartons/site_carton.rb +0 -12
  52. data/lib/orange-more/administration/cartons/user.rb +0 -27
  53. data/lib/orange-more/administration/middleware/access_control.rb +0 -156
  54. data/lib/orange-more/administration/middleware/site_load.rb +0 -25
  55. data/lib/orange-more/administration/plugin.rb +0 -23
  56. data/lib/orange-more/administration/resources/admin_resource.rb +0 -27
  57. data/lib/orange-more/administration/resources/site_resource.rb +0 -10
  58. data/lib/orange-more/administration/resources/user_resource.rb +0 -40
  59. data/lib/orange-more/administration/templates/admin.haml +0 -25
  60. data/lib/orange-more/administration/views/openid_login.haml +0 -14
  61. data/lib/orange-more/administration/views/users/create.haml +0 -10
  62. data/lib/orange-more/administration/views/users/edit.haml +0 -15
  63. data/lib/orange-more/adverts.rb +0 -1
  64. data/lib/orange-more/adverts/cartons/adverts_carton.rb +0 -14
  65. data/lib/orange-more/adverts/plugin.rb +0 -13
  66. data/lib/orange-more/adverts/resources/adverts_resource.rb +0 -27
  67. data/lib/orange-more/adverts/views/adverts/adverts.haml +0 -2
  68. data/lib/orange-more/analytics.rb +0 -1
  69. data/lib/orange-more/analytics/middleware/analytics.rb +0 -30
  70. data/lib/orange-more/analytics/plugin.rb +0 -11
  71. data/lib/orange-more/analytics/resources/analytics_resource.rb +0 -42
  72. data/lib/orange-more/assets.rb +0 -1
  73. data/lib/orange-more/assets/cartons/asset_carton.rb +0 -27
  74. data/lib/orange-more/assets/plugin.rb +0 -13
  75. data/lib/orange-more/assets/resources/asset_resource.rb +0 -115
  76. data/lib/orange-more/assets/views/assets/change.haml +0 -1
  77. data/lib/orange-more/assets/views/assets/create.haml +0 -13
  78. data/lib/orange-more/assets/views/assets/insert.haml +0 -1
  79. data/lib/orange-more/blog.rb +0 -1
  80. data/lib/orange-more/blog/cartons/blog.rb +0 -8
  81. data/lib/orange-more/blog/cartons/blog_post.rb +0 -60
  82. data/lib/orange-more/blog/plugin.rb +0 -14
  83. data/lib/orange-more/blog/resources/blog_post_resource.rb +0 -53
  84. data/lib/orange-more/blog/resources/blog_resource.rb +0 -104
  85. data/lib/orange-more/blog/views/blog/blog_archive_view.haml +0 -6
  86. data/lib/orange-more/blog/views/blog/blog_offset_list_view.haml +0 -12
  87. data/lib/orange-more/blog/views/blog/blog_post_view.haml +0 -4
  88. data/lib/orange-more/blog/views/blog/sitemap_row.haml +0 -14
  89. data/lib/orange-more/blog/views/blog_posts/edit.haml +0 -8
  90. data/lib/orange-more/blog/views/blog_posts/show.haml +0 -4
  91. data/lib/orange-more/cloud.rb +0 -1
  92. data/lib/orange-more/cloud/plugin.rb +0 -10
  93. data/lib/orange-more/cloud/resources/cloud_resource.rb +0 -21
  94. data/lib/orange-more/contactforms.rb +0 -1
  95. data/lib/orange-more/contactforms/assets/js/jquery.validate.pack.js +0 -15
  96. data/lib/orange-more/contactforms/assets/js/lib/jquery-1.4.2.js +0 -6240
  97. data/lib/orange-more/contactforms/assets/js/lib/jquery.form.js +0 -660
  98. data/lib/orange-more/contactforms/assets/js/lib/jquery.js +0 -4376
  99. data/lib/orange-more/contactforms/assets/js/lib/jquery.metadata.js +0 -122
  100. data/lib/orange-more/contactforms/cartons/contactforms_carton.rb +0 -12
  101. data/lib/orange-more/contactforms/plugin.rb +0 -13
  102. data/lib/orange-more/contactforms/resources/contactforms_resource.rb +0 -56
  103. data/lib/orange-more/contactforms/views/contactforms/contactform.haml +0 -20
  104. data/lib/orange-more/debugger.rb +0 -1
  105. data/lib/orange-more/debugger/assets/css/debug_bar.css +0 -46
  106. data/lib/orange-more/debugger/middleware/debugger.rb +0 -50
  107. data/lib/orange-more/debugger/plugin.rb +0 -12
  108. data/lib/orange-more/debugger/views/debug_bar.haml +0 -87
  109. data/lib/orange-more/disqus.rb +0 -1
  110. data/lib/orange-more/disqus/plugin.rb +0 -11
  111. data/lib/orange-more/disqus/resources/disqus_resource.rb +0 -9
  112. data/lib/orange-more/disqus/views/disqus/comment_thread.haml +0 -7
  113. data/lib/orange-more/donations.rb +0 -1
  114. data/lib/orange-more/donations/cartons/donation_carton.rb +0 -9
  115. data/lib/orange-more/donations/plugin.rb +0 -12
  116. data/lib/orange-more/donations/resources/donations_resource.rb +0 -51
  117. data/lib/orange-more/donations/views/donations/donate_form.haml +0 -21
  118. data/lib/orange-more/donations/views/donations/donate_thanks.haml +0 -2
  119. data/lib/orange-more/donations/views/donations/paypal_form.haml +0 -13
  120. data/lib/orange-more/events.rb +0 -1
  121. data/lib/orange-more/events/assets/js/events.js +0 -55
  122. data/lib/orange-more/events/cartons/orange_calendar.rb +0 -8
  123. data/lib/orange-more/events/cartons/orange_event.rb +0 -60
  124. data/lib/orange-more/events/plugin.rb +0 -14
  125. data/lib/orange-more/events/resources/calendar_resource.rb +0 -33
  126. data/lib/orange-more/events/resources/event_resource.rb +0 -147
  127. data/lib/orange-more/events/views/calendar/calendar.haml +0 -8
  128. data/lib/orange-more/events/views/events/create.haml +0 -55
  129. data/lib/orange-more/events/views/events/edit.haml +0 -59
  130. data/lib/orange-more/events/views/events/list.haml +0 -13
  131. data/lib/orange-more/events/views/events/show.haml +0 -4
  132. data/lib/orange-more/events/views/events/table_row.haml +0 -17
  133. data/lib/orange-more/members.rb +0 -1
  134. data/lib/orange-more/members/cartons/member_carton.rb +0 -38
  135. data/lib/orange-more/members/plugin.rb +0 -13
  136. data/lib/orange-more/members/resources/members_resource.rb +0 -327
  137. data/lib/orange-more/members/views/members/create.haml +0 -12
  138. data/lib/orange-more/members/views/members/edit.haml +0 -15
  139. data/lib/orange-more/members/views/members/live.show.haml +0 -1
  140. data/lib/orange-more/members/views/members/login.haml +0 -17
  141. data/lib/orange-more/members/views/members/logout.haml +0 -1
  142. data/lib/orange-more/members/views/members/profile.haml +0 -50
  143. data/lib/orange-more/members/views/members/register.haml +0 -37
  144. data/lib/orange-more/news.rb +0 -1
  145. data/lib/orange-more/news/cartons/news.rb +0 -12
  146. data/lib/orange-more/news/plugin.rb +0 -13
  147. data/lib/orange-more/news/resources/news_resource.rb +0 -82
  148. data/lib/orange-more/news/views/news/archive.haml +0 -14
  149. data/lib/orange-more/news/views/news/edit.haml +0 -7
  150. data/lib/orange-more/news/views/news/latest.haml +0 -8
  151. data/lib/orange-more/news/views/news/sitemap_row.haml +0 -14
  152. data/lib/orange-more/pages.rb +0 -1
  153. data/lib/orange-more/pages/cartons/page_carton.rb +0 -14
  154. data/lib/orange-more/pages/cartons/page_version_carton.rb +0 -12
  155. data/lib/orange-more/pages/plugin.rb +0 -13
  156. data/lib/orange-more/pages/resources/page_resource.rb +0 -179
  157. data/lib/orange-more/pages/views/pages/edit.haml +0 -34
  158. data/lib/orange-more/pages/views/pages/show.haml +0 -6
  159. data/lib/orange-more/sitemap.rb +0 -1
  160. data/lib/orange-more/sitemap/assets/img/sitemap_down.png +0 -0
  161. data/lib/orange-more/sitemap/assets/img/sitemap_down_d.png +0 -0
  162. data/lib/orange-more/sitemap/assets/img/sitemap_indent.png +0 -0
  163. data/lib/orange-more/sitemap/assets/img/sitemap_indent_d.png +0 -0
  164. data/lib/orange-more/sitemap/assets/img/sitemap_outdent.png +0 -0
  165. data/lib/orange-more/sitemap/assets/img/sitemap_outdent_d.png +0 -0
  166. data/lib/orange-more/sitemap/assets/img/sitemap_up.png +0 -0
  167. data/lib/orange-more/sitemap/assets/img/sitemap_up_d.png +0 -0
  168. data/lib/orange-more/sitemap/assets/js/sitemap.js +0 -11
  169. data/lib/orange-more/sitemap/cartons/route.rb +0 -43
  170. data/lib/orange-more/sitemap/middleware/flex_router.rb +0 -25
  171. data/lib/orange-more/sitemap/plugin.rb +0 -17
  172. data/lib/orange-more/sitemap/resources/sitemap_resource.rb +0 -295
  173. data/lib/orange-more/sitemap/views/default_resource/sitemap_row.haml +0 -30
  174. data/lib/orange-more/sitemap/views/sitemap/breadcrumb.haml +0 -12
  175. data/lib/orange-more/sitemap/views/sitemap/list.haml +0 -4
  176. data/lib/orange-more/sitemap/views/sitemap/one_level.haml +0 -7
  177. data/lib/orange-more/sitemap/views/sitemap/route_actions.haml +0 -15
  178. data/lib/orange-more/sitemap/views/sitemap/sitemap_links.haml +0 -14
  179. data/lib/orange-more/sitemap/views/sitemap/table_row.haml +0 -30
  180. data/lib/orange-more/sitemap/views/sitemap/two_level.haml +0 -13
  181. data/lib/orange-more/slices.rb +0 -1
  182. data/lib/orange-more/slices/middleware/radius_parser.rb +0 -24
  183. data/lib/orange-more/slices/plugin.rb +0 -15
  184. data/lib/orange-more/slices/resources/radius.rb +0 -117
  185. data/lib/orange-more/slices/resources/slices.rb +0 -35
  186. data/lib/orange-more/subsites.rb +0 -1
  187. data/lib/orange-more/subsites/cartons/subsite.rb +0 -8
  188. data/lib/orange-more/subsites/middleware/subsite_load.rb +0 -29
  189. data/lib/orange-more/subsites/plugin.rb +0 -17
  190. data/lib/orange-more/subsites/resources/subsite_resource.rb +0 -54
  191. data/lib/orange-more/subsites/views/subsites/index.haml +0 -2
  192. data/lib/orange-more/testimonials.rb +0 -1
  193. data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +0 -15
  194. data/lib/orange-more/testimonials/plugin.rb +0 -13
  195. data/lib/orange-more/testimonials/resources/testimonials_resource.rb +0 -42
  196. data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +0 -4
  197. data/spec/orange-core/application_spec.rb +0 -183
  198. data/spec/orange-core/carton_spec.rb +0 -136
  199. data/spec/orange-core/core_spec.rb +0 -248
  200. data/spec/orange-core/magick_spec.rb +0 -96
  201. data/spec/orange-core/middleware/base_spec.rb +0 -38
  202. data/spec/orange-core/middleware/globals_spec.rb +0 -3
  203. data/spec/orange-core/middleware/rerouter_spec.rb +0 -3
  204. data/spec/orange-core/middleware/restful_router_spec.rb +0 -3
  205. data/spec/orange-core/middleware/route_context_spec.rb +0 -3
  206. data/spec/orange-core/middleware/route_site_spec.rb +0 -3
  207. data/spec/orange-core/middleware/show_exceptions_spec.rb +0 -3
  208. data/spec/orange-core/middleware/static_file_spec.rb +0 -3
  209. data/spec/orange-core/middleware/static_spec.rb +0 -3
  210. data/spec/orange-core/mock/mock_app.rb +0 -16
  211. data/spec/orange-core/mock/mock_carton.rb +0 -43
  212. data/spec/orange-core/mock/mock_core.rb +0 -2
  213. data/spec/orange-core/mock/mock_middleware.rb +0 -25
  214. data/spec/orange-core/mock/mock_mixins.rb +0 -19
  215. data/spec/orange-core/mock/mock_model_resource.rb +0 -47
  216. data/spec/orange-core/mock/mock_pulp.rb +0 -24
  217. data/spec/orange-core/mock/mock_resource.rb +0 -26
  218. data/spec/orange-core/mock/mock_router.rb +0 -10
  219. data/spec/orange-core/orange_spec.rb +0 -19
  220. data/spec/orange-core/packet_spec.rb +0 -203
  221. data/spec/orange-core/resource_spec.rb +0 -96
  222. data/spec/orange-core/resources/mapper_spec.rb +0 -5
  223. data/spec/orange-core/resources/model_resource_spec.rb +0 -246
  224. data/spec/orange-core/resources/parser_spec.rb +0 -5
  225. data/spec/orange-core/resources/routable_resource_spec.rb +0 -5
  226. data/spec/orange-core/stack_spec.rb +0 -232
@@ -1,50 +0,0 @@
1
- html * { padding:0; margin:0; }
2
- body * { padding:10px 20px; }
3
- body * * { padding:0; }
4
- body { font:small sans-serif; }
5
- body>div { border-bottom:1px solid #ddd; }
6
- h1 { font-weight:normal; }
7
- h2 { margin-bottom:.8em; }
8
- h2 span { font-size:80%; color:#666; font-weight:normal; }
9
- h3 { margin:1em 0 .5em 0; }
10
- h4 { margin:0 0 .5em 0; font-weight: normal; }
11
- table {
12
- border:1px solid #ccc; border-collapse: collapse; background:white; }
13
- tbody td, tbody th { vertical-align:top; padding:2px 3px; }
14
- thead th {
15
- padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
16
- font-weight:normal; font-size:11px; border:1px solid #ddd; }
17
- tbody th { text-align:right; color:#666; padding-right:.5em; }
18
- table.vars { margin:5px 0 2px 40px; }
19
- table.vars td, table.req td { font-family:monospace; }
20
- table td.code { width:100%;}
21
- table td.code div { overflow:hidden; }
22
- table.source th { color:#666; }
23
- table.source td {
24
- font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
25
- ul.traceback { list-style-type:none; }
26
- ul.traceback li.frame { margin-bottom:1em; }
27
- div.context { margin: 10px 0; }
28
- div.context ol {
29
- padding-left:30px; margin:0 10px; list-style-position: inside; }
30
- div.context ol li {
31
- font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
32
- div.context ol.context-line li { color:black; background-color:#ccc; }
33
- div.context ol.context-line li span { float: right; }
34
- div.commands { margin-left: 40px; }
35
- div.commands a { color:black; text-decoration:none; }
36
- #summary { background: #fda; }
37
- #summary h2 { font-weight: normal; color: #666; }
38
- #summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
39
- #summary ul#quicklinks li { float: left; padding: 0 1em; }
40
- #summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
41
- #explanation { background:#eee; }
42
- #template, #template-not-exist { background:#f6f6f6; }
43
- #template-not-exist ul { margin: 0 0 0 20px; }
44
- #traceback { background:#eee; }
45
- #requestinfo { background:#f6f6f6; padding-left:120px; }
46
- #summary table { border:none; background:transparent; }
47
- #requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
48
- #requestinfo h3 { margin-bottom:-1em; }
49
- .error { background: #ffc; }
50
- .specific { color:#cc3300; font-weight:bold; }
@@ -1,44 +0,0 @@
1
- function getElementsByClassName(oElm, strTagName, strClassName){
2
- // Written by Jonathan Snook, http://www.snook.ca/jon;
3
- // Add-ons by Robert Nyman, http://www.robertnyman.com
4
- var arrElements = (strTagName == "*" && document.all)? document.all :
5
- oElm.getElementsByTagName(strTagName);
6
- var arrReturnElements = new Array();
7
- strClassName = strClassName.replace(/\-/g, "\\-");
8
- var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$$)");
9
- var oElement;
10
- for(var i=0; i<arrElements.length; i++){
11
- oElement = arrElements[i];
12
- if(oRegExp.test(oElement.className)){
13
- arrReturnElements.push(oElement);
14
- }
15
- }
16
- return (arrReturnElements)
17
- }
18
- function hideAll(elems) {
19
- for (var e = 0; e < elems.length; e++) {
20
- elems[e].style.display = 'none';
21
- }
22
- }
23
- window.onload = function() {
24
- hideAll(getElementsByClassName(document, 'table', 'vars'));
25
- hideAll(getElementsByClassName(document, 'ol', 'pre-context'));
26
- hideAll(getElementsByClassName(document, 'ol', 'post-context'));
27
- }
28
- function toggle() {
29
- for (var i = 0; i < arguments.length; i++) {
30
- var e = document.getElementById(arguments[i]);
31
- if (e) {
32
- e.style.display = e.style.display == 'none' ? 'block' : 'none';
33
- }
34
- }
35
- return false;
36
- }
37
- function varToggle(link, id) {
38
- toggle('v' + id);
39
- var s = link.getElementsByTagName('span')[0];
40
- var uarr = String.fromCharCode(0x25b6);
41
- var darr = String.fromCharCode(0x25bc);
42
- s.innerHTML = s.innerHTML == uarr ? darr : uarr;
43
- return false;
44
- }
@@ -1,178 +0,0 @@
1
- require 'dm-core'
2
-
3
- module Orange
4
- # Orange::Carton is the main model class for Orange. It's based on Datamapper.
5
- # In addition to handling the database interactions, the carton keeps
6
- # track of declared properties, which is used to create scaffolds.
7
- #
8
- # All subclasses should start by declaring the "id" attribute. All models
9
- # are assumed to have an id attribute by most everything else, so it's
10
- # a good idea to have one. Also, we use this to tie in initialization before
11
- # using the other dsl-ish methods (since these other methods are class level
12
- # and would happen before initialize ever gets called)
13
- #
14
- # Orange::Carton adds many shortcut methods for adding various datatypes
15
- # to the model in a more declarative style (`id` vs `property :id, Serial`)
16
- #
17
- # For classes that don't need anything but scaffolding, there's the
18
- # as_resource method, which automatically creates a scaffolding resource
19
- # for the model.
20
- #
21
- # A model that doesn't need scaffolded at all could optionally forgo the carton
22
- # class and just include DataMapper::Resource. All carton methods are to
23
- # improve scaffolding capability.
24
- class Carton
25
- SCAFFOLD_OPTIONS = [:display_name, :levels] unless defined?(SCAFFOLD_OPTIONS)
26
- extend ClassInheritableAttributes
27
- cattr_accessor :scaffold_properties
28
-
29
- # Declares a ModelResource subclass that scaffolds this carton
30
- # The Subclass will have the name of the carton followed by "_Resource"
31
- def self.as_resource
32
- name = self.to_s
33
- eval <<-HEREDOC
34
- class ::#{name}_Resource < Orange::ModelResource
35
- use #{name}
36
- end
37
- HEREDOC
38
- end
39
-
40
- # Include DataMapper types (required to be able to use Serial)
41
- include DataMapper::Types
42
-
43
- # Do setup of object and declare an id
44
- def self.id
45
- include DataMapper::Resource
46
- property(:id, Serial)
47
- self.scaffold_properties ||= []
48
- self.init
49
- end
50
-
51
- # Stub init method
52
- def self.init
53
- end
54
-
55
- # Return properties that should be shown for a given context
56
- def self.form_props(context = :live)
57
- self.scaffold_properties.select{|p| p[:levels].include?(context) }
58
- end
59
-
60
- # Helper to wrap properties into admin level
61
- def self.admin(&block)
62
- @levels = [:admin, :orange]
63
- instance_eval(&block)
64
- @levels = false
65
- end
66
-
67
- # Helper to wrap properties into orange level
68
- def self.orange(&block)
69
- @levels = [:orange]
70
- instance_eval(&block)
71
- @levels = false
72
- end
73
-
74
- # Helper to wrap properties into front level
75
- def self.front(&block)
76
- @levels = [:live, :admin, :orange]
77
- instance_eval(&block)
78
- @levels = false
79
- end
80
-
81
- def self.add_scaffold(name, type, dm_type, opts)
82
- self.scaffold_properties << {:name => name, :type => type, :levels => @levels}.merge(opts) if @levels || opts.has_key?(:levels)
83
- opts = opts.delete_if{|k,v| SCAFFOLD_OPTIONS.include?(k)} # DataMapper doesn't like arbitrary opts
84
- self.property(name, dm_type, opts)
85
- end
86
-
87
- # Define a helper for title type database stuff
88
- # Show in a context if wrapped in one of the helpers
89
- def self.title(name, opts = {})
90
- add_scaffold(name, :title, String, opts)
91
- end
92
-
93
- # Define a helper for title type database stuff
94
- # Show in a context if wrapped in one of the helpers
95
- def self.datetime(name, opts = {})
96
- add_scaffold(name, :datetime, DateTime, opts)
97
- end
98
-
99
- # Define a helper for title type database stuff
100
- # Show in a context if wrapped in one of the helpers
101
- def self.date(name, opts = {})
102
- add_scaffold(name, :date, Date, opts)
103
- end
104
-
105
- # Define a helper for title type database stuff
106
- # Show in a context if wrapped in one of the helpers
107
- def self.time(name, opts = {})
108
- add_scaffold(name, :time, Time, opts)
109
- end
110
-
111
- # Define a helper for fulltext type database stuff
112
- # Show in a context if wrapped in one of the helpers
113
- def self.fulltext(name, opts = {})
114
- add_scaffold(name, :fulltext, Text, opts)
115
- end
116
-
117
- # Define a helper for boolean type database stuff
118
- # Show in a context if wrapped in one of the helpers
119
- def self.boolean(name, opts = {})
120
- add_scaffold(name, :boolean, Boolean, opts)
121
- end
122
-
123
- # Define a helper for input type="text" type database stuff
124
- # Show in a context if wrapped in one of the helpers
125
- def self.text(name, opts = {})
126
- add_scaffold(name, :text, String, opts)
127
- end
128
-
129
- # Define a helper for type database stuff
130
- # Show in a context if wrapped in one of the helpers
131
- def self.expose(name, opts = {})
132
- self.scaffold_properties << {:name => name, :type => :text, :levels => @levels, :opts => opts} if @levels
133
- end
134
-
135
- # Define a helper for input type="text" type database stuff
136
- # Show in a context if wrapped in one of the helpers
137
- def self.string(name, opts = {})
138
- self.text(name, opts)
139
- end
140
-
141
- # Override DataMapper to include context sensitivity (as set by helpers)
142
- def self.scaffold_property(name, type, opts = {})
143
- my_type = type.to_s.downcase.to_sym
144
- add_scaffold(name, my_type, type, opts)
145
- end
146
-
147
-
148
- # For more generic cases, use same syntax as DataMapper does.
149
- # The difference is that this will make it an admin property.
150
- def self.admin_property(name, type, opts = {})
151
- my_type = type.to_s.downcase.to_sym
152
- opts[:levels] = [:admin, :orange]
153
- add_scaffold(name, my_type, type, opts)
154
- end
155
-
156
- # For more generic cases, use same syntax as DataMapper does.
157
- # The difference is that this will make it a front property.
158
- def self.front_property(name, type, opts = {})
159
- my_type = type.to_s.downcase.to_sym
160
- opts[:levels] = [:live, :admin, :orange]
161
- add_scaffold(name, my_type, type, opts)
162
- end
163
-
164
- # For more generic cases, use same syntax as DataMapper does.
165
- # The difference is that this will make it an orange property.
166
- def self.orange_property(name, type, opts = {})
167
- my_type = type.to_s.downcase.to_sym
168
- opts[:levels] = [:orange]
169
- add_scaffold(name, my_type, type, opts)
170
- end
171
-
172
- def to_s
173
- <<-DOC
174
- {"class": "#{self.class.to_s}", "id": "#{self.id}"}
175
- DOC
176
- end
177
- end
178
- end
@@ -1,266 +0,0 @@
1
- require 'dm-core'
2
- require 'rack'
3
- require 'rack/builder'
4
-
5
- module Orange
6
- # Declare submodules for later use
7
- module Pulp; end
8
- module Mixins; end
9
- module Plugins; end
10
-
11
- attr_accessor :plugins
12
-
13
- # Support for plugins
14
- def self.plugins
15
- @plugins ||= []
16
- end
17
-
18
- # Allows adding plugins
19
- def self.plugin(plugin)
20
- self.plugins << plugin if plugin.kind_of?(Orange::Plugins::Base)
21
- end
22
-
23
- # Allow mixins directly from Orange
24
- def self.mixin(inc)
25
- Core.mixin inc
26
- end
27
-
28
- # Allow pulp directly from Orange
29
- def self.add_pulp(inc)
30
- Packet.mixin inc
31
- end
32
-
33
- # Core is one of two main sources of interaction for Orange Applications
34
- #
35
- # All portions of Orange based code have access to the Core upon
36
- # initialization. Orange allows access to individual resources,
37
- # and also allows single point for event registration and firing.
38
- #
39
- # Functionality of the core can be extended by loading resources,
40
- # or by mixins that directly affect the Core. Generally, resources
41
- # are the less convoluted (easier to debug) way to do it.
42
- class Core
43
- # Sets the default options for Orange Applications
44
- DEFAULT_CORE_OPTIONS =
45
- {
46
- :contexts => [:live, :admin, :orange],
47
- :default_context => :live,
48
- :default_resource => :not_found,
49
- :default_database => 'sqlite3::memory:'
50
- } unless defined?(DEFAULT_CORE_OPTIONS)
51
-
52
- # Args will be set to the @options array.
53
- # Block DSL style option setting also available:
54
- #
55
- # orange = Orange::Core.new(:optional_option => 'foo') do
56
- # haml true
57
- # site_name "Banana"
58
- # custom_router MyRouterClass.new
59
- # end
60
- #
61
- # orange.options[:site_name] #=> "Banana"
62
- #
63
- # This method calls afterLoad when it is done. Subclasses can override
64
- # the afterLoad method for initialization needs.
65
- def initialize(*args, &block)
66
- @options = Options.new(*args, &block).hash.with_defaults(DEFAULT_CORE_OPTIONS)
67
- @resources = {}
68
- @application = false
69
- @stack = false
70
- @middleware = []
71
- @events = {}
72
- @file = __FILE__
73
- load(Orange::Parser.new, :parser)
74
- load(Orange::Mapper.new, :mapper)
75
- load(Orange::Scaffold.new, :scaffold)
76
- load(Orange::PageParts.new, :page_parts)
77
- Orange.plugins.each{|p| p.resources.each{|args| load(*args)} if p.has_resources?}
78
- self.register(:stack_loaded) do |s|
79
- @middleware.each{|m| m.stack_init if m.respond_to?(:stack_init)}
80
- @application.stack_init if @application
81
- end
82
- self.register(:stack_reloading){|s| @middleware = []} # Dump middleware on stack reload
83
- # load(Orange::AdminResource.new, :admin)
84
- afterLoad
85
- self
86
- end
87
-
88
- # Returns the orange library directory
89
- # @return [String] the directory name indicating where the core file is
90
- # located
91
- def core_dir(*args)
92
- if args
93
- File.join((options[:core_dir] ||= File.dirname(__FILE__)), *args)
94
- else
95
- options[:core_dir] ||= File.dirname(__FILE__)
96
- end
97
- end
98
-
99
- # Returns the directory of the currently executing file (using Dir.pwd),
100
- # can be overriden using the option :app_dir in initialization
101
- #
102
- # @return [String] the directory name of the currently running application
103
- def app_dir(*args)
104
- if args
105
- File.join((options[:app_dir] ||= Dir.pwd), *args)
106
- else
107
- options[:app_dir] ||= Dir.pwd
108
- end
109
- end
110
-
111
- # Called by initialize after finished loading
112
- def afterLoad
113
- true
114
- end
115
-
116
- # Returns status of a given resource by short name
117
- # @param [Symbol] resource_name The short name of the resource
118
- # @return [Boolean] result of has_key? in the resources list
119
- def loaded?(resource_name)
120
- @resources.has_key?(resource_name)
121
- end
122
-
123
- # Takes an instance of a Orange::Resource subclass, sets orange
124
- # then adds it to the orange resources
125
- #
126
- # It can be assigned a short name to be used for accessing later
127
- # on. If no short name is assigned, one will be generated by downcasing
128
- # the class name and changing it to a symbol
129
- #
130
- # Resources must respond to set_orange, which is automatically used to
131
- # create a link back to the Core, and to notify the resource of its assigned
132
- # short name.
133
- #
134
- # @param [Orange::Resource] resource An instance of Orange::Resource subclass
135
- # @param [optional, Symbol, String] name A short name to assign as key in Hash
136
- # list of resources.
137
- # Doesn't necessarily need to be a symbol, but generally is.
138
- # Set to the class name lowercase as a symbol by default.
139
- def load(resource, name = false)
140
- name = resource.orange_name if(!name)
141
- name = resource.class.to_s.gsub(/::/, '_').downcase.to_sym if(!name)
142
- @resources[name] = resource.set_orange(self, name)
143
- end
144
-
145
- # Takes an instance of Orange::Middleware::Base subclass and
146
- # keeps it for later. This way we can provide introspection into the
147
- # middleware instances (useful for calling stack_init on them)
148
- def middleware(middle = false)
149
- @middleware << middle if middle
150
- @middleware
151
- end
152
-
153
- # Takes an instance of Orange::Application and saves it.
154
- def application(app = false)
155
- @application = app if app
156
- @application
157
- end
158
-
159
- # Takes an instance of Orange::Stack and saves it.
160
- def stack(new_stack = false)
161
- @stack = new_stack if new_stack
162
- @stack
163
- end
164
-
165
- # Takes an instance of Orange::Stack and saves it.
166
- def stack=(new_stack)
167
- @stack = new_stack
168
- end
169
-
170
- # Convenience self for consistent naming across middleware
171
- # @return [Orange::Core] self
172
- def orange; self; end
173
-
174
- # Registers interest in a callback for a named event.
175
- #
176
- # Event registration is stored as a hash list of events and arrays
177
- # of procs to be executed on each event.
178
- #
179
- # @param [Symbol] event the name of the event registered for
180
- # @param [optional, Integer] position the position to place the event in,
181
- # by default goes to the front of the list. Doesn't necessarily need
182
- # to be exact count, empty spaces in array are taken out. Forcing the
183
- # event to be at 99 or some such position will typically make sure it
184
- # happens last in the firing process.
185
- # @param [Block] block The code to be executed upon event firing.
186
- # Saved to an array of procs that are called when #fire is called.
187
- # Block must accept one param, which is the intended to be the packet
188
- # causing the block to fire, unless the event happens in setup.
189
- def register(event, position = 0, &block)
190
- if block_given?
191
- if @events[event]
192
- @events[event].insert(position, Proc.new)
193
- else
194
- @events[event] = Array.new.insert(position, Proc.new)
195
- end
196
- end
197
- end
198
-
199
- # Fires a callback for a given packet (or other object)
200
- #
201
- # @param [Symbol] event name of event something has registered for
202
- # @param [Orange::Packet, object] packet Object, generally Orange::Packet,
203
- # causing the fire. This is passed to each Proc registered.
204
- # @return [Boolean] returns false if nothing has been registered for the
205
- # event, otherwise true.
206
- def fire(event, packet, *args)
207
- return false unless @events[event]
208
- @events[event].compact!
209
- for callback in @events[event]
210
- callback.call(packet, *args)
211
- end
212
- true
213
- end
214
-
215
- # Returns options of the orange core
216
- #
217
- # @return [Hash] Hash of options
218
- def options
219
- @options
220
- end
221
-
222
-
223
- # Accesses resources array, stored as a hash {:short_name => Resource instance,...}
224
- #
225
- # @param [Symbol] name the short name for the requested resource
226
- # @param [optional, Boolean] ignore Whether to ignore any calls to resource if not found
227
- # (false is default). This will allow method calls to non-existent resources. Should be
228
- # used with caution.
229
- # @return [Orange::Resource] the resource for the given short name
230
- def [](name, ignore = false)
231
- if ignore && !loaded?(name)
232
- Ignore.new
233
- else
234
- @resources[name]
235
- end
236
- end
237
-
238
- # Includes module in the Packet class
239
- # @param [Module] inc module to be included
240
- def add_pulp(inc)
241
- self.class.add_pulp inc
242
- end
243
-
244
- # Includes module in this class
245
- # @param [Module] inc module to be included
246
- def mixin(inc)
247
- self.class.mixin inc
248
- end
249
-
250
- # Includes module in this class
251
- # @param [Module] inc module to be included
252
- def self.mixin(inc)
253
- include inc
254
- end
255
-
256
- # Includes module in the Packet class
257
- # @param [Module] inc module to be included
258
- def self.add_pulp(inc)
259
- Packet.mixin inc
260
- end
261
-
262
- def inspect
263
- "#<Orange::Core:0x#{self.object_id.to_s(16)}>"
264
- end
265
- end
266
- end