quadro 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +194 -0
  4. data/Rakefile +39 -0
  5. data/app/assets/images/quadro/close.png +0 -0
  6. data/app/assets/images/quadro/favicon.ico +0 -0
  7. data/app/assets/images/quadro/loading.gif +0 -0
  8. data/app/assets/images/quadro/missing/cover/large.png +0 -0
  9. data/app/assets/images/quadro/missing/cover/medium.png +0 -0
  10. data/app/assets/images/quadro/missing/cover/small.png +0 -0
  11. data/app/assets/images/quadro/missing/cover/thumb.png +0 -0
  12. data/app/assets/images/quadro/missing/image/large.png +0 -0
  13. data/app/assets/images/quadro/missing/image/medium.png +0 -0
  14. data/app/assets/images/quadro/missing/image/small.png +0 -0
  15. data/app/assets/images/quadro/missing/image/thumb.png +0 -0
  16. data/app/assets/images/quadro/missing/slide/large.png +0 -0
  17. data/app/assets/images/quadro/missing/slide/medium.png +0 -0
  18. data/app/assets/images/quadro/missing/slide/small.png +0 -0
  19. data/app/assets/images/quadro/missing/slide/thumb.png +0 -0
  20. data/app/assets/images/quadro/next.png +0 -0
  21. data/app/assets/images/quadro/prev.png +0 -0
  22. data/app/assets/images/quadro/quadro-logo-mini.png +0 -0
  23. data/app/assets/images/quadro/quadro-logo.png +0 -0
  24. data/app/assets/javascripts/quadro/application.js.coffee +27 -0
  25. data/app/assets/javascripts/quadro/message.js.coffee +6 -0
  26. data/app/assets/javascripts/quadro/plugins/gmaps.min.js +1 -0
  27. data/app/assets/javascripts/quadro/plugins/humane.min.js +11 -0
  28. data/app/assets/javascripts/quadro/plugins/jasny-bootstrap.min.js +6 -0
  29. data/app/assets/javascripts/quadro/plugins/jquery.fs.dropper.min.js +9 -0
  30. data/app/assets/javascripts/quadro/plugins/jquery.show_char_limit.min.js +1 -0
  31. data/app/assets/javascripts/quadro/plugins/jquery.smartmenus.bootstrap.min.js +3 -0
  32. data/app/assets/javascripts/quadro/plugins/jquery.smartmenus.min.js +3 -0
  33. data/app/assets/javascripts/quadro/plugins/lightbox.min.js +13 -0
  34. data/app/assets/javascripts/quadro/plugins/pace.min.js +2 -0
  35. data/app/assets/javascripts/quadro/quadro.js.coffee +43 -0
  36. data/app/assets/javascripts/quadro/site.js.coffee +0 -0
  37. data/app/assets/javascripts/quadro/uploader.js.coffee +17 -0
  38. data/app/assets/javascripts/quadro/widget.js.coffee +80 -0
  39. data/app/assets/stylesheets/bootstrap/_mixins.scss +40 -0
  40. data/app/assets/stylesheets/quadro/application.css.sass +19 -0
  41. data/app/assets/stylesheets/quadro/plugins/humane-libnotify.min.css +1 -0
  42. data/app/assets/stylesheets/quadro/plugins/jasny-bootstrap.min.css +7 -0
  43. data/app/assets/stylesheets/quadro/plugins/jquery.fs.dropper.min.css +9 -0
  44. data/app/assets/stylesheets/quadro/plugins/jquery.smartmenus.bootstrap.min.css +1 -0
  45. data/app/assets/stylesheets/quadro/plugins/lightbox.min.css +1 -0
  46. data/app/assets/stylesheets/quadro/plugins/pace.min.css +1 -0
  47. data/app/assets/stylesheets/quadro/quadro.css.sass +99 -0
  48. data/app/assets/stylesheets/quadro/site.css.sass +0 -0
  49. data/app/controllers/quadro/application_controller.rb +122 -0
  50. data/app/controllers/quadro/assets_controller.rb +21 -0
  51. data/app/controllers/quadro/feeds_controller.rb +6 -0
  52. data/app/controllers/quadro/pages_controller.rb +42 -0
  53. data/app/controllers/quadro/robots_controller.rb +6 -0
  54. data/app/controllers/quadro/users_controller.rb +15 -0
  55. data/app/controllers/quadro/widgets_controller.rb +14 -0
  56. data/app/helpers/quadro/application_helper.rb +4 -0
  57. data/app/helpers/quadro/asset_helper.rb +7 -0
  58. data/app/helpers/quadro/navigation_helper.rb +43 -0
  59. data/app/helpers/quadro/widget_helper.rb +54 -0
  60. data/app/models/quadro/asset.rb +11 -0
  61. data/app/models/quadro/asset/cover.rb +18 -0
  62. data/app/models/quadro/asset/image.rb +18 -0
  63. data/app/models/quadro/asset/slide.rb +18 -0
  64. data/app/models/quadro/interaction.rb +13 -0
  65. data/app/models/quadro/page.rb +88 -0
  66. data/app/models/quadro/user.rb +19 -0
  67. data/app/models/quadro/widget.rb +21 -0
  68. data/app/models/quadro/widget/form.rb +13 -0
  69. data/app/models/quadro/widget/gallery.rb +17 -0
  70. data/app/models/quadro/widget/html.rb +14 -0
  71. data/app/models/quadro/widget/map.rb +13 -0
  72. data/app/models/quadro/widget/slider.rb +17 -0
  73. data/app/views/layouts/quadro/application.html.haml +33 -0
  74. data/app/views/layouts/quadro/devise.html.haml +11 -0
  75. data/app/views/quadro/assets/create.js.erb +11 -0
  76. data/app/views/quadro/assets/destroy.js.erb +11 -0
  77. data/app/views/quadro/assets/edit.js.erb +9 -0
  78. data/app/views/quadro/assets/image/_form.html.haml +25 -0
  79. data/app/views/quadro/assets/image/_image.html.haml +10 -0
  80. data/app/views/quadro/assets/slide/_form.html.haml +26 -0
  81. data/app/views/quadro/assets/slide/_slide.html.haml +9 -0
  82. data/app/views/quadro/assets/update.js.erb +18 -0
  83. data/app/views/quadro/feeds/atom.xml.builder +27 -0
  84. data/app/views/quadro/feeds/rss.xml.builder +25 -0
  85. data/app/views/quadro/interactions/_interaction.html.haml +22 -0
  86. data/app/views/quadro/pages/_edit.html.haml +35 -0
  87. data/app/views/quadro/pages/_new.html.haml +11 -0
  88. data/app/views/quadro/pages/_page.html.haml +1 -0
  89. data/app/views/quadro/pages/create.js.erb +7 -0
  90. data/app/views/quadro/pages/destroy.js.erb +5 -0
  91. data/app/views/quadro/pages/edit.js.erb +4 -0
  92. data/app/views/quadro/pages/form.js.erb +6 -0
  93. data/app/views/quadro/pages/index.html.haml +1 -0
  94. data/app/views/quadro/pages/new.js.erb +2 -0
  95. data/app/views/quadro/pages/show.html.haml +1 -0
  96. data/app/views/quadro/pages/update.js.erb +7 -0
  97. data/app/views/quadro/robots/index.text.erb +4 -0
  98. data/app/views/quadro/shared/_modal.html.haml +3 -0
  99. data/app/views/quadro/shared/_navigation.html.haml +17 -0
  100. data/app/views/quadro/shared/_toolbar.html.haml +55 -0
  101. data/app/views/quadro/shared/templates/_blank.html.haml +11 -0
  102. data/app/views/quadro/shared/templates/_demo.html.haml +22 -0
  103. data/app/views/quadro/shared/templates/_jumbotron.html.haml +10 -0
  104. data/app/views/quadro/shared/templates/_sidebar.html.haml +15 -0
  105. data/app/views/quadro/shared/templates/page/_list.html.haml +9 -0
  106. data/app/views/quadro/shared/templates/page/_thumbnail.html.haml +9 -0
  107. data/app/views/quadro/users/_edit.html.haml +15 -0
  108. data/app/views/quadro/users/edit.js.erb +2 -0
  109. data/app/views/quadro/users/update.js.erb +7 -0
  110. data/app/views/quadro/widgets/edit.js.erb +0 -0
  111. data/app/views/quadro/widgets/form/_empty.html.haml +4 -0
  112. data/app/views/quadro/widgets/form/_fields.html.haml +1 -0
  113. data/app/views/quadro/widgets/form/_form.html.haml +0 -0
  114. data/app/views/quadro/widgets/form/_signed_off.html.haml +6 -0
  115. data/app/views/quadro/widgets/form/_signed_on.html.haml +14 -0
  116. data/app/views/quadro/widgets/form/_toolbar.html.haml +7 -0
  117. data/app/views/quadro/widgets/form/_widget.html.haml +1 -0
  118. data/app/views/quadro/widgets/gallery/_empty.html.haml +20 -0
  119. data/app/views/quadro/widgets/gallery/_form.html.haml +0 -0
  120. data/app/views/quadro/widgets/gallery/_signed_off.html.haml +6 -0
  121. data/app/views/quadro/widgets/gallery/_signed_on.html.haml +10 -0
  122. data/app/views/quadro/widgets/gallery/_toolbar.html.haml +7 -0
  123. data/app/views/quadro/widgets/gallery/_uploader.html.haml +5 -0
  124. data/app/views/quadro/widgets/gallery/_widget.html.haml +6 -0
  125. data/app/views/quadro/widgets/html/_empty.html.haml +2 -0
  126. data/app/views/quadro/widgets/html/_form.html.haml +0 -0
  127. data/app/views/quadro/widgets/html/_signed_off.html.haml +6 -0
  128. data/app/views/quadro/widgets/html/_signed_on.html.haml +9 -0
  129. data/app/views/quadro/widgets/html/_toolbar.html.haml +7 -0
  130. data/app/views/quadro/widgets/html/_widget.html.haml +1 -0
  131. data/app/views/quadro/widgets/map/_empty.html.haml +18 -0
  132. data/app/views/quadro/widgets/map/_form.html.haml +0 -0
  133. data/app/views/quadro/widgets/map/_signed_off.html.haml +4 -0
  134. data/app/views/quadro/widgets/map/_signed_on.html.haml +6 -0
  135. data/app/views/quadro/widgets/map/_toolbar.html.haml +7 -0
  136. data/app/views/quadro/widgets/map/_widget.html.haml +45 -0
  137. data/app/views/quadro/widgets/slider/_empty.html.haml +7 -0
  138. data/app/views/quadro/widgets/slider/_form.html.haml +0 -0
  139. data/app/views/quadro/widgets/slider/_signed_off.html.haml +6 -0
  140. data/app/views/quadro/widgets/slider/_signed_on.html.haml +10 -0
  141. data/app/views/quadro/widgets/slider/_toolbar.html.haml +7 -0
  142. data/app/views/quadro/widgets/slider/_uploader.html.haml +5 -0
  143. data/app/views/quadro/widgets/slider/_widget.html.haml +4 -0
  144. data/app/views/quadro/widgets/update.js.erb +0 -0
  145. data/app/views/users/mailer/reset_password_instructions.html.haml +6 -0
  146. data/app/views/users/mailer/unlock_instructions.html.haml +5 -0
  147. data/app/views/users/passwords/edit.html.haml +15 -0
  148. data/app/views/users/passwords/new.html.haml +13 -0
  149. data/app/views/users/sessions/new.html.haml +15 -0
  150. data/app/views/users/shared/_links.html.haml +19 -0
  151. data/app/views/users/unlocks/new.html.haml +13 -0
  152. data/config/initializers/crummy.rb +5 -0
  153. data/config/initializers/devise.rb +261 -0
  154. data/config/initializers/gravatar_image_tag.rb +7 -0
  155. data/config/initializers/kaminari_config.rb +10 -0
  156. data/config/initializers/simple_form.rb +142 -0
  157. data/config/initializers/simple_form_bootstrap.rb +79 -0
  158. data/config/initializers/sitemap.rb +9 -0
  159. data/config/locales/devise.en.yml +60 -0
  160. data/config/locales/kaminari.en.yml +17 -0
  161. data/config/locales/quadro.en.yml +5 -0
  162. data/config/locales/simple_form.en.yml +26 -0
  163. data/config/routes.rb +25 -0
  164. data/db/migrate/20141122163450_create_quadro_widgets.rb +19 -0
  165. data/db/migrate/20141129022344_create_quadro_pages.rb +20 -0
  166. data/db/migrate/20141206085127_create_quadro_assets.rb +16 -0
  167. data/db/migrate/20141207202401_devise_create_quadro_users.rb +28 -0
  168. data/db/migrate/20160606213156_create_quadro_interactions.rb +11 -0
  169. data/lib/generators/quadro/install/USAGE +8 -0
  170. data/lib/generators/quadro/install/install_generator.rb +35 -0
  171. data/lib/generators/quadro/install/templates/app/assets/images/quadro/favicon.ico +0 -0
  172. data/lib/generators/quadro/install/templates/app/assets/images/quadro/quadro-logo-mini.png +0 -0
  173. data/lib/generators/quadro/install/templates/app/assets/images/quadro/quadro-logo.png +0 -0
  174. data/lib/generators/quadro/install/templates/app/assets/javascripts/quadro/site.js.coffee +0 -0
  175. data/lib/generators/quadro/install/templates/app/assets/stylesheets/quadro/site.css.sass +0 -0
  176. data/lib/generators/quadro/install/templates/app/views/quadro/shared/_navigation.html.haml +17 -0
  177. data/lib/generators/quadro/install/templates/app/views/quadro/shared/templates/_blank.html.haml +11 -0
  178. data/lib/generators/quadro/install/templates/app/views/quadro/shared/templates/_demo.html.haml +22 -0
  179. data/lib/generators/quadro/install/templates/app/views/quadro/shared/templates/_jumbotron.html.haml +10 -0
  180. data/lib/generators/quadro/install/templates/app/views/quadro/shared/templates/_sidebar.html.haml +15 -0
  181. data/lib/generators/quadro/install/templates/app/views/quadro/shared/templates/page/_list.html.haml +9 -0
  182. data/lib/generators/quadro/install/templates/app/views/quadro/shared/templates/page/_thumbnail.html.haml +9 -0
  183. data/lib/generators/quadro/install/templates/config/initializers/quadro.rb +12 -0
  184. data/lib/generators/quadro/install/templates/db/GeoLite2-Country.mmdb +0 -0
  185. data/lib/generators/quadro/install/templates/public/404.html +37 -0
  186. data/lib/generators/quadro/install/templates/public/422.html +37 -0
  187. data/lib/generators/quadro/install/templates/public/500.html +37 -0
  188. data/lib/generators/quadro/install/templates/public/maintenance.html +37 -0
  189. data/lib/quadro.rb +16 -0
  190. data/lib/quadro/engine.rb +44 -0
  191. data/lib/quadro/loader.rb +30 -0
  192. data/lib/quadro/signature.rb +3 -0
  193. data/lib/quadro/version.rb +3 -0
  194. data/lib/tasks/quadro_tasks.rake +15 -0
  195. data/test/dummy/README.rdoc +261 -0
  196. data/test/dummy/Rakefile +7 -0
  197. data/test/dummy/app/assets/images/quadro/favicon.ico +0 -0
  198. data/test/dummy/app/assets/images/quadro/quadro-logo-mini.png +0 -0
  199. data/test/dummy/app/assets/images/quadro/quadro-logo.png +0 -0
  200. data/test/dummy/app/assets/javascripts/application.js +15 -0
  201. data/test/dummy/app/assets/javascripts/quadro/site.js.coffee +0 -0
  202. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  203. data/test/dummy/app/assets/stylesheets/quadro/site.css.sass +0 -0
  204. data/test/dummy/app/controllers/application_controller.rb +3 -0
  205. data/test/dummy/app/helpers/application_helper.rb +2 -0
  206. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  207. data/test/dummy/app/views/quadro/shared/_navigation.html.haml +17 -0
  208. data/test/dummy/app/views/quadro/shared/templates/_blank.html.haml +11 -0
  209. data/test/dummy/app/views/quadro/shared/templates/_demo.html.haml +22 -0
  210. data/test/dummy/app/views/quadro/shared/templates/_jumbotron.html.haml +10 -0
  211. data/test/dummy/app/views/quadro/shared/templates/_sidebar.html.haml +15 -0
  212. data/test/dummy/app/views/quadro/shared/templates/page/_list.html.haml +9 -0
  213. data/test/dummy/app/views/quadro/shared/templates/page/_thumbnail.html.haml +9 -0
  214. data/test/dummy/config.ru +4 -0
  215. data/test/dummy/config/application.rb +59 -0
  216. data/test/dummy/config/boot.rb +10 -0
  217. data/test/dummy/config/database.yml +25 -0
  218. data/test/dummy/config/environment.rb +5 -0
  219. data/test/dummy/config/environments/development.rb +37 -0
  220. data/test/dummy/config/environments/production.rb +67 -0
  221. data/test/dummy/config/environments/test.rb +37 -0
  222. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  223. data/test/dummy/config/initializers/inflections.rb +15 -0
  224. data/test/dummy/config/initializers/mime_types.rb +5 -0
  225. data/test/dummy/config/initializers/quadro.rb +12 -0
  226. data/test/dummy/config/initializers/secret_token.rb +7 -0
  227. data/test/dummy/config/initializers/session_store.rb +8 -0
  228. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  229. data/test/dummy/config/locales/en.yml +5 -0
  230. data/test/dummy/config/routes.rb +3 -0
  231. data/test/dummy/db/GeoLite2-Country.mmdb +0 -0
  232. data/test/dummy/db/migrate/20160615055717_create_quadro_widgets.quadro.rb +20 -0
  233. data/test/dummy/db/migrate/20160615055718_create_quadro_pages.quadro.rb +21 -0
  234. data/test/dummy/db/migrate/20160615055719_create_quadro_assets.quadro.rb +17 -0
  235. data/test/dummy/db/migrate/20160615055720_devise_create_quadro_users.quadro.rb +29 -0
  236. data/test/dummy/db/migrate/20160615055721_create_quadro_interactions.quadro.rb +12 -0
  237. data/test/dummy/db/schema.rb +105 -0
  238. data/test/dummy/db/test.sqlite3 +0 -0
  239. data/test/dummy/log/development.log +0 -0
  240. data/test/dummy/log/test.log +3 -0
  241. data/test/dummy/public/404.html +37 -0
  242. data/test/dummy/public/422.html +37 -0
  243. data/test/dummy/public/500.html +37 -0
  244. data/test/dummy/public/maintenance.html +37 -0
  245. data/test/dummy/script/rails +6 -0
  246. data/test/integration/navigation_test.rb +10 -0
  247. data/test/quadro_test.rb +7 -0
  248. data/test/test_helper.rb +18 -0
  249. metadata +806 -0
