occams 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +23 -40
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile +17 -17
  5. data/LICENSE +1 -1
  6. data/README.md +15 -18
  7. data/Rakefile +1 -1
  8. data/TODOS.md +6 -0
  9. data/app/controllers/occams/admin/base_controller.rb +1 -1
  10. data/app/controllers/occams/admin/cms/base_controller.rb +7 -7
  11. data/app/controllers/occams/admin/cms/files_controller.rb +17 -17
  12. data/app/controllers/occams/admin/cms/layouts_controller.rb +7 -7
  13. data/app/controllers/occams/admin/cms/pages_controller.rb +25 -25
  14. data/app/controllers/occams/admin/cms/revisions/base_controller.rb +5 -5
  15. data/app/controllers/occams/admin/cms/revisions/layout_controller.rb +1 -1
  16. data/app/controllers/occams/admin/cms/revisions/page_controller.rb +3 -3
  17. data/app/controllers/occams/admin/cms/revisions/snippet_controller.rb +1 -1
  18. data/app/controllers/occams/admin/cms/revisions/translation_controller.rb +3 -3
  19. data/app/controllers/occams/admin/cms/sites_controller.rb +6 -6
  20. data/app/controllers/occams/admin/cms/snippets_controller.rb +6 -6
  21. data/app/controllers/occams/admin/cms/translations_controller.rb +24 -24
  22. data/app/controllers/occams/cms/assets_controller.rb +5 -5
  23. data/app/controllers/occams/cms/base_controller.rb +7 -12
  24. data/app/controllers/occams/cms/content_controller.rb +14 -10
  25. data/app/helpers/occams/admin/cms_helper.rb +3 -3
  26. data/app/helpers/occams/cms_helper.rb +8 -8
  27. data/app/models/concerns/occams/cms/with_categories.rb +3 -3
  28. data/app/models/concerns/occams/cms/with_fragments.rb +3 -3
  29. data/app/models/occams/cms/categorization.rb +1 -1
  30. data/app/models/occams/cms/category.rb +1 -1
  31. data/app/models/occams/cms/file.rb +4 -4
  32. data/app/models/occams/cms/fragment.rb +2 -2
  33. data/app/models/occams/cms/layout.rb +5 -5
  34. data/app/models/occams/cms/page.rb +6 -6
  35. data/app/models/occams/cms/revision.rb +1 -1
  36. data/app/models/occams/cms/site.rb +8 -8
  37. data/app/models/occams/cms/snippet.rb +1 -1
  38. data/app/models/occams/cms/translation.rb +1 -1
  39. data/app/views/layouts/occams/admin/cms/_left.html.haml +3 -0
  40. data/config/application.rb +4 -4
  41. data/config/boot.rb +4 -3
  42. data/config/environment.rb +1 -1
  43. data/config/environments/development.rb +2 -2
  44. data/config/environments/test.rb +1 -1
  45. data/config/initializers/occams.rb +2 -2
  46. data/config.ru +1 -1
  47. data/lib/generators/occams/cms/assets_generator.rb +3 -3
  48. data/lib/generators/occams/cms/cms_generator.rb +13 -13
  49. data/lib/generators/occams/cms/controllers_generator.rb +2 -2
  50. data/lib/generators/occams/cms/models_generator.rb +2 -2
  51. data/lib/generators/occams/cms/views_generator.rb +2 -2
  52. data/lib/generators/occams/scaffold/scaffold_generator.rb +18 -18
  53. data/lib/occams/configuration.rb +33 -33
  54. data/lib/occams/content/params_parser.rb +3 -3
  55. data/lib/occams/content/renderer.rb +8 -8
  56. data/lib/occams/content/tag.rb +1 -1
  57. data/lib/occams/content/tags/asset.rb +13 -13
  58. data/lib/occams/content/tags/audio.rb +41 -0
  59. data/lib/occams/content/tags/checkbox.rb +4 -4
  60. data/lib/occams/content/tags/date.rb +2 -2
  61. data/lib/occams/content/tags/datetime.rb +4 -4
  62. data/lib/occams/content/tags/file.rb +8 -8
  63. data/lib/occams/content/tags/file_link.rb +8 -8
  64. data/lib/occams/content/tags/files.rb +5 -5
  65. data/lib/occams/content/tags/fragment.rb +4 -4
  66. data/lib/occams/content/tags/helper.rb +6 -6
  67. data/lib/occams/content/tags/markdown.rb +2 -2
  68. data/lib/occams/content/tags/mixins/file_content.rb +3 -3
  69. data/lib/occams/content/tags/number.rb +1 -1
  70. data/lib/occams/content/tags/page_file_link.rb +8 -8
  71. data/lib/occams/content/tags/partial.rb +5 -5
  72. data/lib/occams/content/tags/snippet.rb +3 -3
  73. data/lib/occams/content/tags/template.rb +5 -5
  74. data/lib/occams/content/tags/text.rb +1 -1
  75. data/lib/occams/content/tags/textarea.rb +1 -1
  76. data/lib/occams/content/tags/wysiwyg.rb +1 -1
  77. data/lib/occams/content.rb +23 -22
  78. data/lib/occams/engine.rb +10 -10
  79. data/lib/occams/extensions/acts_as_tree.rb +1 -1
  80. data/lib/occams/extensions/has_revisions.rb +3 -3
  81. data/lib/occams/form_builder.rb +4 -4
  82. data/lib/occams/render_methods.rb +2 -2
  83. data/lib/occams/routes/cms.rb +3 -3
  84. data/lib/occams/routes/cms_admin.rb +6 -6
  85. data/lib/occams/routing.rb +2 -2
  86. data/lib/occams/seeds/file/exporter.rb +7 -11
  87. data/lib/occams/seeds/file/importer.rb +5 -5
  88. data/lib/occams/seeds/layout/exporter.rb +9 -9
  89. data/lib/occams/seeds/layout/importer.rb +9 -9
  90. data/lib/occams/seeds/page/exporter.rb +19 -21
  91. data/lib/occams/seeds/page/importer.rb +14 -14
  92. data/lib/occams/seeds/snippet/exporter.rb +6 -6
  93. data/lib/occams/seeds/snippet/importer.rb +6 -6
  94. data/lib/occams/seeds.rb +5 -5
  95. data/lib/occams/version.rb +1 -1
  96. data/lib/occams/view_hooks.rb +1 -1
  97. data/lib/occams.rb +24 -24
  98. data/lib/tasks/cms_seeds.rake +2 -2
  99. data/occams.gemspec +22 -21
  100. metadata +8 -6
  101. data/LICENSE.comfy +0 -20
