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,96 +0,0 @@
1
- require 'orange-core/core'
2
-
3
- module Orange
4
- # Orange Resource for being subclassed
5
- class Resource
6
- extend ClassInheritableAttributes
7
- # Defines a model class as an inheritable class attribute and also an instance
8
- # attribute
9
- cattr_accessor :called
10
-
11
- def initialize(*args, &block)
12
- @options = DefaultHash.new.merge!(Options.new(*args, &block).hash)
13
- end
14
-
15
- def set_orange(orange, name)
16
- @orange = orange
17
- @my_orange_name = name
18
- init
19
- orange.register(:stack_loaded) { |s| stack_init } if self.respond_to? :stack_init
20
- self
21
- end
22
-
23
- def self.set_orange(*args)
24
- raise 'instantiate the resource before calling set orange'
25
- end
26
-
27
- def init
28
- afterLoad
29
- end
30
-
31
- def afterLoad
32
- end
33
-
34
- def self.call_me(name)
35
- self.called = name
36
- end
37
-
38
- def orange
39
- @orange
40
- end
41
-
42
- def routable
43
- false
44
- end
45
-
46
- def view(packet = false, *args)
47
- ''
48
- end
49
-
50
- def orange_name
51
- @my_orange_name || self.class.called || false
52
- end
53
-
54
- def options
55
- @options
56
- end
57
-
58
- # Renders a view, with all options set for haml to access.
59
- # Calls #view_opts to generate the haml options.
60
- # @param [Orange::Packet] packet the packet we are returning a view for
61
- # @param [Symbol] mode the mode we are trying to view (used to find template name)
62
- # @param [optional, Array] args the args array
63
- # @return [String] haml parsed string to be placed in packet[:content] by #route
64
- def do_view(packet, mode, *args)
65
- haml_opts = view_opts(packet, mode, *args)
66
- orange[:parser].haml("#{mode.to_s}.haml", packet, haml_opts)
67
- end
68
-
69
-
70
- # Returns the options for including in template rendering. All keys passed in the args array
71
- # will automatically be local variables in the haml template.
72
- # In addition, the props, resource, and model_name variables will be available.
73
- # @param [Orange::Packet] packet the packet we are returning a view for
74
- # @param [Symbol] mode the mode we are trying to view (used to find template name)
75
- # @param [boolean] is_list whether we want a list or not (view_opts will automatically look up
76
- # a single object or a list of objects, so we need to know which)
77
- # @param [optional, Array] args the args array
78
- # @return [Hash] hash of options to be used
79
- def view_opts(packet, mode, *args)
80
- opts = args.extract_options!.with_defaults({:path => ''})
81
- all_opts = {:resource => self, :model_name => @my_orange_name}.merge!(opts)
82
- all_opts.with_defaults! find_extras(packet, mode)
83
- all_opts
84
- end
85
-
86
- # Returns a hash of extra options to be set and made available by the haml parser.
87
- # Overriding this method is useful for passing extra bits of info to rendering
88
- # for certain view modes without rewriting all of the other scaffolding
89
- # @param [Orange::Packet] packet the packet we are returning a view for
90
- # @param [Symbol] mode the mode we are trying to view (used to find template name)
91
- # @return [Hash] a hash of extras to be included in the rendering
92
- def find_extras(packet, mode)
93
- {}
94
- end
95
- end
96
- end
@@ -1,36 +0,0 @@
1
- require 'orange-core/core'
2
-
3
- module Orange
4
- class Mapper < Resource
5
- # Takes a packet extracts request information, then calls packet.route
6
- def afterLoad
7
- orange.add_pulp Pulp::Packet_Mapper
8
- end
9
-
10
- def route_to(packet, resource, *args)
11
- opts = args.extract_options!
12
- packet = DefaultHash.new unless packet
13
- context = opts[:context]
14
- context = packet['route.context', nil] unless (context || (packet['route.context'] == :live))
15
- site = packet['route.faked_site'] ? packet['route.site_url', nil] : nil
16
- args.unshift(resource)
17
- args.unshift(context)
18
- args.unshift(site)
19
- '/'+args.compact.join('/')
20
- end
21
- end
22
-
23
- module Pulp::Packet_Mapper
24
- def route_to(resource, *args)
25
- orange[:mapper].route_to(self, resource, *args)
26
- end
27
-
28
- def reroute(url, type = :real, *args)
29
- packet['reroute.to'] = url
30
- packet['reroute.type'] = type
31
- packet['reroute.args'] = *args if args
32
- raise Reroute.new(self), 'Unhandled reroute'
33
- end
34
- end
35
-
36
- end
@@ -1,228 +0,0 @@
1
- require 'orange-core/resources/routable_resource'
2
-
3
- module Orange
4
- class ModelResource < RoutableResource
5
- # Defines a model class as an inheritable class attribute and also an instance
6
- # attribute
7
- cattr_accessor :model_class
8
- attr_accessor :model_class
9
-
10
- # Tells the Model resource which Carton class to scaffold
11
- # @param [Orange::Carton] my_model_class class name of the carton class to scaffold
12
- def self.use(my_model_class)
13
- self.model_class = my_model_class
14
- end
15
-
16
- # Overrides the instantiation of new Resource object to set instance model
17
- # class to the class-level model class defined by #use
18
- def self.new(*args, &block)
19
- me = super(*args, &block)
20
- me.model_class = self.model_class
21
- me
22
- end
23
-
24
- # Views a packet by calling method defined as opts[:mode].
25
- # Defaults mode to show or list, if it can't find opts[:mode].
26
- # Decision between show or list is determined by whether an id has been chosen.
27
- # An id is set in opts[:id], or extracted from the packet['route.resource_id'].
28
- # Calling view is equivalent to calling a viewable method directly, view just
29
- # sets up safe defaults so method missing errors are less likely.
30
- # @param [Orange::Packet] packet the packet calling view on this resource
31
- def view(packet, opts = {})
32
- resource_id = opts[:id] || packet['route.resource_id', false]
33
- mode = opts[:mode] || packet['route.resource_action'] ||
34
- (resource_id ? :show : :index)
35
- self.__send__(mode, packet, opts)
36
- end
37
-
38
- # Renders a view, with all options set for haml to access.
39
- # Calls #view_opts to generate the haml options.
40
- # @param [Orange::Packet] packet the packet we are returning a view for
41
- # @param [Symbol] mode the mode we are trying to view (used to find template name)
42
- # @param [optional, Array] args the args array
43
- # @return [String] haml parsed string to be placed in packet[:content] by #route
44
- def do_view(packet, mode, *args)
45
- haml_opts = view_opts(packet, mode, false, *args)
46
- orange[:parser].haml("#{mode.to_s}.haml", packet, haml_opts)
47
- end
48
-
49
- # Renders a view, with all options set for haml to access. Same as do_view, but
50
- # calls #view_opts with is_list set to true to generate the haml options.
51
- # @param [Orange::Packet] packet the packet we are returning a view for
52
- # @param [Symbol] mode the mode we are trying to view (used to find template name)
53
- # @param [optional, Array] args the args array
54
- # @return [String] haml parsed string to be placed in packet[:content] by #route
55
- def do_list_view(packet, mode, *args)
56
- haml_opts = view_opts(packet, mode, true, *args)
57
- orange[:parser].haml("#{mode.to_s}.haml", packet, haml_opts)
58
- end
59
-
60
- # Returns the options for including in template rendering. All keys passed in the args array
61
- # will automatically be local variables in the haml template.
62
- # In addition, the props, resource, and model_name variables will be available.
63
- # @param [Orange::Packet] packet the packet we are returning a view for
64
- # @param [Symbol] mode the mode we are trying to view (used to find template name)
65
- # @param [boolean] is_list whether we want a list or not (view_opts will automatically look up
66
- # a single object or a list of objects, so we need to know which)
67
- # @param [optional, Array] args the args array
68
- # @return [Hash] hash of options to be used
69
- def view_opts(packet, mode, is_list, *args)
70
- opts = args.extract_options!.with_defaults({:path => ''})
71
- props = model_class.form_props(packet['route.context'])
72
- resource_id = opts[:id] || packet['route.resource_id'] || false
73
- all_opts = {:props => props, :resource => self, :model_name => @my_orange_name}.merge!(opts)
74
- all_opts.with_defaults! :model => find_one(packet, mode, resource_id) unless is_list
75
- all_opts.with_defaults! :list => find_list(packet, mode) if is_list
76
- all_opts.with_defaults! find_extras(packet, mode)
77
- all_opts
78
- end
79
-
80
- # Returns a single object found by the model class, given an id.
81
- # If id isn't given, we return false.
82
- # @param [Orange::Packet] packet the packet we are returning a view for
83
- # @param [Symbol] mode the mode we are trying to view (used to find template name)
84
- # @param [Numeric] id the id to lookup on the model class
85
- # @return [Object] returns an object of type set by #use, if one found with same id
86
- def find_one(packet, mode, id = false)
87
- return false unless id
88
- model_class.get(id)
89
- end
90
-
91
- # Returns a list of all objects found by the model class
92
- # If none, returns an empty array
93
- # @param [Orange::Packet] packet the packet we are returning a view for
94
- # @param [Symbol] mode the mode we are trying to view (used to find template name)
95
- # @param [Numeric] id the id to lookup on the model class
96
- # @return [Enumerable] returns a collection of objects of type set by #use
97
- def find_list(packet, mode)
98
- model_class.all || []
99
- end
100
-
101
- # Creates a new model object and saves it (if a post), then reroutes to the main page
102
- # @param [Orange::Packet] packet the packet being routed
103
- def new(packet, opts = {})
104
- no_reroute = opts.delete(:no_reroute)
105
- if packet.request.post? || !opts.blank?
106
- params = opts.with_defaults(opts.delete(:params) || packet.request.params[@my_orange_name.to_s] || {})
107
- before = beforeNew(packet, params)
108
- obj = onNew(packet, params) if before
109
- afterNew(packet, obj, params) if before
110
- obj.save if obj && before
111
- end
112
- packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
113
- obj || false
114
- end
115
-
116
- # A callback for the actual new item event
117
- def onNew(packet, opts = {})
118
- model_class.new(opts)
119
- end
120
-
121
- # A callback for before a new item is created
122
- # @param [Orange::Packet] packet the packet being routed
123
- def beforeNew(packet, opts = {})
124
- true
125
- end
126
-
127
- # A callback for after a new item is created
128
- # @param [Orange::Packet] packet the packet being routed
129
- # @param [Object] obj the model class just created
130
- def afterNew(packet, obj, opts = {})
131
- end
132
-
133
- # Deletes an object specified by packet['route.resource_id'], then reroutes to main.
134
- # The request must come in as a delete. Rack::MethodOverride can be used to do this.
135
- # @param [Orange::Packet] packet the packet being routed
136
- def delete(packet, opts = {})
137
- no_reroute = opts.delete(:no_reroute)
138
- if packet.request.delete? || !opts.blank?
139
- id = opts.delete(:resource_id) || packet['route.resource_id']
140
- m = model_class.get(packet['route.resource_id'])
141
- before = beforeDelete(packet, m, opts)
142
- onDelete(packet, m, opts) if m && before
143
- afterDelete(packet, m, opts) if before
144
- orange.fire(:model_resource_deleted, packet, {:resource_id => id, :resource => @my_orange_name})
145
- end
146
- packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
147
- end
148
-
149
- def beforeDelete(packet, obj, opts = {})
150
- true
151
- end
152
-
153
- # Delete object
154
- def onDelete(packet, obj, opts = {})
155
- obj.destroy
156
- end
157
-
158
- def afterDelete(packet, obj, opts = {})
159
- end
160
-
161
- # Saves updates to an object specified by packet['route.resource_id'], then reroutes to main
162
- # @param [Orange::Packet] packet the packet being routed
163
- def save(packet, opts = {})
164
- no_reroute = opts.delete(:no_reroute)
165
- if packet.request.post? || !opts.blank?
166
- my_id = opts.delete(:resource_id) || packet['route.resource_id']
167
- m = opts.delete(:model) || model_class.get(my_id)
168
- params = opts.with_defaults(opts.delete(:params) || packet.request.params[@my_orange_name.to_s] || {})
169
- if m
170
- before = beforeSave(packet, m, params)
171
- onSave(packet, m, params) if before
172
- afterSave(packet, m, params) if before
173
- end
174
- end
175
- packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
176
- m || false
177
- end
178
-
179
- def beforeSave(packet, obj, opts = {})
180
- true
181
- end
182
-
183
- def onSave(packet, obj, opts = {})
184
- obj.update(opts)
185
- end
186
-
187
- def afterSave(packet, obj, opts = {})
188
- end
189
-
190
- # Calls #do_view with :show mode
191
- # @param [Orange::Packet] packet the packet being routed
192
- def show(packet, *opts)
193
- do_view(packet, :show, *opts)
194
- end
195
-
196
- # Calls #do_view with :edit mode
197
- # @param [Orange::Packet] packet the packet being routed
198
- def edit(packet, *opts)
199
- do_view(packet, :edit, *opts)
200
- end
201
-
202
- # Calls #do_view with :create mode
203
- # @param [Orange::Packet] packet the packet being routed
204
- def create(packet, *opts)
205
- do_view(packet, :create, *opts)
206
- end
207
-
208
- # Calls #do_view with :table_row mode
209
- # @param [Orange::Packet] packet the packet being routed
210
- def table_row(packet, *opts)
211
- do_view(packet, :table_row, *opts)
212
- end
213
-
214
- # Calls #do_list_view with :list mode
215
- # @param [Orange::Packet] packet the packet being routed
216
- def list(packet, *opts)
217
- do_list_view(packet, :list, *opts)
218
- end
219
-
220
- # Calls #do_list_view with :list mode.
221
- # @param [Orange::Packet] packet the packet being routed
222
- def index(packet, *opts)
223
- do_list_view(packet, :list, *opts)
224
- end
225
-
226
- end
227
-
228
- end
@@ -1,10 +0,0 @@
1
- require 'orange-core/resource'
2
- module Orange
3
- class NotFound < Orange::Resource
4
- call_me :not_found
5
- def route(packet)
6
- packet[:content] = orange[:parser].haml("404.haml", packet, :resource => self)
7
- packet[:status] = 404
8
- end
9
- end
10
- end
@@ -1,68 +0,0 @@
1
- require 'orange-core/resource'
2
- module Orange
3
- class PageParts < Resource
4
- def afterLoad
5
- orange.add_pulp Orange::Pulp::PageParts
6
- end
7
-
8
- def part(packet)
9
- unless packet[:page_parts, false]
10
- packet[:page_parts] = DefaultHash.new
11
- packet[:page_parts].default = ''
12
- end
13
- packet[:page_parts]
14
- end
15
-
16
-
17
- def add_css(packet, file, opts = {})
18
- ie = opts[:ie] || false
19
- mod = opts[:module] || 'public'
20
- # module set to false gives the root assets dir
21
- assets = File.join('assets', mod)
22
- file = File.join('', assets, 'css', file)
23
- unless packet[:css_files, []].include?(file)
24
- if ie
25
- part(packet)[:ie_css] = part(packet)[:ie_css] + "<link rel=\"stylesheet\" href=\"#{file}\" type=\"text/css\" media=\"screen\" charset=\"utf-8\" />"
26
- else
27
- part(packet)[:css] = part(packet)[:css] + "<link rel=\"stylesheet\" href=\"#{file}\" type=\"text/css\" media=\"screen\" charset=\"utf-8\" />"
28
- end
29
- packet[:css_files] ||= []
30
- packet[:css_files].insert((opts[:position] ? opts[:position] : -1), file)
31
- end
32
- end
33
-
34
- def add_js(packet, file, opts = {})
35
- ie = opts[:ie] || false
36
- mod = opts[:module] || 'public'
37
- assets = File.join('assets', mod)
38
- file = File.join('', assets, 'js', file)
39
- unless packet[:js_files, []].include?(file)
40
- if ie
41
- part(packet)[:ie_js] = part(packet)[:ie_js] + "<script src=\"#{file}\" type=\"text/javascript\"></script>"
42
- else
43
- part(packet)[:js] = part(packet)[:js] + "<script src=\"#{file}\" type=\"text/javascript\"></script>"
44
- end
45
- packet[:js_files] ||= []
46
- packet[:js_files].insert((opts[:position] ? opts[:position] : -1), file)
47
- end
48
- end
49
- end
50
-
51
- module Pulp::PageParts
52
- def part
53
- orange[:page_parts].part(packet)
54
- end
55
-
56
- # Feels like part should be plural, no?
57
- def parts; part; end
58
-
59
-
60
- def add_css(file, opts = {})
61
- orange[:page_parts].add_css(packet, file, opts)
62
- end
63
-
64
- def add_js(file, opts = {})
65
- orange[:page_parts].add_js(packet, file, opts)
66
- end
67
- end
68
- end
@@ -1,113 +0,0 @@
1
- require 'orange-core/core'
2
- require 'haml'
3
- require 'yaml'
4
- require 'crack'
5
-
6
- module Orange
7
- class Parser < Resource
8
- def afterLoad
9
- orange.add_pulp Orange::Pulp::ParserPulp
10
- @template_dirs = [File.join(orange.core_dir, 'templates')]
11
- @view_dirs = [File.join(orange.core_dir, 'views')]
12
- Orange.plugins.each{|p| @template_dirs << p.templates if p.has_templates? }
13
- Orange.plugins.each{|p| @view_dirs << p.views if p.has_views? }
14
- end
15
-
16
- def yaml(file)
17
- return nil unless File.exists?(file)
18
- string = File.read(file)
19
- string.gsub!('__ORANGE__', orange.app_dir)
20
- out = YAML::load(string)
21
- end
22
-
23
- def haml(file, packet_binding, *vars, &block)
24
-
25
- opts = vars.extract_options!
26
- # Initial info
27
- temp = opts.delete(:template)
28
- opts[:resource_name] = opts[:resource].orange_name.to_s if
29
- opts[:resource] && opts[:resource].respond_to?(:orange_name)
30
- resource = (opts[:resource_name] || '').downcase
31
-
32
- if packet_binding.is_a? Orange::Packet
33
- context = packet_binding['route.context'].to_s
34
- unless temp
35
- packet_binding['parser.haml-templates'] ||= {}
36
- haml_engine = packet_binding['parser.haml-templates']["#{context}-#{resource}-#{file}"] || false
37
- end
38
- end
39
- unless haml_engine
40
- opts.merge :orange => orange
41
-
42
- string = false
43
- if temp
44
- string ||= read_if_exists('templates', file)
45
- @template_dirs.each do |templates_dir|
46
- string ||= read_if_exists(templates_dir, file)
47
- end unless string
48
- end
49
-
50
- if context
51
- #Check for context specific overrides
52
- string ||= read_if_exists('views', resource, context+"."+file) if resource
53
- string ||= read_if_exists('views', context+"."+file)
54
- @view_dirs.each do |views_dir|
55
- string ||= read_if_exists(views_dir, resource, context+"."+file) if resource
56
- string ||= read_if_exists(views_dir, context+"."+file)
57
- end unless string
58
- end
59
-
60
- # Check for standard views
61
- string ||= read_if_exists('views', resource, file) if resource
62
- string ||= read_if_exists('views', file)
63
- @view_dirs.each do |views_dir|
64
- string ||= read_if_exists(views_dir, resource, file) if resource
65
- string ||= read_if_exists(views_dir, file)
66
- end unless string
67
-
68
- # Check for default resource views
69
- string ||= read_if_exists('views', 'default_resource', file)
70
- @view_dirs.each do |views_dir|
71
- string ||= read_if_exists(views_dir, 'default_resource', file) if resource
72
- end unless string
73
- raise LoadError, "Couldn't find haml file '#{file}'" unless string
74
-
75
- haml_engine = Haml::Engine.new(string)
76
- if packet_binding.is_a? Orange::Packet
77
- packet_binding['parser.haml-templates']["#{context}-#{resource}-#{file}"] = haml_engine
78
- end
79
- end
80
- out = haml_engine.render(packet_binding, opts, &block)
81
- end
82
-
83
- def read_if_exists(*args)
84
- return File.read(File.join(*args)) if File.exists?(File.join(*args))
85
- false
86
- end
87
-
88
- def hpricot(text)
89
- require 'hpricot'
90
- Hpricot(text)
91
- end
92
-
93
- def xml(text)
94
- Crack::XML.parse(text)
95
- end
96
-
97
- def json(text)
98
- Crack::JSON.parse(text)
99
- end
100
- end
101
-
102
- module Pulp::ParserPulp
103
- def html(&block)
104
- if block_given?
105
- unless(packet[:content].blank?)
106
- doc = orange[:parser].hpricot(packet[:content])
107
- yield doc
108
- packet[:content] = doc.to_s
109
- end
110
- end
111
- end
112
- end
113
- end