orange-more 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/README.markdown +17 -0
  2. data/lib/orange-more.rb +23 -0
  3. data/lib/orange-more/administration.rb +1 -0
  4. data/lib/orange-more/administration/assets/css/admin.css +286 -0
  5. data/lib/orange-more/administration/assets/css/blueprint-ie.css +35 -0
  6. data/lib/orange-more/administration/assets/css/blueprint-print.css +29 -0
  7. data/lib/orange-more/administration/assets/css/blueprint.css +257 -0
  8. data/lib/orange-more/administration/assets/js/jquery.js +152 -0
  9. data/lib/orange-more/administration/cartons/site.rb +7 -0
  10. data/lib/orange-more/administration/cartons/site_carton.rb +12 -0
  11. data/lib/orange-more/administration/cartons/user.rb +27 -0
  12. data/lib/orange-more/administration/middleware/access_control.rb +156 -0
  13. data/lib/orange-more/administration/middleware/site_load.rb +25 -0
  14. data/lib/orange-more/administration/plugin.rb +23 -0
  15. data/lib/orange-more/administration/resources/admin_resource.rb +27 -0
  16. data/lib/orange-more/administration/resources/site_resource.rb +10 -0
  17. data/lib/orange-more/administration/resources/user_resource.rb +40 -0
  18. data/lib/orange-more/administration/templates/admin.haml +25 -0
  19. data/lib/orange-more/administration/views/openid_login.haml +14 -0
  20. data/lib/orange-more/administration/views/users/create.haml +10 -0
  21. data/lib/orange-more/administration/views/users/edit.haml +15 -0
  22. data/lib/orange-more/adverts.rb +1 -0
  23. data/lib/orange-more/adverts/cartons/adverts_carton.rb +14 -0
  24. data/lib/orange-more/adverts/plugin.rb +13 -0
  25. data/lib/orange-more/adverts/resources/adverts_resource.rb +27 -0
  26. data/lib/orange-more/adverts/views/adverts/adverts.haml +2 -0
  27. data/lib/orange-more/analytics.rb +1 -0
  28. data/lib/orange-more/analytics/middleware/analytics.rb +30 -0
  29. data/lib/orange-more/analytics/plugin.rb +11 -0
  30. data/lib/orange-more/analytics/resources/analytics_resource.rb +42 -0
  31. data/lib/orange-more/assets.rb +1 -0
  32. data/lib/orange-more/assets/cartons/asset_carton.rb +27 -0
  33. data/lib/orange-more/assets/plugin.rb +13 -0
  34. data/lib/orange-more/assets/resources/asset_resource.rb +115 -0
  35. data/lib/orange-more/assets/views/assets/change.haml +1 -0
  36. data/lib/orange-more/assets/views/assets/create.haml +13 -0
  37. data/lib/orange-more/assets/views/assets/insert.haml +1 -0
  38. data/lib/orange-more/blog.rb +1 -0
  39. data/lib/orange-more/blog/cartons/blog.rb +8 -0
  40. data/lib/orange-more/blog/cartons/blog_post.rb +60 -0
  41. data/lib/orange-more/blog/plugin.rb +14 -0
  42. data/lib/orange-more/blog/resources/blog_post_resource.rb +54 -0
  43. data/lib/orange-more/blog/resources/blog_resource.rb +104 -0
  44. data/lib/orange-more/blog/views/blog/blog_archive_view.haml +6 -0
  45. data/lib/orange-more/blog/views/blog/blog_offset_list_view.haml +12 -0
  46. data/lib/orange-more/blog/views/blog/blog_post_view.haml +4 -0
  47. data/lib/orange-more/blog/views/blog/sitemap_row.haml +14 -0
  48. data/lib/orange-more/blog/views/blog_posts/edit.haml +8 -0
  49. data/lib/orange-more/blog/views/blog_posts/show.haml +4 -0
  50. data/lib/orange-more/cloud.rb +1 -0
  51. data/lib/orange-more/cloud/plugin.rb +10 -0
  52. data/lib/orange-more/cloud/resources/cloud_resource.rb +21 -0
  53. data/lib/orange-more/contactforms.rb +1 -0
  54. data/lib/orange-more/contactforms/assets/js/jquery.validate.pack.js +15 -0
  55. data/lib/orange-more/contactforms/assets/js/lib/jquery-1.4.2.js +6240 -0
  56. data/lib/orange-more/contactforms/assets/js/lib/jquery.form.js +660 -0
  57. data/lib/orange-more/contactforms/assets/js/lib/jquery.js +4376 -0
  58. data/lib/orange-more/contactforms/assets/js/lib/jquery.metadata.js +122 -0
  59. data/lib/orange-more/contactforms/cartons/contactforms_carton.rb +12 -0
  60. data/lib/orange-more/contactforms/plugin.rb +13 -0
  61. data/lib/orange-more/contactforms/resources/contactforms_resource.rb +56 -0
  62. data/lib/orange-more/contactforms/views/contactforms/contactform.haml +20 -0
  63. data/lib/orange-more/debugger.rb +1 -0
  64. data/lib/orange-more/debugger/assets/css/debug_bar.css +46 -0
  65. data/lib/orange-more/debugger/middleware/debugger.rb +50 -0
  66. data/lib/orange-more/debugger/plugin.rb +12 -0
  67. data/lib/orange-more/debugger/views/debug_bar.haml +87 -0
  68. data/lib/orange-more/disqus.rb +1 -0
  69. data/lib/orange-more/disqus/plugin.rb +11 -0
  70. data/lib/orange-more/disqus/resources/disqus_resource.rb +9 -0
  71. data/lib/orange-more/disqus/views/disqus/comment_thread.haml +7 -0
  72. data/lib/orange-more/donations.rb +1 -0
  73. data/lib/orange-more/donations/cartons/donation_carton.rb +9 -0
  74. data/lib/orange-more/donations/plugin.rb +12 -0
  75. data/lib/orange-more/donations/resources/donations_resource.rb +51 -0
  76. data/lib/orange-more/donations/views/donations/donate_form.haml +21 -0
  77. data/lib/orange-more/donations/views/donations/donate_thanks.haml +2 -0
  78. data/lib/orange-more/donations/views/donations/paypal_form.haml +13 -0
  79. data/lib/orange-more/events.rb +1 -0
  80. data/lib/orange-more/events/assets/js/events.js +55 -0
  81. data/lib/orange-more/events/cartons/orange_calendar.rb +8 -0
  82. data/lib/orange-more/events/cartons/orange_event.rb +60 -0
  83. data/lib/orange-more/events/plugin.rb +14 -0
  84. data/lib/orange-more/events/resources/calendar_resource.rb +33 -0
  85. data/lib/orange-more/events/resources/event_resource.rb +147 -0
  86. data/lib/orange-more/events/views/calendar/calendar.haml +8 -0
  87. data/lib/orange-more/events/views/events/create.haml +55 -0
  88. data/lib/orange-more/events/views/events/edit.haml +59 -0
  89. data/lib/orange-more/events/views/events/list.haml +13 -0
  90. data/lib/orange-more/events/views/events/show.haml +4 -0
  91. data/lib/orange-more/events/views/events/table_row.haml +17 -0
  92. data/lib/orange-more/members.rb +1 -0
  93. data/lib/orange-more/members/cartons/member_carton.rb +38 -0
  94. data/lib/orange-more/members/plugin.rb +13 -0
  95. data/lib/orange-more/members/resources/members_resource.rb +327 -0
  96. data/lib/orange-more/members/views/members/create.haml +12 -0
  97. data/lib/orange-more/members/views/members/edit.haml +15 -0
  98. data/lib/orange-more/members/views/members/live.show.haml +1 -0
  99. data/lib/orange-more/members/views/members/login.haml +17 -0
  100. data/lib/orange-more/members/views/members/logout.haml +1 -0
  101. data/lib/orange-more/members/views/members/profile.haml +50 -0
  102. data/lib/orange-more/members/views/members/register.haml +37 -0
  103. data/lib/orange-more/news.rb +1 -0
  104. data/lib/orange-more/news/cartons/news.rb +12 -0
  105. data/lib/orange-more/news/plugin.rb +13 -0
  106. data/lib/orange-more/news/resources/news_resource.rb +83 -0
  107. data/lib/orange-more/news/views/news/archive.haml +14 -0
  108. data/lib/orange-more/news/views/news/edit.haml +7 -0
  109. data/lib/orange-more/news/views/news/latest.haml +8 -0
  110. data/lib/orange-more/news/views/news/sitemap_row.haml +14 -0
  111. data/lib/orange-more/pages.rb +1 -0
  112. data/lib/orange-more/pages/cartons/page_carton.rb +14 -0
  113. data/lib/orange-more/pages/cartons/page_version_carton.rb +12 -0
  114. data/lib/orange-more/pages/plugin.rb +13 -0
  115. data/lib/orange-more/pages/resources/page_resource.rb +179 -0
  116. data/lib/orange-more/pages/views/pages/edit.haml +34 -0
  117. data/lib/orange-more/pages/views/pages/show.haml +6 -0
  118. data/lib/orange-more/sitemap.rb +1 -0
  119. data/lib/orange-more/sitemap/assets/img/sitemap_down.png +0 -0
  120. data/lib/orange-more/sitemap/assets/img/sitemap_down_d.png +0 -0
  121. data/lib/orange-more/sitemap/assets/img/sitemap_indent.png +0 -0
  122. data/lib/orange-more/sitemap/assets/img/sitemap_indent_d.png +0 -0
  123. data/lib/orange-more/sitemap/assets/img/sitemap_outdent.png +0 -0
  124. data/lib/orange-more/sitemap/assets/img/sitemap_outdent_d.png +0 -0
  125. data/lib/orange-more/sitemap/assets/img/sitemap_up.png +0 -0
  126. data/lib/orange-more/sitemap/assets/img/sitemap_up_d.png +0 -0
  127. data/lib/orange-more/sitemap/assets/js/sitemap.js +11 -0
  128. data/lib/orange-more/sitemap/cartons/route.rb +44 -0
  129. data/lib/orange-more/sitemap/middleware/flex_router.rb +25 -0
  130. data/lib/orange-more/sitemap/plugin.rb +17 -0
  131. data/lib/orange-more/sitemap/resources/sitemap_resource.rb +295 -0
  132. data/lib/orange-more/sitemap/views/default_resource/sitemap_row.haml +30 -0
  133. data/lib/orange-more/sitemap/views/sitemap/breadcrumb.haml +12 -0
  134. data/lib/orange-more/sitemap/views/sitemap/list.haml +4 -0
  135. data/lib/orange-more/sitemap/views/sitemap/one_level.haml +7 -0
  136. data/lib/orange-more/sitemap/views/sitemap/route_actions.haml +15 -0
  137. data/lib/orange-more/sitemap/views/sitemap/sitemap_links.haml +14 -0
  138. data/lib/orange-more/sitemap/views/sitemap/table_row.haml +30 -0
  139. data/lib/orange-more/sitemap/views/sitemap/two_level.haml +13 -0
  140. data/lib/orange-more/slices.rb +1 -0
  141. data/lib/orange-more/slices/middleware/radius_parser.rb +24 -0
  142. data/lib/orange-more/slices/plugin.rb +15 -0
  143. data/lib/orange-more/slices/resources/radius.rb +117 -0
  144. data/lib/orange-more/slices/resources/slices.rb +35 -0
  145. data/lib/orange-more/subsites.rb +1 -0
  146. data/lib/orange-more/subsites/cartons/subsite.rb +8 -0
  147. data/lib/orange-more/subsites/middleware/subsite_load.rb +29 -0
  148. data/lib/orange-more/subsites/plugin.rb +17 -0
  149. data/lib/orange-more/subsites/resources/subsite_resource.rb +54 -0
  150. data/lib/orange-more/subsites/views/subsites/index.haml +2 -0
  151. data/lib/orange-more/testimonials.rb +1 -0
  152. data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +15 -0
  153. data/lib/orange-more/testimonials/plugin.rb +13 -0
  154. data/lib/orange-more/testimonials/resources/testimonials_resource.rb +42 -0
  155. data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +4 -0
  156. data/spec/orange-core/application_spec.rb +183 -0
  157. data/spec/orange-core/carton_spec.rb +136 -0
  158. data/spec/orange-core/core_spec.rb +248 -0
  159. data/spec/orange-core/magick_spec.rb +96 -0
  160. data/spec/orange-core/middleware/base_spec.rb +38 -0
  161. data/spec/orange-core/middleware/globals_spec.rb +3 -0
  162. data/spec/orange-core/middleware/rerouter_spec.rb +3 -0
  163. data/spec/orange-core/middleware/restful_router_spec.rb +3 -0
  164. data/spec/orange-core/middleware/route_context_spec.rb +3 -0
  165. data/spec/orange-core/middleware/route_site_spec.rb +3 -0
  166. data/spec/orange-core/middleware/show_exceptions_spec.rb +3 -0
  167. data/spec/orange-core/middleware/static_file_spec.rb +3 -0
  168. data/spec/orange-core/middleware/static_spec.rb +3 -0
  169. data/spec/orange-core/mock/mock_app.rb +16 -0
  170. data/spec/orange-core/mock/mock_carton.rb +43 -0
  171. data/spec/orange-core/mock/mock_core.rb +2 -0
  172. data/spec/orange-core/mock/mock_middleware.rb +25 -0
  173. data/spec/orange-core/mock/mock_mixins.rb +19 -0
  174. data/spec/orange-core/mock/mock_model_resource.rb +47 -0
  175. data/spec/orange-core/mock/mock_pulp.rb +24 -0
  176. data/spec/orange-core/mock/mock_resource.rb +26 -0
  177. data/spec/orange-core/mock/mock_router.rb +10 -0
  178. data/spec/orange-core/orange_spec.rb +19 -0
  179. data/spec/orange-core/packet_spec.rb +203 -0
  180. data/spec/orange-core/resource_spec.rb +96 -0
  181. data/spec/orange-core/resources/mapper_spec.rb +5 -0
  182. data/spec/orange-core/resources/model_resource_spec.rb +246 -0
  183. data/spec/orange-core/resources/parser_spec.rb +5 -0
  184. data/spec/orange-core/resources/routable_resource_spec.rb +5 -0
  185. data/spec/orange-core/spec_helper.rb +53 -0
  186. data/spec/orange-core/stack_spec.rb +232 -0
  187. data/spec/stats.rb +182 -0
  188. metadata +312 -0
