wheels 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (300) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +17 -0
  3. data/Rakefile +22 -22
  4. data/VERSION +1 -0
  5. data/app/controllers/access_control_entries_controller.rb +38 -0
  6. data/app/controllers/app_configs_controller.rb +17 -0
  7. data/app/controllers/application_controller.rb +39 -0
  8. data/app/controllers/attachments_controller.rb +16 -0
  9. data/app/controllers/blogs_controller.rb +39 -0
  10. data/app/controllers/discussions_controller.rb +10 -0
  11. data/app/controllers/external_links_controller.rb +5 -0
  12. data/app/controllers/feedbacks_controller.rb +10 -0
  13. data/app/controllers/forum_messages_controller.rb +13 -0
  14. data/app/controllers/forums_controller.rb +2 -0
  15. data/app/controllers/galleries_controller.rb +60 -0
  16. data/app/controllers/images_controller.rb +30 -0
  17. data/app/controllers/menus_controller.rb +2 -0
  18. data/app/controllers/pages_controller.rb +80 -0
  19. data/app/controllers/profiles_controller.rb +16 -0
  20. data/app/controllers/sitemaps_controller.rb +135 -0
  21. data/app/controllers/users_controller.rb +28 -0
  22. data/app/helpers/access_control_entries_helper.rb +2 -0
  23. data/app/helpers/app_configs_helper.rb +2 -0
  24. data/app/helpers/application_helper.rb +43 -0
  25. data/app/helpers/blogs_helper.rb +10 -0
  26. data/app/helpers/discussions_helper.rb +2 -0
  27. data/app/helpers/external_links_helper.rb +2 -0
  28. data/app/helpers/feedbacks_helper.rb +2 -0
  29. data/app/helpers/forums_helper.rb +2 -0
  30. data/app/helpers/menus_helper.rb +2 -0
  31. data/app/helpers/pages_helper.rb +192 -0
  32. data/app/helpers/sitemaps_helper.rb +12 -0
  33. data/app/mailers/feedback_mailer.rb +10 -0
  34. data/app/models/ability.rb +43 -0
  35. data/app/models/access_control_entry.rb +109 -0
  36. data/app/models/app_config.rb +26 -0
  37. data/app/models/attachment.rb +10 -0
  38. data/app/models/blog.rb +10 -0
  39. data/app/models/discussion.rb +19 -0
  40. data/app/models/external_link.rb +10 -0
  41. data/app/models/feedback.rb +11 -0
  42. data/app/models/forum.rb +4 -0
  43. data/app/models/forum_message.rb +5 -0
  44. data/app/models/gallery.rb +5 -0
  45. data/app/models/image.rb +10 -0
  46. data/app/models/menu.rb +5 -0
  47. data/app/models/page.rb +8 -0
  48. data/app/models/page_revision.rb +2 -0
  49. data/app/models/profile.rb +12 -0
  50. data/app/models/role.rb +29 -0
  51. data/app/models/s3_provider.rb +84 -0
  52. data/app/models/sitemap.rb +175 -0
  53. data/app/models/tagging.rb +4 -0
  54. data/app/models/user.rb +69 -0
  55. data/app/validators/email_validator.rb +22 -0
  56. data/app/views/access_control_entries/_form.html.haml +33 -0
  57. data/app/views/access_control_entries/_index.html.haml +53 -0
  58. data/app/views/access_control_entries/_show.html.haml +12 -0
  59. data/app/views/access_control_entries/create.js.haml +3 -0
  60. data/app/views/access_control_entries/destroy.js.haml +3 -0
  61. data/app/views/access_control_entries/edit.html.haml +7 -0
  62. data/app/views/access_control_entries/edit.js.haml +3 -0
  63. data/app/views/access_control_entries/index.html.haml +2 -0
  64. data/app/views/access_control_entries/index.js.haml +3 -0
  65. data/app/views/access_control_entries/new.html.haml +5 -0
  66. data/app/views/access_control_entries/new.js.haml +3 -0
  67. data/app/views/access_control_entries/show.html.haml +2 -0
  68. data/app/views/access_control_entries/show.js.haml +4 -0
  69. data/app/views/access_control_entries/update.js.haml +3 -0
  70. data/app/views/app_configs/_form.html.haml +11 -0
  71. data/app/views/app_configs/_index.html.haml +6 -0
  72. data/app/views/app_configs/_show.html.haml +3 -0
  73. data/app/views/app_configs/create.js.haml +3 -0
  74. data/app/views/app_configs/css.css.haml +2 -0
  75. data/app/views/app_configs/destroy.js.haml +3 -0
  76. data/app/views/app_configs/edit.html.haml +2 -0
  77. data/app/views/app_configs/edit.js.haml +3 -0
  78. data/app/views/app_configs/index.html.haml +2 -0
  79. data/app/views/app_configs/index.js.haml +3 -0
  80. data/app/views/app_configs/new.html.haml +2 -0
  81. data/app/views/app_configs/new.js.haml +3 -0
  82. data/app/views/app_configs/show.html.haml +2 -0
  83. data/app/views/app_configs/show.js.haml +3 -0
  84. data/app/views/app_configs/update.js.haml +3 -0
  85. data/app/views/attachments/_form.html.haml +26 -0
  86. data/app/views/attachments/_index.html.haml +9 -0
  87. data/app/views/attachments/_show.html.haml +6 -0
  88. data/app/views/attachments/_uploadify.html.erb +12 -0
  89. data/app/views/attachments/create.js.haml +3 -0
  90. data/app/views/attachments/destroy.js.haml +3 -0
  91. data/app/views/attachments/edit.js.haml +3 -0
  92. data/app/views/attachments/index.html.haml +2 -0
  93. data/app/views/attachments/index.js.haml +3 -0
  94. data/app/views/attachments/new.html.haml +3 -0
  95. data/app/views/attachments/new.js.haml +3 -0
  96. data/app/views/attachments/show.html.haml +2 -0
  97. data/app/views/attachments/show.js.haml +3 -0
  98. data/app/views/attachments/update.js.haml +3 -0
  99. data/app/views/blogs/_form.html.haml +22 -0
  100. data/app/views/blogs/edit.html.haml +8 -0
  101. data/app/views/blogs/index.html.haml +21 -0
  102. data/app/views/blogs/index.xml.builder +27 -0
  103. data/app/views/blogs/new.html.haml +6 -0
  104. data/app/views/blogs/show.html.haml +25 -0
  105. data/app/views/discussions/_form.html.haml +16 -0
  106. data/app/views/discussions/edit.html.haml +7 -0
  107. data/app/views/discussions/index.html.haml +10 -0
  108. data/app/views/discussions/new.html.haml +25 -0
  109. data/app/views/discussions/show.html.haml +16 -0
  110. data/app/views/external_links/_fields_for.html.haml +2 -0
  111. data/app/views/external_links/_form.html.haml +18 -0
  112. data/app/views/external_links/_show.html.haml +7 -0
  113. data/app/views/external_links/create.js.haml +3 -0
  114. data/app/views/external_links/destroy.js.haml +3 -0
  115. data/app/views/external_links/edit.html.haml +7 -0
  116. data/app/views/external_links/edit.js.haml +3 -0
  117. data/app/views/external_links/index.html.haml +23 -0
  118. data/app/views/external_links/index.js.haml +3 -0
  119. data/app/views/external_links/new.html.haml +5 -0
  120. data/app/views/external_links/new.js.haml +3 -0
  121. data/app/views/external_links/show.html.haml +2 -0
  122. data/app/views/external_links/show.js.haml +3 -0
  123. data/app/views/external_links/update.js.haml +3 -0
  124. data/app/views/feedback_mailer/submit_feedback.html.haml +22 -0
  125. data/app/views/feedbacks/_form.html.haml +38 -0
  126. data/app/views/feedbacks/index.html.haml +27 -0
  127. data/app/views/feedbacks/new.html.haml +6 -0
  128. data/app/views/feedbacks/show.html.haml +19 -0
  129. data/app/views/forum_messages/_form.html.haml +6 -0
  130. data/app/views/forum_messages/index.html.haml +11 -0
  131. data/app/views/forum_messages/new.html.haml +5 -0
  132. data/app/views/forums/_form.html.haml +13 -0
  133. data/app/views/forums/edit.html.haml +7 -0
  134. data/app/views/forums/index.html.haml +23 -0
  135. data/app/views/forums/new.html.haml +5 -0
  136. data/app/views/forums/show.html.haml +20 -0
  137. data/app/views/galleries/_form.html.haml +30 -0
  138. data/app/views/galleries/_show.html.haml +21 -0
  139. data/app/views/galleries/edit.html.haml +7 -0
  140. data/app/views/galleries/index.html.haml +15 -0
  141. data/app/views/galleries/new.html.haml +5 -0
  142. data/app/views/galleries/show.html.haml +4 -0
  143. data/app/views/images/_form.html.haml +10 -0
  144. data/app/views/images/create.js.haml +3 -0
  145. data/app/views/images/destroy.js.haml +3 -0
  146. data/app/views/images/edit.html.haml +7 -0
  147. data/app/views/images/edit.js.haml +3 -0
  148. data/app/views/images/index.html.haml +17 -0
  149. data/app/views/images/index.js.haml +3 -0
  150. data/app/views/images/new.html.haml +5 -0
  151. data/app/views/images/new.js.haml +3 -0
  152. data/app/views/images/show.html.haml +5 -0
  153. data/app/views/images/show.js.haml +3 -0
  154. data/app/views/images/update.js.haml +3 -0
  155. data/app/views/layouts/application.html.haml +60 -0
  156. data/app/views/layouts/bare.html.haml +2 -0
  157. data/app/views/layouts/image_dialog.html.haml +18 -0
  158. data/app/views/loadbehind/_destroy.js.haml +3 -0
  159. data/app/views/loadbehind/_edit.js.haml +4 -0
  160. data/app/views/loadbehind/_errors.html.haml +5 -0
  161. data/app/views/loadbehind/_growl_template.html.haml +65 -0
  162. data/app/views/loadbehind/_show_box.html.haml +9 -0
  163. data/app/views/loadbehind/_view.js.haml +4 -0
  164. data/app/views/loadbehind/growl.js.haml +4 -0
  165. data/app/views/loadbehind/index.js.haml +4 -0
  166. data/app/views/menus/_form.html.haml +13 -0
  167. data/app/views/menus/edit.html.haml +7 -0
  168. data/app/views/menus/index.html.haml +19 -0
  169. data/app/views/menus/new.html.haml +5 -0
  170. data/app/views/menus/show.html.haml +7 -0
  171. data/app/views/pages/_child_pages_links.html.haml +5 -0
  172. data/app/views/pages/_control_panel.html.haml +15 -0
  173. data/app/views/pages/_form.html.haml +27 -0
  174. data/app/views/pages/_form_fields.html.haml +23 -0
  175. data/app/views/pages/_show.html.haml +4 -0
  176. data/app/views/pages/_show_attachment.html.haml +6 -0
  177. data/app/views/pages/_show_small.html.haml +2 -0
  178. data/app/views/pages/create.js.haml +3 -0
  179. data/app/views/pages/destroy.js.haml +3 -0
  180. data/app/views/pages/edit.html.haml +16 -0
  181. data/app/views/pages/edit.js.haml +4 -0
  182. data/app/views/pages/index.html.haml +19 -0
  183. data/app/views/pages/index.js.haml +3 -0
  184. data/app/views/pages/new.html.haml +5 -0
  185. data/app/views/pages/new.js.haml +3 -0
  186. data/app/views/pages/show.html.haml +18 -0
  187. data/app/views/pages/show.js.haml +3 -0
  188. data/app/views/pages/update.js.haml +3 -0
  189. data/app/views/profiles/_form.html.haml +26 -0
  190. data/app/views/profiles/edit.html.haml +7 -0
  191. data/app/views/profiles/index.html.haml +25 -0
  192. data/app/views/profiles/new.html.haml +5 -0
  193. data/app/views/profiles/show.html.haml +21 -0
  194. data/app/views/sitemaps/edit.html.haml +12 -0
  195. data/app/views/sitemaps/index.html.haml +83 -0
  196. data/app/views/sitemaps/index.json.erb +23 -0
  197. data/app/views/sitemaps/new.html.haml +8 -0
  198. data/app/views/sitemaps/new.js.erb +0 -0
  199. data/app/views/users/edit.html.haml +45 -0
  200. data/app/views/users/index.html.haml +19 -0
  201. data/config/amazon_s3.yml +15 -0
  202. data/db/migrate/0000_devise_create_users.rb +26 -0
  203. data/db/migrate/0010_add_fields_to_users.rb +28 -0
  204. data/db/migrate/0020_create_blogs.rb +16 -0
  205. data/db/migrate/0030_create_galleries.rb +15 -0
  206. data/db/migrate/0040_create_images.rb +17 -0
  207. data/db/migrate/0050_create_profiles.rb +24 -0
  208. data/db/migrate/0060_insert_admin_user_and_roles.rb +24 -0
  209. data/db/migrate/0070_create_pages.rb +16 -0
  210. data/db/migrate/0080_create_forums.rb +13 -0
  211. data/db/migrate/0090_create_discussions.rb +14 -0
  212. data/db/migrate/0100_create_forum_messages.rb +15 -0
  213. data/db/migrate/0110_create_access_control_entries.rb +23 -0
  214. data/db/migrate/0120_create_attachments.rb +17 -0
  215. data/db/migrate/0130_create_roles.rb +13 -0
  216. data/db/migrate/0140_create_feedbacks.rb +20 -0
  217. data/db/migrate/0150_create_external_links.rb +14 -0
  218. data/db/migrate/0160_create_sitemaps.rb +17 -0
  219. data/db/migrate/0170_create_menus.rb +14 -0
  220. data/db/migrate/0180_acts_as_taggable_on_migration.rb +28 -0
  221. data/db/migrate/20100912194121_add_stylesheet_to_pages.rb +9 -0
  222. data/db/migrate/20100913073354_add_position_to_access_control_entries.rb +9 -0
  223. data/init.rb +2 -0
  224. data/lib/{core_extensions.rb → generators/core_extensions.rb} +2 -2
  225. data/lib/generators/templates/haml/app/views/layouts/application.html.haml +0 -0
  226. data/lib/generators/wheels/wheels_generator.rb +2 -0
  227. data/lib/generators/wheels_update/wheels_update_generator.rb +1 -1
  228. data/lib/wheels/routes.rb +13 -2
  229. data/wheels.gemspec +254 -122
  230. metadata +268 -124
  231. data/README +0 -2
  232. data/lib/generators/wheels/recipes/public.rb +0 -9
  233. data/lib/generators/wheels_update/core_extensions.3.rb +0 -64
  234. data/lib/wheels/base.rb +0 -7
  235. data/test/functional/access_control_entries_controller_test.rb +0 -49
  236. data/test/functional/app_configs_controller_test.rb +0 -49
  237. data/test/functional/discussions_controller_test.rb +0 -49
  238. data/test/functional/external_links_controller_test.rb +0 -49
  239. data/test/functional/feedback_mailer_test.rb +0 -8
  240. data/test/functional/feedbacks_controller_test.rb +0 -49
  241. data/test/functional/forums_controller_test.rb +0 -49
  242. data/test/functional/layouts_controller_test.rb +0 -49
  243. data/test/functional/member_pages_controller_test.rb +0 -49
  244. data/test/functional/members_controller_test.rb +0 -8
  245. data/test/functional/menus_controller_test.rb +0 -49
  246. data/test/functional/pages_controller_test.rb +0 -49
  247. data/test/functional/product_revisions_controller_test.rb +0 -49
  248. data/test/performance/browsing_test.rb +0 -9
  249. data/test/test_helper.rb +0 -13
  250. data/test/unit/access_control_entry_test.rb +0 -8
  251. data/test/unit/app_config_test.rb +0 -8
  252. data/test/unit/attachment_test.rb +0 -8
  253. data/test/unit/discussion_test.rb +0 -8
  254. data/test/unit/external_link_test.rb +0 -8
  255. data/test/unit/feedback_test.rb +0 -8
  256. data/test/unit/forum_message_test.rb +0 -8
  257. data/test/unit/forum_test.rb +0 -8
  258. data/test/unit/helpers/access_control_entries_helper_test.rb +0 -4
  259. data/test/unit/helpers/app_configs_helper_test.rb +0 -4
  260. data/test/unit/helpers/discussions_helper_test.rb +0 -4
  261. data/test/unit/helpers/external_links_helper_test.rb +0 -4
  262. data/test/unit/helpers/feedbacks_helper_test.rb +0 -4
  263. data/test/unit/helpers/forums_helper_test.rb +0 -4
  264. data/test/unit/helpers/layouts_helper_test.rb +0 -4
  265. data/test/unit/helpers/member_pages_helper_test.rb +0 -4
  266. data/test/unit/helpers/members_helper_test.rb +0 -4
  267. data/test/unit/helpers/menus_helper_test.rb +0 -4
  268. data/test/unit/helpers/pages_helper_test.rb +0 -4
  269. data/test/unit/helpers/product_revisions_helper_test.rb +0 -4
  270. data/test/unit/layout_test.rb +0 -8
  271. data/test/unit/member_page_test.rb +0 -8
  272. data/test/unit/menu_test.rb +0 -8
  273. data/test/unit/page_revision_test.rb +0 -8
  274. data/test/unit/page_test.rb +0 -8
  275. data/test/unit/product_revision_test.rb +0 -8
  276. data/test/unit/settings_test.rb +0 -8
  277. data/test/unit/sitemap_test.rb +0 -8
  278. data/test/unit/user_test.rb +0 -8
  279. /data/{lib/generators/wheels/templates/haml/app/views/layouts/application.html.haml → app/views/sitemaps/edit.js.erb} +0 -0
  280. /data/lib/generators/{wheels/recipes → recipes}/cancan.rb +0 -0
  281. /data/lib/generators/{wheels/recipes → recipes}/cucumber.rb +0 -0
  282. /data/lib/generators/{wheels/recipes → recipes}/default.rb +0 -0
  283. /data/lib/generators/{wheels/recipes → recipes}/design.rb +0 -0
  284. /data/lib/generators/{wheels/recipes → recipes}/devise.rb +0 -0
  285. /data/lib/generators/{wheels/recipes → recipes}/factory_girl.rb +0 -0
  286. /data/lib/generators/{wheels/recipes → recipes}/haml.rb +0 -0
  287. /data/lib/generators/{wheels/recipes → recipes}/jquery.rb +0 -0
  288. /data/lib/generators/{wheels/recipes → recipes}/mongoid.rb +0 -0
  289. /data/lib/generators/{wheels/recipes → recipes}/postgresql.rb +0 -0
  290. /data/lib/generators/{wheels/recipes → recipes}/recipes.rb +0 -0
  291. /data/lib/generators/{wheels/recipes → recipes}/remarkable.rb +0 -0
  292. /data/lib/generators/{wheels/recipes → recipes}/rspec.rb +0 -0
  293. /data/lib/generators/{wheels/recipes → recipes}/wheels.rb +0 -0
  294. /data/lib/generators/{wheels_update/recipes/wheels.rb → recipes/wheels_update.rb} +0 -0
  295. /data/lib/generators/{wheels/snippets → snippets}/cucumber/database_config +0 -0
  296. /data/lib/generators/{wheels/templates → templates}/cancan/ability.rb +0 -0
  297. /data/lib/generators/{wheels/templates → templates}/database/postgresql.yml +0 -0
  298. /data/lib/generators/{wheels/templates → templates}/git/gitignore +0 -0
  299. /data/lib/generators/{wheels/templates → templates}/mongoid/features/step_definitions/mongoid_steps.rb +0 -0
  300. /data/lib/generators/{wheels/templates → templates}/mongoid/features/support/hooks.rb +0 -0