@@ -0,0 +1,6 @@
1
+ require_dependency 'quadro/application_controller'
2
+
3
+ module Quadro
4
+ class FeedsController < ApplicationController
5
+ end
6
+ end
@@ -0,0 +1,42 @@
1
+ require_dependency 'quadro/application_controller'
2
+
3
+ module Quadro
4
+ class PagesController < ApplicationController
5
+ before_filter :authenticate_user!, except: [:index, :show, :form]
6
+ before_filter :page_exists?
7
+ before_filter :prepare_breadcrumbs
8
+
9
+ respond_to :html, :js
10
+
11
+ def create
12
+ page.user = current_user
13
+ page.save
14
+ end
15
+
16
+ def update
17
+ page.update_attributes(params[:page])
18
+ end
19
+
20
+ def destroy
21
+ page.destroy unless page.is_root?
22
+ end
23
+
24
+ def form
25
+ interaction.ip_address = request.remote_ip
26
+ interaction.user_agent = request.user_agent
27
+ interaction.update_attributes(content: params[:form])
28
+ end
29
+
30
+ private
31
+
32
+ def page_exists?
33
+ not_found_page and return if page.nil?
34
+ end
35
+
36
+ def prepare_breadcrumbs
37
+ page.path.each do |path|
38
+ page.id == path.id ? add_crumb(path.title) : add_crumb(path.title, page_path(path))
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ require_dependency 'quadro/application_controller'
2
+
3
+ module Quadro
4
+ class RobotsController < ApplicationController
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ require_dependency 'quadro/application_controller'
2
+
3
+ module Quadro
4
+ class UsersController < ApplicationController
5
+ before_filter :authenticate_user!
6
+
7
+ respond_to :js, :json, :xml
8
+
9
+ def update
10
+ if user.update_with_password(params[:user])
11
+ sign_in user, bypass: true
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require_dependency 'quadro/application_controller'
2
+
3
+ module Quadro
4
+ class WidgetsController < ApplicationController
5
+ before_filter :authenticate_user!
6
+
7
+ respond_to :js, :json, :xml
8
+
9
+ def update
10
+ widget.update_attributes(params[:widget])
11
+ respond_with widget
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module Quadro
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Quadro
2
+ module AssetHelper
3
+ def absolute_url(relative_url)
4
+ [request.base_url, relative_url].join
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ module Quadro
2
+ module NavigationHelper
3
+ def navigation_for(node, *args)
4
+ return '' unless node
5
+
6
+ options = args[0] || {}
7
+
8
+ content_tag :ul, class: options[:class] do
9
+ unless node.is_childless?
10
+ link_or_dropdown_for(node)
11
+ end
12
+ end.html_safe
13
+ end
14
+
15
+ def dropdown_for(node, *args)
16
+ return '' unless node
17
+
18
+ options = args[0] || {}
19
+
20
+ content_tag :li, class: options[:class] do
21
+ concat(content_tag :a, (node.title + tag(:span, class: 'caret')).html_safe, class: 'dropdown', href: page_path(node))
22
+ concat(content_tag(:ul, class: 'dropdown-menu') do
23
+ link_or_dropdown_for(node)
24
+ end)
25
+ end
26
+ end
27
+
28
+ def link_or_dropdown_for(node, *args)
29
+ return '' unless node
30
+
31
+ options = args[0] || {}
32
+
33
+ node.children.each do |child|
34
+ css_class = 'active' if page.path_ids.include?(child.id)
35
+ if child.has_children?
36
+ concat dropdown_for child, class: 'dropdown'
37
+ else
38
+ concat content_tag :li, content_tag(:a, child.title, href: page_path(child)), class: css_class
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,54 @@
1
+ module Quadro
2
+ module WidgetHelper
3
+ def widget_for(name, *args, &block)
4
+ return "" unless name
5
+
6
+ options = args.extract_options!
7
+
8
+ new_widget =
9
+ case options[:type]
10
+ when :html
11
+ page.widgets.select{ |w| w.name == name.to_s && w.type == Quadro::Widget::Html.to_s }.first || page.widgets.create(name: name, type: Quadro::Widget::Html.to_s).becomes(Quadro::Widget::Html)
12
+ when :slider
13
+ page.widgets.select{ |w| w.name == name.to_s && w.type == Quadro::Widget::Slider.to_s }.first || page.widgets.create(name: name, type: Quadro::Widget::Slider.to_s).becomes(Quadro::Widget::Slider)
14
+ when :gallery
15
+ page.widgets.select{ |w| w.name == name.to_s && w.type == Quadro::Widget::Gallery.to_s }.first || page.widgets.create(name: name, type: Quadro::Widget::Gallery.to_s).becomes(Quadro::Widget::Gallery)
16
+ when :map
17
+ page.widgets.select{ |w| w.name == name.to_s && w.type == Quadro::Widget::Map.to_s }.first || page.widgets.create(name: name, type: Quadro::Widget::Map.to_s).becomes(Quadro::Widget::Map)
18
+ when :form
19
+ page.widgets.select{ |w| w.name == name.to_s && w.type == Quadro::Widget::Form.to_s }.first || page.widgets.create(name: name, type: Quadro::Widget::Form.to_s).becomes(Quadro::Widget::Form)
20
+ else
21
+ page.widgets.select{ |w| w.name == name.to_s && w.type == Quadro::Widget::Html.to_s }.first || page.widgets.create(name: name, type: Quadro::Widget::Html.to_s)
22
+ end
23
+
24
+ widget_block(new_widget, options, &block)
25
+ end
26
+
27
+ def widget_block(widget, options, &block)
28
+ return "" unless widget
29
+
30
+ widget_type = widget.type.constantize.short_name
31
+
32
+ case widget_type
33
+ when 'form'
34
+ simple_form_for(widget.name, url: form_page_path(widget.page), remote: true, html: { id: widget.name }) do |form|
35
+ content = block_given? ? capture(form, &block) : nil
36
+ if user_signed_in?
37
+ options.merge!({ id: widget.id, type: widget.type, name: widget.name, page: widget.page_id, path: page_widget_path(page_id: widget.page_id, id: widget.id) }).reject!{ |k, v| v.nil? }
38
+ render("quadro/widgets/#{widget_type}/signed_on", widget: widget, options: options, content: content, form: form)
39
+ else
40
+ render("quadro/widgets/#{widget_type}/signed_off", widget: widget, options: options, content: content, form: form)
41
+ end
42
+ end
43
+ else
44
+ content = block_given? ? capture(&block) : nil
45
+ if user_signed_in?
46
+ options.merge!({ id: widget.id, type: widget.type, name: widget.name, page: widget.page_id, path: page_widget_path(page_id: widget.page_id, id: widget.id) }).reject!{ |k, v| v.nil? }
47
+ render("quadro/widgets/#{widget_type}/signed_on", widget: widget, options: options, content: content)
48
+ else
49
+ render("quadro/widgets/#{widget_type}/signed_off", widget: widget, options: options, content: content)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ module Quadro
2
+ class Asset < ActiveRecord::Base
3
+ # attributes
4
+ attr_accessible :attachment
5
+
6
+ delegate :url, to: :attachment
7
+
8
+ # associations
9
+ belongs_to :assetable, polymorphic: true
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Quadro
2
+ class Asset::Cover < Asset
3
+ # attributes
4
+ store :settings, accessors: [:width, :height, :alt]
5
+ attr_accessible :width, :height, :alt
6
+ has_attached_file :attachment, styles: { thumb: '200x200#', small: '800x600>', medium: '1024x768>', large: '1280x1024>' }, default_url: '/assets/quadro/missing/cover/:style.png'
7
+
8
+ # validations
9
+ validates_attachment :attachment, content_type: { content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'] }
10
+
11
+ # methods
12
+ class << self
13
+ def short_name
14
+ 'cover'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Quadro
2
+ class Asset::Image < Asset
3
+ # attributes
4
+ store :settings, accessors: [:width, :height, :alt]
5
+ attr_accessible :width, :height, :alt
6
+ has_attached_file :attachment, styles: { thumb: '200x200#', small: '320x240>', medium: '640x480>', large: '800x600>' }, default_url: '/assets/quadro/missing/image/:style.png'
7
+
8
+ # validations
9
+ validates_attachment :attachment, content_type: { content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'] }
10
+
11
+ # methods
12
+ class << self
13
+ def short_name
14
+ 'image'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Quadro
2
+ class Asset::Slide < Asset
3
+ # attributes
4
+ store :settings, accessors: [:width, :height, :alt, :href]
5
+ attr_accessible :width, :height, :alt, :href
6
+ has_attached_file :attachment, styles: { thumb: '200x200#', small: '640x480>', medium: '800x600>', large: '1024x768>' }, default_url: '/assets/quadro/missing/slide/:style.png'
7
+
8
+ # validations
9
+ validates_attachment :attachment, content_type: { content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'] }
10
+
11
+ # methods
12
+ class << self
13
+ def short_name
14
+ 'slide'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Quadro
2
+ class Interaction < ActiveRecord::Base
3
+ # attributes
4
+ attr_accessible :content, :ip_address, :user_agent
5
+ serialize :content, Hash
6
+
7
+ # associations
8
+ belongs_to :interactable, polymorphic: true
9
+
10
+ # scopes
11
+ default_scope order('quadro_interactions.created_at DESC')
12
+ end
13
+ end
@@ -0,0 +1,88 @@
1
+ module Quadro
2
+ class Page < ActiveRecord::Base
3
+ # constants
4
+ PAGE_TEMPLATES_PATH = 'app/views/quadro/shared/templates/'
5
+ SITEMAP_FREQUENCY = %w(always hourly daily weekly monthly yearly never).freeze
6
+ SITEMAP_PRIORITY = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0].freeze
7
+
8
+ # attributes
9
+ attr_accessible :title, :summary, :template, :frequency, :priority, :cover_attributes, :author_id
10
+ store :settings, accessors: [:template, :frequency, :priority]
11
+
12
+ # validations
13
+ validates :title, presence: true, length: { maximum: 60 }
14
+ validates :slug, uniqueness: true
15
+ validates :summary, length: { maximum: 160 }
16
+
17
+ # associations
18
+ belongs_to :author, class_name: Quadro::User
19
+ has_many :widgets, dependent: :destroy
20
+ has_many :assets, as: :assetable, dependent: :destroy
21
+ has_many :images, as: :assetable, class_name: Quadro::Asset::Image
22
+ has_one :cover, as: :assetable, class_name: Quadro::Asset::Cover
23
+
24
+ # nested attributes
25
+ accepts_nested_attributes_for :cover, allow_destroy: false
26
+
27
+ # behaviours
28
+ has_ancestry orphan_strategy: :destroy
29
+ acts_as_url :title, url_attribute: :slug, sync_url: true
30
+
31
+ # callbacks
32
+ after_initialize :initialize_defaults, if: :new_record?
33
+ after_save :ensure_cover
34
+
35
+ # delegation
36
+ delegate :name, :email, to: :author, prefix: true, allow_nil: true
37
+
38
+ # scopes
39
+ scope :ordered, order('quadro_pages.created_at DESC')
40
+
41
+ # methods
42
+ def to_param
43
+ slug
44
+ end
45
+
46
+ def to_s
47
+ title
48
+ end
49
+
50
+ def templates
51
+ templates = []
52
+ Dir.glob("#{PAGE_TEMPLATES_PATH}*.html.haml").each do |file|
53
+ file = File.basename(file, '.html.haml')
54
+ templates << file[1..-1] if file.start_with?('_')
55
+ end
56
+ templates
57
+ end
58
+
59
+ def find_asset(asset_id)
60
+ new_asset = assets.find(asset_id) rescue nil
61
+ new_asset.becomes(new_asset.type.constantize) unless new_asset.nil?
62
+ new_asset
63
+ end
64
+
65
+ def ensure_cover
66
+ generate_cover if self.cover.nil?
67
+ end
68
+
69
+ private
70
+
71
+ def initialize_defaults
72
+ self.template = Quadro.config.template if self.template.blank?
73
+ self.frequency = Quadro.config.frequency if self.frequency.blank?
74
+ self.priority = Quadro.config.priority if self.priority.blank?
75
+ end
76
+
77
+ def generate_cover
78
+ self.build_cover
79
+ self.cover.save
80
+ end
81
+
82
+ class << self
83
+ def short_name
84
+ 'page'
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,19 @@
1
+ module Quadro
2
+ class User < ActiveRecord::Base
3
+ # attributes
4
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :name
5
+
6
+ # behaviours
7
+ devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :lockable
8
+ acts_as_url :name, url_attribute: :slug, sync_url: true
9
+
10
+ # validations
11
+ validates :name, presence: true, length: { maximum: 60 }
12
+
13
+ # associations
14
+ has_many :pages, dependent: :destroy
15
+
16
+ # scopes
17
+ scope :ordered, order('quadro_users.name ASC')
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Quadro
2
+ class Widget < ActiveRecord::Base
3
+ # attributes
4
+ attr_accessible :name, :type
5
+
6
+ # validations
7
+ validates :name, uniqueness: { scope: :page_id }
8
+
9
+ # associations
10
+ belongs_to :page
11
+ has_many :assets, as: :assetable, dependent: :destroy
12
+ has_many :interactions, as: :interactable, dependent: :destroy
13
+
14
+ # methods
15
+ def find_asset(asset_id)
16
+ new_asset = assets.find(asset_id) rescue nil
17
+ new_asset.becomes(new_asset.type.constantize) unless new_asset.nil?
18
+ new_asset
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Quadro
2
+ class Widget::Form < Widget
3
+ # attributes
4
+ store :settings, accessors: [:width, :height]
5
+
6
+ # methods
7
+ class << self
8
+ def short_name
9
+ 'form'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Quadro
2
+ class Widget::Gallery < Widget
3
+ # attributes
4
+ attr_accessible :content
5
+ store :settings, accessors: [:width, :height]
6
+
7
+ # associations
8
+ has_many :images, as: :assetable, class_name: Quadro::Asset::Image
9
+
10
+ # methods
11
+ class << self
12
+ def short_name
13
+ 'gallery'
14
+ end
15
+ end
16
+ end
17
+ end