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,16 +0,0 @@
1
- require 'orange-core/resource'
2
-
3
- module Orange
4
- class RoutableResource < Resource
5
- def routable; true; end
6
-
7
- def route(path, packet)
8
- parts = path.split('/')
9
- first = parts[0].respond_to?(:to_sym) ? parts.shift.to_sym : :index
10
- new_path = parts.join('/')
11
- if self.respond_to?(first)
12
- packet[:content] = self.__send__(first, new_path, packet)
13
- end
14
- end
15
- end
16
- end
@@ -1,106 +0,0 @@
1
- require 'orange-core/core'
2
-
3
- module Orange
4
- class Scaffold < Resource
5
- # Load the scaffold helpers
6
- def afterLoad
7
- orange.add_pulp Pulp::ScaffoldHelpers
8
- Packet.meta_methods(/view_([a-zA-Z_]+)/) do |packet, match, args|
9
- model = args.shift
10
- args = args.extract_with_defaults(:mode => match[1].to_sym)
11
- packet.view(model, args)
12
- end
13
- @scaffold_types = {}
14
- add_scaffold_type(:boolean) do |name, val, opts|
15
- if opts[:show]
16
- val ? "true" : "false"
17
- else
18
- ret = "<input type='hidden' name='#{opts[:model_name]}[#{name}]' value='0' /><input type='checkbox' name='#{opts[:model_name]}[#{name}]' value='1' #{'checked="checked"' if (val && val != '')}/>"
19
- ret = "<label for=''>#{opts[:display_name]}</label><br />" + ret if opts[:label]
20
- end
21
- end
22
- end
23
-
24
- def add_scaffold_type(type, &block)
25
- @scaffold_types[type] = Proc.new
26
- end
27
-
28
- def scaffold_attribute(packet, prop, model_name, *args)
29
- args = args.extract_options!
30
- args.with_defaults!({:packet => packet, :value => '', :label => false, :show => false})
31
- val = args[:value]
32
- label = args[:label]
33
- show = args[:show]
34
- name = prop[:name]
35
- human_readable_name = name.to_s.split('_').each{|w| w.capitalize!}.join(' ')
36
- display_name = prop[:display_name] || human_readable_name
37
- return @scaffold_types[prop[:type]].call(name, val, args.with_defaults!(:display_name => display_name, :model_name => model_name)) if @scaffold_types.has_key?(prop[:type])
38
- unless show
39
- case prop[:type]
40
- when :title
41
- val.gsub!('"', '&quot;')
42
- ret = "<input class=\"title\" type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
43
- when :text
44
- val.gsub!('"', '&quot;')
45
- ret = "<input type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
46
- when :fulltext
47
- ret = "<textarea name='#{model_name}[#{name}]'>#{val}</textarea>"
48
- when :boolean
49
- human_readable_name = human_readable_name + '?'
50
- ret = "<input type='hidden' name='#{model_name}[#{name}]' value='0' /><input type='checkbox' name='#{model_name}[#{name}]' value='1' #{'checked="checked"' if (val && val != '')}/>"
51
- when :date
52
- val.gsub!('"', '&quot;')
53
- ret = "<input class=\"date\" type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
54
- else
55
- val.gsub!('"', '&quot;')
56
- ret = "<input type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
57
- end
58
- ret = "<label for=''>#{display_name}</label><br />" + ret if label
59
- else
60
- case prop[:type]
61
- when :title
62
- ret = "<h3 class='#{model_name}-#{name}'>#{val}</h3>"
63
- when :text
64
- ret = "<p class='#{model_name}-#{name}'>#{val}</p>"
65
- when :fulltext
66
- ret = "<div class='#{model_name}-#{name}'>#{val}</div>"
67
- else
68
- ret = "<div class='#{model_name}-#{name}'>#{val}</div>"
69
- end
70
- end
71
- return ret
72
- end
73
- end
74
-
75
- module Pulp::ScaffoldHelpers
76
- # Creates a button that appears to be a link but
77
- # does form submission with custom method (_method param in POST)
78
- # This is to avoid issues of a destructive get.
79
- # @param [String] text link text to show
80
- # @param [String] link the actual href value of the link
81
- # @param [String, false] confirm text of the javascript confirm (false for none [default])
82
- # @param [optional, Array] args array of optional arguments, only opts[:method] defined
83
- # @option opts [String] method method name (Should be 'DELETE', 'PUT' or 'POST')
84
- def form_link(text, link, confirm = false, opts = {})
85
- text = "<img src='#{opts[:img]}' alt='#{text}' />" if opts[:img]
86
- css = opts[:class]? opts[:class] : 'form_button_link'
87
- meth = (opts[:method]? "<input type='hidden' name='_method' value='#{opts[:method]}' />" : '')
88
- if confirm
89
- "<form action='#{link}' method='post' class='mini' onsubmit='return confirm(\"#{confirm}\")'><button class='link_button'><a href='#' class='#{css}'>#{text}</a></button>#{meth}</form>"
90
- else
91
- "<form action='#{link}' method='post' class='mini'><button class='link_button'><a href='#' class='#{css}'>#{text}</a></button>#{meth}</form>"
92
- end
93
- end
94
-
95
- # Calls view for an orange resource.
96
- def view(model_name, *args)
97
- orange[model_name].view(self, *args)
98
- end
99
-
100
- # Returns a scaffolded attribute
101
- def view_attribute(prop, model_name, *args)
102
- orange[:scaffold].scaffold_attribute(self, prop, model_name, *args)
103
- end
104
- end
105
-
106
- end
@@ -1,226 +0,0 @@
1
- require 'orange-core/core'
2
- require 'rack/builder'
3
- module Orange
4
- # Builds an orange stack of middleware
5
- # Use in the rackup file as follows:
6
- # app = Orange::Stack.new do
7
- # stack Orange::DataMapper 'sqlite3::memory:' <= loads orange specific middleware
8
- # use OtherMiddleware
9
- # run SomeApp.new
10
- # end
11
- # run app
12
- #
13
- # All middleware placed inside the Orange::Stack will have access
14
- # to the Orange Core (as long as it's been written to accept it as the second
15
- # initialization argument) when added with the 'stack' method
16
- #
17
- # In general, Orange::Stack works like Rack::Builder.
18
- class Stack
19
-
20
- # Creates a new Orange::Stack out of the passed block.
21
- #
22
- # If a block is not passed, it will try to build one from scratch.
23
- # The bare minimum will be `run app_class.new(@core)`, there are also
24
- # other stacks that can be used.
25
- #
26
- # @param [Orange::Application] app_class the class of the main application
27
- # @param [Orange::Core] core the orange core
28
- # @param [Symbol] prebuilt the optional prebuilt stack, if one isn't passed as block
29
- def initialize(app_class = nil, core = false, prebuilt = :none, &block)
30
- @build = Rack::Builder.new
31
- @core = core || Orange::Core.new
32
- @core.stack = self # Set a back reference in the core.
33
- @auto_reload = false
34
- @app = false
35
- @middleware = []
36
- @recapture = true
37
- @main_app = app_class
38
- if block_given?
39
- instance_eval(&block)
40
- else
41
- @main_app = app_class.new(@core) unless app_class.nil?
42
- prebuild(prebuilt)
43
- end
44
- end
45
-
46
- # Runs methods necessary to build a stack. Don't use if a stack
47
- # has already been built by the initialize block.
48
- #
49
- # @todo Offer more choices for default stacks
50
- def prebuild(choice)
51
- case choice
52
- when :none
53
- run @main_app
54
- else
55
- run @main_app
56
- end
57
- end
58
-
59
- # Returns the main application instance that was added by the
60
- # run method. Obviously won't return anything useful if the
61
- # middleware stack hasn't been set up with an explicit exit point,
62
- # as could be the case for a pure orange middleware stack on
63
- # top of a different exit application (like Sinatra or Rails)
64
- def main_app
65
- @main_app
66
- end
67
-
68
- # Adds middleware using the Rack::Builder#use method
69
- # @param [Object] middleware A class of middleware that meets rack middleware requirements
70
- def use(middleware, *args, &block)
71
- @build.use(middleware, *args, &block)
72
- end
73
-
74
- # Loads resources into the core using the Orange::Core#load method
75
- #
76
- # all args are passed on
77
- def load(*args, &block)
78
- orange.load(*args, &block)
79
- end
80
-
81
- # Adds Orange-aware middleware using the Rack::Builder#use method, adding
82
- # the orange core to the args passed on
83
- def stack(middleware, *args, &block)
84
- @build.use(middleware, @core, *args, &block)
85
- end
86
-
87
- # Set the auto_reload option, called without args, defaults to true,
88
- # other option is to set it to false
89
- def auto_reload!(val = true)
90
- @auto_reload = val
91
- end
92
-
93
- # Shortcut for adding Orange::Middleware::ShowExceptions to the middleware
94
- # stack
95
- def use_exceptions
96
- stack Orange::Middleware::ShowExceptions
97
- end
98
-
99
- # Alias for use_exceptions
100
- def show_exceptions
101
- use_exceptions
102
- end
103
-
104
- # Turn off recapture middleware, which is normally just on top of the exit
105
- # point
106
- # @see Orange::Middleware::Recapture
107
- def no_recapture
108
- @recapture = false
109
- end
110
-
111
- # A shortcut for adding many of the routing middleware options
112
- # simultaneously. Includes:
113
- # * Orange::Middleware::Rerouter
114
- # * Orange::Middleware::Static
115
- # * Rack::AbstractFormat
116
- # * Orange::Middleware::RouteSite
117
- # * Orange::Middleware::RouteContext
118
- #
119
- # All of these are passed the args hash to use as they will, except
120
- # for Rack::AbstractFormat
121
- #
122
- def prerouting(*args)
123
- opts = args.extract_options!
124
- stack Orange::Middleware::Globals
125
- stack Orange::Middleware::Loader
126
- stack Orange::Middleware::Rerouter, opts.dup
127
- stack Orange::Middleware::Static, opts.dup
128
- use Rack::AbstractFormat unless opts[:no_abstract_format]
129
- # Must be used before non-destructive route altering done by Orange,
130
- # since all orange stuff is non-destructive
131
- stack Orange::Middleware::RouteSite, opts.dup
132
- stack Orange::Middleware::RouteContext, opts.dup
133
- stack Orange::Middleware::Database
134
- Orange.plugins.each{|p| p.middleware(:prerouting).each{|m| stack m, opts.dup} if p.has_middleware?}
135
- end
136
-
137
- # A shortcut for routing via Orange::Middleware::RestfulRouter and any plugins
138
- #
139
- # Any args are passed on to the middleware
140
- def routing(opts ={})
141
- stack Orange::Middleware::RestfulRouter, opts.dup
142
- Orange.plugins.each{|p| p.middleware(:routing).each{|m| stack m, opts.dup} if p.has_middleware?}
143
- end
144
-
145
- def postrouting(opts ={})
146
- Orange.plugins.each{|p| p.middleware(:postrouting).each{|m| stack m, opts.dup} if p.has_middleware?}
147
- stack Orange::Middleware::Template
148
- stack Orange::Middleware::FourOhFour, opts.dup # Last ditch, send route to 404 page.
149
- end
150
-
151
- def responders(opts ={})
152
- Orange.plugins.each{|p| p.middleware(:responders).each{|m| stack m, opts.dup} if p.has_middleware?}
153
- end
154
-
155
- # # A shortcut to enable Rack::OpenID and Orange::Middleware::AccessControl
156
- # #
157
- # # Args will be passed on to Orange::Middleware::AccessControl
158
- # def openid_access_control(*args)
159
- # opts = args.extract_options!
160
- #
161
- # end
162
-
163
- # Adds pulp to the core via the Orange::Core#add_pulp method
164
- # @param [Orange::Mixin] mod a mixin to be included in the packet
165
- def add_pulp(mod)
166
- orange.add_pulp(mod)
167
- end
168
-
169
- # The exit point for the middleware stack,
170
- # add the app to @main_app and then call Rack::Builder#run with the main app
171
- def run(app, *args)
172
- opts = args.extract_options!
173
- @main_app = app
174
- @build.run(app)
175
- end
176
-
177
- # Returns the Orange::Core
178
- # @return [Orange::Core] The orange core
179
- def orange
180
- @core
181
- end
182
-
183
- # Passes through to Rack::Builder#map
184
- # @todo Make this work - passing the block on to builder
185
- # means we can't intercept anything, which will yield
186
- # unexpected results
187
- def map(path, &block)
188
- raise 'not yet supported'
189
- @build.map(path, &block)
190
- end
191
-
192
- # Builds the middleware stack (or uses a cached one)
193
- #
194
- # If auto_reload is enabled ({#auto_reload!}), builds every time
195
- #
196
- # @return [Object] a full stack of middleware and the exit application,
197
- # conforming to Rack guidelines
198
- def app
199
- if @auto_reload
200
- orange.fire(:stack_reloading, @app) if orange.stack # Alert we are rebuilding
201
- @app = false # Rebuild no matter what if autoload
202
- end
203
- unless @app
204
- @app = do_build # Build if necessary
205
- orange.fire(:stack_loaded, @app)
206
- end
207
- @app
208
- end
209
-
210
- def do_build
211
- @build.to_app
212
- end
213
-
214
- # Sets the core and then passes on to the stack, according to standard
215
- # rack procedure
216
- def call(env)
217
- env['orange.core'] = @core
218
- app.call(env)
219
- end
220
-
221
- # Debug helping
222
- def inspect
223
- "#<Orange::Stack:0x#{self.object_id.to_s(16)} @build=#{@build.inspect}, @core=#{@core.inspect}>"
224
- end
225
- end
226
- end
@@ -1,111 +0,0 @@
1
- -# adapted from Django <djangoproject.com>
2
- -# Copyright (c) 2005, the Lawrence Journal-World
3
- -# Used under the modified BSD license:
4
- -# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
5
- !!!
6
- %html
7
- %head
8
- %meta{:name=>"robots", :content=>"NONE,NOARCHIVE"}
9
- %title Orange raised #{h exception.class} at #{h path}
10
- %link{:rel=>"stylesheet", :href=>"/assets/_orange_/css/exceptions.css", :type=>"text/css"}
11
- %script{:type=>"text/javascript", :src=>"/assets/_orange_/js/exceptions.js"}
12
- %body
13
- #summary
14
- %h1 #{h exception.class} at #{h path}
15
- %h2 #{h exception.message}
16
- %table
17
- %tr
18
- %th Ruby
19
- %td= "<code>#{h frames.first.filename}</code>: in <code>#{h frames.first.function}</code>, line #{h frames.first.lineno }"
20
- %tr
21
- %th Web
22
- %td= "<code>#{h req.request_method} #{h(req.host + path)}</code>"
23
- %h3= "Jump to:"
24
- %ul#quicklinks
25
- %li
26
- %a{:href=>"#get-info"} GET
27
- %li
28
- %a{:href=>"#post-info"} POST
29
- %li
30
- %a{:href=>"#cookie-info"} Cookies
31
- %li
32
- %a{:href=>"#env-info"} ENV
33
- %li
34
- %a{:href=>"#orange-info"} Orange
35
- #traceback
36
- %h2= "Traceback <span>(innermost first)</span>"
37
- %ul.traceback
38
- - frames.each do |frame|
39
- %li.frame
40
- = "<code>#{h frame.filename}</code>: in <code>#{h frame.function}</code>"
41
- - if frame.context_line
42
- .context{:id => "c#{frame.object_id}"}
43
- - if frame.pre_context
44
- %ol.pre-context{:start=>"#{h frame.pre_context_lineno+1}", :id=>"pre#{h frame.object_id }"}
45
- - frame.pre_context.each do |line|
46
- %li{:onclick=>"toggle('pre#{h frame.object_id}', 'post#{h frame.object_id }')"} #{h line}
47
- %ol.context-line{:start=>"#{h frame.lineno}"}
48
- %li{ :onclick=>"toggle('pre#{h frame.object_id}', 'post#{h frame.object_id }')"}= "#{h frame.context_line} <span>...</span>"
49
- - if frame.post_context
50
- %ol.post-context{ :start=>"#{h frame.lineno+1 }", :id=>"post#{h frame.object_id}"}
51
- - frame.post_context.each do |line|
52
- %li{:onclick=>"toggle('pre#{h frame.object_id}', 'post#{h frame.object_id }')"} #{h line}
53
- #requestinfo
54
- %h2 Request information
55
- - for var in [:GET, :POST, :cookies]
56
- %h3{:id => "#{var.to_s.downcase}-info"}= "#{var.to_s}"
57
- - unless req.__send__(var).empty?
58
- %table.req
59
- %thead
60
- %tr
61
- %th Variable
62
- %th Value
63
- %tbody
64
- - req.__send__(var).sort_by { |k, v| k.to_s }.each do |key, val|
65
- %tr
66
- %td #{h key}
67
- %td.code
68
- %div #{h val.inspect}
69
- - else
70
- %p No #{var.to_s} data.
71
- %h3#env-info Rack ENV
72
- %table.req
73
- %thead
74
- %tr
75
- %th Variable
76
- %th Value
77
- %tbody
78
- - env.sort_by { |k, v| k.to_s }.each do |key, val|
79
- - unless key =~ /^orange\./
80
- %tr
81
- %td #{h key}
82
- %td.code
83
- %div #{h val}
84
- %h3#orange-info Orange ENV
85
- %table.req
86
- %thead
87
- %tr
88
- %th Variable
89
- %th Value
90
- %tbody
91
- - env['orange.env'].sort_by { |k, v| k.to_s }.each do |key, val|
92
- - if(![:request, :headers, :content].include?(key))
93
- %tr
94
- %td #{h key}
95
- %td.code
96
- %div #{h val}
97
- %h3#orange-info= 'Orange<br /> Response'
98
- %table.req
99
- %thead
100
- %tr
101
- %th Variable
102
- %th Value
103
- %tbody
104
- - env['orange.env'].sort_by { |k, v| k.to_s }.each do |key, val|
105
- - if([:request, :headers, :content].include?(key))
106
- %tr
107
- %td #{h key}
108
- %td.code
109
- %div #{h val}
110
- #explanation
111
- %p= "You're seeing this error because you use <code>Orange::Middleware::ShowExceptions</code>."