@@ -0,0 +1,84 @@
1
+ class S3Provider
2
+ attr_accessor :bucket, :access_key_id, :secret_access_key, :key, :content_type,
3
+ :acl, :expiration_date, :max_filesize, :policy, :signature, :form_fields
4
+
5
+ def initialize(options = {})
6
+ filename = "#{Rails.root}/config/amazon_s3.yml"
7
+ config = YAML.load_file(filename)
8
+
9
+ self.bucket = config["development"]['bucket']
10
+ self.access_key_id = config["development"]['access_key_id']
11
+ self.secret_access_key = config["development"]['secret_access_key']
12
+ self.key = options[:key] || ''
13
+ self.content_type = options[:content_type] || ''
14
+ self.acl = options[:acl] || 'public-read'
15
+ self.expiration_date = (options[:expiration_date] || 10.hours).from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z')
16
+ self.max_filesize = options[:max_filesize] || 500.megabyte
17
+
18
+ self.policy = Base64.encode64(
19
+ "{'expiration': '#{self.expiration_date}',
20
+ 'conditions': [
21
+ {'bucket': '#{self.bucket}'},
22
+ ['starts-with', '$key', '#{self.key}'],
23
+ {'acl': '#{self.acl}'},
24
+ {'success_action_status': '201'},
25
+ ['content-length-range', 0, #{self.max_filesize}],
26
+ ['starts-with', '$Content-Type', '']
27
+ ]
28
+ }").gsub(/\n|\r/, '')
29
+
30
+ self.signature = Base64.encode64(
31
+ OpenSSL::HMAC.digest(
32
+ OpenSSL::Digest::Digest.new('sha1'),
33
+ self.secret_access_key, self.policy)).gsub("\n","")
34
+
35
+ self.form_fields = %(
36
+ <form action="#{form_action}" method="post" enctype="multipart/form-data" id="upload-form">
37
+ <input type="hidden" name="key" value="#{self.key}/${filename}">
38
+ <input type="hidden" name="AWSAccessKeyId" value="#{self.access_key_id}">
39
+ <input type="hidden" name="acl" value="#{self.policy}">
40
+ <input type="hidden" name="success_action_redirect" value="http://localhost/">
41
+ <input type="hidden" name="policy" value="#{self.policy}">
42
+ <input type="hidden" name="signature" value="#{self.signature}">
43
+ <input type="hidden" name="Content-Type" value="image/jpeg">
44
+ <input name="file" type="file">
45
+ <input type="submit" value="Upload File to S3">
46
+ </form>
47
+ )
48
+ end
49
+ def form_action
50
+ "https://#{self.bucket}.s3.amazonaws.com/"
51
+ end
52
+ def script_data
53
+ %(
54
+ "AWSAccessKeyId": #{s self.access_key_id},
55
+ "key": #{s self.key},
56
+ "acl": #{s self.acl},
57
+ "policy": #{url_encoded(%("#{self.policy}"), 2)},
58
+ "signature": #{s self.signature}
59
+ )
60
+ end
61
+
62
+ def foolbar
63
+ %(<input type="hidden" name="key" value="#{self.key}/${filename}">
64
+ <input type="hidden" name="AWSAccessKeyId" value="#{self.access_key_id}">
65
+ <input type="hidden" name="acl" value="#{self.acl}">
66
+ <input type="hidden" name="policy" value="#{self.policy}">
67
+ <input type="hidden" name="signature" value="#{self.signature}">
68
+ <input type="hidden" name="success_action_status" value="201">
69
+ <input type="hidden" name="Content-Type" value="#{self.content_type}">
70
+ <input name="file" type="file" id="file_input" />
71
+ <input name="submit" value="Upload" type="submit" />)
72
+ end
73
+ private
74
+ def url_encoded(str, num=1)
75
+ str = url_encoded(str) if num==2
76
+ "encodeURIComponent(#{str})"
77
+ end
78
+ def s(str)
79
+ "\"#{str}\""
80
+ end
81
+
82
+
83
+ end
84
+
@@ -0,0 +1,175 @@
1
+ class Sitemap < ActiveRecord::Base
2
+ has_many :children, :class_name=>'Sitemap', :foreign_key=>'parent_id', :dependent => :destroy do
3
+ def sorted
4
+ sort{|t, u| if t.nil? || t.position.nil?; 1;
5
+ elsif u.nil? || u.position.nil?; -1;
6
+ else t.position <=> u.position end}
7
+ end
8
+ end
9
+
10
+ has_many :access_control_entries, :as => :resource
11
+
12
+ alias_attribute :name, :menu_text
13
+
14
+ def self.new_main_menu_page(name)
15
+ Sitemap.create( :parent=>self.main_menu,
16
+ :menu_text=>name,
17
+ :resource=>Page.create(:title=>name),
18
+ :position=>Sitemap.main_menu.children.count)
19
+ end
20
+
21
+ belongs_to :parent, :class_name=>'Sitemap', :foreign_key=>'parent_id'
22
+ belongs_to :resource, :polymorphic => true
23
+ after_create :create_resource
24
+ before_destroy :on_before_destroy
25
+ after_save :reload_root
26
+ validates :resource, :presence=>true
27
+ accepts_nested_attributes_for :children
28
+
29
+ def reload_root
30
+ Sitemap.instance_variable_set('@_root', nil)
31
+ end
32
+
33
+ def on_before_destroy
34
+ resource.destroy if resource && resource.sitemaps.size==1
35
+ end
36
+
37
+ scope :orphans, where(:parent_id=>nil).where("menu_text <> 'root'")
38
+
39
+ def as_json(*a)
40
+ {
41
+ :position=>self.position,
42
+ :data=>{
43
+ :title=>self.menu_text,
44
+ :icon=>icon_name,
45
+ },
46
+ :attr=>{
47
+ :id=>"node_#{id}",
48
+ :rel=>resource_type.underscore,
49
+ :data_menu_text => self.menu_text,
50
+ :data_resource_type => self.resource_type,
51
+ :data_resource_id => self.resource_id,
52
+ :data_id => self.id
53
+ },
54
+ :state=>treeview_state,
55
+ :children=> children.sorted
56
+ }.as_json(*a)
57
+ end
58
+
59
+ def resource_attributes=(attrib={})
60
+ raise "Cant build resource without resource_type" if resource_type.empty?
61
+ resource = create_resource
62
+ resource.attributes = attrib
63
+ resource.save
64
+ end
65
+
66
+ def create_resource
67
+ if self.resource_type && !self.resource_id
68
+ self.resource = resource_type.constantize.new
69
+ self.save
70
+ end
71
+ end
72
+
73
+ def url
74
+ if self == Sitemap.main_menu
75
+ '/'
76
+ elsif resource.is_a? ExternalLink
77
+ resource.url
78
+ else
79
+ %(#{(a=parent.url)=='/'?'':a}/#{menu_text.gsub(/ /, '_')})
80
+ end
81
+ end
82
+
83
+
84
+ #########################################################################
85
+ #
86
+ # Class Methods
87
+ #
88
+ #########################################################################
89
+
90
+ def self.root
91
+ @_root ||= Sitemap.find_by_menu_text_and_parent_id('root', nil)
92
+ end
93
+
94
+ def self.lost_and_found
95
+ root.children.select{|t| t.menu_text=='Lost + Found'}[0]
96
+ end
97
+
98
+ def self.main_menu
99
+ root.children.select{|t| t.menu_text=='Main Menu'}[0]
100
+ end
101
+
102
+ def self.settings
103
+ root.children.select{|t| t.menu_text=='Settings'}[0]
104
+ end
105
+
106
+ def self.find_by_path(*path_args)
107
+ path = path_args.reverse
108
+ path.delete(nil)
109
+ obj = Sitemap.main_menu
110
+ while (path_piece=path.pop)
111
+ obj = obj.children.select{|t| t.menu_text.downcase==path_piece.downcase.gsub(/_/, ' ')}[0]
112
+ raise "Path error '#{path_piece}' in '#{path_args.join('/')}'" unless obj
113
+ end
114
+ return obj
115
+ end
116
+
117
+ #########################################################################
118
+ #
119
+ # Private Methods
120
+ #
121
+ #########################################################################
122
+
123
+ private
124
+ def build_resource(params={})
125
+ if resource_class
126
+ a = resource_class.new(params)
127
+ self.resource = a
128
+ a
129
+ end
130
+ end
131
+
132
+ def create_resource(params={})
133
+ if resource_class
134
+ a = resource_class.create(params)
135
+ self.resource = a
136
+ a
137
+ end
138
+ end
139
+
140
+ def new_model
141
+ resource_class.new(:sitemaps=>[self]) if resource_class
142
+ end
143
+
144
+ def resource_class
145
+ resource_type.camelize.constantize unless resource_type.empty?
146
+ end
147
+
148
+ def icon_name
149
+ case resource_type
150
+ when "Page"
151
+ "page"
152
+ when "ExternalLink"
153
+ "folder"
154
+ when "Menu"
155
+ "drive"
156
+ end
157
+ end
158
+
159
+ def treeview_state
160
+ if resource.is_a?(Menu)
161
+ "open"
162
+ elsif resource.is_a? Page
163
+ "closed"
164
+ else
165
+ "open"
166
+ end
167
+ end
168
+ end
169
+
170
+ class SitemapArray < Array
171
+ def to_json
172
+ "[" + map(&:to_json).join(",") + "]"
173
+ end
174
+ end
175
+
@@ -0,0 +1,4 @@
1
+ class ActsAsTaggableOn::Tagging
2
+
3
+ end
4
+
@@ -0,0 +1,69 @@
1
+ class User < ActiveRecord::Base
2
+ belongs_to :role
3
+ has_many :blogs, :dependent => :destroy
4
+ has_one :profile, :dependent => :destroy
5
+ has_many :galleries, :dependent => :destroy
6
+ has_many :access_control_entries, :dependent=>:destroy
7
+
8
+ accepts_nested_attributes_for :profile
9
+
10
+ def initialize(*args)
11
+ super(*args)
12
+ build_profile unless profile
13
+ end
14
+
15
+ def self.nobody
16
+ User.new(:role=>Role.nobody)
17
+ end
18
+
19
+ def self.root
20
+ User.where(:role_id=>Role.root.id)[0]
21
+ end
22
+
23
+ def create_profile
24
+
25
+ Profile.create(:user=>self) unless self.profile
26
+ end
27
+
28
+ def role?(role)
29
+ if role.kind_of?(Role)
30
+ return role==self.role
31
+ elsif role.is_numeric?
32
+ return self.role_id==role
33
+ else
34
+ return self.role.name.underscore==role.underscore
35
+ end
36
+ end
37
+
38
+ def role=(role)
39
+ if role.kind_of? Role
40
+ self.role_id = role.id
41
+ else
42
+ role = role.to_s.camelize
43
+ if role.is_numeric?
44
+ self.role_id= role
45
+ else
46
+ self.role_id= Role.find_by_name(role).id
47
+ end
48
+ end
49
+ end
50
+
51
+ def confirm!
52
+ self.confirmed_at = DateTime::now
53
+ save
54
+ end
55
+ devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :lockable, :timeoutable
56
+
57
+ end
58
+
59
+ class FullyValidatedUser < User
60
+ def class
61
+ User
62
+ end
63
+ attr_accessor :old_password
64
+ validates :email, :presence => true, :email => true
65
+ validates :old_password, :presence=>true , :password=>true
66
+ validates :password, :presence=>true , :length=>{:minimum=>6}
67
+ validates :password_confirmation, :equal_to=>{:other=>:password}
68
+ end
69
+
@@ -0,0 +1,22 @@
1
+ require 'mail'
2
+ class EmailValidator < ActiveModel::EachValidator
3
+ def validate_each(record,attribute,value)
4
+ begin
5
+ m = Mail::Address.new(value)
6
+ # We must check that value contains a domain and that value is an email address
7
+ r = m.domain && m.address == value
8
+ t = m.__send__(:tree)
9
+ # We need to dig into treetop
10
+ # A valid domain must have dot_atom_text elements size > 1
11
+ # user@localhost is excluded
12
+ # treetop must respond to domain
13
+ # We exclude valid email values like <user@localhost.com>
14
+ # Hence we use m.__send__(tree).domain
15
+ r &&= (t.domain.dot_atom_text.elements.size > 1)
16
+ rescue Exception => e
17
+ r = false
18
+ end
19
+ record.errors[attribute] << (options[:message] || "is invalid") unless r
20
+ end
21
+ end
22
+
@@ -0,0 +1,33 @@
1
+ = form_for @access_control_entry, :remote=>true do |f|
2
+ -if @access_control_entry.errors.any?
3
+ #errorExplanation
4
+ %h2= "#{pluralize(@access_control_entry.errors.count, "error")} prohibited this access_control_entry from being saved:"
5
+ %ul
6
+ - @access_control_entry.errors.full_messages.each do |msg|
7
+ %li= msg
8
+ = hidden_field_tag :container, "ace_listing"
9
+ = hidden_field_tag :ajax_function, "append"
10
+ %ul.ace_form_fields
11
+ %li
12
+ .name Email
13
+ = f.text_field :user_email, :class=>"email"
14
+ %li
15
+ .name Role
16
+ = f.select :role, Role.collection_entries
17
+ %li
18
+ .name Can?
19
+ = f.check_box :can
20
+ %li
21
+ .name verb
22
+ = f.text_field :verb, :class=>"verb"
23
+ - if parent.is_a?(User) || parent.is_a? (Role)
24
+ %li
25
+ .name Resource
26
+ = f.select :resource_type, [["Forum", "Forum"], ["Page", "Page"]]
27
+ = f.hidden_field :resource_id
28
+ - else
29
+ = hidden_field_tag resource.class.name.foreign_key.to_sym, resource.id
30
+
31
+ %li
32
+ = f.submit 'Save', :disable_with=>"Saving..."
33
+
@@ -0,0 +1,53 @@
1
+ %h1 Listing Access Control for #{parent.class.name} '#{parent.name}'
2
+
3
+ %ul.listing#ace_listing
4
+ - @access_control_entries.each do |ace|
5
+ %li
6
+ %ul.ace{:id=>ace.element_id}
7
+ %li= ace.user.email if ace.user
8
+ %li= ace.role.fieldName if ace.role
9
+ %li= ace.can ? "Can" : "Cannot"
10
+ %li= ace.verb
11
+ %li= ace.resource_type
12
+ %li= ace.resource_id if ace.resource_id
13
+ %li= ace.options_str if ace.options_str
14
+ - if can? :edit, ace
15
+ %li= link_to "Edit", edit_access_control_entry_path(ace), :remote=>true
16
+ - if can? :destroy, ace
17
+ %li= link_to "X", ace, :method=>:delete, :remote=>true, "data-confirm"=>"Are you sure?"
18
+
19
+ - if can? :create, AccessControlEntry
20
+ %h2 Enter a new Access Control Entry
21
+ = form_for new_ace, :remote=>true do |f|
22
+ = hidden_field_tag :container, "ace_listing"
23
+ = hidden_field_tag :ajax_function, "append"
24
+ %ul.ace_form_fields
25
+ - if parent.is_a? User
26
+ = hidden_field_tag :user_id, parent.id
27
+ - else
28
+ %li
29
+ .fieldName Email
30
+ = f.text_field :user_email, :class=>"email"
31
+ - if parent.is_a? Role
32
+ = hidden_field_tag :role_id, parent.id
33
+ - else
34
+ %li
35
+ .fieldName Role
36
+ = f.select :role, Role.collection_entries
37
+ %li
38
+ .fieldName Can?
39
+ = f.check_box :can
40
+ %li
41
+ .fieldName verb
42
+ = f.select :verb, %w(read manage create update destroy)
43
+ - if parent.is_a?(User) || parent.is_a?(Role)
44
+ %li
45
+ .fieldName Resource
46
+ = f.select :resource_type, [["Forum", "Forum"], ["Page", "Sitemap"]]
47
+ = f.hidden_field :resource_id
48
+ - else
49
+ = hidden_field_tag parent.class.name.foreign_key.to_sym, parent.id
50
+
51
+ %li
52
+ = f.submit 'Save', :disable_with=>"Saving..."
53
+
@@ -0,0 +1,12 @@
1
+ %ul.ace{:id=>resource.element_id}
2
+ %li= resource.user.email if resource.user
3
+ %li= resource.role.name if resource.role
4
+ %li= resource.can ? "Can" : "Cannot"
5
+ %li= resource.verb
6
+ %li= resource.resource_type
7
+ %li= resource.options_str if resource.options_str
8
+ - if can? :edit, resource
9
+ %li= link_to "Edit", edit_access_control_entry_path(resource), :remote=>true
10
+ - if can? :destroy, resource
11
+ %li= link_to "X", resource, :method=>:delete, :remote=>true, "data-confirm"=>"Are you sure?"
12
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('show')});
2
+ = render :partial => "loadbehind/view"
3
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').remove();
2
+ = render :partial => "loadbehind/destroy"
3
+
@@ -0,0 +1,7 @@
1
+ %h1 Editing access_control_entry
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @access_control_entry
6
+ \|
7
+ = link_to 'Back', access_control_entries_path
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('form')});
2
+ = render :partial => "loadbehind/edit"
3
+
@@ -0,0 +1,2 @@
1
+ = render :partial => "index"
2
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('index')});
2
+ = render :partial => "loadbehind/view"
3
+
@@ -0,0 +1,5 @@
1
+ %h1 New access_control_entry
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', access_control_entries_path
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('form')});
2
+ = render :partial => "loadbehind/edit"
3
+
@@ -0,0 +1,2 @@
1
+ = render :partial => "show"
2
+
@@ -0,0 +1,4 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('show')});
2
+ alert('#{container}');
3
+ = render :partial => "loadbehind/view"
4
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('show')});
2
+ = render :partial => "loadbehind/view"
3
+
@@ -0,0 +1,11 @@
1
+ = form_for resource, :remote=>true do |f|
2
+ = hidden_field_tag :container, 'content_pane'
3
+ = hidden_field_tag :ajax_function, 'html'
4
+ .field
5
+ .fieldName Name:
6
+ .fieldValue= f.text_field :name
7
+ .field
8
+ .fieldName Value:
9
+ .fieldValue.text_area= f.text_area :value
10
+ .field= f.submit "Save", :disable_with=>"Saving..."
11
+
@@ -0,0 +1,6 @@
1
+ %ul#app_configs
2
+ - collection.each do |app_config|
3
+ %li
4
+ .fieldName= app_config.name
5
+ .fieldValue= app_config.value
6
+
@@ -0,0 +1,3 @@
1
+ %h2= resource.name + ":"
2
+ %pre.fieldValue!= resource.value
3
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('show')});
2
+ = render :partial => "loadbehind/view"
3
+
@@ -0,0 +1,2 @@
1
+ = @stylesheet
2
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').remove;
2
+ = render :partial => "loadbehind/destroy"
3
+
@@ -0,0 +1,2 @@
1
+ = render :partial=>'form'
2
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('form')});
2
+ = render :partial => "loadbehind/edit"
3
+
@@ -0,0 +1,2 @@
1
+ = render :partial=>'index'
2
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('index')});
2
+ = render :partial => "loadbehind/view"
3
+
@@ -0,0 +1,2 @@
1
+ = render :partial=>'form'
2
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('form')});
2
+ = render :partial => "loadbehind/edit"
3
+
@@ -0,0 +1,2 @@
1
+ = render :partial=>'show'
2
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('show')});
2
+ = render :partial => "loadbehind/view"
3
+
@@ -0,0 +1,3 @@
1
+ $('##{container}').#{ajax_function}(#{raw render_js('show')});
2
+ = render :partial => "loadbehind/view"
3
+
@@ -0,0 +1,26 @@
1
+ -if resource.errors.any?
2
+ #errorExplanation
3
+ %h2= "#{pluralize(resource.errors.count, "error")} prohibited this image from being saved:"
4
+ %ul
5
+ - resource.errors.full_messages.each do |msg|
6
+ %li= msg
7
+
8
+ = form_for [@page, Attachment.new(:page=>@page)], :remote=>true, :html=>{:multipart=>true, :id=>"upload_form"} do |f|
9
+ = f.file_field :file, :id=>"file_input"
10
+ = f.hidden_field :file_file_name, :id=>"file_file_name_input"
11
+ = f.hidden_field :file_file_size, :id=>"file_file_size_input"
12
+ = f.hidden_field :file_content_type, :id=>"file_content_type_input"
13
+ = f.hidden_field :file_updated_at, :id=>"file_updated_at_input"
14
+ = f.submit "Upload File", :id=>"upload_button"
15
+
16
+ = content_for :head do
17
+ = javascript_include_tag *%w(swfobject jquery.uploadify)
18
+ :javascript
19
+ $(function(){
20
+ $('#upload_button').hide();
21
+ });
22
+
23
+ = uploadify_s3(:file_input_selector => '#file_input', :button_text => 'Add File', |
24
+ :on_success => %(function(f) {submitFileForm(f.name, f.size, f.type)}), |
25
+ :on_error => %(function(type, text) {alert("Problem during file upload type: " + type + " text: " + text);}))
26
+
@@ -0,0 +1,9 @@
1
+
2
+ %ul#attachments_list
3
+ - @attachments.each do |attachment|
4
+ %li{:id=>attachment.element_id}
5
+ .file_link= link_to attachment.file.original_filename, attachment.file.url
6
+ .file_size= number_to_human_size attachment.file.size
7
+
8
+ = render :partial=>'form'
9
+
@@ -0,0 +1,6 @@
1
+ %li.attachment
2
+ %ul{:id=>@attachment.element_id}
3
+ %li= link_to @attachment.file.original_filename, @attachment.file.url
4
+ %li Size: #{number_to_human_size @attachment.file.size}
5
+ %li Modified: #{@attachment.updated_at.try(:strftime, "%D %R")}
6
+
@@ -0,0 +1,12 @@
1
+ $(function(){
2
+ $('#upload_button').hide();
3
+ });
4
+
5
+ function submitFileForm(fileName, fileSize, updatedAt, contentType) {
6
+ $('#file_file_name_input').val(fileName);
7
+ $('#file_file_size_input').val(fileSize);
8
+ $('#file_update_at').val(updatedAt);
9
+ $('#file_content_type').val(contentType);
10
+ $('#upload_form').submit();
11
+ }
12
+
@@ -0,0 +1,3 @@
1
+ $('#attachments_list').append(#{raw render_js('show')});
2
+ = render :partial => "loadbehind/view"
3
+