rails_admin_cms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +36 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/javascripts/rails_admin_cms/all.js.coffee +2 -0
  6. data/app/assets/javascripts/rails_admin_cms/cms.js.coffee +18 -0
  7. data/app/assets/javascripts/rails_admin_cms/cms/flashes.js.coffee +2 -0
  8. data/app/assets/javascripts/rails_admin_cms/cms/with_scope/forms.js.coffee +4 -0
  9. data/app/assets/javascripts/rails_admin_cms/cms/with_scope/viewables.js.coffee +14 -0
  10. data/app/assets/stylesheets/rails_admin_cms/all.css.sass +0 -0
  11. data/app/controllers/cms/attachments_controller.rb +20 -0
  12. data/app/controllers/cms/files_controller.rb +19 -0
  13. data/app/controllers/cms/forms_controller.rb +89 -0
  14. data/app/controllers/cms/pages_controller.rb +13 -0
  15. data/app/controllers/cms/viewables_controller.rb +49 -0
  16. data/app/controllers/concerns/cms/editing.rb +21 -0
  17. data/app/controllers/concerns/cms/localize.rb +15 -0
  18. data/app/helpers/cms/cache_helper.rb +26 -0
  19. data/app/helpers/cms/form_helper.rb +67 -0
  20. data/app/helpers/cms/locale_helper.rb +34 -0
  21. data/app/helpers/cms/view_helper.rb +37 -0
  22. data/app/helpers/cms/viewable_helper.rb +155 -0
  23. data/app/helpers/rails_admin/form_builder_decorator.rb +11 -0
  24. data/app/helpers/rails_admin/navigation_helper.rb +77 -0
  25. data/app/mailers/cms/forms_mailer.rb +48 -0
  26. data/app/models/admin/form/email.rb +41 -0
  27. data/app/models/admin/form/field.rb +25 -0
  28. data/app/models/admin/form/row.rb +36 -0
  29. data/app/models/admin/form/static/object.rb +15 -0
  30. data/app/models/admin/form/structure.rb +18 -0
  31. data/app/models/admin/setting.rb +21 -0
  32. data/app/models/admin/unique_key.rb +15 -0
  33. data/app/models/admin/viewable/block.rb +25 -0
  34. data/app/models/admin/viewable/form.rb +36 -0
  35. data/app/models/admin/viewable/image.rb +18 -0
  36. data/app/models/admin/viewable/link.rb +21 -0
  37. data/app/models/admin/viewable/page.rb +27 -0
  38. data/app/models/admin/viewable/select.rb +15 -0
  39. data/app/models/admin/viewable/text.rb +16 -0
  40. data/app/models/callbacks/form/field_after_create.rb +16 -0
  41. data/app/models/callbacks/form/field_after_destroy.rb +16 -0
  42. data/app/models/callbacks/form/field_before_update.rb +29 -0
  43. data/app/models/callbacks/restrictor.rb +30 -0
  44. data/app/models/callbacks/unique_key_before_update.rb +46 -0
  45. data/app/models/callbacks/viewable_after_destroy.rb +27 -0
  46. data/app/models/callbacks/viewable_before_update.rb +15 -0
  47. data/app/models/form.rb +43 -0
  48. data/app/models/form/email.rb +21 -0
  49. data/app/models/form/field.rb +75 -0
  50. data/app/models/form/row.rb +30 -0
  51. data/app/models/form/static.rb +17 -0
  52. data/app/models/form/static/attachment.rb +62 -0
  53. data/app/models/form/static/base.rb +10 -0
  54. data/app/models/form/static/email.rb +23 -0
  55. data/app/models/form/static/object.rb +12 -0
  56. data/app/models/form/structure.rb +90 -0
  57. data/app/models/setting.rb +85 -0
  58. data/app/models/unique_key.rb +62 -0
  59. data/app/models/viewable.rb +93 -0
  60. data/app/models/viewable/block.rb +39 -0
  61. data/app/models/viewable/field/url.rb +45 -0
  62. data/app/models/viewable/field/uuid.rb +61 -0
  63. data/app/models/viewable/form.rb +67 -0
  64. data/app/models/viewable/image.rb +6 -0
  65. data/app/models/viewable/link.rb +10 -0
  66. data/app/models/viewable/page.rb +24 -0
  67. data/app/models/viewable/select.rb +6 -0
  68. data/app/models/viewable/text.rb +6 -0
  69. data/app/presenters/base_list_presenter.rb +42 -0
  70. data/app/presenters/base_presenter.rb +17 -0
  71. data/app/presenters/viewable/block_presenter.rb +10 -0
  72. data/app/presenters/viewable/form_presenter.rb +15 -0
  73. data/app/presenters/viewable/image_presenter.rb +11 -0
  74. data/app/presenters/viewable/link_list_presenter.rb +44 -0
  75. data/app/presenters/viewable/link_presenter.rb +64 -0
  76. data/app/presenters/viewable/page_presenter.rb +4 -0
  77. data/app/presenters/viewable/select_list_presenter.rb +7 -0
  78. data/app/presenters/viewable/select_presenter.rb +15 -0
  79. data/app/presenters/viewable/text_presenter.rb +11 -0
  80. data/app/presenters/viewable/view_presenter.rb +38 -0
  81. data/app/presenters/viewable_list_presenter.rb +54 -0
  82. data/app/presenters/viewable_presenter.rb +27 -0
  83. data/app/views/cms/forms/create.js.erb +3 -0
  84. data/app/views/cms/shared/_flash_messages.js.erb +2 -0
  85. data/app/views/cms/viewables/update.js.erb +1 -0
  86. data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +10 -0
  87. data/config/initializers/assets.rb +6 -0
  88. data/config/initializers/route_translator.rb +3 -0
  89. data/config/locales/cms.en.yml +32 -0
  90. data/config/locales/cms.fr.yml +32 -0
  91. data/config/locales/flash.en.yml +43 -0
  92. data/config/locales/flash.fr.yml +43 -0
  93. data/config/locales/routes.en.yml +3 -0
  94. data/config/locales/routes.fr.yml +3 -0
  95. data/config/routes.rb +36 -0
  96. data/config/spring.rb +1 -0
  97. data/db/migrate/20151226023652_create_unique_key.rb +19 -0
  98. data/db/migrate/20151226054335_create_viewable_link.rb +14 -0
  99. data/db/migrate/20151227064933_create_viewable_text.rb +10 -0
  100. data/db/migrate/20151227072412_create_rich_rich_images.rich.rb +18 -0
  101. data/db/migrate/20151227072413_add_uri_cache_to_rich_image.rich.rb +6 -0
  102. data/db/migrate/20151227072414_refactor_image_to_file.rich.rb +13 -0
  103. data/db/migrate/20151228231201_create_viewable_image.rb +10 -0
  104. data/db/migrate/20151230050603_create_setting.rb +13 -0
  105. data/db/migrate/20151230072904_add_cms_mail_from_and_bcc_settings.rb +14 -0
  106. data/db/migrate/20151230085947_create_viewable_select.rb +10 -0
  107. data/db/migrate/20151231054310_create_viewable_block.rb +9 -0
  108. data/db/migrate/20151231102148_create_viewable_page.rb +13 -0
  109. data/db/migrate/20160101124428_create_viewable_form.rb +15 -0
  110. data/db/migrate/20160101140244_create_form_structure.rb +9 -0
  111. data/db/migrate/20160101141844_create_form_row.rb +13 -0
  112. data/db/migrate/20160102010317_create_form_field.rb +17 -0
  113. data/db/migrate/20160103120544_create_form_email.rb +18 -0
  114. data/lib/generators/cms/install/USAGE +8 -0
  115. data/lib/generators/cms/install/install_generator.rb +14 -0
  116. data/lib/generators/cms/install/templates/Gemfile +47 -0
  117. data/lib/generators/cms/install/templates/app/assets/javascripts/application.js +19 -0
  118. data/lib/generators/cms/install/templates/app/assets/stylesheets/application.css +17 -0
  119. data/lib/generators/cms/install/templates/app/controllers/application_controller.rb +9 -0
  120. data/lib/generators/cms/install/templates/app/controllers/cms/authenticate.rb +34 -0
  121. data/lib/generators/cms/install/templates/app/models/form/contact.rb +20 -0
  122. data/lib/generators/cms/install/templates/app/views/cms/blocks/_example.html.erb +13 -0
  123. data/lib/generators/cms/install/templates/app/views/cms/forms/contact/_form.html.erb +30 -0
  124. data/lib/generators/cms/install/templates/app/views/cms/forms/contact/new.html.erb +19 -0
  125. data/lib/generators/cms/install/templates/app/views/cms/forms_mailer/contact.html.erb +6 -0
  126. data/lib/generators/cms/install/templates/app/views/cms/forms_mailer/contact.text.erb +6 -0
  127. data/lib/generators/cms/install/templates/app/views/cms/pages/page.html.erb +29 -0
  128. data/lib/generators/cms/install/templates/app/views/layouts/application.html.erb +23 -0
  129. data/lib/generators/cms/install/templates/config/application.rb +36 -0
  130. data/lib/generators/cms/install/templates/config/initializers/rails_admin.rb +97 -0
  131. data/lib/generators/cms/install/templates/config/initializers/rich.rb +142 -0
  132. data/lib/generators/cms/install/templates/config/initializers/simple_form.rb +165 -0
  133. data/lib/generators/cms/install/templates/config/initializers/simple_form_bootstrap.rb +149 -0
  134. data/lib/generators/cms/install/templates/config/locales/routes.en.yml +4 -0
  135. data/lib/generators/cms/install/templates/config/locales/simple_form.en.yml +31 -0
  136. data/lib/generators/cms/install/templates/config/routes.rb +61 -0
  137. data/lib/generators/cms/install/templates/vendor/assets/javascripts/rails_admin/custom/ui.js.coffee +1 -0
  138. data/lib/generators/cms/install/templates/vendor/assets/stylesheets/rails_admin/custom/mixins.sass +0 -0
  139. data/lib/generators/cms/install/templates/vendor/assets/stylesheets/rails_admin/custom/theming.sass +1 -0
  140. data/lib/generators/cms/install/templates/vendor/assets/stylesheets/rails_admin/custom/variables.sass +0 -0
  141. data/lib/generators/cms/install/templates/vendor/assets/stylesheets/rich/editor.css +20 -0
  142. data/lib/rails_admin_cms.rb +28 -0
  143. data/lib/rails_admin_cms/config.rb +45 -0
  144. data/lib/rails_admin_cms/core_ext/boolean.rb +29 -0
  145. data/lib/rails_admin_cms/engine.rb +11 -0
  146. data/lib/rails_admin_cms/inflections.rb +4 -0
  147. data/lib/rails_admin_cms/utils.rb +30 -0
  148. data/lib/rails_admin_cms/version.rb +3 -0
  149. data/lib/tasks/rails_admin_cms_tasks.rake +4 -0
  150. metadata +669 -0
