refinerycms-core 0.9.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. data/app/controllers/admin/base_controller.rb +10 -0
  2. data/app/controllers/admin/dialogs_controller.rb +26 -0
  3. data/app/controllers/admin/refinery_core_controller.rb +12 -0
  4. data/app/controllers/application_controller.rb +6 -0
  5. data/app/controllers/refinery/fast_controller.rb +9 -0
  6. data/app/controllers/sitemap_controller.rb +14 -0
  7. data/app/helpers/application_helper.rb +5 -0
  8. data/app/views/admin/_head.html.erb +43 -0
  9. data/app/views/admin/_javascripts.html.erb +32 -0
  10. data/app/views/admin/_menu.html.erb +17 -0
  11. data/app/views/admin/dialogs/show.html.erb +19 -0
  12. data/app/views/layouts/admin.html.erb +24 -0
  13. data/app/views/layouts/admin_dialog.html.erb +14 -0
  14. data/app/views/layouts/application.html.erb +21 -0
  15. data/app/views/shared/_content_page.html.erb +63 -0
  16. data/app/views/shared/_draft_page_message.html.erb +3 -0
  17. data/app/views/shared/_footer.html.erb +4 -0
  18. data/app/views/shared/_google_analytics.html.erb +8 -0
  19. data/app/views/shared/_head.html.erb +42 -0
  20. data/app/views/shared/_header.html.erb +8 -0
  21. data/app/views/shared/_html_tag.html.erb +6 -0
  22. data/app/views/shared/_ie6check.html.erb +63 -0
  23. data/app/views/shared/_javascripts.html.erb +10 -0
  24. data/app/views/shared/_menu.html.erb +30 -0
  25. data/app/views/shared/_menu_branch.html.erb +26 -0
  26. data/app/views/shared/_message.html.erb +10 -0
  27. data/app/views/shared/_no_script.html.erb +9 -0
  28. data/app/views/shared/_site_bar.html.erb +25 -0
  29. data/app/views/shared/admin/_continue_editing.html.erb +3 -0
  30. data/app/views/shared/admin/_error_messages.html.erb +16 -0
  31. data/app/views/shared/admin/_form_actions.html.erb +75 -0
  32. data/app/views/shared/admin/_image_picker.html.erb +60 -0
  33. data/app/views/shared/admin/_make_sortable.html.erb +13 -0
  34. data/app/views/shared/admin/_resource_picker.html.erb +66 -0
  35. data/app/views/shared/admin/_search.html.erb +6 -0
  36. data/app/views/shared/admin/_sortable_list.html.erb +7 -0
  37. data/app/views/shared/admin/_tabbed_fields.html.erb +42 -0
  38. data/app/views/welcome.html.erb +17 -0
  39. data/app/views/wymiframe.html.erb +15 -0
  40. data/config/locales/cs.yml +77 -0
  41. data/config/locales/da.yml +75 -0
  42. data/config/locales/de.yml +75 -0
  43. data/config/locales/el.yml +75 -0
  44. data/config/locales/en.yml +75 -0
  45. data/config/locales/es.yml +68 -0
  46. data/config/locales/fr.yml +72 -0
  47. data/config/locales/it.yml +96 -0
  48. data/config/locales/lolcat.yml +68 -0
  49. data/config/locales/lt.yml +75 -0
  50. data/config/locales/lv.yml +72 -0
  51. data/config/locales/nb.yml +75 -0
  52. data/config/locales/nl.yml +75 -0
  53. data/config/locales/pl.yml +75 -0
  54. data/config/locales/pt-BR.yml +72 -0
  55. data/config/locales/rs.yml +76 -0
  56. data/config/locales/ru.yml +71 -0
  57. data/config/locales/sl.yml +72 -0
  58. data/config/locales/sv.yml +75 -0
  59. data/config/locales/vi.yml +75 -0
  60. data/config/locales/zh-CN.yml +75 -0
  61. data/config/locales/zh-TW.yml +75 -0
  62. data/config/routes.rb +19 -0
  63. data/crud.md +197 -0
  64. data/doc/included-jquery-ui-packages.jpg +0 -0
  65. data/engines.md +179 -0
  66. data/features/search.feature +55 -0
  67. data/features/site_bar.feature +24 -0
  68. data/features/step_definitions/core_steps.rb +61 -0
  69. data/features/support/paths.rb +14 -0
  70. data/features/uploads/beach.jpeg +0 -0
  71. data/features/uploads/refinery_is_awesome.txt +1 -0
  72. data/lib/gemspec.rb +43 -0
  73. data/lib/generators/refinerycms_generator.rb +110 -0
  74. data/lib/generators/templates/.gitignore +83 -0
  75. data/lib/generators/templates/app/views/sitemap/index.xml.builder +22 -0
  76. data/lib/generators/templates/autotest/autotest.rb +17 -0
  77. data/lib/generators/templates/autotest/discover.rb +2 -0
  78. data/lib/generators/templates/config/database.yml.mysql +20 -0
  79. data/lib/generators/templates/config/database.yml.postgresql +57 -0
  80. data/lib/generators/templates/config/database.yml.sqlite3 +26 -0
  81. data/lib/generators/templates/config/i18n-js.yml +6 -0
  82. data/lib/generators/templates/config/initializers/devise.rb +142 -0
  83. data/lib/generators/templates/config/settings.rb +2 -0
  84. data/lib/generators/templates/db/seeds.rb +5 -0
  85. data/lib/refinery/activity.rb +45 -0
  86. data/lib/refinery/admin/base_controller.rb +111 -0
  87. data/lib/refinery/admin_base_controller.rb +5 -0
  88. data/lib/refinery/application.rb +48 -0
  89. data/lib/refinery/application_controller.rb +120 -0
  90. data/lib/refinery/application_helper.rb +19 -0
  91. data/lib/refinery/base_presenter.rb +27 -0
  92. data/lib/refinery/catch_all_routes.rb +11 -0
  93. data/lib/refinery/crud.rb +295 -0
  94. data/lib/refinery/helpers/form_helper.rb +66 -0
  95. data/lib/refinery/helpers/head_helper.rb +17 -0
  96. data/lib/refinery/helpers/html_truncation_helper.rb +25 -0
  97. data/lib/refinery/helpers/image_helper.rb +49 -0
  98. data/lib/refinery/helpers/menu_helper.rb +68 -0
  99. data/lib/refinery/helpers/meta_helper.rb +67 -0
  100. data/lib/refinery/helpers/pagination_helper.rb +16 -0
  101. data/lib/refinery/helpers/script_helper.rb +36 -0
  102. data/lib/refinery/helpers/site_bar_helper.rb +24 -0
  103. data/lib/refinery/helpers/tag_helper.rb +21 -0
  104. data/lib/refinery/helpers/translation_helper.rb +17 -0
  105. data/lib/refinery/link_renderer.rb +55 -0
  106. data/lib/refinery/plugin.rb +106 -0
  107. data/lib/refinery/plugins.rb +75 -0
  108. data/lib/refinerycms-core.rb +156 -0
  109. data/lib/tasks/doc.rake +29 -0
  110. data/lib/tasks/refinery.rake +231 -0
  111. data/lib/tasks/yard.rake +30 -0
  112. data/license.md +21 -0
  113. data/public/404.html +26 -0
  114. data/public/422.html +26 -0
  115. data/public/500.html +26 -0
  116. data/public/favicon.ico +0 -0
  117. data/public/images/refinery/add.png +0 -0
  118. data/public/images/refinery/admin_bg.png +0 -0
  119. data/public/images/refinery/ajax-loader.gif +0 -0
  120. data/public/images/refinery/branch-end.gif +0 -0
  121. data/public/images/refinery/branch-start.gif +0 -0
  122. data/public/images/refinery/branch.gif +0 -0
  123. data/public/images/refinery/carousel-left.png +0 -0
  124. data/public/images/refinery/carousel-right.png +0 -0
  125. data/public/images/refinery/cross.png +0 -0
  126. data/public/images/refinery/dialogLoadingAnimation.gif +0 -0
  127. data/public/images/refinery/header_background.png +0 -0
  128. data/public/images/refinery/hover-gradient.jpg +0 -0
  129. data/public/images/refinery/icons/accept.png +0 -0
  130. data/public/images/refinery/icons/add.png +0 -0
  131. data/public/images/refinery/icons/ajax-loader.gif +0 -0
  132. data/public/images/refinery/icons/application_edit.png +0 -0
  133. data/public/images/refinery/icons/application_go.png +0 -0
  134. data/public/images/refinery/icons/arrow_left.png +0 -0
  135. data/public/images/refinery/icons/arrow_switch.png +0 -0
  136. data/public/images/refinery/icons/arrow_up.png +0 -0
  137. data/public/images/refinery/icons/bin.png +0 -0
  138. data/public/images/refinery/icons/bin_closed.png +0 -0
  139. data/public/images/refinery/icons/cancel.png +0 -0
  140. data/public/images/refinery/icons/cog_add.png +0 -0
  141. data/public/images/refinery/icons/cog_edit.png +0 -0
  142. data/public/images/refinery/icons/cross.png +0 -0
  143. data/public/images/refinery/icons/delete.png +0 -0
  144. data/public/images/refinery/icons/doc.png +0 -0
  145. data/public/images/refinery/icons/down.gif +0 -0
  146. data/public/images/refinery/icons/edit.png +0 -0
  147. data/public/images/refinery/icons/email.png +0 -0
  148. data/public/images/refinery/icons/email_edit.png +0 -0
  149. data/public/images/refinery/icons/email_go.png +0 -0
  150. data/public/images/refinery/icons/email_open.png +0 -0
  151. data/public/images/refinery/icons/eye.png +0 -0
  152. data/public/images/refinery/icons/folder_page_white.png +0 -0
  153. data/public/images/refinery/icons/image_add.png +0 -0
  154. data/public/images/refinery/icons/image_edit.png +0 -0
  155. data/public/images/refinery/icons/img.png +0 -0
  156. data/public/images/refinery/icons/information.png +0 -0
  157. data/public/images/refinery/icons/layout_add.png +0 -0
  158. data/public/images/refinery/icons/layout_edit.png +0 -0
  159. data/public/images/refinery/icons/music.png +0 -0
  160. data/public/images/refinery/icons/page_add.png +0 -0
  161. data/public/images/refinery/icons/page_edit.png +0 -0
  162. data/public/images/refinery/icons/page_white_edit.png +0 -0
  163. data/public/images/refinery/icons/page_white_gear.png +0 -0
  164. data/public/images/refinery/icons/page_white_put.png +0 -0
  165. data/public/images/refinery/icons/pdf.png +0 -0
  166. data/public/images/refinery/icons/ppt.png +0 -0
  167. data/public/images/refinery/icons/star.png +0 -0
  168. data/public/images/refinery/icons/tick.png +0 -0
  169. data/public/images/refinery/icons/up.gif +0 -0
  170. data/public/images/refinery/icons/user_add.png +0 -0
  171. data/public/images/refinery/icons/user_comment.png +0 -0
  172. data/public/images/refinery/icons/user_edit.png +0 -0
  173. data/public/images/refinery/icons/xls.png +0 -0
  174. data/public/images/refinery/icons/zip.png +0 -0
  175. data/public/images/refinery/icons/zoom.png +0 -0
  176. data/public/images/refinery/logo-large.png +0 -0
  177. data/public/images/refinery/logo-medium.png +0 -0
  178. data/public/images/refinery/logo-site-bar.png +0 -0
  179. data/public/images/refinery/logo-small-medium.png +0 -0
  180. data/public/images/refinery/logo-small.png +0 -0
  181. data/public/images/refinery/logo-tiny.png +0 -0
  182. data/public/images/refinery/logo.png +0 -0
  183. data/public/images/refinery/nav-3-background.gif +0 -0
  184. data/public/images/refinery/nav_inactive_background.png +0 -0
  185. data/public/images/refinery/orange_button.png +0 -0
  186. data/public/images/refinery/page_bg.png +0 -0
  187. data/public/images/refinery/resolve_digital_footer_logo.png +0 -0
  188. data/public/images/refinery/text_field_background.png +0 -0
  189. data/public/images/refinery/tooltip-nib.gif +0 -0
  190. data/public/images/refinery/tooltip-nib.png +0 -0
  191. data/public/images/wymeditor/skins/refinery/arrow_redo.png +0 -0
  192. data/public/images/wymeditor/skins/refinery/arrow_undo.png +0 -0
  193. data/public/images/wymeditor/skins/refinery/eye.png +0 -0
  194. data/public/images/wymeditor/skins/refinery/iframe/lbl-blockquote.png +0 -0
  195. data/public/images/wymeditor/skins/refinery/iframe/lbl-h1.png +0 -0
  196. data/public/images/wymeditor/skins/refinery/iframe/lbl-h2.png +0 -0
  197. data/public/images/wymeditor/skins/refinery/iframe/lbl-h3.png +0 -0
  198. data/public/images/wymeditor/skins/refinery/iframe/lbl-h4.png +0 -0
  199. data/public/images/wymeditor/skins/refinery/iframe/lbl-h5.png +0 -0
  200. data/public/images/wymeditor/skins/refinery/iframe/lbl-h6.png +0 -0
  201. data/public/images/wymeditor/skins/refinery/iframe/lbl-p.png +0 -0
  202. data/public/images/wymeditor/skins/refinery/iframe/lbl-pre.png +0 -0
  203. data/public/images/wymeditor/skins/refinery/link_add.png +0 -0
  204. data/public/images/wymeditor/skins/refinery/link_break.png +0 -0
  205. data/public/images/wymeditor/skins/refinery/page_code.png +0 -0
  206. data/public/images/wymeditor/skins/refinery/page_paste.png +0 -0
  207. data/public/images/wymeditor/skins/refinery/photo_add.png +0 -0
  208. data/public/images/wymeditor/skins/refinery/right.png +0 -0
  209. data/public/images/wymeditor/skins/refinery/style.png +0 -0
  210. data/public/images/wymeditor/skins/refinery/table_add.png +0 -0
  211. data/public/images/wymeditor/skins/refinery/text_align_center.png +0 -0
  212. data/public/images/wymeditor/skins/refinery/text_align_justify.png +0 -0
  213. data/public/images/wymeditor/skins/refinery/text_align_left.png +0 -0
  214. data/public/images/wymeditor/skins/refinery/text_align_right.png +0 -0
  215. data/public/images/wymeditor/skins/refinery/text_bold.png +0 -0
  216. data/public/images/wymeditor/skins/refinery/text_heading_1.png +0 -0
  217. data/public/images/wymeditor/skins/refinery/text_heading_2.png +0 -0
  218. data/public/images/wymeditor/skins/refinery/text_heading_3.png +0 -0
  219. data/public/images/wymeditor/skins/refinery/text_heading_4.png +0 -0
  220. data/public/images/wymeditor/skins/refinery/text_heading_5.png +0 -0
  221. data/public/images/wymeditor/skins/refinery/text_heading_6.png +0 -0
  222. data/public/images/wymeditor/skins/refinery/text_indent.png +0 -0
  223. data/public/images/wymeditor/skins/refinery/text_indent_remove.png +0 -0
  224. data/public/images/wymeditor/skins/refinery/text_italic.png +0 -0
  225. data/public/images/wymeditor/skins/refinery/text_list_bullets.png +0 -0
  226. data/public/images/wymeditor/skins/refinery/text_list_numbers.png +0 -0
  227. data/public/images/wymeditor/skins/refinery/text_paragraph.png +0 -0
  228. data/public/images/wymeditor/skins/refinery/text_strikethrough.png +0 -0
  229. data/public/images/wymeditor/skins/refinery/text_subscript.png +0 -0
  230. data/public/images/wymeditor/skins/refinery/text_superscript.png +0 -0
  231. data/public/images/wymeditor/skins/refinery/text_underline.png +0 -0
  232. data/public/images/wymeditor/skins/wymeditor_icon.png +0 -0
  233. data/public/javascripts/admin.js +7 -0
  234. data/public/javascripts/application.js +1 -0
  235. data/public/javascripts/dd_belatedpng.js +13 -0
  236. data/public/javascripts/i18n-messages.js +2 -0
  237. data/public/javascripts/jquery-min.js +16 -0
  238. data/public/javascripts/jquery-ui-custom-min.js +251 -0
  239. data/public/javascripts/jquery.js +8176 -0
  240. data/public/javascripts/jquery/GPL-LICENSE.txt +278 -0
  241. data/public/javascripts/jquery/MIT-LICENSE.txt +20 -0
  242. data/public/javascripts/jquery/jquery.corner.js +345 -0
  243. data/public/javascripts/jquery/jquery.html5-placeholder-shim.js +88 -0
  244. data/public/javascripts/jquery/jquery.jcarousel.js +900 -0
  245. data/public/javascripts/jquery/jquery.textTruncate.js +174 -0
  246. data/public/javascripts/jquery/jquery.timers.js +138 -0
  247. data/public/javascripts/modernizr-min.js +30 -0
  248. data/public/javascripts/rails.js +175 -0
  249. data/public/javascripts/refinery/admin.js +1114 -0
  250. data/public/javascripts/refinery/boot_wym.js +285 -0
  251. data/public/javascripts/refinery/core.js +18 -0
  252. data/public/javascripts/refinery/i18n.js +340 -0
  253. data/public/javascripts/refinery/nestedsortables.js +164 -0
  254. data/public/javascripts/refinery/serializelist.js +66 -0
  255. data/public/javascripts/refinery/site_bar.js +16 -0
  256. data/public/javascripts/refinery/submenu.js +49 -0
  257. data/public/javascripts/wymeditor/jquery.refinery.wymeditor.js +5156 -0
  258. data/public/javascripts/wymeditor/lang/ca.js +45 -0
  259. data/public/javascripts/wymeditor/lang/cs.js +45 -0
  260. data/public/javascripts/wymeditor/lang/da.js +48 -0
  261. data/public/javascripts/wymeditor/lang/de.js +45 -0
  262. data/public/javascripts/wymeditor/lang/en.js +47 -0
  263. data/public/javascripts/wymeditor/lang/es.js +48 -0
  264. data/public/javascripts/wymeditor/lang/fa.js +46 -0
  265. data/public/javascripts/wymeditor/lang/fr.js +45 -0
  266. data/public/javascripts/wymeditor/lang/he.js +45 -0
  267. data/public/javascripts/wymeditor/lang/hu.js +45 -0
  268. data/public/javascripts/wymeditor/lang/it.js +48 -0
  269. data/public/javascripts/wymeditor/lang/lv.js +47 -0
  270. data/public/javascripts/wymeditor/lang/nb.js +48 -0
  271. data/public/javascripts/wymeditor/lang/nl.js +47 -0
  272. data/public/javascripts/wymeditor/lang/nn.js +45 -0
  273. data/public/javascripts/wymeditor/lang/pl.js +45 -0
  274. data/public/javascripts/wymeditor/lang/pt-BR.js +47 -0
  275. data/public/javascripts/wymeditor/lang/pt.js +45 -0
  276. data/public/javascripts/wymeditor/lang/rs.js +47 -0
  277. data/public/javascripts/wymeditor/lang/ru.js +45 -0
  278. data/public/javascripts/wymeditor/lang/sl.js +47 -0
  279. data/public/javascripts/wymeditor/lang/sv.js +45 -0
  280. data/public/javascripts/wymeditor/lang/tr.js +45 -0
  281. data/public/javascripts/wymeditor/lang/vi.js +47 -0
  282. data/public/javascripts/wymeditor/lang/zh_cn.js +47 -0
  283. data/public/javascripts/wymeditor/skins/refinery/skin.js +48 -0
  284. data/public/robots.txt +3 -0
  285. data/public/stylesheets/application.css +4 -0
  286. data/public/stylesheets/formatting.css +4 -0
  287. data/public/stylesheets/home.css +4 -0
  288. data/public/stylesheets/refinery/application.css +72 -0
  289. data/public/stylesheets/refinery/formatting.css +57 -0
  290. data/public/stylesheets/refinery/home.css +0 -0
  291. data/public/stylesheets/refinery/refinery.css +1579 -0
  292. data/public/stylesheets/refinery/site_bar.css +87 -0
  293. data/public/stylesheets/refinery/submenu.css +22 -0
  294. data/public/stylesheets/refinery/theme.css +36 -0
  295. data/public/stylesheets/refinery/tooltips.css +34 -0
  296. data/public/stylesheets/refinery/ui.css +107 -0
  297. data/public/stylesheets/theme.css +4 -0
  298. data/public/stylesheets/wymeditor/skins/refinery/skin.css +528 -0
  299. data/public/stylesheets/wymeditor/skins/refinery/wymiframe.css +96 -0
  300. data/public/wymeditor/GPL-license.txt +278 -0
  301. data/public/wymeditor/MIT-license.txt +20 -0
  302. data/public/wymeditor/README +35 -0
  303. data/refinerycms-core.gemspec +391 -0
  304. data/spec/lib/refinery/plugins_spec.rb +90 -0
  305. metadata +482 -0