@@ -6,7 +6,7 @@ private
6
6
  def load_record
7
7
  @record = @site.snippets.find(params[:snippet_id])
8
8
  rescue ActiveRecord::RecordNotFound
9
- flash[:danger] = I18n.t("occams.admin.cms.revisions.record_not_found")
9
+ flash[:danger] = I18n.t('occams.admin.cms.revisions.record_not_found')
10
10
  redirect_to occams_admin_cms_site_snippets_path(@site)
11
11
  end
12
12
 
@@ -6,11 +6,11 @@ class Occams::Admin::Cms::Revisions::TranslationController < Occams::Admin::Cms:
6
6
  c[b.identifier] = b.content
7
7
  end
8
8
  @versioned_content = @record.fragments.each_with_object({}) do |b, c|
9
- d = @revision.data["fragments_attributes"].detect { |r| r[:identifier] == b.identifier }
9
+ d = @revision.data['fragments_attributes'].detect { |r| r[:identifier] == b.identifier }
10
10
  c[b.identifier] = d.try(:[], :content)
11
11
  end
12
12
 
13
- render "occams/admin/cms/revisions/show"
13
+ render 'occams/admin/cms/revisions/show'
14
14
  end
15
15
 
16
16
  private
@@ -19,7 +19,7 @@ private
19
19
  @page = @site.pages.find(params[:page_id])
20
20
  @record = @page.translations.find(params[:translation_id])
21
21
  rescue ActiveRecord::RecordNotFound
22
- flash[:danger] = I18n.t("occams.admin.cms.revisions.record_not_found")
22
+ flash[:danger] = I18n.t('occams.admin.cms.revisions.record_not_found')
23
23
  redirect_to occams_admin_cms_site_pages_path(@site)
24
24
  end
25
25
 
@@ -25,25 +25,25 @@ class Occams::Admin::Cms::SitesController < Occams::Admin::Cms::BaseController
25
25
 
26
26
  def create
27
27
  @site.save!
28
- flash[:success] = I18n.t("occams.admin.cms.sites.created")
28
+ flash[:success] = I18n.t('occams.admin.cms.sites.created')
29
29
  redirect_to occams_admin_cms_site_layouts_path(@site)