@@ -0,0 +1,15 @@
1
+ module Admin
2
+ module Form
3
+ module Static
4
+ module Object
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ rails_admin do
9
+ visible false
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module Admin
2
+ module Form
3
+ module Structure
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ visible false
9
+
10
+ field :email
11
+ field :fields do
12
+ sortable true
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Admin
2
+ module Setting
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ rails_admin do
7
+ navigation_label I18n.t('cms.setting.navigation')
8
+ label I18n.t('cms.setting.one')
9
+ label_plural I18n.t('cms.setting.other')
10
+
11
+ edit do
12
+ field :name do
13
+ read_only true
14
+ end
15
+ field :value, :string
16
+ field :unit
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Admin
2
+ module UniqueKey
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ rails_admin do
7
+ visible false
8
+
9
+ object_label_method do
10
+ :id
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module Admin
2
+ module Viewable
3
+ module Block
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ visible false
9
+
10
+ object_label_method do
11
+ :rails_admin_label
12
+ end
13
+
14
+ group :default do
15
+ hide
16
+ end
17
+ end
18
+ end
19
+
20
+ def rails_admin_label
21
+ "#{partial_name}-#{id}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ module Admin
2
+ module Viewable
3
+ module Form
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ navigation_label I18n.t('cms.form.navigation')
9
+ label I18n.t('cms.form.one')
10
+ label_plural I18n.t('cms.form.other')
11
+
12
+ field :structure do
13
+ pretty_value do
14
+ h = bindings[:view]
15
+ p = ViewablePresenter.new value, h
16
+ h.link_to value.name, p.__send__(:edit_path)
17
+ end
18
+
19
+ inline_add false
20
+ end
21
+ field :url, :string do
22
+ pretty_value do
23
+ bindings[:view].link_to value, value, target: '_blank'
24
+ end
25
+ end
26
+ field :title
27
+ fields :meta_keywords, :meta_description
28
+
29
+ list do
30
+ scopes [:localized]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,18 @@
1
+ module Admin
2
+ module Viewable
3
+ module Image
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ visible false
9
+
10
+ field :title
11
+ field :image, :rich_picker do
12
+ config scoped: 'cms'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Admin
2
+ module Viewable
3
+ module Link
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ visible false
9
+
10
+ field :title
11
+ field :url, :string
12
+ field :page
13
+ field :file, :rich_picker do
14
+ config type: :file, allowed_styles: [:original], scoped: 'cms'
15
+ end
16
+ fields :target_blank, :turbolink
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module Admin
2
+ module Viewable
3
+ module Page
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ navigation_label I18n.t('cms.page.navigation')
9
+ label I18n.t('cms.page.one')
10
+ label_plural I18n.t('cms.page.other')
11
+
12
+ field :url, :string do
13
+ pretty_value do
14
+ bindings[:view].link_to value, value, target: '_blank'
15
+ end
16
+ end
17
+ field :title
18
+ fields :meta_keywords, :meta_description
19
+
20
+ list do
21
+ scopes [:localized]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module Admin
2
+ module Viewable
3
+ module Select
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ visible false
9
+
10
+ fields :value, :label
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Admin
2
+ module Viewable
3
+ module Text
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ visible false
9
+
10
+ field :title
11
+ field :text, :rich_editor, scoped: 'cms'
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Callbacks
2
+ module Form
3
+ class FieldAfterCreate
4
+ include Restrictor
5
+
6
+ def call
7
+ range = m.position..Float::INFINITY
8
+ query = m.fields.where(position: range)
9
+ query.each.with_index(m.position) do |field, position|
10
+ field.update_column(:position, position)
11
+ end
12
+ m.update_header
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Callbacks
2
+ module Form
3
+ class FieldAfterDestroy
4
+ include Restrictor
5
+
6
+ def call
7
+ range = (m.position + 1)..Float::INFINITY
8
+ query = m.fields.where(position: range)
9
+ query.each.with_index(m.position) do |field, position|
10
+ field.update_column(:position, position)
11
+ end
12
+ m.update_header
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module Callbacks
2
+ module Form
3
+ class FieldBeforeUpdate
4
+ include Restrictor
5
+
6
+ def call
7
+ if m.position_was < m.position
8
+ # move list range downward
9
+ range = (m.position_was + 1)..m.position
10
+ reverse = false
11
+ else
12
+ # move list range upward
13
+ range = m.position..(m.position_was - 1)
14
+ reverse = true
15
+ end
16
+ query = m.fields.where(position: range)
17
+ if reverse
18
+ query = query.reverse_order
19
+ end
20
+ query.each.with_index do |field, i|
21
+ position = reverse ? m.position_was - i : m.position_was + i
22
+
23
+ field.update_column(:position, position)
24
+ end
25
+ m.update_header
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ module Callbacks
2
+ module Restrictor
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ mattr_accessor :initiator
7
+ self.initiator = true
8
+
9
+ attr_accessor :m
10
+
11
+ define_method callback do |model|
12
+ return unless initiator
13
+ begin
14
+ self.initiator = false
15
+ self.m = model
16
+ try :init
17
+ __send__ "call"
18
+ ensure
19
+ self.initiator = true
20
+ end
21
+ end
22
+ end
23
+
24
+ class_methods do
25
+ def callback
26
+ "#{name.demodulize.underscore.split('_').last(2).join('_')}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,46 @@
1
+ module Callbacks
2
+ class UniqueKeyBeforeUpdate
3
+ include Restrictor
4
+
5
+ def init
6
+ # keep position and position_was, because buffered_position rewrites them
7
+ @position, @position_was = m.position, m.position_was
8
+ if @position_was < @position
9
+ # move list range downward
10
+ @range = (@position_was + 1)..@position
11
+ @reverse = false
12
+ else
13
+ # move list range upward
14
+ @range = @position..(@position_was - 1)
15
+ @reverse = true
16
+ end
17
+ end
18
+
19
+ def call
20
+ m.with_buffered_position(@position) do
21
+ update_list
22
+ m.other_locales(@position_was).each do |unique_key|
23
+ unique_key.with_buffered_position(@position) do
24
+ update_list(unique_key.locale)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def update_list(locale = nil)
33
+ query = m.list(locale).where(position: @range).order(:position)
34
+ if @reverse
35
+ query = query.reverse_order
36
+ end
37
+
38
+ query.each.with_index do |unique_key, i|
39
+ position = @reverse ? m.position_was - i : m.position_was + i
40
+
41
+ unique_key.update_column(:position, position)
42
+ unique_key.viewable.touch
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ module Callbacks
2
+ class ViewableAfterDestroy
3
+ include Restrictor
4
+
5
+ def init
6
+ @range = (m.position + 1)..Float::INFINITY
7
+ end
8
+
9
+ def call
10
+ update_list
11
+ m.other_locales.each do |viewable|
12
+ viewable.destroy!
13
+ update_list(viewable.locale)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def update_list(locale = nil)
20
+ query = m.list(locale).where(unique_keys: { position: @range }).order('unique_keys.position')
21
+
22
+ query.each.with_index(m.position) do |viewable, position|
23
+ viewable.unique_key.update_column(:position, position)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module Callbacks
2
+ class ViewableBeforeUpdate
3
+ include Restrictor
4
+
5
+ def call
6
+ return unless m.has_unlocalized_fields?
7
+
8
+ attributes = m.slice(*m.unlocalized_fields)
9
+
10
+ m.other_locales.each do |viewable|
11
+ viewable.update! attributes
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ module Form
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ attr_accessor :_subtitle
6
+
7
+ validates :_subtitle, invisible_captcha: true
8
+
9
+ delegate :virtual?, :has_attachments?, :has_collections?, to: :class
10
+ end
11
+
12
+ class_methods do
13
+ def virtual?
14
+ false
15
+ end
16
+
17
+ def has_attachments?
18
+ respond_to? :attachments
19
+ end
20
+
21
+ def has_collections?
22
+ respond_to? :collections
23
+ end
24
+
25
+ def has_collections(*collections)
26
+ define_singleton_method :collections do
27
+ collections
28
+ end
29
+
30
+ delegate :collections, to: :class
31
+ end
32
+ end
33
+
34
+ class << self
35
+ def structure_models
36
+ %w[
37
+ Form::Structure
38
+ Form::Field
39
+ Form::Email
40
+ ]
41
+ end
42
+ end
43
+ end