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,34 +0,0 @@
1
- - if model
2
- - if resource.options[:sitemappable, false]
3
- = orange[:sitemap, true].sitemap_links(packet, {:slug_me => orange[:sitemap, true].slug_for(model, props)})
4
- %form{:action => route_to(model_name, model[:id], 'save'), :method => 'post'}
5
- - for prop in props
6
- %p~ view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
7
- %a{:href => route_to(model_name, model['id'], {:context => 'preview', :mode => 'show'}), :rel => 'external', :target => "_blank"}Preview
8
- :javascript
9
- $(function(){
10
- $('button.link_button').click(
11
- function(){
12
- $('input[name="pages[published]"]').val('1');
13
- }
14
- );
15
- });
16
- %input{:type => 'hidden', :id => 'pages[published]', :name => 'pages[published]', :value => '0'}
17
- %input{:type => 'submit', :value => 'Save Changes'}
18
- / = route_to(model_name, model[:id], 'publish')
19
- = form_link('Publish', packet.route_to(model_name, model[:id], 'save'))
20
- %h3 Published Versions
21
- %ul.version_list
22
- / %li (Current Draft)
23
- - for version in model.versions.all(:order => :version.desc, :limit=> 3)
24
- %li
25
- .version_container
26
- %span.version_info
27
- %strong Version #{version.version}
28
- %span.version_info
29
- Last Updated:
30
- %strong #{fuzzy_time(version.updated_at)}
31
- %span.version_info
32
- %a{:href => route_to(model_name, model[:id], 'edit', "version", version.version)}Edit
33
- - else
34
- %p Couldn't find the item you're looking for.
@@ -1,6 +0,0 @@
1
- - if model
2
- %div{ :class => model_name}
3
- - for prop in props
4
- = view_attribute(prop, model_name, :show => true, :value => model.attribute_get(prop[:name]))
5
- - if props.empty?
6
- %p= model.body
@@ -1 +0,0 @@
1
- require File.join('orange-more', 'sitemap', 'plugin')
@@ -1,11 +0,0 @@
1
- jQuery(function($){
2
- $('.sitemap_links_info a.more_info').toggle(
3
- function(){
4
- jQuery('.sitemap_links').show();
5
- jQuery('.sitemap_links_info a.more_info').text('Less Info');
6
- },
7
- function(){
8
- jQuery('.sitemap_links').hide();
9
- jQuery('.sitemap_links_info a.more_info').text('More Info');
10
- });
11
- });
@@ -1,43 +0,0 @@
1
- require 'orange-more/administration/cartons/site_carton'
2
- require 'dm-is-awesome_set'
3
-
4
- class OrangeRoute < Orange::SiteCarton
5
- id
6
- admin do
7
- text :slug, :display_name => "Search Engine Friendly Page URL", :length => 255
8
- text :link_text, :length => 255
9
- text :reroute_to, :length => 255
10
- boolean :show_in_nav, :default => false, :display_name => 'Show in Navigation?'
11
- end
12
- orange do
13
- string :resource
14
- string :resource_id
15
- string :resource_action
16
- boolean :accept_args, :default => true
17
- end
18
- include DataMapper::Transaction::Resource # Make sure Transactions are included (for awesome_set)
19
- is :awesome_set, :scope => [:orange_site_id]
20
-
21
- def full_path
22
- self_and_ancestors.inject('') do |path, part|
23
- if part.parent # Check if this is a child
24
- path = path + part.slug + '/'
25
- else # The root slug is just the initial '/'
26
- path = path + '/'
27
- end
28
- end
29
- end
30
-
31
- def self.home_for_site(site_id)
32
- root(:orange_site_id => site_id)
33
- end
34
-
35
-
36
- def self.create_home_for_site(site_id, opts = {})
37
- opts = opts.with_defaults({:orange_site_id => site_id, :slug => '_index_', :accept_args => false, :link_text => 'Home'})
38
- home = self.new(opts)
39
- home.move(:root)
40
- home.save
41
- home
42
- end
43
- end
@@ -1,25 +0,0 @@
1
- require 'orange-core/middleware/base'
2
-
3
- module Orange::Middleware
4
- # The FlexRouter middleware takes a resource that can route paths and
5
- # then intercepts routes for that resource. By default,
6
- # it uses the Orange::SitemapResource.
7
- #
8
- # The resource is automatically loaded into the core as
9
- # :sitemap. The resource must respond to "route?(path)"
10
- # and "route(packet)".
11
- #
12
- # Pass a different routing resource using the :resource arg
13
- class FlexRouter < Base
14
- # Sets the sitemap resource as the router if the resource can accept
15
- # the path.
16
- def packet_call(packet)
17
- return (pass packet) if packet['route.router'] # Don't route if other middleware
18
- # already has
19
- path = packet['route.path'] || packet.request.path_info
20
- packet['route.router'] = orange[:sitemap] if orange[:sitemap].route?(packet, path)
21
- pass packet
22
- end
23
-
24
- end
25
- end
@@ -1,17 +0,0 @@
1
- Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
2
- Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
3
- Dir.glob(File.join(File.dirname(__FILE__), 'middleware', '*.rb')).each {|f| require f }
4
-
5
- module Orange::Plugins
6
- class Sitemap < Base
7
- assets_dir File.join(File.dirname(__FILE__), 'assets')
8
- views_dir File.join(File.dirname(__FILE__), 'views')
9
-
10
- resource Orange::SitemapResource.new
11
- router Orange::Middleware::FlexRouter
12
-
13
- end
14
- end
15
-
16
- Orange.plugin(Orange::Plugins::Sitemap.new)
17
-
@@ -1,295 +0,0 @@
1
- require 'orange-core/core'
2
- require 'orange-core/resources/model_resource'
3
- module Orange
4
-
5
- class SitemapResource < ModelResource
6
- use OrangeRoute
7
- call_me :sitemap
8
- def stack_init
9
- orange[:admin, true].add_link('Content', :resource => @my_orange_name, :text => 'Sitemap')
10
- orange[:radius, true].define_tag "link" do |tag|
11
- packet = tag.locals.packet
12
- slug = tag.expand
13
- id = tag.attr['id'] if tag.attr['id']
14
- route = orange[:sitemap].find_route(packet, {:id => id}) if id
15
- route = orange[:sitemap].find_route(packet, {:slug => slug}) unless route
16
- route = orange[:sitemap].find_route(packet, {:link_text => slug}) unless route
17
-
18
- orange[:sitemap].to_html(packet, route, tag.attr["text"])
19
- end
20
- orange.register(:model_resource_deleted) do |packet, opts|
21
- model_class.all(opts).destroy!
22
- end
23
- end
24
-
25
- def to_href(packet, route)
26
- unless route.is_a? model_class
27
- route = model_class.get(route)
28
- end
29
- full_path = route ? route.full_path : "#not-found"
30
- end
31
-
32
- def to_html(packet, route, text = false)
33
- unless route.is_a? model_class
34
- route = model_class.get(route)
35
- end
36
- full_path = route ? route.full_path : "#not-found"
37
- link_text = route ? link_text_for(route) : "(Broken link tag)"
38
- link_text = text if text
39
- "<a href='#{full_path}'>#{link_text}</a>"
40
- end
41
-
42
- def route_actions(packet, opts = {})
43
- do_view(packet, :route_actions, opts)
44
- end
45
-
46
- def route(packet)
47
- return packet.reroute(packet['route.reroute']) if packet['route.reroute']
48
- resource = packet['route.resource']
49
- raise 'resource not found' unless orange.loaded? resource
50
- unless (packet['route.resource_action'])
51
- packet['route.resource_action'] = (packet['route.resource_id'] ? :show : :index)
52
- end
53
-
54
- packet[:content] = (orange[resource].view packet)
55
- end
56
-
57
- # Path should be an array of path parts
58
- def find_route_info(packet, path)
59
- parts = path.split('/')
60
- pad = parts.shift
61
- matched = home(packet, :subsite => true)
62
- extras = ''
63
- while (!parts.empty?)
64
- next_part = parts.shift
65
- matches = matched.children.first(:slug => next_part)
66
- if(matches)
67
- matched = matches
68
- else
69
- extras = parts.unshift(next_part).unshift(pad).join('/')
70
- parts = []
71
- end
72
- end
73
- [extras, matched]
74
- end
75
-
76
- def route?(packet, path)
77
- extras, matched = find_route_info(packet, path)
78
- return false if(extras.length > 0 && !matched.accept_args)
79
- return false if matched.resource.blank? && matched.reroute_to.blank?
80
- packet['route.reroute'] = matched.reroute_to unless matched.reroute_to.blank?
81
- packet['route.path'] = path
82
- packet['route.route'] = matched
83
- packet['route.resource'] = matched.resource.to_sym unless matched.resource.blank?
84
- packet['route.resource_id'] = matched.resource_id.to_i unless matched.resource_id.blank?
85
- packet['route.resource_action'] = matched.resource_action.to_sym unless matched.resource_action.blank?
86
- # allow "resource_paths" - extra arguments added as path parts
87
- packet['route.resource_path'] = extras
88
- return true
89
- end
90
-
91
- # Creates a new model object and saves it (if a post), then reroutes to the main page
92
- # @param [Orange::Packet] packet the packet being routed
93
- def onNew(packet, params = {})
94
- params.with_defaults!(:orange_site_id => (packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id))
95
- model_class.new(params)
96
- end
97
-
98
- def afterNew(packet, obj, params = {})
99
- obj.move(:into => home(packet))
100
- end
101
-
102
- def move(packet, obj, opts = {})
103
- no_reroute = opts.delete(:no_reroute)
104
- if packet.request.post? || !opts.blank?
105
- dir = opts[:direction]
106
- dir = {:into => opts[:parent]} if (dir == :into)
107
- obj ||= find_one(packet, :move, (opts[:id] || packet['route.resource_id']))
108
- obj.move(dir) if obj
109
- end
110
- packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
111
- end
112
-
113
- def show_in_nav(packet, opts = {})
114
- no_reroute = opts.delete(:no_reroute)
115
- if packet.request.post? || !opts.blank?
116
- obj = find_one(packet, :show_in_nav, (opts[:id] || opts[:resource_id] || packet['route.resource_id']))
117
- obj.show_in_nav = true
118
- obj.save
119
- end
120
- packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
121
- end
122
-
123
- def unshow_in_nav(packet, opts = {})
124
- no_reroute = opts.delete(:no_reroute)
125
- if packet.request.post? || !opts.blank?
126
- obj = find_one(packet, :unshow_in_nav, (opts[:id] || opts[:resource_id] || packet['route.resource_id']))
127
- obj.show_in_nav = false
128
- obj.save
129
- end
130
- packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
131
- end
132
-
133
- def higher(packet, opts = {})
134
- move(packet, false, :direction => :higher)
135
- end
136
-
137
- def into(packet, opts = {})
138
- opts[:parent_id] ||= packet['route.resource_path'].split('/').last
139
- opts[:parent] = find_one(packet, :move, (opts[:parent_id])) unless opts[:parent]
140
- move(packet, false, :direction => :into, :parent => opts[:parent])
141
- end
142
-
143
- def lower(packet, opts = {})
144
- move(packet, false, :direction => :lower)
145
- end
146
-
147
- def outdent(packet, opts = {})
148
- move(packet, false, :direction => :outdent)
149
- end
150
-
151
- def indent(packet, opts = {})
152
- move(packet, false, :direction => :indent)
153
- end
154
-
155
- def home(packet, opts = {})
156
- if(opts[:subsite])
157
- site_id = opts[:orange_site_id] || packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id
158
- else
159
- site_id = opts[:orange_site_id] || packet['site'].id
160
- end
161
- model_class.home_for_site(site_id) || create_home_for_site(packet, site_id)
162
- end
163
-
164
- def create_home_for_site(packet, site_id)
165
- page = orange[:pages, true].new(packet, :title => 'Homepage', :body => 'this is an orange webpage', :no_reroute => true)
166
- if page
167
- model_class.create_home_for_site(site_id, :resource => 'pages', :resource_id => page.id)
168
- else
169
- model_class.create_home_for_site(site_id)
170
- end
171
- end
172
-
173
- def one_level(packet, opts = {})
174
- opts.with_defaults!(:model => home(packet))
175
- do_view(packet, :one_level, opts)
176
- end
177
-
178
- def two_level(packet, opts = {})
179
- opts.with_defaults!(:model => home(packet))
180
- do_view(packet, :two_level, opts)
181
- end
182
-
183
- def breadcrumb(packet, opts = {})
184
- opts.with_defaults!(:model => packet['route.route'])
185
- do_view(packet, :breadcrumb, opts)
186
- end
187
-
188
- def routes_for(packet, opts = {})
189
- keys = {}
190
- keys[:resource] = opts[:resource] || packet['route.resource']
191
- keys[:resource_id] = opts[:resource_id] || packet['route.resource_id']
192
- keys[:orange_site_id] = opts[:orange_site_id] || (packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id)
193
- keys[:slug] = opts[:slug]
194
- keys.delete_if{|k,v| v.blank? }
195
- model_class.all(keys)
196
- end
197
-
198
- def find_route(packet, opts = {})
199
- site_id = packet['site'].id
200
- subsite_id = packet['subsite'].blank? ? nil : packet['subsite'].id
201
- # First try subsite, if necessary
202
- m = model_class.first(opts.merge(:orange_site_id => subsite_id)) if subsite_id
203
- m = model_class.first(opts.merge(:orange_site_id => site_id)) unless m
204
- m
205
- end
206
-
207
- def add_link_for(packet)
208
- linky = ['add_route']
209
- linky << (packet['subsite'].blank? ? (packet['site'].blank? ? '0' : packet['site'].id) : packet['subsite'].id)
210
- linky << (packet['route.resource'].blank? ? '0' : packet['route.resource'])
211
- linky << (packet['route.resource_id'].blank? ? '0' : packet['route.resource_id'])
212
- packet.route_to(:sitemap, linky.join('/') )
213
- end
214
-
215
- def add_route_for(packet, opts = {})
216
- unless opts.blank?
217
- parent = opts.delete(:parent) || home(packet, opts)
218
- unless parent.is_a? model_class
219
- parent = model_class.get(parent) # Get parent object if parent was an id number
220
- end
221
- me = model_class.new(opts)
222
- me.save
223
- me.move(:into => parent)
224
- end
225
- end
226
-
227
- def url_for(packet, opts = {})
228
- include_subsite = opts.delete(:include_subsite) || false
229
- m = model_class.first(opts)
230
- if !packet['subsite'].blank? && include_subsite
231
- return orange[:subsites].url_for(packet).gsub(/\/$/, '') + (m ? m.full_path : '#not_found')
232
- else
233
- return (m ? m.full_path : '#not_found')
234
- end
235
- end
236
-
237
- def add_route(packet, opts = {})
238
- args = packet['route.resource_path'].split('/')
239
- args.shift
240
- args = [:orange_site_id, :resource, :resource_id, :slug].inject_hash{|results, key|
241
- results[key] = args.shift
242
- }
243
- me = model_class.new(args)
244
- me.save
245
- me.move(:into => home(packet))
246
- packet.reroute(@my_orange_name, :orange, me.id, 'edit')
247
- do_view(packet, :add_route, {})
248
- end
249
-
250
- def slug_for(model, props)
251
- hash = model.attributes
252
- # return slug(model.title) if hash.has_key?(:title)
253
- # return slug(model.name) if hash.has_key?(:name)
254
- return 'page-'+model.id.to_s
255
- end
256
-
257
- def link_text_for(route)
258
- return route.link_text unless route.resource && route.resource_id
259
- if match = route.link_text.match(/^\{([-a-z0-9A-Z_]+)\}$/)
260
- resource = route.resource.to_sym
261
- return route.link_text unless orange.loaded?(resource)
262
- orange[resource].model_class.get(route.resource_id).__send__(match[1])
263
- else
264
- route.link_text
265
- end
266
- end
267
-
268
- def slug(str)
269
- str.downcase.gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "-")
270
- end
271
-
272
- def find_list(packet, mode, *args)
273
- home(packet, :subsite => true).self_and_descendants
274
- end
275
-
276
- def table_row(packet, opts ={})
277
- opts[:route] = opts[:model] || find_one(packet, :table_row, opts[:id])
278
- resource = opts[:route].resource
279
- resource = resource.to_sym unless resource.blank?
280
- if resource && orange[resource].respond_to?(:sitemap_row)
281
- opts.delete(:model)
282
- orange[resource].sitemap_row(packet, opts.merge(:resource_name => resource, :id => opts[:route].resource_id))
283
- else
284
- do_view(packet, :table_row, opts)
285
- end
286
- end
287
-
288
- def sitemap_links(packet, opts = {})
289
- packet.add_js('sitemap.js', :module => '_sitemap_')
290
- opts.with_defaults!({:list => routes_for(packet) })
291
- opts.merge!({:add_route_link => add_link_for(packet)})
292
- do_list_view(packet, :sitemap_links, opts)
293
- end
294
- end
295
- end