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,60 +0,0 @@
1
- require 'orange-core/core'
2
- require 'orange-core/middleware/base'
3
-
4
- module Orange::Middleware
5
-
6
- class Template < Base
7
- def init(*args)
8
- @core.add_pulp(Orange::Pulp::Template)
9
- @core.mixin(Orange::Mixins::Template)
10
-
11
- end
12
-
13
- def packet_call(packet)
14
- packet['template.file'] = orange.template_for packet
15
- status, headers, content = pass packet
16
- if needs_wrapped?(packet)
17
- content = wrap(packet, content)
18
- packet[:content] = content.first
19
- orange.fire(:wrapped, packet)
20
- end
21
- orange.fire(:after_wrap, packet)
22
- packet.finish
23
- end
24
-
25
- def needs_wrapped?(packet)
26
- return false if packet.request.xhr? && !packet['template.enable'] # don't wrap xhr unless specifically asked to
27
- packet['template.file'] && !packet['template.disable']
28
- end
29
-
30
- def wrap(packet, content = false)
31
- content = packet.content unless content
32
- content = content.join
33
- content = orange[:parser].haml(packet['template.file'], packet, :wrapped_content => content, :template => true) do
34
- content
35
- end
36
- [content]
37
- end
38
- end
39
- end
40
-
41
- module Orange::Pulp::Template
42
- def wrap
43
- packet[:content] = orange[:parser].haml(packet['template.file'], packet, :wrapped_content => packet[:content], :template => true) do
44
- content
45
- end
46
- end
47
- end
48
-
49
- module Orange::Mixins::Template
50
- def template_for(packet)
51
- template_chooser.call(packet)
52
- end
53
- def template_chooser(&block)
54
- if block_given?
55
- @template_chooser = Proc.new
56
- else
57
- @template_chooser ||= Proc.new {|packet| false}
58
- end
59
- end
60
- end
@@ -1,232 +0,0 @@
1
- module Orange
2
- # Orange::Packet is a wrapper for Rack's basic env variable.
3
- # It acts somewhat like Rack::Request, except with more functionality.
4
- # For each request a unique Packet is generated, and this packet is
5
- # used to by middleware to create the response.
6
- #
7
- # All orange enhanced middleware has a packet_call method that
8
- # automatically turns the generic rack call(env) into a call
9
- # that has a packet instead, so all functions for the packet should
10
- # be available for the request.
11
- #
12
- # Pulps are modules that are mixed into the Packet, allowing
13
- # additional functionality to be used by the packet.
14
- #
15
- # By default, haml files are parsed in the context of their
16
- # packet. This means all of instance variables and functions should
17
- # be available to the haml parser.
18
- class Packet
19
- # By default, header will be content-type
20
- DEFAULT_HEADERS = {"Content-Type" => 'text/html'} unless defined?(DEFAULT_HEADERS)
21
-
22
- # We override the instantiation to only create one packet per env
23
- # @param [Orange::Core] orange a pointer to the orange core
24
- # @param [Hash] env a standard Rack hash
25
- def self.new(orange, env)
26
- return env['orange.packet'] if env['orange.packet']
27
- super(orange, env)
28
- end
29
-
30
- # Allows tying in to the method_missing method without redefining it
31
- # elsewhere. This lets dynamic methods be defined on the packet.
32
- # Regexes are defined to match method names. #method_missing will
33
- # loop through and try to find a match, executing the proc defined in
34
- # the block.
35
- # @param [Regexp] regex the regex to match
36
- # @yield [Orange::Packet, MatchData, args] the block to execute if matched
37
- # (passed instance, match data and args)
38
- def self.meta_methods(regex, &block)
39
- return unless block_given?
40
- proc = block
41
- @@matchers ||= {}
42
- @@matchers[regex] = proc
43
- end
44
-
45
- # Allows access to the matchers added via the #meta_methods method
46
- # @return [Hash] the matchers hash
47
- def matchers
48
- @@matchers || {}
49
- end
50
-
51
- # Initialize is only called if a packet hasn't already been called for
52
- # this env. Sets up the basic env, creating a pointer back to self
53
- # and a Rack::Request object.
54
- # @param [Orange::Core] orange a pointer to the orange core
55
- # @param [Hash] env a standard Rack hash
56
- def initialize(orange, env)
57
- @orange = orange
58
- @env = env
59
- @env['orange.packet'] = self
60
- @env['orange.env'] = {} unless @env['orange.env']
61
- @env['orange.env'][:request] = Rack::Request.new(env)
62
- @env['orange.env'][:headers] = {}
63
- end
64
-
65
- # Gives access to the orange.env key in the env, optionally
66
- # including a default if key isn't involved.
67
- # @param [Symbol, String] key the key to be found
68
- # @param [optional, Object] default the return value if key doesn't exist (default is false)
69
- # @return [Object] any value stored in the env
70
- def [](key, default = false)
71
- @env['orange.env'].has_key?(key) ? @env['orange.env'][key] : default
72
- end
73
-
74
- # Lets user set a value in the orange.env
75
- # @param [Symbol, String] key the key to be set
76
- # @param [Object] val the value to be set
77
- def []=(key, val)
78
- @env['orange.env'][key] = val
79
- end
80
-
81
- # Access to the main env (orange env is stored within the main env)
82
- # @return [Hash] the request's env hash
83
- def env
84
- @env
85
- end
86
-
87
- # Access to the rack session
88
- # @return [Hash] the session information made available by Rack
89
- def session
90
- env['rack.session']["flash"] ||= {}
91
- env['rack.session']
92
- end
93
-
94
- # Access to the rack session flash
95
- # @return [String] the string stored in the flash
96
- def flash(key = nil, val = nil)
97
- env['rack.session']["flash"] ||= {}
98
- if key.nil? && val.nil?
99
- env['rack.session']["flash"]
100
- elsif val.nil?
101
- env['rack.session']["flash"].delete(key)
102
- else
103
- env['rack.session']["flash"][key] = val
104
- end
105
- end
106
-
107
- # Generate headers for finalization
108
- # @return [Hash] the header information stored in the orange.env, combined with the defaults
109
- # set as DEFAULT_HEADERS
110
- def headers
111
- packet[:headers, {}].with_defaults(DEFAULT_HEADERS)
112
- end
113
-
114
- # Set a header
115
- # @param [String] key the key to be set
116
- # @param [Object] val the value to be set
117
- def header(key, val)
118
- @env['orange.env'][:headers][key] = val
119
- end
120
-
121
- # Set a header (same as #header)
122
- # @param [String] key the key to be set
123
- # @param [Object] val the value to be set
124
- def add_header(key, val)
125
- header key, val
126
- end
127
-
128
- # Returns the content ready to be used by Rack (wrapped in an array)
129
- # @return [Array] array of strings to be rendered
130
- def content
131
- # Stringify content if it isn't a string for some weird reason.
132
- packet[:content] = packet[:content].to_s unless packet[:content].is_a? String
133
- return [packet[:content]] if packet[:content]
134
- return ['']
135
- end
136
-
137
- # Returns the request object generated by Rack::Request(packet.env)
138
- # @return [Rack::Request] the request object
139
- def request
140
- packet[:request]
141
- end
142
-
143
- # A pointer to the Orange::Core instance
144
- # @return [Orange::Core] the orange core run by the application
145
- def orange
146
- @orange
147
- end
148
-
149
- # Returns the array of [status, headers, content] Rack expects
150
- # @return [Array] the triple array expected by Rack at the end
151
- # of a call
152
- def finish
153
- headers = packet.headers
154
- status = packet[:status, 200]
155
- content = packet.content
156
- if content.respond_to?(:to_ary)
157
- headers["Content-Length"] = content.to_ary.
158
- inject(0) { |len, part| len + Rack::Utils.bytesize(part) }.to_s
159
- end
160
- [status, headers, content]
161
- end
162
-
163
- # Returns self
164
- # @return [Orange::Packet] self
165
- def packet
166
- self
167
- end
168
-
169
- # Includes the module passed
170
- # @param [Module] inc the module to be mixed into the class
171
- def self.mixin(inc)
172
- include inc
173
- end
174
-
175
- # Route calls the router object set in the packet
176
- # @return [void] route doesn't return anything directly, the
177
- # main application calls packet.route then returns packet.finish.
178
- # Routers set content, headers and status if necessary.
179
- # They can also raise redirect errors to circumvent the process.
180
- def route
181
- router = packet['route.router']
182
- raise 'Router not found' unless router
183
- router.route(self)
184
- end
185
-
186
- # Pulls options set out of the packet and places them into
187
- # a hash. Options are retrieved from POST, GET, and route.resource_path
188
- # and take that order of precedence (POST overrides GET, etc)
189
- # @param [Array] key_list an array of keys to retrieve and merge together
190
- # in order of precedence. :GET and :POST for request vars, the rest
191
- # are keys directly available on packet
192
- # @return [Hash] A hash of options set in the packet
193
- def extract_opts(key_list = [:POST, :GET, 'route.resource_path'])
194
- opts = {}
195
- key_list.reverse.each do |key|
196
- case key
197
- when :GET then opts.merge! packet.request.GET
198
- when :POST then opts.merge! packet.request.POST
199
- else
200
- opts.merge!(packet[key, {}].kind_of?(String) ? url_to_hash(packet[key]) : packet[key, {}])
201
- end
202
- end
203
- opts
204
- end
205
-
206
- # Converts a url path to a hash with symbol keys. URL must
207
- # be in /key/val/key/val/etc format
208
- def url_to_hash(url)
209
- parts = url.split('/')
210
- hash = {}
211
- while !parts.blank?
212
- key = parts.shift
213
- key = parts.shift if key.blank?
214
- val = parts.shift
215
- hash[key.to_sym] = val unless key.blank? or val.blank?
216
- end
217
- hash
218
- end
219
-
220
- # Method Missing allows defining custom methods
221
- def method_missing(id, *args)
222
- matched = false
223
- id = id.to_s
224
- @@matchers.each_key do |k|
225
- matched = k if id =~ k
226
- break if matched
227
- end
228
- return @@matchers[matched].call(packet, matched.match(id), args) if matched
229
- raise NoMethodError.new("No method ##{id} found", id)
230
- end
231
- end
232
- end
@@ -1,172 +0,0 @@
1
- require 'orange-core/magick'
2
- require 'orange-core/core'
3
- module Orange::Plugins
4
- # This class defines a basic Orange plugin. A plugin simply defines
5
- # a bunch of possible classes/files that can be called up by the main
6
- # orange system.
7
- #
8
- # The plugins are used in several places. When the core is initialized,
9
- # it will ask all plugins if they have any resources that should be added,
10
- # and load those resources if they exist.
11
- #
12
- # The stack will call the list of plugins several times in building a stack
13
- # once for each possible middleware location.
14
- class Base
15
- extend ClassInheritableAttributes
16
- cattr_accessor :prerouting_middleware, :routing_middleware,
17
- :responder_middleware, :postrouting_middleware, :has_middleware
18
- cattr_accessor :assets, :assets_name
19
- cattr_accessor :resources
20
- cattr_accessor :views
21
- cattr_accessor :templates
22
-
23
- # Adds a single prerouting middleware class to list of prerouting middleware
24
- def self.prerouter(r)
25
- prerouters(r)
26
- end
27
-
28
- # Adds several prerouting middleware classes to list of prerouting middleware
29
- def self.prerouters(*routers)
30
- self.has_middleware = true
31
- routers.each do |prerouter|
32
- self.prerouting_middleware << prerouter
33
- end
34
- end
35
-
36
- # Adds a single postrouting middleware class to list of postrouting middleware
37
- def self.postrouter(r)
38
- postrouters(r)
39
- end
40
-
41
- # Adds several postrouting middleware classes to list of postrouting middleware
42
- def self.postrouters(*routers)
43
- self.has_middleware = true
44
- routers.each do |postrouter|
45
- self.postrouting_middleware << postrouter
46
- end
47
- end
48
-
49
- # Adds a router middleware class to the list of routing middleware
50
- def self.router(r)
51
- routers(r)
52
- end
53
- # Adds several router middleware classes
54
- def self.routers(*routers)
55
- self.has_middleware = true
56
- routers.each do |router|
57
- self.routing_middleware << router
58
- end
59
- end
60
- # Adds a responder middleware class
61
- def self.responder(r)
62
- responders(r)
63
- end
64
- # Adds several responder middleware classes
65
- def self.responders(*respones)
66
- self.has_middleware = true
67
- respones.each do |response|
68
- self.responder_middleware << response
69
- end
70
- end
71
-
72
- # Returns the list of prerouting_middleware defined or
73
- # an empty array if none defined
74
- def self.prerouting_middleware
75
- super || self.prerouting_middleware = []
76
- end
77
-
78
- # Returns the list of prerouting_middleware defined or
79
- # an empty array if none defined
80
- def self.postrouting_middleware
81
- super || self.postrouting_middleware = []
82
- end
83
-
84
- # Returns the list of routing_middleware defined or
85
- # an empty array if none defined
86
- def self.routing_middleware
87
- super || self.routing_middleware = []
88
- end
89
-
90
- # Returns the list of responder_middleware defined or
91
- # an empty array if none defined
92
- def self.responder_middleware
93
- super || self.responder_middleware = []
94
- end
95
-
96
- def self.templates_dir(arg)
97
- self.templates = arg
98
- end
99
-
100
- def self.views_dir(arg)
101
- self.views = arg
102
- end
103
-
104
- def self.assets_dir(arg)
105
- self.assets = arg
106
- end
107
-
108
- def self.resource(instance, name = false)
109
- self.resources << [instance, name]
110
- end
111
-
112
- def self.resources
113
- super || self.resources = []
114
- end
115
-
116
- # Returns the assigned asset dir name,
117
- # or Plugin class name formatted like this: PluginClass -> _pluginclass_
118
- def assets_name
119
- self.class.assets_name || '_'+self.class.to_s.gsub(/Orange::Plugins::/, '').gsub(/::/, '_').downcase+'_'
120
- end
121
-
122
- # Returns the assets directory for this plugin
123
- def assets
124
- self.class.assets
125
- end
126
-
127
- # Whether this plugin has assets for the static middleware to worry
128
- # about
129
- def has_assets?
130
- !assets.blank?
131
- end
132
-
133
- def resources
134
- self.class.resources
135
- end
136
-
137
- def has_resources?
138
- !resources.blank?
139
- end
140
-
141
- def views
142
- self.class.views
143
- end
144
-
145
- def has_views?
146
- !views.blank?
147
- end
148
-
149
- def templates
150
- self.class.templates
151
- end
152
-
153
- def has_templates?
154
- !templates.blank?
155
- end
156
-
157
- def middleware(type = :has)
158
- case type
159
- when :responders then self.class.responder_middleware
160
- when :routing then self.class.routing_middleware
161
- when :prerouting then self.class.prerouting_middleware
162
- when :postrouting then self.class.postrouting_middleware
163
- when :has then self.class.has_middleware
164
- else nil
165
- end
166
- end
167
-
168
- def has_middleware?
169
- !middleware.blank?
170
- end
171
- end
172
- end