@@ -0,0 +1,12 @@
1
+ %form{:action => "#{packet.route_to(model_name, 'new')}", :method => 'post'}
2
+ - for prop in props
3
+ %p!= view_attribute(prop, model_name, :label => true)
4
+ %p
5
+ %label{:for => "my_password"} Password
6
+ %br
7
+ %input{:id => "my_password", :type => "password", :name => "#{model_name}[password]"}
8
+ %p
9
+ %label{:for => "my_repeat_password"} Repeat Password
10
+ %br
11
+ %input{:id => "my_repeat_password", :type => "password", :name => "#{model_name}[repeat_password]"}
12
+ %input{:type => 'submit', :value => 'Save New Item'}
@@ -0,0 +1,15 @@
1
+ - if model
2
+ %form{:action => packet.route_to(model_name, model[:id], 'save'), :method => 'post'}
3
+ - for prop in props
4
+ %p!= view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
5
+ %p
6
+ %label{:for => "my_password"} Password
7
+ %br
8
+ %input{:id => "my_password", :type => "password", :name => "#{model_name}[password]"}
9
+ %p
10
+ %label{:for => "my_repeat_password"} Repeat Password
11
+ %br
12
+ %input{:id => "my_repeat_password", :type => "password", :name => "#{model_name}[repeat_password]"}
13
+ %input{:type => 'submit', :value => 'Save Changes'}
14
+ - else
15
+ %p Couldn't find the item you're looking for.
@@ -0,0 +1 @@
1
+ %p You don't have permission to view this.
@@ -0,0 +1,17 @@
1
+ %form{:action => packet.route_to(model_name, 'login'), :method => 'post'}
2
+ - if(packet.flash['error'])
3
+ .error
4
+ %p= packet.flash('error')
5
+ %p
6
+ %label Email
7
+ %br
8
+ %input{:type => "text", :name => "members[login_email]"}
9
+ %p
10
+ %label Password
11
+ %br
12
+ %input{:type => "password", :name => "members[login_password]"}
13
+ %input{:type => "submit", :value => "Log in"}
14
+ %hr
15
+ %p
16
+ Not a member? You can
17
+ %a{:href => route_to(model_name, 'register')} register here
@@ -0,0 +1 @@
1
+ %p You have been logged out.
@@ -0,0 +1,50 @@
1
+ - if model
2
+ %form{:action => packet.route_to(model_name, 'profile'), :method => 'post'}
3
+ - if(packet.flash['error'])
4
+ .error
5
+ %p= packet.flash('error')
6
+ - if(packet.flash['info'])
7
+ .info
8
+ %p= packet.flash('info')
9
+ - for prop in props
10
+ %p!= view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
11
+ %fieldset
12
+ %legend Change Password
13
+ %p You only need to fill out the following information if you want to change your password
14
+ %p
15
+ %label{:for => "my_currrent_password"} Current Password
16
+ %br
17
+ %input{:id => "my_currrent_password", :type => "password", :name => "#{model_name}[current_password]"}
18
+ %p
19
+ %label{:for => "my_password"} Password
20
+ %br
21
+ %input{:id => "my_password", :type => "password", :name => "#{model_name}[password]"}
22
+ %p
23
+ %label{:for => "my_repeat_password"} Repeat Password
24
+ %br
25
+ %input{:id => "my_repeat_password", :type => "password", :name => "#{model_name}[repeat_password]"}
26
+ %fieldset
27
+ %legend Mailing Lists
28
+ %p
29
+ %input{:type => "hidden", :name => "members[email_subscribe]", :value => "0"}
30
+ %input{:type => "checkbox", :name => "members[email_subscribe]", :value => "1"}
31
+ Sign up for the mailing list?
32
+ %p We separate our mailing list into multiple topics to avoid spamming our users with unwanted emails. Choose the information you would like to receive email about.
33
+ - for group in list_groups
34
+ %h2= group["name"].capitalize
35
+ %input{:type => "hidden", :name => "members[groups][#{group['name']}][]", :value => ""}
36
+ - for opt in group["groups"]
37
+ %p
38
+ %input{:type => "checkbox", :name => "members[groups][#{group['name']}][]", :value => opt["name"]}
39
+ = opt["name"]
40
+ %fieldset
41
+ %legend Payment
42
+ - if(orange[:members].paid?(packet, model))
43
+ %p Thanks for supporting the WNSF. You can keep your subscription up to date below:
44
+ %a{:href => orange[:members].subscription_url(packet, model)} Make a payment
45
+ - else
46
+ %p To access parts of this site, you'll need to be a supporting member.
47
+ %a{:href => orange[:members].subscription_url(packet, model)} You can become a supporting member here.
48
+ %input{:type => 'submit', :value => 'Save Changes'}
49
+ - else
50
+ %p Couldn't find the item you're looking for.
@@ -0,0 +1,37 @@
1
+ %form{:action => packet.route_to(model_name, 'register'), :method => 'post'}
2
+ - if(packet.flash['error'])
3
+ .error
4
+ %p= packet.flash('error')
5
+ %p Fill out the following details to register for an account.
6
+ %p
7
+ %label Email
8
+ %br
9
+ %input{:type => "text", :name => "members[email]"}
10
+ %p.registration-name
11
+ %label Name*
12
+ %br
13
+ *Ignore this field unless you are a spam robot.
14
+ %br
15
+ %input{:type => "text", :name => "members[name]"}
16
+ %p
17
+ %label Password
18
+ %br
19
+ %input{:type => "password", :name => "members[password]"}
20
+ %p
21
+ %label Repeat Password
22
+ %br
23
+ %input{:type => "password", :name => "members[repeat_password]"}
24
+ %fieldset
25
+ %legend Mailing Lists
26
+ %p
27
+ %input{:type => "checkbox", :name => "members[email_subscribe]", :value => "1"}
28
+ Sign up for the mailing list?
29
+ %p We separate our mailing list into multiple topics to avoid spamming our users with unwanted emails. Choose the information you would like to receive email about.
30
+ - for group in list_groups
31
+ %h2= group["name"].capitalize
32
+ %input{:type => "hidden", :name => "members[groups][#{group['name']}][]", :value => ""}
33
+ - for opt in group["groups"]
34
+ %p
35
+ %input{:type => "checkbox", :name => "members[groups][#{group['name']}][]", :value => opt["name"]}
36
+ = opt["name"]
37
+ %input{:type => "submit", :value => "Register"}
@@ -0,0 +1 @@
1
+ require File.join('orange-more', 'news', 'plugin')
@@ -0,0 +1,12 @@
1
+ require 'dm-timestamps'
2
+ class OrangeNews < Orange::Carton
3
+ id
4
+ front do
5
+ title :title, :length => 255
6
+ text :link, :length => 255
7
+ fulltext :description
8
+ end
9
+
10
+ property :created_at, DateTime
11
+ property :updated_at, DateTime
12
+ end
@@ -0,0 +1,13 @@
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
+
4
+ module Orange::Plugins
5
+ class News < Base
6
+ views_dir File.join(File.dirname(__FILE__), 'views')
7
+
8
+ resource Orange::NewsResource.new
9
+ end
10
+ end
11
+
12
+ Orange.plugin(Orange::Plugins::News.new)
13
+
@@ -0,0 +1,83 @@
1
+ module Orange
2
+ class NewsResource < Orange::ModelResource
3
+ use OrangeNews
4
+ call_me :news
5
+ def stack_init
6
+ orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'News')
7
+ orange[:radius, true].define_tag "latest_news" do |tag|
8
+ orange[:news].latest(tag.locals.packet)
9
+ end
10
+ end
11
+
12
+ def beforeNew(packet, opts = {})
13
+ unless OrangeRoute.first(:resource => 'news', :orange_site_id => packet['site'].id)
14
+ orange[:sitemap, true].add_route_for(packet,
15
+ :orange_site_id => packet['site'].id,
16
+ :resource => :news,
17
+ :resource_action => :archive,
18
+ :slug => 'news-archive',
19
+ :link_text => 'Orange News Archive'
20
+ )
21
+ end
22
+ true
23
+ end
24
+
25
+ def link_for(packet, news)
26
+ match = news.link.match(/\[(\d+)\]/)
27
+ if match
28
+ orange[:sitemap, true].to_href(packet, match[1].to_i)
29
+ else
30
+ news.link
31
+ end
32
+ end
33
+
34
+ def sitemap_row(packet, opts = {})
35
+ do_view(packet, :sitemap_row, opts)
36
+ end
37
+
38
+ def news_view(packet, opts = {})
39
+ resource_path = packet['route.resource_path']
40
+ if resource_path.blank?
41
+ archive_view(packet, opts)
42
+ elsif resource_path =~ /^\/page/
43
+ archive(packet, opts)
44
+ else
45
+ archive_view(packet, opts)
46
+ end
47
+ end
48
+
49
+ def latest(packet, opts = {})
50
+ limit = packet['news.latest_news_limit', 3]
51
+ do_list_view(packet, :latest, {
52
+ :list => model_class.all(:order => :updated_at.desc, :limit => limit)
53
+ })
54
+ end
55
+
56
+ def archive(packet, opts = {})
57
+ opts.merge!(packet.extract_opts)
58
+ opts.merge!( :archive_url => archive_url(packet))
59
+ opts[:page] = opts[:page].blank? ? 1 : opts[:page].to_i
60
+ page = opts[:page].blank? ? 0 : opts[:page] - 1
61
+ opts[:list] = model_class.all(:order => [:updated_at.desc],
62
+ :limit => 5,
63
+ :offset => (5*page)
64
+ )
65
+ opts[:pages] = (model_class.count / 5) + 1
66
+ do_list_view(packet, :archive, opts)
67
+ end
68
+
69
+ def archive_view(packet, opts = {})
70
+ archive(packet, opts.merge!({:page => 1}))
71
+ end
72
+
73
+ def archive_url(packet)
74
+ url = orange[:sitemap, true].url_for(packet, :resource => :news, :resource_action => :archive)
75
+ url.gsub!(/\/$/, '')
76
+ end
77
+
78
+ def find_list(packet, mode, opts = {})
79
+ opts[:order] = [:updated_at.desc]
80
+ model_class.all(opts) || []
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,14 @@
1
+ .news_items
2
+ - for news in list
3
+ .news_item
4
+ %h2.news_title
5
+ %a{:href => (resource.link_for(packet, news))} #{news.title}
6
+ .news_description
7
+ = news.description
8
+ %p
9
+ %a{:href => (resource.link_for(packet, news)), :class => 'view_story'} View Story &raquo;
10
+ .news_nav
11
+ - if page > 1
12
+ %a.newer{:href => "#{archive_url}/page/#{page-1}"} Newer Posts
13
+ - if page < pages
14
+ %a.older{:href => "#{archive_url}/page/#{page+1}"} Older Posts
@@ -0,0 +1,7 @@
1
+ - if model
2
+ %form{:action => route_to(model_name, model[:id], 'save'), :method => 'post'}
3
+ - for prop in props
4
+ %p~ view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
5
+ %input{:type => 'submit', :value => 'Save Changes'}
6
+ - else
7
+ %p Couldn't find the item you're looking for.
@@ -0,0 +1,8 @@
1
+ - list.each do |news|
2
+ .news_item
3
+ %p.news_title
4
+ %a{:href => (resource.link_for(packet, news))} #{news.title}
5
+ .news_description
6
+ = news.description
7
+ %p
8
+ %a{:href => (resource.link_for(packet, news)), :class => 'view_story'} View Story &raquo;
@@ -0,0 +1,14 @@
1
+ - if route
2
+ .sitemap_item{:class => "sitemap_level_#{route.level}"}
3
+ - if route.level > 0
4
+ = orange[:sitemap].route_actions(packet, :model => route)
5
+ %h4 #{route.link_text} <span>(#{route.full_path})</span>
6
+ .linked_to
7
+ %p
8
+ News Archive
9
+ %br
10
+ %a{:href => route_to(:news, 'create')} Add New News Post
11
+ .actions
12
+ = form_link('Delete', route_to(:sitemap, route.id, 'delete'), 'Are you sure you want to delete this?', {:method => 'delete'})
13
+ %a{:href => route_to(:sitemap, route.id, 'edit')} Edit
14
+ %br.clear
@@ -0,0 +1 @@
1
+ require File.join('orange-more', 'pages', 'plugin')
@@ -0,0 +1,14 @@
1
+ require 'dm-timestamps'
2
+ require 'orange-more/administration/cartons/site_carton'
3
+
4
+ class OrangePage < Orange::SiteCarton
5
+ id
6
+ front do
7
+ title :title, :length => 255
8
+ fulltext :body
9
+ end
10
+ boolean :published, :default => false
11
+
12
+ property :updated_at, DateTime
13
+ has n, :versions, "OrangePageVersion"
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'dm-timestamps'
2
+ require 'orange-more/administration/cartons/site_carton'
3
+
4
+ class OrangePageVersion < Orange::SiteCarton
5
+ id
6
+ title :title, :length => 255
7
+ fulltext :body
8
+ property :updated_at, DateTime
9
+ boolean :published
10
+ property :version, Integer, :default => 0
11
+ belongs_to :orange_page, "OrangePage"
12
+ end
@@ -0,0 +1,13 @@
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
+
4
+ module Orange::Plugins
5
+ class Pages < Base
6
+ views_dir File.join(File.dirname(__FILE__), 'views')
7
+
8
+ resource Orange::PageResource.new
9
+ end
10
+ end
11
+
12
+ Orange.plugin(Orange::Plugins::Pages.new)
13
+
@@ -0,0 +1,179 @@
1
+ module Orange
2
+ module Pulp::PageHelpers
3
+ def fuzzy_time(from_time)
4
+ to_time = Time.new
5
+ from_time = from_time.to_time if from_time.respond_to?(:to_time)
6
+ to_time = to_time.to_time if to_time.respond_to?(:to_time)
7
+ distance_in_minutes = (((to_time - from_time).abs)/60).round
8
+ distance_in_seconds = ((to_time - from_time).abs).round
9
+ case distance_in_minutes
10
+ when 0..1
11
+ return distance_in_minutes == 0 ? "Less than 1 minute ago" : "About 1 minute ago"
12
+ when 2..44 then "#{distance_in_minutes} minutes ago"
13
+ when 45..89 then "An hour ago"
14
+ when 90..1439 then "#{(distance_in_minutes.to_f / 60.0).round} hours ago"
15
+ when 1440..2879 then "Yesterday"
16
+ when 2880..43199 then "#{(distance_in_minutes / 1440).round} days ago"
17
+ when 43200..86399 then "1 Month ago"
18
+ when 86400..525599 then "#{(distance_in_minutes / 43200).round} months ago"
19
+ when 525600..1051199 then "1 year ago"
20
+ else "Over #{(distance_in_minutes / 525600).round} years ago"
21
+ end
22
+ end
23
+ end
24
+ class PageResource < Orange::ModelResource
25
+ use OrangePage
26
+ call_me :pages
27
+ def init
28
+ options[:sitemappable] = true
29
+ orange.add_pulp(Orange::Pulp::PageHelpers)
30
+ end
31
+
32
+ def stack_init
33
+ orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Pages')
34
+ end
35
+
36
+ def publish(packet, opts = {})
37
+ no_reroute = opts[:no_reroute]
38
+ if packet.request.post? || !opts.blank?
39
+ my_id = opts[:resource_id] || packet['route.resource_id']
40
+ m = opts[:model] || model_class.get(my_id)
41
+ if m
42
+ params = {}
43
+ params[:published] = true
44
+ m.update(params)
45
+
46
+ params = m.attributes.merge(params)
47
+ params.delete(:id)
48
+ max = m.versions.max(:version) || 0
49
+ m.versions.new(params.merge(:version => max + 1))
50
+ m.save
51
+
52
+ r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name, :orange_site_id => m.orange_site.id)
53
+ # Add route if none.
54
+ if (r.blank? && orange.loaded?(:sitemap))
55
+
56
+ route_hash = {
57
+ :orange_site_id => m.orange_site.id,
58
+ :resource => @my_orange_name,
59
+ :resource_id => m.id,
60
+ :slug => orange[:sitemap].slug_for(m, params),
61
+ :show_in_nav => false,
62
+ :link_text => "{title}"
63
+ }
64
+ parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages", :orange_site_id => m.orange_site.id)
65
+ route_hash[:parent] = parents.first unless parents.blank?
66
+ orange[:sitemap].add_route_for(packet, route_hash)
67
+ end
68
+ end
69
+ end
70
+ packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
71
+ end
72
+
73
+ # Creates a new model object and saves it (if a post), then reroutes to the main page
74
+ # @param [Orange::Packet] packet the packet being routed
75
+ def onNew(packet, params = {})
76
+ params[:published] = false
77
+ m = model_class.new(params)
78
+ m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site
79
+ # m.versions.new(params.merge(:version => 1))
80
+ m
81
+ end
82
+
83
+ # Saves updates to an object specified by packet['route.resource_id'], then reroutes to main
84
+ # @param [Orange::Packet] packet the packet being routed
85
+ def onSave(packet, m, params = {})
86
+ r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name, :orange_site_id => m.orange_site.id)
87
+ # Add route if none.
88
+ if (r.blank? && orange.loaded?(:sitemap))
89
+ route_hash = {
90
+ :orange_site_id => m.orange_site.id,
91
+ :resource => @my_orange_name,
92
+ :resource_id => m.id,
93
+ :slug => orange[:sitemap].slug_for(m, params),
94
+ :show_in_nav => false,
95
+ :link_text => "{title}"
96
+ }
97
+ parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages", :orange_site_id => m.orange_site.id)
98
+ route_hash[:parent] = parents.first unless parents.blank?
99
+ orange[:sitemap].add_route_for(packet, route_hash)
100
+ end
101
+ if (params["published"] == "1")
102
+ params["published"] = true
103
+ m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site
104
+
105
+ m.update(params)
106
+ orange[:pages].publish(packet, :no_reroute => true, :model => m)
107
+ else
108
+ params["published"] = false
109
+ m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site
110
+ m.update(params)
111
+ end
112
+ end
113
+
114
+ def find_list(packet, mode)
115
+ model_class.all(:orange_site => packet['site']) || []
116
+ end
117
+
118
+ # Returns a single object found by the model class, given an id.
119
+ # If id isn't given, we return false.
120
+ # @param [Orange::Packet] packet the packet we are returning a view for
121
+ # @param [Symbol] mode the mode we are trying to view (used to find template name)
122
+ # @param [Numeric] id the id to lookup on the model class
123
+ # @return [Object] returns an object of type set by #use, if one found with same id
124
+ def find_one(packet, mode, id = false)
125
+ return false unless id
126
+ m = model_class.get(id)
127
+ if packet['route.resource_path',''] =~ /version\//
128
+ parts = packet['route.resource_path'].split('/')
129
+ version = parts[2]
130
+ v = m.versions.first(:version => version)
131
+ if v
132
+ attrs = v.attributes
133
+ [:version, :orange_page_id, :page_id, :id].each { |i| attrs.delete(i) }
134
+ m.attributes = attrs
135
+ end
136
+ end # end if version
137
+ if mode == :show
138
+ case packet['route.context']
139
+ when :live
140
+ # Automatically set title, if possible
141
+ unless orange[:page_parts].part(packet)[:title] != ''
142
+ orange[:page_parts].part(packet)[:title] = m.title + " - " + packet['site'].name
143
+ end
144
+ m = m.versions.last(:published => '1')
145
+ raise Orange::NotFoundException unless m
146
+ when :preview
147
+ # Automatically set title, if possible
148
+ unless orange[:page_parts].part(packet)[:title] != ''
149
+ orange[:page_parts].part(packet)[:title] = m.title + " - " + packet['site'].name
150
+ end
151
+ m
152
+ end
153
+ end # end if show
154
+ m
155
+ end
156
+
157
+ def find_extras(packet, mode, opts = {})
158
+ case mode
159
+ when :edit
160
+ return {:routes => orange[:sitemap, true].routes_for(packet)}
161
+ else {}
162
+ end
163
+ end
164
+
165
+ def routes(packet, opts = {})
166
+ model = opts if opts.is_a? model_class
167
+ model ||= opts[:model] || model_class.get(opts[:resource_id])
168
+ orange[:sitemap].routes_for(packet, {:resource => :pages, :resource_id => model.id})
169
+ end
170
+
171
+ def sitemap_row(packet, opts = {})
172
+ do_view(packet, :sitemap_row, opts)
173
+ end
174
+
175
+ def route_for(packet, id, opts = {})
176
+ return orange[:sitemap].url_for(packet, {:resource => 'pages', :resource_id => id})
177
+ end
178
+ end
179
+ end