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,17 +0,0 @@
1
- require 'orange-core/middleware/base'
2
- module Orange::Middleware
3
-
4
- class Globals < Base
5
- def init(opts = {})
6
- opts = opts.with_defaults(:file => "__ORANGE__/config.yml")
7
- @file = opts[:file].gsub('__ORANGE__', orange.app_dir)
8
- @globals = orange[:parser].yaml(@file) || {}
9
- @globals.each{|k,v| orange.options[k] = v}
10
- end
11
- def packet_call(packet)
12
- packet['orange.globals'] ||= orange.options
13
- pass packet
14
- end
15
-
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- require 'orange-core/middleware/base'
2
- module Orange::Middleware
3
- class Loader < Base
4
- def init(*args)
5
- Dir.glob(File.join(orange.app_dir, 'resources', '*.rb')).each do |f|
6
- require f
7
- orange.load Orange::Inflector.constantize(Orange::Inflector.camelize(File.basename(f, '.rb'))).new
8
- end
9
- Dir.glob(File.join(orange.app_dir, 'cartons', '*.rb')).each { |f| require f }
10
- Dir.glob(File.join(orange.app_dir, 'middleware', '*.rb')).each { |f| require f }
11
- end
12
- end
13
- end
@@ -1,53 +0,0 @@
1
- require 'orange-core/middleware/base'
2
- module Orange::Middleware
3
-
4
- class Rerouter < Base
5
- def init(*args)
6
- orange.add_pulp Orange::Pulp::Packet_Reroute
7
- end
8
-
9
- def packet_call(packet)
10
- begin
11
- pass packet
12
- rescue Orange::Reroute
13
- packet.finish
14
- end
15
- end
16
- end
17
- end
18
-
19
- module Orange
20
-
21
- module Pulp::Packet_Reroute
22
- def reroute(url, type = :real, *args)
23
- packet['reroute.to'] = url
24
- packet['reroute.type'] = type
25
- packet['reroute.args'] = *args if args
26
- raise Reroute.new(self), 'Unhandled reroute'
27
- end
28
- end
29
-
30
- class Reroute < Exception
31
- def initialize(packet)
32
- @packet = packet
33
- @packet[:headers] = {"Content-Type" => 'text/html', "Location" => self.url}
34
- @packet[:status] = 302
35
- end
36
-
37
- def url
38
- case packet['reroute.type']
39
- when :real
40
- packet['reroute.to']
41
- # Parsing for orange urls or something
42
- when :orange
43
- packet.route_to(packet['reroute.to'], *packet['reroute.args', []])
44
- else
45
- packet['reroute.to']
46
- end
47
- end
48
-
49
- def packet
50
- @packet
51
- end
52
- end
53
- end
@@ -1,99 +0,0 @@
1
- require 'orange-core/middleware/base'
2
-
3
- module Orange::Middleware
4
- class RestfulRouter < Base
5
- def init(*args)
6
- opts = args.extract_options!.with_defaults(:restful_contexts => [:admin, :orange], :not_found => false, :exposed_actions => {:admin => :all, :orange => :all})
7
- @exposed = opts[:exposed_actions]
8
- @contexts = opts[:restful_contexts]
9
- @not_found = opts[:not_found]
10
- end
11
-
12
- # sets resource, resource_id, resource_action and resource_path
13
- # /resource/id/action/[resource/path/if/any]
14
- # /resource/action/[resource/path/if/any]
15
- #
16
- # In future - support for nested resources
17
- def packet_call(packet)
18
- return (pass packet) if packet['route.router'] # Don't route if other middleware
19
- # already has
20
- parts = route_parts(packet)
21
- if(should_route?(packet, parts))
22
- # Take parts of route and set packet info
23
- packet['route.resource'] = parts[:resource] if parts[:resource]
24
- packet['route.resource_id'] = parts[:resource_id] if parts[:resource_id]
25
- packet['route.resource_action'] = parts[:resource_action] if parts[:resource_action]
26
-
27
- # Take remainder and set to resource_path
28
- packet['route.resource_path'] = parts[:remainder]
29
-
30
- # Set self as router if resource was found
31
- if(packet['route.resource', false])
32
- packet['route.router'] = self
33
- elsif(@not_found)
34
- packet['route.resource'] = @not_found
35
- packet['route.router'] = self
36
- end
37
- end
38
-
39
- pass packet
40
- end
41
-
42
- def route_parts(packet)
43
- return_parts = {}
44
- path = packet['route.path'] || packet.request.path_info
45
- parts = path.split('/')
46
- pad = parts.shift
47
- if !parts.empty?
48
- resource = parts.shift
49
- if orange.loaded?(resource.to_sym)
50
- return_parts[:resource] = resource.to_sym
51
- if !parts.empty?
52
- second = parts.shift
53
- if second =~ /^\d+$/
54
- return_parts[:resource_id] = second
55
- if !parts.empty?
56
- return_parts[:resource_action] = parts.shift.to_sym
57
- else
58
- return_parts[:resource_action] = :show
59
- end
60
- else
61
- return_parts[:resource_action] = second.to_sym
62
- end
63
- else
64
- return_parts[:resource_action] = :list
65
- end # end check for second part
66
- else
67
- parts.unshift(resource)
68
- end # end check for loaded resource
69
- end # end check for nonempty route
70
- return_parts[:remainder] = parts.unshift(pad).join('/')
71
- return_parts
72
- end
73
-
74
- def should_route?(packet, parts)
75
- return false unless @exposed.has_key?(packet['route.context'])
76
- action_exposed?(@exposed[packet['route.context']], parts)
77
- end
78
-
79
- def action_exposed?(list, route_parts)
80
- return true if list == :all
81
- return true if list == route_parts[:resource_action]
82
- return true if list.is_a?(Array) && list.include?(route_parts[:resource_action])
83
- if list.is_a?(Hash)
84
- all = list.has_key?(:all) ? action_exposed?(list[:all], route_parts) : false
85
- one = list.has_key?(route_parts[:resource]) ? action_exposed?(list[route_parts[:resource]], route_parts) : false
86
- return all || one
87
- end
88
- false
89
- end
90
-
91
- def route(packet)
92
- resource = packet['route.resource']
93
- raise 'resource not found' unless orange.loaded? resource
94
- mode = packet['route.resource_action'] ||
95
- (packet['route.resource_id'] ? :show : :list)
96
- packet[:content] = orange[resource].view packet
97
- end
98
- end
99
- end
@@ -1,39 +0,0 @@
1
- require 'orange-core/middleware/base'
2
-
3
- module Orange::Middleware
4
- # This middleware handles setting orange.env['route.context']
5
- # to a value based on the route, if any. The route is then
6
- # trimmed before continuing on.
7
- class RouteContext < Base
8
- def initialize(app, core, *args)
9
- opts = args.extract_options!
10
- opts.with_defaults!(:contexts => [:preview, :live, :admin, :orange],
11
- :default => :live,
12
- :urls => {})
13
- @app = app
14
- @core = core
15
- @contexts = opts[:contexts]
16
- @default = opts[:default]
17
- @urls = opts[:urls]
18
- end
19
- def packet_call(packet)
20
- path_info = packet['route.path'] || packet.env['PATH_INFO']
21
- path = path_info.split('/')
22
- pad = path.shift # Shift off empty first part
23
- if @urls[packet.request.host]
24
- packet['route.context'] = urls[packet.request.host]
25
- elsif path.empty?
26
- packet['route.context'] = @default
27
- else
28
- if(@contexts.include?(path.first.to_sym))
29
- packet['route.context'] = path.shift.to_sym
30
- path.unshift(pad)
31
- packet['route.path'] = path.join('/')
32
- else
33
- packet['route.context'] = @default
34
- end
35
- end
36
- pass packet
37
- end
38
- end
39
- end
@@ -1,51 +0,0 @@
1
- require 'orange-core/middleware/base'
2
-
3
- module Orange::Middleware
4
- # This middleware handles setting orange.env['route.site_url']
5
- # to a value based on the route, if any. The route is then
6
- # trimmed before continuing on.
7
- #
8
- # Options -
9
- # :multi - does Orange need to handle multiple urls
10
- # :fake_it - host url(s) that Orange will fake requests on
11
- # ex: :multi => true, :fake_it => 'localhost'
12
- # will fake hostnames as first component of url
13
- # only on localhost
14
- class RouteSite < Base
15
- def initialize(app, core, *args)
16
- opts = args.extract_options!
17
- opts.with_defaults!(:multi => false, :fake_it => ['localhost'])
18
- @app = app
19
- @core = core
20
- @multi = opts[:multi]
21
- # Put fake_it into an array, if necessary
22
- @fake_it = opts[:fake_it].respond_to?(:include?) ?
23
- opts[:fake_it] : [opts[:fake_it]]
24
- end
25
-
26
- def packet_call(packet)
27
- request = packet.request
28
- path_info = packet['route.path'] || packet.env['PATH_INFO']
29
- path = path_info.split('/')
30
- pad = path.shift # Shift off empty first part
31
- packet['route.faked_site'] = false
32
- if @multi
33
- if path.empty?
34
- packet['route.site_url'] = request.host
35
- else
36
- if @fake_it.include?(request.host)
37
- packet['route.site_url'] = path.shift
38
- packet['route.faked_site'] = true
39
- else
40
- packet['route.site_url'] = request.host
41
- end
42
- path.unshift(pad)
43
- packet['route.path'] = path.join('/')
44
- end
45
- else
46
- packet['route.site_url'] = request.host
47
- end
48
- pass packet
49
- end
50
- end
51
- end
@@ -1,80 +0,0 @@
1
- require 'ostruct'
2
- require 'rack/request'
3
- require 'rack/utils'
4
- require 'orange-core/middleware/base'
5
-
6
- module Orange::Middleware
7
- # Rack::ShowExceptions catches all exceptions raised from the app it
8
- # wraps. It shows a useful backtrace with the sourcefile and
9
- # clickable context, the whole Rack environment and the request
10
- # data.
11
- #
12
- # Be careful when you use this on public-facing sites as it could
13
- # reveal information helpful to attackers.
14
- #
15
- # Orange::Middleware::ShowExceptions is a slightly modified
16
- # version of Rack::ShowExceptions
17
- class ShowExceptions < Base
18
- CONTEXT = 7
19
-
20
- def call(env)
21
- @app.call(env)
22
- rescue Exception => e
23
- backtrace = pretty(env, e)
24
-
25
- [500,
26
- {"Content-Type" => "text/html",
27
- "Content-Length" => backtrace.join.size.to_s},
28
- backtrace]
29
- end
30
-
31
- def packet_call(packet)
32
- backtrace = pretty()
33
- end
34
-
35
- def pretty(env, exception)
36
- req = Rack::Request.new(env)
37
- path = (req.script_name + req.path_info).squeeze("/")
38
-
39
- frames = exception.backtrace.map { |line|
40
- frame = OpenStruct.new
41
- if line =~ /(.*?):(\d+)(:in `(.*)')?/
42
- frame.filename = $1
43
- frame.lineno = $2.to_i
44
- frame.function = $4
45
-
46
- begin
47
- lineno = frame.lineno-1
48
- lines = ::File.readlines(frame.filename)
49
- frame.pre_context_lineno = [lineno-CONTEXT, 0].max
50
- frame.pre_context = lines[frame.pre_context_lineno...lineno]
51
- frame.context_line = lines[lineno].chomp
52
- frame.post_context_lineno = [lineno+CONTEXT, lines.size].min
53
- frame.post_context = lines[lineno+1..frame.post_context_lineno]
54
- rescue
55
- end
56
-
57
- frame
58
- else
59
- nil
60
- end
61
- }.compact
62
-
63
- env["rack.errors"].puts "#{exception.class}: #{exception.message}"
64
- env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l }
65
- env["rack.errors"].flush
66
- orange_env = env["orange.env"]
67
- parse = orange[:parser].haml("exceptions.haml", binding, :template => true)
68
- [parse]
69
- end
70
-
71
- def h(obj) # :nodoc:
72
- case obj
73
- when String
74
- Rack::Utils.escape_html(obj)
75
- else
76
- Rack::Utils.escape_html(obj.inspect)
77
- end
78
- end
79
- end
80
- end
@@ -1,67 +0,0 @@
1
- require 'orange-core/middleware/base'
2
- require 'orange-core/middleware/static_file'
3
-
4
- module Orange::Middleware
5
- # The Orange::Middleware::Static middleware intercepts requests for static files
6
- # (javascript files, images, stylesheets, etc) based on the url prefixes
7
- # passed in the options, and serves them using a Rack::File object.
8
- #
9
- # This differs from Rack::Static in that it can serve from multiple roots
10
- # to accommodate both Orange static files and site specific ones.
11
- # urls and root act the same as they do for Rack::Static. Only :libs option acts
12
- # specially.
13
- #
14
- # Each lib is responsible for responding to static_url and static_dir
15
- #
16
- # Examples:
17
- # use Orange::Middleware::Static :libs => [Orange::Core, AwesomeMod]
18
- # use Orange::Middleware::Static :libs => [Orange::Core, AwesomeMod],
19
- # :urls => ["/favicon.ico"]
20
- #
21
- # => Example 1 would load a file root for Orange::Core and Awesome Mod
22
- # Orange::Core static_url is _orange_, and dir is the
23
- # orange lib/assets folder
24
- # => Example 2 would also redirect favicon.ico to the assets dir
25
- #
26
- #
27
- # Note that as a general rule, Orange will assume everything static to be in an
28
- # /assets/ subfolder, therefore, '/assets' will be prepended to the url given
29
- # by static_url
30
- # Also note, that since this is the case - setting up a match for general '/assets'
31
- # could yield unpredictable results
32
- #
33
- # a static_url corresponds to the :module => in the add_css and add_js helpers
34
- class Static < Base
35
-
36
- def initialize(app, core, options={})
37
- @lib_urls = {'_orange_' => File.join(core.core_dir, 'assets') }
38
- Orange.plugins.each{|p| @lib_urls[p.assets_name] = p.assets if p.has_assets?}
39
-
40
- @app = app
41
- @core = core
42
- @urls = options[:urls] || ["/favicon.ico", "/assets/public", "/assets/uploaded"]
43
- @root = options[:root] || File.join(orange.app_dir, 'assets')
44
- @file_server = Orange::Middleware::StaticFile.new(@root)
45
- end
46
-
47
- def packet_call(packet)
48
- path = packet.env["PATH_INFO"]
49
- can_serve_lib = @lib_urls.select { |url, server|
50
- path.index(File.join('', 'assets', url)) == 0
51
- }.first
52
- can_serve = @urls.any?{|url| path.index(url) == 0 }
53
- if can_serve_lib
54
- lib_url = can_serve_lib.first
55
- packet['file.root'] = can_serve_lib.last
56
- packet['route.path'] = path.split(lib_url, 2).last
57
- @file_server.call(packet.env)
58
- elsif can_serve
59
- packet['route.path'] = path.gsub(/^\/assets/, '')
60
- @file_server.call(packet.env)
61
- else
62
- pass packet
63
- end
64
- end
65
-
66
- end
67
- end
@@ -1,32 +0,0 @@
1
- require 'rack'
2
- require 'rack/utils'
3
-
4
- module Orange::Middleware
5
- # Rack::File serves files below the +root+ given, according to the
6
- # path info of the Rack request.
7
- # Orange::Middleware::StaticFile acts the same as Rack::File, but acts on
8
- # the orange specific path if available. (So site url would be ignored, etc.)
9
- #
10
- # Handlers can detect if bodies are a Rack::File, and use mechanisms
11
- # like sendfile on the +path+.
12
-
13
- class StaticFile < Rack::File
14
- def _call(env)
15
- @path_info = Rack::Utils.unescape(env['orange.env']["route.path"]) || Rack::Utils.unescape(env["PATH_INFO"])
16
- @root = env['orange.env']['file.root'] || @root
17
- return forbidden if @path_info.include? ".."
18
-
19
- @path = F.join(@root, @path_info)
20
-
21
- begin
22
- if F.file?(@path) && F.readable?(@path)
23
- serving
24
- else
25
- raise Errno::EPERM
26
- end
27
- rescue SystemCallError
28
- not_found
29
- end
30
- end
31
- end
32
- end