30
30
  rescue ActiveRecord::RecordInvalid
31
- flash.now[:danger] = I18n.t("occams.admin.cms.sites.creation_failure")
31
+ flash.now[:danger] = I18n.t('occams.admin.cms.sites.creation_failure')
32
32
  render action: :new
33
33
  end
34
34
 
35
35
  def update
36
36
  @site.update!(site_params)
37
- flash[:success] = I18n.t("occams.admin.cms.sites.updated")
37
+ flash[:success] = I18n.t('occams.admin.cms.sites.updated')
38
38
  redirect_to action: :edit, id: @site
39
39
  rescue ActiveRecord::RecordInvalid
40
- flash.now[:danger] = I18n.t("occams.admin.cms.sites.update_failure")
40
+ flash.now[:danger] = I18n.t('occams.admin.cms.sites.update_failure')
41
41
  render action: :edit
42
42
  end
43
43
 
44
44
  def destroy
45
45
  @site.destroy
46
- flash[:success] = I18n.t("occams.admin.cms.sites.deleted")
46
+ flash[:success] = I18n.t('occams.admin.cms.sites.deleted')
47
47
  redirect_to action: :index
48
48
  end
49
49
 
@@ -58,7 +58,7 @@ protected
58
58
  @site = ::Occams::Cms::Site.find(params[:id])
59
59
  I18n.locale = Occams.config.admin_locale || @site.locale
60
60
  rescue ActiveRecord::RecordNotFound
61
- flash[:danger] = I18n.t("occams.admin.cms.sites.not_found")
61
+ flash[:danger] = I18n.t('occams.admin.cms.sites.not_found')
62
62
  redirect_to action: :index
63
63
  end
64
64
 
@@ -24,25 +24,25 @@ class Occams::Admin::Cms::SnippetsController < Occams::Admin::Cms::BaseControlle
24
24
 
25
25
  def create
26
26
  @snippet.save!
27
- flash[:success] = I18n.t("occams.admin.cms.snippets.created")
27
+ flash[:success] = I18n.t('occams.admin.cms.snippets.created')
28
28
  redirect_to action: :edit, id: @snippet
29
29
  rescue ActiveRecord::RecordInvalid
30
- flash.now[:danger] = I18n.t("occams.admin.cms.snippets.creation_failure")
30
+ flash.now[:danger] = I18n.t('occams.admin.cms.snippets.creation_failure')
31
31
  render action: :new
32
32
  end
33
33
 
34
34
  def update
35
35
  @snippet.update!(snippet_params)
36
- flash[:success] = I18n.t("occams.admin.cms.snippets.updated")
36
+ flash[:success] = I18n.t('occams.admin.cms.snippets.updated')
37
37
  redirect_to action: :edit, id: @snippet
38
38
  rescue ActiveRecord::RecordInvalid
39
- flash.now[:danger] = I18n.t("occams.admin.cms.snippets.update_failure")
39
+ flash.now[:danger] = I18n.t('occams.admin.cms.snippets.update_failure')
40
40
  render action: :edit
41
41
  end
42
42
 
43
43
  def destroy
44
44
  @snippet.destroy
45
- flash[:success] = I18n.t("occams.admin.cms.snippets.deleted")
45
+ flash[:success] = I18n.t('occams.admin.cms.snippets.deleted')
46
46
  redirect_to action: :index
47
47
  end
48
48
 
@@ -55,7 +55,7 @@ protected
55
55
  def load_snippet
56
56
  @snippet = @site.snippets.find(params[:id])
57
57
  rescue ActiveRecord::RecordNotFound
58
- flash[:danger] = I18n.t("occams.admin.cms.snippets.not_found")
58
+ flash[:danger] = I18n.t('occams.admin.cms.snippets.not_found')
59
59
  redirect_to action: :index
60
60
  end
61
61
 
@@ -19,25 +19,25 @@ class Occams::Admin::Cms::TranslationsController < Occams::Admin::Cms::BaseContr
19
19
 
20
20
  def create
21
21
  @translation.save!
22
- flash[:success] = I18n.t("occams.admin.cms.translations.created")
22
+ flash[:success] = I18n.t('occams.admin.cms.translations.created')
23
23
  redirect_to action: :edit, id: @translation
24
24
  rescue ActiveRecord::RecordInvalid
25
- flash.now[:danger] = I18n.t("occams.admin.cms.translations.creation_failure")
25
+ flash.now[:danger] = I18n.t('occams.admin.cms.translations.creation_failure')
26
26
  render action: :new