@@ -0,0 +1,111 @@
1
+ require 'action_controller'
2
+ require 'application_helper'
3
+
4
+ module Refinery
5
+ module Admin
6
+ module BaseController
7
+
8
+ def self.included(controller)
9
+ controller.send :include, ::Refinery::Admin::BaseController::InstanceMethods
10
+ controller.send :include, ::Refinery::Admin::BaseController::ClassMethods
11
+ end
12
+
13
+ module ClassMethods
14
+ def self.included(c)
15
+ c.layout :layout?
16
+
17
+ c.before_filter :authenticate_user!, :restrict_plugins, :restrict_controller
18
+ c.after_filter :store_location?, :except => [:new, :create, :edit, :update, :destroy, :update_positions] # for redirect_back_or_default
19
+
20
+ c.helper_method :searching?, :group_by_date
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+ def admin?
26
+ true # we're in the admin base controller, so always true.
27
+ end
28
+
29
+ def searching?
30
+ params[:search].present?
31
+ end
32
+
33
+ def error_404(exception=nil)
34
+ if (@page = Page.find_by_menu_match("^/404$", :include => [:parts, :slugs])).present?
35
+ params[:action] = 'error_404'
36
+ # change any links in the copy to the admin_root_path
37
+ # and any references to "home page" to "Dashboard"
38
+ part_symbol = Page.default_parts.first.to_sym
39
+ @page[part_symbol] = @page[part_symbol].to_s.gsub(
40
+ /href=(\'|\")\/(\'|\")/, "href='#{admin_root_path}'"
41
+ ).gsub("home page", "Dashboard")
42
+
43
+ render :template => "/pages/show",
44
+ :layout => layout?,
45
+ :status => 404
46
+ else
47
+ # fallback to the default 404.html page.
48
+ render :file => Rails.root.join("public", "404.html").cleanpath.to_s,
49
+ :layout => false,
50
+ :status => 404
51
+ end
52
+ end
53
+
54
+ protected
55
+
56
+ def group_by_date(records)
57
+ new_records = []
58
+
59
+ records.each do |record|
60
+ key = record.created_at.strftime("%Y-%m-%d")
61
+ record_group = new_records.collect{|records| records.last if records.first == key }.flatten.compact << record
62
+ (new_records.delete_if {|i| i.first == key}) << [key, record_group]
63
+ end
64
+
65
+ new_records
66
+ end
67
+
68
+ def restrict_plugins
69
+ current_length = (plugins = current_user.authorized_plugins).length
70
+
71
+ # Superusers get granted access if they don't already have access.
72
+ if current_user.has_role?(:superuser)
73
+ if (plugins = plugins | ::Refinery::Plugins.registered.names).length > current_length
74
+ current_user.plugins = plugins
75
+ end
76
+ end
77
+
78
+ Refinery::Plugins.set_active(plugins)
79
+ end
80
+
81
+ def restrict_controller
82
+ if Refinery::Plugins.active.reject { |plugin| params[:controller] !~ Regexp.new(plugin.menu_match)}.empty?
83
+ warn "'#{current_user.username}' tried to access '#{params[:controller]}' but was rejected."
84
+ error_404
85
+ end
86
+ end
87
+
88
+ # Override method from application_controller. Not needed in this controller.
89
+ def find_pages_for_menu; end
90
+
91
+ private
92
+ def layout?
93
+ "admin#{"_dialog" if from_dialog?}"
94
+ end
95
+
96
+ # Check whether it makes sense to return the user to the last page they
97
+ # were at instead of the default e.g. admin_pages_url
98
+ # right now we just want to snap back to index actions and definitely not to dialogues.
99
+ def store_location?
100
+ store_location unless action_name !~ /index/ or request.xhr? or from_dialog?
101
+ end
102
+
103
+ # Override authorized? so that only users with the Refinery role can admin the website.
104
+ def authorized?
105
+ refinery_user?
106
+ end
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ # This is a dummy to enable updates from 0.9.8.x onward.
2
+ module Refinery
3
+ class AdminBaseController < ActionController::Base
4
+ end
5
+ end
@@ -0,0 +1,48 @@
1
+ module Refinery
2
+ module Application
3
+ class << self
4
+ def refine!
5
+ ::ApplicationHelper.send :include, ::Refinery::ApplicationHelper
6
+
7
+ [::ApplicationController, ::Admin::BaseController].each do |c|
8
+ c.send :include, ::Refinery::ApplicationController
9
+ c.send :helper, :application
10
+ end
11
+
12
+ ::Admin::BaseController.send :include, ::Refinery::Admin::BaseController
13
+ end
14
+
15
+ def included(base)
16
+ self.instance_eval %(
17
+ def self.method_missing(method_sym, *arguments, &block)
18
+ #{base}.send(method_sym)
19
+ end
20
+ )
21
+
22
+ # JavaScript files you want as :defaults (application.js is always included).
23
+ base.config.action_view.javascript_expansions[:defaults] = %w()
24
+
25
+ # Configure the default encoding used in templates for Ruby 1.9.
26
+ base.config.encoding = "utf-8"
27
+
28
+ # Configure sensitive parameters which will be filtered from the log file.
29
+ base.config.filter_parameters += [:password, :password_confirmation]
30
+
31
+ # Specify a cache store to use
32
+ base.config.cache_store = :memory_store
33
+
34
+ # Include the refinery controllers and helpers dynamically
35
+ base.config.to_prepare do
36
+ ::Refinery::Application.refine!
37
+ end
38
+
39
+ # load in any settings that the developer wants after the initialization.
40
+ base.config.after_initialize do
41
+ if (settings = Rails.root.join('config', 'settings.rb')).exist?
42
+ require settings.to_s
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,120 @@
1
+ require 'action_controller'
2
+ # require application helper so that we can include our helpers into it.
3
+ if defined?(Rails) and !Rails.root.nil?
4
+ if (app_helper = Rails.root.join('app', 'helpers', 'application_helper.rb')).file?
5
+ require app_helper.to_s
6
+ end
7
+ end
8
+
9
+ module Refinery
10
+ module ApplicationController
11
+
12
+ def self.included(controller)
13
+ controller.send :include, ::Refinery::ApplicationController::InstanceMethods
14
+ controller.send :include, ::Refinery::ApplicationController::ClassMethods
15
+ end
16
+
17
+ module ClassMethods
18
+ def self.included(c) # Extend controller
19
+ c.helper_method :home_page?,
20
+ :local_request?,
21
+ :just_installed?,
22
+ :from_dialog?,
23
+ :admin?,
24
+ :login?
25
+
26
+ c.protect_from_forgery # See ActionController::RequestForgeryProtection
27
+
28
+ c.send :include, Crud # basic create, read, update and delete methods
29
+
30
+ c.send :before_filter, :find_pages_for_menu,
31
+ :show_welcome_page?
32
+
33
+ c.send :after_filter, :store_current_location!,
34
+ :if => Proc.new {|c| c.send(:refinery_user?) rescue false }
35
+
36
+ if Refinery.rescue_not_found
37
+ c.send :rescue_from, ActiveRecord::RecordNotFound,
38
+ ActionController::UnknownAction,
39
+ ActionView::MissingTemplate,
40
+ :with => :error_404
41
+ end
42
+ end
43
+ end
44
+
45
+ module InstanceMethods
46
+ def admin?
47
+ controller_name =~ %r{^admin/}
48
+ end
49
+
50
+ def error_404(exception=nil)
51
+ if (@page = Page.where(:menu_match => "^/404$").includes(:parts, :slugs).first).present?
52
+ # render the application's custom 404 page with layout and meta.
53
+ render :template => "/pages/show",
54
+ :format => 'html',
55
+ :status => 404
56
+ else
57
+ # fallback to the default 404.html page.
58
+ file = Rails.root.join('public', '404.html')
59
+ file = Refinery.roots('core').join('public', '404.html') unless file.exist?
60
+ render :file => file.cleanpath.to_s,
61
+ :layout => false,
62
+ :status => 404
63
+ end
64
+ end
65
+
66
+ def from_dialog?
67
+ params[:dialog] == "true" or params[:modal] == "true"
68
+ end
69
+
70
+ def home_page?
71
+ root_path == request.path
72
+ end
73
+
74
+ def just_installed?
75
+ Role[:refinery].users.empty?
76
+ end
77
+
78
+ def local_request?
79
+ Rails.env.development? or request.remote_ip =~ /(::1)|(127.0.0.1)|((192.168).*)/
80
+ end
81
+
82
+ def login?
83
+ (controller_name =~ /^(user|session)(|s)/ and not admin?) or just_installed?
84
+ end
85
+
86
+ protected
87
+
88
+ # get all the pages to be displayed in the site menu.
89
+ def find_pages_for_menu
90
+ @menu_pages = Page.live.in_menu.order('lft ASC')
91
+ end
92
+
93
+ # use a different model for the meta information.
94
+ def present(model)
95
+ presenter = (Object.const_get("#{model.class}Presenter") rescue ::Refinery::BasePresenter)
96
+ @meta = presenter.new(model)
97
+ end
98
+
99
+ # this hooks into the Rails render method.
100
+ def render(action = nil, options = {}, &blk)
101
+ present(@page) unless admin? or @meta.present?
102
+ super
103
+ end
104
+
105
+ def show_welcome_page?
106
+ render :template => "/welcome", :layout => "login" if just_installed? and %w(registrations).exclude?(controller_name)
107
+ end
108
+
109
+ private
110
+ def store_current_location!
111
+ if admin?
112
+ # ensure that we don't redirect to AJAX or POST/PUT/DELETE urls
113
+ session[:refinery_return_to] = request.path if request.get? and !request.xhr? and !from_dialog?
114
+ elsif defined?(@page) and @page.present?
115
+ session[:website_return_to] = @page.url
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,19 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ Dir[File.expand_path('../helpers/*.rb', __FILE__).to_s].each {|helper| require helper}
3
+
4
+ module Refinery
5
+ module ApplicationHelper
6
+ def self.included(base)
7
+ base.send :include, Refinery::Helpers::HeadHelper
8
+ base.send :include, Refinery::Helpers::HtmlTruncationHelper
9
+ base.send :include, Refinery::Helpers::ImageHelper
10
+ base.send :include, Refinery::Helpers::MenuHelper
11
+ base.send :include, Refinery::Helpers::MetaHelper
12
+ base.send :include, Refinery::Helpers::PaginationHelper
13
+ base.send :include, Refinery::Helpers::ScriptHelper
14
+ base.send :include, Refinery::Helpers::SiteBarHelper
15
+ base.send :include, Refinery::Helpers::TagHelper
16
+ base.send :include, Refinery::Helpers::TranslationHelper
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ class Refinery::BasePresenter
2
+
3
+ DEFAULT_FIELDS = {
4
+ :title => Proc.new { |p| (p.model.class.name.titleize if p.model.present?) },
5
+ :path => Proc.new { |p| p.title },
6
+ :browser_title => nil,
7
+ :meta_description => nil,
8
+ :meta_keywords => nil
9
+ }
10
+
11
+ attr_reader :model
12
+
13
+ def initialize(obj)
14
+ @model = obj
15
+ end
16
+
17
+ def method_missing(method, *args)
18
+ if @model.respond_to? method
19
+ @model.send method
20
+ elsif DEFAULT_FIELDS.has_key? method
21
+ (value = DEFAULT_FIELDS[method]).is_a?(Proc) ? value.call(self) : value
22
+ else
23
+ raise NoMethodError.new("#{self.class.name} doesn't know #{method}. Define or delegate it.", method)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,11 @@
1
+ ::Refinery::Application.routes.draw do
2
+ match '/admin(/*path)', :to => redirect {|params, request|
3
+ request.flash[:message] = "<p>
4
+ The URL '/<strong>admin</strong>#{"/#{params[:path]}" unless params[:path].blank?}' will be removed in Refinery CMS version 1.0
5
+ <br/>
6
+ Please use '/<strong>refinery</strong>#{"/#{params[:path]}" unless params[:path].blank?}' instead.
7
+ </p>".html_safe
8
+ "/refinery#{"/#{params[:path]}" unless params[:path].blank?}"
9
+ }
10
+ match '/refinery/*path' => 'admin/base#error_404'
11
+ end
@@ -0,0 +1,295 @@
1
+ # Base methods for CRUD actions
2
+ # Simply override any methods in your action controller you want to be customised
3
+ # Don't forget to add:
4
+ # resources :plural_model_name_here
5
+ # to your routes.rb file.
6
+ # Full documentation about CRUD and resources go here:
7
+ # -> http://caboo.se/doc/classes/ActionController/Resources.html#M003716
8
+ # Example (add to your controller):
9
+ # crudify :foo, {:title_attribute => 'name'}
10
+
11
+ module Refinery
12
+ module Crud
13
+
14
+ def self.default_options(model_name)
15
+ singular_name = model_name.to_s
16
+ class_name = singular_name.camelize
17
+ plural_name = singular_name.pluralize
18
+ this_class = class_name.constantize.base_class
19
+
20
+ {
21
+ :title_attribute => "title",
22
+ :order => ('position ASC' if this_class.table_exists? and this_class.column_names.include?('position')),
23
+ :conditions => '',
24
+ :sortable => true,
25
+ :searchable => true,
26
+ :include => [],
27
+ :paging => true,
28
+ :search_conditions => '',
29
+ :redirect_to_url => "admin_#{plural_name}_url"
30
+ }
31
+ end
32
+
33
+ def self.append_features(base)
34
+ super
35
+ base.extend(ClassMethods)
36
+ end
37
+
38
+ module ClassMethods
39
+
40
+ def crudify(model_name, options = {})
41
+ options = ::Refinery::Crud.default_options(model_name).merge(options)
42
+
43
+ singular_name = model_name.to_s
44
+ class_name = singular_name.camelize
45
+ plural_name = singular_name.pluralize
46
+
47
+ module_eval %(
48
+ prepend_before_filter :find_#{singular_name},
49
+ :only => [:update, :destroy, :edit, :show]
50
+
51
+ def new
52
+ @#{singular_name} = #{class_name}.new
53
+ end
54
+
55
+ def create
56
+ # if the position field exists, set this object as last object, given the conditions of this class.
57
+ if #{class_name}.column_names.include?("position")
58
+ params[:#{singular_name}].merge!({
59
+ :position => ((#{class_name}.maximum(:position, :conditions => #{options[:conditions].inspect})||-1) + 1)
60
+ })
61
+ end
62
+
63
+ if (@#{singular_name} = #{class_name}.create(params[:#{singular_name}])).valid?
64
+ (request.xhr? ? flash.now : flash).notice = t(
65
+ 'refinery.crudify.created',
66
+ :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'"
67
+ )
68
+
69
+ unless from_dialog?
70
+ unless params[:continue_editing] =~ /true|on|1/
71
+ redirect_back_or_default(#{options[:redirect_to_url]})
72
+ else
73
+ unless request.xhr?
74
+ redirect_to :back
75
+ else
76
+ render :partial => "/shared/message"
77
+ end
78
+ end
79
+ else
80
+ render :text => "<script>parent.window.location = '\#{#{options[:redirect_to_url]}}';</script>"
81
+ end
82
+ else
83
+ unless request.xhr?
84
+ render :action => 'new'
85
+ else
86
+ render :partial => "/shared/admin/error_messages",
87
+ :locals => {
88
+ :object => @#{singular_name},
89
+ :include_object_name => true
90
+ }
91
+ end
92
+ end
93
+ end
94
+
95
+ def edit
96
+ # object gets found by find_#{singular_name} function
97
+ end
98
+
99
+ def update
100
+ if @#{singular_name}.update_attributes(params[:#{singular_name}])
101
+ (request.xhr? ? flash.now : flash).notice = t(
102
+ 'refinery.crudify.updated',
103
+ :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'"
104
+ )
105
+
106
+ unless from_dialog?
107
+ unless params[:continue_editing] =~ /true|on|1/
108
+ redirect_back_or_default(#{options[:redirect_to_url]})
109
+ else
110
+ unless request.xhr?
111
+ redirect_to :back
112
+ else
113
+ render :partial => "/shared/message"
114
+ end
115
+ end
116
+ else
117
+ render :text => "<script>parent.window.location = '\#{#{options[:redirect_to_url]}}';</script>"
118
+ end
119
+ else
120
+ unless request.xhr?
121
+ render :action => 'edit'
122
+ else
123
+ render :partial => "/shared/admin/error_messages",
124
+ :locals => {
125
+ :object => @#{singular_name},
126
+ :include_object_name => true
127
+ }
128
+ end
129
+ end
130
+ end
131
+
132
+ def destroy
133
+ # object gets found by find_#{singular_name} function
134
+ title = @#{singular_name}.#{options[:title_attribute]}
135
+ if @#{singular_name}.destroy
136
+ flash.notice = t('destroyed', :scope => 'refinery.crudify', :what => "'\#{title}'")
137
+ end
138
+
139
+ redirect_to #{options[:redirect_to_url]}
140
+ end
141
+
142
+ # Finds one single result based on the id params.
143
+ def find_#{singular_name}
144
+ @#{singular_name} = #{class_name}.find(params[:id],
145
+ :include => #{options[:include].map(&:to_sym).inspect})
146
+ end
147
+
148
+ # Find the collection of @#{plural_name} based on the conditions specified into crudify
149
+ # It will be ordered based on the conditions specified into crudify
150
+ # And eager loading is applied as specified into crudify.
151
+ def find_all_#{plural_name}(conditions = #{options[:conditions].inspect})
152
+ @#{plural_name} = #{class_name}.where(conditions).includes(
153
+ #{options[:include].map(&:to_sym).inspect}
154
+ ).order("#{options[:order]}")
155
+ end
156
+
157
+ # Paginate a set of @#{plural_name} that may/may not already exist.
158
+ def paginate_all_#{plural_name}
159
+ # If we have already found a set then we don't need to again
160
+ find_all_#{plural_name} if @#{plural_name}.nil?
161
+
162
+ paging_options = {:page => params[:page]}
163
+
164
+ # Seems will_paginate doesn't always use the implicit method.
165
+ if #{class_name}.methods.map(&:to_sym).include?(:per_page)
166
+ paging_options.update({:per_page => #{class_name}.per_page})
167
+ end
168
+
169
+ @#{plural_name} = @#{plural_name}.paginate(paging_options)
170
+ end
171
+
172
+ # Returns a weighted set of results based on the query specified by the user.
173
+ def search_all_#{plural_name}
174
+ # First find normal results.
175
+ find_all_#{plural_name}(#{options[:search_conditions].inspect})
176
+
177
+ # Now get weighted results by running the query against the results already found.
178
+ @#{plural_name} = @#{plural_name}.with_query(params[:search])
179
+ end
180
+
181
+ # Ensure all methods are protected so that they should only be called
182
+ # from within the current controller.
183
+ protected :find_#{singular_name},
184
+ :find_all_#{plural_name},
185
+ :paginate_all_#{plural_name},
186
+ :search_all_#{plural_name}
187
+ )
188
+
189
+ # Methods that are only included when this controller is searchable.
190
+ if options[:searchable]
191
+ if options[:paging]
192
+ module_eval %(
193
+ def index
194
+ search_all_#{plural_name} if searching?
195
+ paginate_all_#{plural_name}
196
+ end
197
+ )
198
+ else
199
+ module_eval %(
200
+ def index
201
+ unless searching?
202
+ find_all_#{plural_name}
203
+ else
204
+ search_all_#{plural_name}
205
+ end
206
+ end
207
+ )
208
+ end
209
+
210
+ else
211
+ if options[:paging]
212
+ module_eval %(
213
+ def index
214
+ paginate_all_#{plural_name}
215
+ end
216
+ )
217
+ else
218
+ module_eval %(
219
+ def index
220
+ find_all_#{plural_name}
221
+ end
222
+ )
223
+ end
224
+
225
+ end
226
+
227
+ if options[:sortable]
228
+ module_eval %(
229
+ def reorder
230
+ find_all_#{plural_name}
231
+ end
232
+
233
+ # Based upon http://github.com/matenia/jQuery-Awesome-Nested-Set-Drag-and-Drop
234
+ def update_positions
235
+ previous = nil
236
+ # The list doesn't come to us in the correct order. Frustration.
237
+ 0.upto((newlist ||= params[:ul]).length - 1) do |index|
238
+ hash = newlist[index.to_s]
239
+ moved_item_id = hash['id'].split(/#{singular_name}\\_?/)
240
+ @current_#{singular_name} = #{class_name}.find_by_id(moved_item_id)
241
+
242
+ if @current_#{singular_name}.respond_to?(:move_to_root)
243
+ if previous.present?
244
+ @current_#{singular_name}.move_to_right_of(#{class_name}.find_by_id(previous))
245
+ else
246
+ @current_#{singular_name}.move_to_root
247
+ end
248
+ else
249
+ @current_#{singular_name}.update_attribute(:position, index)
250
+ end
251
+
252
+ if hash['children'].present?
253
+ update_child_positions(hash, @current_#{singular_name})
254
+ end
255
+
256
+ previous = moved_item_id
257
+ end
258
+
259
+ #{class_name}.rebuild! if #{class_name}.respond_to?(:rebuild!)
260
+ render :nothing => true
261
+ end
262
+
263
+ def update_child_positions(node, #{singular_name})
264
+ 0.upto(node['children'].length - 1) do |child_index|
265
+ child = node['children'][child_index.to_s]
266
+ child_id = child['id'].split(/#{singular_name}\_?/)
267
+ child_#{singular_name} = #{class_name}.find_by_id(child_id)
268
+ child_#{singular_name}.move_to_child_of(#{singular_name})
269
+
270
+ if child['children'].present?
271
+ update_child_positions(child, child_#{singular_name})
272
+ end
273
+ end
274
+ end
275
+
276
+ )
277
+ end
278
+
279
+ module_eval %(
280
+ def self.sortable?
281
+ #{options[:sortable].to_s}
282
+ end
283
+
284
+ def self.searchable?
285
+ #{options[:searchable].to_s}
286
+ end
287
+ )
288
+
289
+
290
+ end
291
+
292
+ end
293
+
294
+ end
295
+ end