27
27
  end
28
28
 
29
29
  def update
30
30
  @translation.update!(translation_params)
31
- flash[:success] = I18n.t("occams.admin.cms.translations.updated")
31
+ flash[:success] = I18n.t('occams.admin.cms.translations.updated')
32
32
  redirect_to action: :edit, id: @translation
33
33
  rescue ActiveRecord::RecordInvalid
34
- flash.now[:danger] = I18n.t("occams.admin.cms.translations.update_failure")
34
+ flash.now[:danger] = I18n.t('occams.admin.cms.translations.update_failure')
35
35
  render action: :edit
36
36
  end
37
37
 
38
38
  def destroy
39
39
  @translation.destroy
40
- flash[:success] = I18n.t("occams.admin.cms.translations.deleted")
40
+ flash[:success] = I18n.t('occams.admin.cms.translations.deleted')
41
41
  redirect_to edit_occams_admin_cms_site_page_path(@site, @page)
42
42
  end
43
43
 
@@ -46,7 +46,7 @@ class Occams::Admin::Cms::TranslationsController < Occams::Admin::Cms::BaseContr
46
46
  @translation.layout = @site.layouts.find_by(id: params[:layout_id])
47
47
 
48
48
  render(
49
- partial: "occams/admin/cms/fragments/form_fragments",
49
+ partial: 'occams/admin/cms/fragments/form_fragments',
50
50
  locals: { record: @translation, scope: :translation },
51
51
  layout: false
52
52
  )
@@ -63,7 +63,7 @@ private
63
63
  def load_page
64
64
  @page = @site.pages.find(params[:page_id])
65
65
  rescue ActiveRecord::RecordNotFound
66
- flash[:danger] = I18n.t("occams.admin.cms.pages.not_found")
66
+ flash[:danger] = I18n.t('occams.admin.cms.pages.not_found')
67
67
  redirect_to occams_admin_cms_site_pages_path(@site)
68
68
  end
69
69
 
@@ -76,7 +76,7 @@ private
76
76
  @translation = @page.translations.find(params[:id])
77
77
  @translation.attributes = translation_params
78
78
  rescue ActiveRecord::RecordNotFound
79
- flash[:danger] = I18n.t("occams.admin.cms.translations.not_found")
79
+ flash[:danger] = I18n.t('occams.admin.cms.translations.not_found')
80
80
  redirect_to edit_occams_admin_cms_site_page_path(@site, @page)
81
81
  end
82
82
 
@@ -85,21 +85,21 @@ private
85
85
  end
86
86
 
87
87
  def preview_translation
88
- if params[:preview]
89
- layout = @translation.layout.app_layout.blank? ? false : @translation.layout.app_layout
90
- @cms_site = @page.site
91
- @cms_layout = @translation.layout
92
- @cms_page = @page
93
-
94
- # Make sure to use the site locale to render the preview becaue it might
95
- # be different from the admin locale.
96
- I18n.locale = @translation.locale
97
-
98
- # Chrome chokes on content with iframes. Issue #434
99
- response.headers["X-XSS-Protection"] = "0"
100
-
101
- # raise
102
- render inline: @translation.render, layout: layout, content_type: "text/html"
103
- end
88
+ return unless params[:preview]
89
+
90
+ layout = @translation.layout.app_layout.blank? ? false : @translation.layout.app_layout
91
+ @cms_site = @page.site
92
+ @cms_layout = @translation.layout
93
+ @cms_page = @page
94
+
95
+ # Make sure to use the site locale to render the preview becaue it might
96
+ # be different from the admin locale.
97
+ I18n.locale = @translation.locale
98
+
99
+ # Chrome chokes on content with iframes. Issue #434
100
+ response.headers['X-XSS-Protection'] = '0'
101
+
102
+ # raise
103
+ render inline: @translation.render, layout: layout, content_type: 'text/html'
104
104
  end
105
105
  end
@@ -9,11 +9,11 @@ class Occams::Cms::AssetsController < Occams::Cms::BaseController
9
9
  after_action :set_cache_control_header
10
10
 
11
11
  def render_css
12
- render body: @cms_layout.css, content_type: "text/css"
12
+ render body: @cms_layout.css, content_type: 'text/css'
13
13
  end
14
14
 
15
15
  def render_js
16
- render body: @cms_layout.js, content_type: "application/javascript"
16
+ render body: @cms_layout.js, content_type: 'application/javascript'
17
17
  end
18
18
 
19
19
  protected
@@ -31,8 +31,8 @@ protected
31
31
  end
32
32
 
33
33
  def set_cache_control_header
34
- if params[:cache_buster].present?
35
- response.headers["Cache-Control"] = "public, max-age=#{1.year.to_i}"
36
- end
34
+ return unless params[:cache_buster].present?
35
+
36
+ response.headers['Cache-Control'] = "public, max-age=#{1.year.to_i}"
37
37
  end
38
38
  end
@@ -15,17 +15,12 @@ protected
15
15
  ::Occams::Cms::Site.find_site(request.host_with_port.downcase, request.fullpath)
16
16
  end
17
17
 
18
- if @cms_site
19
- if @cms_site.path.present? && !params[:site_id]
20
- if params[:cms_path]&.match(%r{\A#{@cms_site.path}})
21
- params[:cms_path].gsub!(%r{\A#{@cms_site.path}}, "")
22
- params[:cms_path]&.gsub!(%r{\A/}, "")
23
- else
24
- raise ActionController::RoutingError, "Site Not Found"
25
- end
26
- end
27
- else
28
- raise ActionController::RoutingError, "Site Not Found"
29
- end
18
+ raise ActionController::RoutingError, 'Site Not Found' unless @cms_site
19
+
20
+ return unless @cms_site.path.present? && !params[:site_id]
21
+ raise ActionController::RoutingError, 'Site Not Found' unless params[:cms_path]&.match(%r{\A#{@cms_site.path}})
22
+
23
+ params[:cms_path].gsub!(%r{\A#{@cms_site.path}}, '')
24
+ params[:cms_path]&.gsub!(%r{\A/}, '')
30
25
  end
31
26
  end
@@ -42,8 +42,8 @@ protected
42
42
 
43
43
  # it's possible to control mimetype of a page by creating a `mime_type` field
44
44
  def mime_type
45
- mime_block = @cms_page.fragments.detect { |f| f.identifier == "mime_type" }
46
- mime_block&.content&.strip || "text/html"
45
+ mime_block = @cms_page.fragments.detect { |f| f.identifier == 'mime_type' }
46
+ mime_block&.content&.strip || 'text/html'
47
47
  end
48
48
 
49
49
  def app_layout
@@ -61,20 +61,24 @@ protected
61
61
  # Attempting to populate @cms_page and @cms_layout instance variables so they
62
62
  # can be used in view helpers/partials
63
63
  def load_cms_page
64
- unless find_cms_page_by_full_path("/#{params[:cms_path]}")
65
- if find_cms_page_by_full_path("/404")
66
- render_page(:not_found)
67
- else
68
- message = "Page Not Found at: \"#{params[:cms_path]}\""
69
- raise ActionController::RoutingError, message
70
- end
64
+ return if find_cms_page_by_full_path("/#{params[:cms_path]}")
65
+
66
+ if find_cms_page_by_full_path('/404')
67
+ render_page(:not_found)
68
+ else
69
+ message = "Page Not Found at: \"#{params[:cms_path]}\""
70
+ raise ActionController::RoutingError, message
71
71
  end
72
72
  end
73
73
 
74
74
  # Getting page and setting content_cache and fragments data if we need to
75
75
  # serve translation data
76
76
  def find_cms_page_by_full_path(full_path)
77
- @cms_page = @cms_site.pages.published.find_by!(full_path: full_path)
77
+ @cms_page = if Rails.env == 'production'
78
+ @cms_site.pages.published.find_by!(full_path: full_path)
79
+ else
80
+ @cms_site.pages.find_by!(full_path: full_path)
81
+ end
78
82
 
79
83
  @cms_page.translate!
80
84
  @cms_layout = @cms_page.layout
@@ -15,7 +15,7 @@ module Occams
15
15
  render path, params
16
16
  rescue ActionView::MissingTemplate
17
17
  if Occams.config.reveal_cms_partials
18
- content_tag(:div, class: "occams-admin-partial") do
18
+ content_tag(:div, class: 'occams-admin-partial') do
19
19
  path
20
20
  end
21
21
  end
@@ -32,14 +32,14 @@ module Occams
32
32
  # @return [String] {{ cms:page_file_link #{fragment_id}, ... }}
33
33
  def cms_page_file_link_tag(fragment_id:, attachment:, multiple:)
34
34
  filename = ", filename: \"#{attachment.filename}\"" if multiple
35
- as = ", as: image" if attachment.image?
35
+ as = ', as: image' if attachment.image?
36
36
  "{{ cms:page_file_link #{fragment_id}#{filename}#{as} }}"
37
37
  end
38
38
 
39
39
  # @param [Occams::Cms::File] file
40
40
  # @return [String] {{ cms:file_link #{file.id}, ... }}
41
41
  def cms_file_link_tag(file)
42
- as = ", as: image" if file.attachment.image?
42
+ as = ', as: image' if file.attachment.image?
43
43
  "{{ cms:file_link #{file.id}#{as} }}"
44
44
  end
45
45
  end
@@ -9,14 +9,14 @@ module Occams
9
9
  # cms_fragment_content(:left_column) # if @cms_page is present
10
10
  def cms_fragment_content(identifier, page = @cms_page)
11
11
  frag = page&.fragments&.detect { |f| f.identifier == identifier.to_s }
12
- return "" unless frag
12
+ return '' unless frag
13
13
 
14
14
  case frag.tag
15
- when "date", "datetime"
15
+ when 'date', 'datetime'
16
16
  frag.datetime
17
- when "checkbox"
17
+ when 'checkbox'
18
18
  frag.boolean
19
- when "file", "files"
19
+ when 'file', 'files'
20
20
  frag.attachments
21
21
  else
22
22
  frag.content
@@ -28,7 +28,7 @@ module Occams
28
28
  # text because this is a potentially expensive call.
29
29
  def cms_fragment_render(identifier, page = @cms_page)
30
30
  node = page.fragment_nodes.detect { |n| n.identifier == identifier.to_s }
31
- return "" unless node
31
+ return '' unless node
32
32
 
33
33
  node.renderable = true
34
34
  render inline: page.render([node])
@@ -40,7 +40,7 @@ module Occams
40
40
  def cms_snippet_content(identifier, cms_site = @cms_site)
41
41
  cms_site ||= cms_site_detect
42
42
  snippet = cms_site&.snippets&.find_by_identifier(identifier)
43
- return "" unless snippet
43
+ return '' unless snippet
44
44
 
45
45
  snippet.content
46
46
  end
@@ -50,7 +50,7 @@ module Occams
50
50
  def cms_snippet_render(identifier, cms_site = @cms_site)
51
51
  cms_site ||= cms_site_detect
52
52
  snippet = cms_site&.snippets&.find_by_identifier(identifier)
53
- return "" unless snippet
53
+ return '' unless snippet
54
54
 
55
55
  r = Occams::Content::Renderer.new(snippet)
56
56
  render inline: r.render(r.nodes(r.tokenize(snippet.content)))
@@ -69,7 +69,7 @@ module Occams
69
69
  if defined?(WillPaginate)
70
70
  will_paginate collection
71
71
  elsif defined?(Kaminari)
72
- paginate collection, theme: "occams"
72
+ paginate collection, theme: 'occams'
73
73
  end
74
74
  end
75
75
  end
@@ -6,11 +6,11 @@ module Occams::Cms::WithCategories
6
6
  included do
7
7
  has_many :categorizations,
8
8
  as: :categorized,
9
- class_name: "Occams::Cms::Categorization",
9
+ class_name: 'Occams::Cms::Categorization',
10
10
  dependent: :destroy
11
11
  has_many :categories,
12
12
  through: :categorizations,
13
- class_name: "Occams::Cms::Category"
13
+ class_name: 'Occams::Cms::Category'
14
14
 
15
15
  attr_writer :category_ids
16
16
 
@@ -20,7 +20,7 @@ module Occams::Cms::WithCategories
20
20
  if (categories = [categories].flatten.compact).present?
21
21
  distinct
22
22
  .joins(categorizations: :category)
23
- .where("occams_cms_categories.label" => categories)
23
+ .where('occams_cms_categories.label' => categories)
24
24
  end
25
25
  }
26
26
  end
@@ -7,10 +7,10 @@ module Occams::Cms::WithFragments
7
7
  attr_accessor :fragments_attributes_changed
8
8
 
9
9
  belongs_to :layout,
10
- class_name: "Occams::Cms::Layout"
10
+ class_name: 'Occams::Cms::Layout'
11
11
 
12
12
  has_many :fragments,
13
- class_name: "Occams::Cms::Fragment",
13
+ class_name: 'Occams::Cms::Fragment',
14
14
  as: :record,
15
15
  autosave: true,
16
16
  dependent: :destroy
@@ -53,7 +53,7 @@ module Occams::Cms::WithFragments
53
53
  end
54
54
 
55
55
  # Snapshop of page fragments data used primarily for saving revisions
56
- def fragments_attributes(was: false)
56
+ def fragments_attributes(was = false)
57
57
  fragments.collect do |frag|
58
58
  attrs = {}
59
59
  %i[identifier tag content datetime boolean].each do |column|
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Categorization < ActiveRecord::Base
4
- self.table_name = "occams_cms_categorizations"
4
+ self.table_name = 'occams_cms_categorizations'
5
5
 
6
6
  # -- Relationships -----------------------------------------------------------
7
7
  belongs_to :category
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Category < ActiveRecord::Base
4
- self.table_name = "occams_cms_categories"
4
+ self.table_name = 'occams_cms_categories'
5
5
 
6
6
  # -- Relationships --------------------------------------------------------
7
7
  belongs_to :site
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::File < ActiveRecord::Base
4
- self.table_name = "occams_cms_files"
4
+ self.table_name = 'occams_cms_files'
5
5
 
6
6
  include Occams::Cms::WithCategories
7
7
 
8
8
  VARIANT_SIZE = {
9
- redactor: { resize: "100x75^", gravity: "center", crop: "100x75+0+0" },
10
- thumb: { resize: "200x150^", gravity: "center", crop: "200x150+0+0" },
11
- icon: { resize: "28x28^", gravity: "center", crop: "28x28+0+0" }
9
+ redactor: { resize: '100x75^', gravity: 'center', crop: '100x75+0+0' },
10
+ thumb: { resize: '200x150^', gravity: 'center', crop: '200x150+0+0' },
11
+ icon: { resize: '28x28^', gravity: 'center', crop: '28x28+0+0' }
12
12
  }.freeze
13
13
 
14
14
  # temporary place to store attachment
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Fragment < ActiveRecord::Base
4
- self.table_name = "occams_cms_fragments"
4
+ self.table_name = 'occams_cms_fragments'
5
5
 
6
6
  has_many_attached :attachments
7
7
 
@@ -52,7 +52,7 @@ protected
52
52
  return if @files.blank?
53
53
 
54
54
  # If we're dealing with a single file
55
- if tag == "file"
55
+ if tag == 'file'
56
56
  @files = [@files.first]
57
57
  attachments&.purge_later
58
58
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Layout < ActiveRecord::Base
4
- self.table_name = "occams_cms_layouts"
4
+ self.table_name = 'occams_cms_layouts'
5
5
 
6
6
  cms_acts_as_tree
7
7
  cms_has_revisions_for :content, :css, :js
@@ -52,8 +52,8 @@ class Occams::Cms::Layout < ActiveRecord::Base
52
52
  def self.app_layouts_for_select(view_paths)
53
53
  view_paths.map(&:to_s).select { |path| path.start_with?(Rails.root.to_s) }.flat_map do |full_path|
54
54
  Dir.glob("#{full_path}/layouts/**/*.html.*").collect do |filename|
55
- filename.gsub!("#{full_path}/layouts/", "")
56
- filename.split("/").last[0...1] == "_" ? nil : filename.split(".").first
55
+ filename.gsub!("#{full_path}/layouts/", '')
56
+ filename.split('/').last[0...1] == '_' ? nil : filename.split('.').first
57
57
  end.compact.sort
58
58
  end.compact.uniq.sort
59
59
  end
@@ -74,8 +74,8 @@ class Occams::Cms::Layout < ActiveRecord::Base
74
74
  parent_tokens = parent.content_tokens
75
75
  replacement_position = parent_tokens.index do |n|
76
76
  n.is_a?(Hash) &&
77
- fragment_tags.member?(n[:tag_class]) &&
78
- n[:tag_params].split(%r{\s}).first == "content"
77
+ fragment_tags.member?(n[:tag_class]) &&
78
+ n[:tag_params].split(%r{\s}).first == 'content'
79
79
  end
80
80
 
81
81
  if replacement_position
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Page < ActiveRecord::Base
4
- self.table_name = "occams_cms_pages"
4
+ self.table_name = 'occams_cms_pages'
5
5
 
6
6
  include Occams::Cms::WithFragments
7
7
  include Occams::Cms::WithCategories
@@ -14,7 +14,7 @@ class Occams::Cms::Page < ActiveRecord::Base
14
14
  # -- Relationships -----------------------------------------------------------
15
15
  belongs_to :site
16
16
  belongs_to :target_page,
17
- class_name: "Occams::Cms::Page",
17
+ class_name: 'Occams::Cms::Page',
18
18
  optional: true
19
19
 
20
20
  has_many :translations,
@@ -74,7 +74,7 @@ class Occams::Cms::Page < ActiveRecord::Base
74
74
 
75
75
  # Somewhat unique method of identifying a page that is not a full_path
76
76
  def identifier
77
- parent_id.blank? ? "index" : full_path[1..].parameterize
77
+ parent_id.blank? ? 'index' : full_path[1..].parameterize
78
78
  end
79
79
 
80
80
  # Full url for a page
@@ -119,9 +119,9 @@ protected
119
119
  def assign_full_path
120
120
  self.full_path =
121
121
  if self.parent
122
- [CGI.escape(self.parent.full_path).gsub("%2F", "/"), slug].join("/").squeeze("/")
122
+ [CGI.escape(self.parent.full_path).gsub('%2F', '/'), slug].join('/').squeeze('/')
123
123
  else
124
- "/"
124
+ '/'
125
125
  end
126
126
  end
127
127
 
@@ -139,7 +139,7 @@ protected
139
139
  p = self
140
140
  while p.target_page
141
141
  if (p = p.target_page) == self
142
- return errors.add(:target_page_id, "Invalid Redirect")
142
+ return errors.add(:target_page_id, 'Invalid Redirect')
143
143
  end
144
144
  end
145
145
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Revision < ActiveRecord::Base
4
- self.table_name = "occams_cms_revisions"
4
+ self.table_name = 'occams_cms_revisions'
5
5
 
6
6
  serialize :data
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Site < ActiveRecord::Base
4
- self.table_name = "occams_cms_sites"
4
+ self.table_name = 'occams_cms_sites'
5
5
 
6
6
  # -- Relationships -----------------------------------------------------------
7
7
  with_options dependent: :destroy do |site|
@@ -38,8 +38,8 @@ class Occams::Cms::Site < ActiveRecord::Base
38
38
  cms_site = nil
39
39
 
40
40
  public_cms_path = Occams.configuration.public_cms_path
41
- if path && public_cms_path != "/"
42
- path = path.sub(%r{\A#{public_cms_path}}, "")
41
+ if path && public_cms_path != '/'
42
+ path = path.sub(%r{\A#{public_cms_path}}, '')
43
43
  end
44
44
 
45
45
  Occams::Cms::Site.where(hostname: real_host_from_aliases(host)).each do |site|
@@ -64,9 +64,9 @@ class Occams::Cms::Site < ActiveRecord::Base
64
64
 
65
65
  # -- Instance Methods --------------------------------------------------------
66
66
  def url(relative: false)
67
- public_cms_path = Occams.config.public_cms_path || "/"
67
+ public_cms_path = Occams.config.public_cms_path || '/'
68
68
  host = "//#{hostname}"
69
- path = ["/", public_cms_path, self.path].compact.join("/").squeeze("/").chomp("/")
69
+ path = ['/', public_cms_path, self.path].compact.join('/').squeeze('/').chomp('/')
70
70
  relative ? path.presence : [host, path].join
71
71
  end
72
72
 
@@ -85,9 +85,9 @@ protected
85
85
  end
86
86
 
87
87
  def clean_path
88
- self.path ||= ""
89
- self.path.squeeze!("/")
90
- self.path.gsub!(%r{/$}, "")
88
+ self.path ||= ''
89
+ self.path.squeeze!('/')
90
+ self.path.gsub!(%r{/$}, '')
91
91
  self.path = nil if self.path.blank?
92
92
  end
93
93
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Snippet < ActiveRecord::Base
4
- self.table_name = "occams_cms_snippets"
4
+ self.table_name = 'occams_cms_snippets'
5
5
 
6
6
  include Occams::Cms::WithCategories
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Occams::Cms::Translation < ActiveRecord::Base
4
- self.table_name = "occams_cms_translations"
4
+ self.table_name = 'occams_cms_translations'
5
5
 
6
6
  include Occams::Cms::WithFragments
7
7
 
@@ -41,3 +41,6 @@
41
41
  %span.version= Rails::version
42
42
  = link_to 'Ruby', 'https://www.ruby-lang.org', target: '_blank'
43
43
  %span.version= RUBY_VERSION
44
+ %br
45
+ = Rails.env.upcase
46
+