occams 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +23 -40
  3. data/CHANGELOG.md +8 -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 +1 -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/checkbox.rb +4 -4
  59. data/lib/occams/content/tags/date.rb +2 -2
  60. data/lib/occams/content/tags/datetime.rb +4 -4
  61. data/lib/occams/content/tags/file.rb +8 -8
  62. data/lib/occams/content/tags/file_link.rb +8 -8
  63. data/lib/occams/content/tags/files.rb +5 -5
  64. data/lib/occams/content/tags/fragment.rb +4 -4
  65. data/lib/occams/content/tags/helper.rb +6 -6
  66. data/lib/occams/content/tags/markdown.rb +2 -2
  67. data/lib/occams/content/tags/mixins/file_content.rb +3 -3
  68. data/lib/occams/content/tags/number.rb +1 -1
  69. data/lib/occams/content/tags/page_file_link.rb +8 -8
  70. data/lib/occams/content/tags/partial.rb +5 -5
  71. data/lib/occams/content/tags/snippet.rb +3 -3
  72. data/lib/occams/content/tags/template.rb +5 -5
  73. data/lib/occams/content/tags/text.rb +1 -1
  74. data/lib/occams/content/tags/textarea.rb +1 -1
  75. data/lib/occams/content/tags/wysiwyg.rb +1 -1
  76. data/lib/occams/content.rb +22 -22
  77. data/lib/occams/engine.rb +10 -10
  78. data/lib/occams/extensions/acts_as_tree.rb +1 -1
  79. data/lib/occams/extensions/has_revisions.rb +3 -3
  80. data/lib/occams/form_builder.rb +4 -4
  81. data/lib/occams/render_methods.rb +2 -2
  82. data/lib/occams/routes/cms.rb +3 -3
  83. data/lib/occams/routes/cms_admin.rb +6 -6
  84. data/lib/occams/routing.rb +2 -2
  85. data/lib/occams/seeds/file/exporter.rb +7 -11
  86. data/lib/occams/seeds/file/importer.rb +5 -5
  87. data/lib/occams/seeds/layout/exporter.rb +9 -9
  88. data/lib/occams/seeds/layout/importer.rb +9 -9
  89. data/lib/occams/seeds/page/exporter.rb +19 -21
  90. data/lib/occams/seeds/page/importer.rb +14 -14
  91. data/lib/occams/seeds/snippet/exporter.rb +6 -6
  92. data/lib/occams/seeds/snippet/importer.rb +6 -6
  93. data/lib/occams/seeds.rb +5 -5
  94. data/lib/occams/version.rb +1 -1
  95. data/lib/occams/view_hooks.rb +1 -1
  96. data/lib/occams.rb +24 -24
  97. data/lib/tasks/cms_seeds.rake +2 -2
  98. data/occams.gemspec +22 -21
  99. metadata +5 -4
  100. data/LICENSE.comfy +0 -20
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "./mixins/file_content"
3
+ require_relative 'mixins/file_content'
4
4
 
5
5
  # This is how you link previously uploaded file to anywhere. Good example may be
6
6
  # a header image you want to use on the layout level.
@@ -30,13 +30,13 @@ class Occams::Content::Tag::FileLink < Occams::Content::Tag
30
30
 
31
31
  options = params.extract_options!
32
32
  @identifier = params[0]
33
- @as = options["as"] || "url"
34
- @class = options["class"]
35
- @variant_attrs = options.slice("resize", "gravity", "crop")
33
+ @as = options['as'] || 'url'
34
+ @class = options['class']
35
+ @variant_attrs = options.slice('resize', 'gravity', 'crop')
36
36
 
37
- unless @identifier.present?
38
- raise Error, "Missing identifier for file link tag"
39
- end
37
+ return if @identifier.present?
38
+
39
+ raise Error, 'Missing identifier for file link tag'
40
40
  end
41
41
 
42
42
  # @return [Occams::Cms::File]
@@ -51,7 +51,7 @@ class Occams::Content::Tag::FileLink < Occams::Content::Tag
51
51
 
52
52
  # @return [String]
53
53
  def label
54
- return "" if file_record.nil?
54
+ return '' if file_record.nil?
55
55
 
56
56
  file_record.label.presence || file.filename.to_s
57
57
  end
@@ -7,21 +7,21 @@
7
7
  #
8
8
  class Occams::Content::Tag::Files < Occams::Content::Tag::File
9
9
  def content
10
- return "" if fragment.attachments.blank?
10
+ return '' if fragment.attachments.blank?
11
11
 
12
12
  fragment.attachments.collect do |attachment|
13
13
  super(file: attachment, label: attachment.filename)
14
- end.join(" ")
14
+ end.join(' ')
15
15
  end
16
16
 
17
17
  def form_field(object_name, view, index)
18
18
  name = "#{object_name}[fragments_attributes][#{index}][files][]"
19
- input = view.send(:file_field_tag, name, id: form_field_id, multiple: true, class: "form-control")
19
+ input = view.send(:file_field_tag, name, id: form_field_id, multiple: true, class: 'form-control')
20
20
 
21
21
  attachments_partial =
22
22
  if fragment.attachments
23
23
  view.render(
24
- partial: "occams/admin/cms/fragments/form_fragment_attachments",
24
+ partial: 'occams/admin/cms/fragments/form_fragment_attachments',
25
25
  locals: {
26
26
  object_name: object_name,
27
27
  index: index,
@@ -32,7 +32,7 @@ class Occams::Content::Tag::Files < Occams::Content::Tag::File
32
32
  )
33
33
  end
34
34
 
35
- yield view.safe_join([input, attachments_partial], "")
35
+ yield view.safe_join([input, attachments_partial], '')
36
36
  end
37
37
  end
38
38
 
@@ -25,8 +25,8 @@ class Occams::Content::Tag::Fragment < Occams::Content::Tag
25
25
  raise Error, "Missing identifier for fragment tag: #{source}"
26
26
  end
27
27
 
28
- @namespace = @options["namespace"] || "default"
29
- @renderable = @options["render"].to_s.downcase != "false"
28
+ @namespace = @options['namespace'] || 'default'
29
+ @renderable = @options['render'].to_s.downcase != 'false'
30
30
  end
31
31
 
32
32
  # Grabs existing fragment record or spins up a new instance if there's none
@@ -43,7 +43,7 @@ class Occams::Content::Tag::Fragment < Occams::Content::Tag
43
43
  # If `render: false` was passed in we won't render anything. Assuming that
44
44
  # that fragment content will be rendered manually
45
45
  def render
46
- renderable ? content : ""
46
+ renderable ? content : ''
47
47
  end
48
48
 
49
49
  # Tag renders its own form inputs via `form_field(template, index)`
@@ -55,7 +55,7 @@ class Occams::Content::Tag::Fragment < Occams::Content::Tag
55
55
  # end
56
56
  # end
57
57
  def form_field
58
- raise "Form field rendering not implemented for this Tag"
58
+ raise 'Form field rendering not implemented for this Tag'
59
59
  end
60
60
 
61
61
  def form_field_id
@@ -16,9 +16,9 @@ class Occams::Content::Tag::Helper < Occams::Content::Tag
16
16
  super
17
17
  @method_name = params.shift
18
18
 
19
- unless @method_name.present?
20
- raise Error, "Missing method name for helper tag"
21
- end
19
+ return if @method_name.present?
20
+
21
+ raise Error, 'Missing method name for helper tag'
22
22
  end
23
23
 
24
24
  # we output erb into rest of the content
@@ -30,11 +30,11 @@ class Occams::Content::Tag::Helper < Occams::Content::Tag
30
30
  helper_params = params.map do |p|
31
31
  case p
32
32
  when Hash
33
- format("%<arg>s", arg: p)
33
+ format('%<arg>s', arg: p)
34
34
  else
35
- format("%<arg>p", arg: p)
35
+ format('%<arg>p', arg: p)
36
36
  end
37
- end.join(",")
37
+ end.join(',')
38
38
  "<%= #{method_name}(#{helper_params}) %>"
39
39
  end
40
40
 
@@ -5,12 +5,12 @@
5
5
  #
6
6
  class Occams::Content::Tag::Markdown < Occams::Content::Tag::Fragment
7
7
  def render
8
- renderable ? Kramdown::Document.new(content.to_s).to_html : ""
8
+ renderable ? Kramdown::Document.new(content.to_s).to_html : ''
9
9
  end
10
10
 
11
11
  def form_field(object_name, view, index)
12
12
  name = "#{object_name}[fragments_attributes][#{index}][content]"
13
- options = { id: form_field_id, data: { "cms-cm-mode" => "text/x-markdown" } }
13
+ options = { id: form_field_id, data: { 'cms-cm-mode' => 'text/x-markdown' } }
14
14
  input = view.send(:text_area_tag, name, content, options)
15
15
 
16
16
  yield input
@@ -9,7 +9,7 @@ module Occams::Content::Tag::Mixins
9
9
  # @param [String] label alt text for `as: "image"`, link text for `as: "link"`
10
10
  # @return [String]
11
11
  def content(file: self.file, as: self.as, variant_attrs: self.variant_attrs, label: self.label)
12
- return "" unless file
12
+ return '' unless file
13
13
 
14
14
  url_helpers = Rails.application.routes.url_helpers
15
15
 
@@ -22,9 +22,9 @@ module Occams::Content::Tag::Mixins
22
22
  end
23
23
 
24
24
  case as
25
- when "link"
25
+ when 'link'
26
26
  "<a href='#{attachment_url}'#{html_class_attribute} target='_blank'>#{label}</a>"
27
- when "image"
27
+ when 'image'
28
28
  "<img src='#{attachment_url}'#{html_class_attribute} alt='#{label}'/>"
29
29
  else
30
30
  attachment_url
@@ -6,7 +6,7 @@
6
6
  class Occams::Content::Tag::Number < Occams::Content::Tag::Fragment
7
7
  def form_field(object_name, view, index)
8
8
  name = "#{object_name}[fragments_attributes][#{index}][content]"
9
- options = { id: form_field_id, class: "form-control" }
9
+ options = { id: form_field_id, class: 'form-control' }
10
10
  input = view.send(:number_field_tag, name, content, options)
11
11
 
12
12
  yield input
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "./mixins/file_content"
3
+ require_relative 'mixins/file_content'
4
4
 
5
5
  # This tag allows you to link page-level files from within the page content.
6
6
  #
@@ -43,14 +43,14 @@ class Occams::Content::Tag::PageFileLink < Occams::Content::Tag
43
43
 
44
44
  options = params.extract_options!
45
45
  @identifier = params[0]
46
- @as = options["as"] || "url"
47
- @class = options["class"]
48
- @variant_attrs = options.slice("resize", "gravity", "crop")
49
- @filename = options["filename"]
46
+ @as = options['as'] || 'url'
47
+ @class = options['class']
48
+ @variant_attrs = options.slice('resize', 'gravity', 'crop')
49
+ @filename = options['filename']
50
50
 
51
- unless @identifier.present?
52
- raise Error, "Missing identifier for page file link tag"
53
- end
51
+ return if @identifier.present?
52
+
53
+ raise Error, 'Missing identifier for page file link tag'
54
54
  end
55
55
 
56
56
  # @return [Occams::Cms::Fragment]
@@ -14,9 +14,9 @@ class Occams::Content::Tag::Partial < Occams::Content::Tag
14
14
  @locals = params.extract_options!
15
15
  @path = params[0]
16
16
 
17
- unless @path.present?
18
- raise Error, "Missing path for partial tag"
19
- end
17
+ return if @path.present?
18
+
19
+ raise Error, 'Missing path for partial tag'
20
20
  end
21
21
 
22
22
  # we output erb into rest of the content
@@ -26,7 +26,7 @@ class Occams::Content::Tag::Partial < Occams::Content::Tag
26
26
 
27
27
  def content
28
28
  format(
29
- "<%%= render partial: %<path>p, locals: %<locals>s %%>",
29
+ '<%%= render partial: %<path>p, locals: %<locals>s %%>',
30
30
  path: @path,
31
31
  locals: @locals
32
32
  )
@@ -35,7 +35,7 @@ class Occams::Content::Tag::Partial < Occams::Content::Tag
35
35
  def render
36
36
  whitelist = Occams.config.allowed_partials
37
37
  if whitelist.is_a?(Array)
38
- whitelist.member?(@path) ? content : ""
38
+ whitelist.member?(@path) ? content : ''
39
39
  else
40
40
  content
41
41
  end
@@ -11,9 +11,9 @@ class Occams::Content::Tag::Snippet < Occams::Content::Tag
11
11
  super
12
12
  @identifier = params[0]
13
13
 
14
- unless @identifier.present?
15
- raise Error, "Missing identifier for snippet tag"
16
- end
14
+ return if @identifier.present?
15
+
16
+ raise Error, 'Missing identifier for snippet tag'
17
17
  end
18
18
 
19
19
  def content
@@ -13,9 +13,9 @@ class Occams::Content::Tag::Template < Occams::Content::Tag
13
13
  super
14
14
  @path = params[0]
15
15
 
16
- unless @path.present?
17
- raise Error, "Missing template path for template tag"
18
- end
16
+ return if @path.present?
17
+
18
+ raise Error, 'Missing template path for template tag'
19
19
  end
20
20
 
21
21
  # we output erb into rest of the content
@@ -24,13 +24,13 @@ class Occams::Content::Tag::Template < Occams::Content::Tag
24
24
  end
25
25
 
26
26
  def content
27
- format("<%%= render template: %<path>p %%>", path: path)
27
+ format('<%%= render template: %<path>p %%>', path: path)
28
28
  end
29
29
 
30
30
  def render
31
31
  whitelist = Occams.config.allowed_templates
32
32
  if whitelist.is_a?(Array)
33
- whitelist.member?(@path) ? content : ""
33
+ whitelist.member?(@path) ? content : ''
34
34
  else
35
35
  content
36
36
  end
@@ -6,7 +6,7 @@
6
6
  class Occams::Content::Tag::Text < Occams::Content::Tag::Fragment
7
7
  def form_field(object_name, view, index)
8
8
  name = "#{object_name}[fragments_attributes][#{index}][content]"
9
- options = { id: form_field_id, class: "form-control" }
9
+ options = { id: form_field_id, class: 'form-control' }
10
10
  input = view.send(:text_field_tag, name, content, options)
11
11
 
12
12
  yield input
@@ -6,7 +6,7 @@
6
6
  class Occams::Content::Tag::TextArea < Occams::Content::Tag::Fragment
7
7
  def form_field(object_name, view, index)
8
8
  name = "#{object_name}[fragments_attributes][#{index}][content]"
9
- options = { id: form_field_id, data: { "cms-cm-mode" => "text/html" } }
9
+ options = { id: form_field_id, data: { 'cms-cm-mode' => 'text/html' } }
10
10
  input = view.send(:text_area_tag, name, content, options)
11
11
 
12
12
  yield input
@@ -8,7 +8,7 @@
8
8
  class Occams::Content::Tag::Wysiwyg < Occams::Content::Tag::Fragment
9
9
  def form_field(object_name, view, index)
10
10
  name = "#{object_name}[fragments_attributes][#{index}][content]"
11
- options = { id: form_field_id, data: { "cms-rich-text" => true } }
11
+ options = { id: form_field_id, data: { 'cms-rich-text' => true } }
12
12
  input = view.send(:text_area_tag, name, content, options)
13
13
  yield input
14
14
  end
@@ -4,28 +4,28 @@ module Occams::Content
4
4
  # ...
5
5
  end
6
6
 
7
- require_relative "content/renderer"
8
- require_relative "content/params_parser"
9
- require_relative "content/tag"
10
- require_relative "content/block"
7
+ require_relative 'content/renderer'
8
+ require_relative 'content/params_parser'
9
+ require_relative 'content/tag'
10
+ require_relative 'content/block'
11
11
 
12
- require_relative "content/tags/fragment"
12
+ require_relative 'content/tags/fragment'
13
13
 
14
- require_relative "content/tags/wysiwyg"
15
- require_relative "content/tags/text"
16
- require_relative "content/tags/textarea"
17
- require_relative "content/tags/markdown"
18
- require_relative "content/tags/datetime"
19
- require_relative "content/tags/date"
20
- require_relative "content/tags/number"
21
- require_relative "content/tags/checkbox"
22
- require_relative "content/tags/file"
23
- require_relative "content/tags/files"
14
+ require_relative 'content/tags/wysiwyg'
15
+ require_relative 'content/tags/text'
16
+ require_relative 'content/tags/textarea'
17
+ require_relative 'content/tags/markdown'
18
+ require_relative 'content/tags/datetime'
19
+ require_relative 'content/tags/date'
20
+ require_relative 'content/tags/number'
21
+ require_relative 'content/tags/checkbox'
22
+ require_relative 'content/tags/file'
23
+ require_relative 'content/tags/files'
24
24
 
25
- require_relative "content/tags/snippet"
26
- require_relative "content/tags/asset"
27
- require_relative "content/tags/file_link"
28
- require_relative "content/tags/page_file_link"
29
- require_relative "content/tags/helper"
30
- require_relative "content/tags/partial"
31
- require_relative "content/tags/template"
25
+ require_relative 'content/tags/snippet'
26
+ require_relative 'content/tags/asset'
27
+ require_relative 'content/tags/file_link'
28
+ require_relative 'content/tags/page_file_link'
29
+ require_relative 'content/tags/helper'
30
+ require_relative 'content/tags/partial'
31
+ require_relative 'content/tags/template'
data/lib/occams/engine.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "occams"
4
- require "rails"
5
- require "rails-i18n"
6
- require "comfy_bootstrap_form"
7
- require "active_link_to"
8
- require "kramdown"
9
- require "jquery-rails"
10
- require "haml-rails"
11
- require "sassc-rails"
3
+ require 'occams'
4
+ require 'rails'
5
+ require 'rails-i18n'
6
+ require 'comfy_bootstrap_form'
7
+ require 'active_link_to'
8
+ require 'kramdown'
9
+ require 'jquery-rails'
10
+ require 'haml-rails'
11
+ require 'sassc-rails'
12
12
 
13
13
  module Occams
14
14
  class Engine < ::Rails::Engine
15
- initializer "occams.setup_assets" do
15
+ initializer 'occams.setup_assets' do
16
16
  ::Occams::Engine.config.assets.precompile += %w[
17
17
  occams/admin/cms/application.js
18
18
  occams/admin/cms/application.css
@@ -8,7 +8,7 @@ module Occams::ActsAsTree
8
8
  module ClassMethods
9
9
  def cms_acts_as_tree(options = {})
10
10
  configuration = {
11
- foreign_key: "parent_id",
11
+ foreign_key: 'parent_id',
12
12
  order: nil,
13
13
  counter_cache: nil,
14
14
  dependent: :destroy,
@@ -14,7 +14,7 @@ module Occams::HasRevisions
14
14
  has_many :revisions,
15
15
  as: :record,
16
16
  dependent: :destroy,
17
- class_name: "Occams::Cms::Revision"
17
+ class_name: 'Occams::Cms::Revision'
18
18
 
19
19
  before_save :prepare_revision
20
20
  after_save :create_revision
@@ -31,7 +31,7 @@ module Occams::HasRevisions
31
31
  return if new_record?
32
32
 
33
33
  if (respond_to?(:fragments_attributes_changed) && fragments_attributes_changed) ||
34
- !(changed & revision_fields).empty?
34
+ !(changed & revision_fields).empty?
35
35
  self.revision_data = revision_fields.each_with_object({}) do |field, c|
36
36
  c[field] = send("#{field}_was")
37
37
  end
@@ -51,7 +51,7 @@ module Occams::HasRevisions
51
51
 
52
52
  # blowing away old revisions
53
53
  ids = [0] + revisions.order(created_at: :desc).limit(limit).pluck(:id)
54
- revisions.where("id NOT IN (?)", ids).destroy_all
54
+ revisions.where('id NOT IN (?)', ids).destroy_all
55
55
  end
56
56
 
57
57
  # Assigning whatever is found in revision data and attempting to save the object
@@ -32,10 +32,10 @@ class Occams::FormBuilder < ComfyBootstrapForm::FormBuilder
32
32
  # = form.submit
33
33
  #
34
34
  def form_actions(&block)
35
- content_tag(:div, class: "form-actions row bg-light") do
36
- content_tag(:div, class: "col-lg-8 offset-lg-2") do
37
- content_tag(:div, class: "form-group row mb-0") do
38
- content_tag(:div, class: "col-sm-10 offset-sm-2", &block)
35
+ content_tag(:div, class: 'form-actions row bg-light') do
36
+ content_tag(:div, class: 'col-lg-8 offset-lg-2') do
37
+ content_tag(:div, class: 'form-group row mb-0') do
38
+ content_tag(:div, class: 'col-sm-10 offset-sm-2', &block)
39
39
  end
40
40
  end
41
41
  end
@@ -5,7 +5,7 @@ module Occams::RenderMethods
5
5
  # If application controller doesn't have template associated with it
6
6
  # CMS will attempt to find one. This is so you don't have to explicitly
7
7
  # call render cms_page: '/something'
8
- base.rescue_from "ActionView::MissingTemplate" do |e|
8
+ base.rescue_from 'ActionView::MissingTemplate' do |e|
9
9
  render cms_page: request.path
10
10
  rescue Occams::MissingPage, Occams::MissingSite
11
11
  raise e
@@ -56,7 +56,7 @@ module Occams::RenderMethods
56
56
  end
57
57
 
58
58
  def render_cms_page(path, options = {}, locals = {}, &block)
59
- path.gsub!(%r{^/#{@cms_site.path}}, "") if @cms_site.path.present?
59
+ path.gsub!(%r{^/#{@cms_site.path}}, '') if @cms_site.path.present?
60
60
 
61
61
  unless (@cms_page = @cms_site.pages.find_by_full_path(path))
62
62
  raise Occams::MissingPage, path
@@ -6,10 +6,10 @@ class ActionDispatch::Routing::Mapper
6
6
 
7
7
  scope module: :occams, as: :occams do
8
8
  namespace :cms, path: options[:path] do
9
- get "cms-css/:site_id/:identifier(/:cache_buster)" => "assets#render_css", as: "render_css"
10
- get "cms-js/:site_id/:identifier(/:cache_buster)" => "assets#render_js", as: "render_js"
9
+ get 'cms-css/:site_id/:identifier(/:cache_buster)' => 'assets#render_css', as: 'render_css'
10
+ get 'cms-js/:site_id/:identifier(/:cache_buster)' => 'assets#render_js', as: 'render_js'
11
11
 
12
- get "(*cms_path)" => "content#show", as: "render_page", action: "/:format"
12
+ get '(*cms_path)' => 'content#show', as: 'render_page', action: '/:format'
13
13
  end
14
14
  end
15
15
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ActionDispatch::Routing::Mapper
4
- def occams_route_cms_admin(path: "admin")
4
+ def occams_route_cms_admin(path: 'admin')
5
5
  scope module: :occams, as: :occams do
6
6
  scope module: :admin do
7
7
  namespace :cms, as: :admin_cms, path: path, except: :show do
8
- get "/", to: "base#jump"
8
+ get '/', to: 'base#jump'
9
9
 
10
10
  concern :with_revisions do |options|
11
11
  resources :revisions, options.merge(only: %i[index show]) do
@@ -25,13 +25,13 @@ class ActionDispatch::Routing::Mapper
25
25
  resources :pages do
26
26
  concerns :with_reorder
27
27
  concerns :with_form_fragments
28
- concerns :with_revisions, controller: "revisions/page"
28
+ concerns :with_revisions, controller: 'revisions/page'
29
29
 
30
30
  get :toggle_branch, on: :member
31
31
 
32
32
  resources :translations, except: [:index] do
33
33
  concerns :with_form_fragments
34
- concerns :with_revisions, controller: "revisions/translation"
34
+ concerns :with_revisions, controller: 'revisions/translation'
35
35
  end
36
36
  end
37
37
 
@@ -39,12 +39,12 @@ class ActionDispatch::Routing::Mapper
39
39
 
40
40
  resources :layouts do
41
41
  concerns :with_reorder
42
- concerns :with_revisions, controller: "revisions/layout"
42
+ concerns :with_revisions, controller: 'revisions/layout'
43
43
  end
44
44
 
45
45
  resources :snippets do
46
46
  concerns :with_reorder
47
- concerns :with_revisions, controller: "revisions/snippet"
47
+ concerns :with_revisions, controller: 'revisions/snippet'
48
48
  end
49
49
 
50
50
  resources :categories
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "routes/cms_admin"
4
- require_relative "routes/cms"
3
+ require_relative 'routes/cms_admin'
4
+ require_relative 'routes/cms'
5
5
 
6
6
  class ActionDispatch::Routing::Mapper
7
7
  def occams_route(identifier, options = {})
@@ -4,7 +4,7 @@ module Occams::Seeds::File
4
4
  class Exporter < Occams::Seeds::Exporter
5
5
  def initialize(from, to = from)
6
6
  super
7
- self.path = ::File.join(Occams.config.seeds_path, to, "files/")
7
+ self.path = ::File.join(Occams.config.seeds_path, to, 'files/')
8
8
  end
9
9
 
10
10
  def export!
@@ -14,19 +14,15 @@ module Occams::Seeds::File
14
14
  file_path = File.join(path, file.attachment.filename.to_s)
15
15
 
16
16
  # writing attributes
17
- ::File.open(::File.join(path, "_#{file.attachment.filename}.yml"), "w") do |f|
18
- f.write({
19
- "label" => file.label,
20
- "description" => file.description,
21
- "categories" => file.categories.map(&:label)
22
- }.to_yaml)
23
- end
17
+ ::File.write(::File.join(path, "_#{file.attachment.filename}.yml"), {
18
+ 'label' => file.label,
19
+ 'description' => file.description,
20
+ 'categories' => file.categories.map(&:label)
21
+ }.to_yaml)
24
22
 
25
23
  # writing content
26
24
  begin
27
- ::File.open(::File.join(path, ::File.basename(file_path)), "wb") do |f|
28
- f.write(file.attachment.download)
29
- end
25
+ ::File.binwrite(::File.join(path, ::File.basename(file_path)), file.attachment.download)
30
26
  rescue Errno::ENOENT, OpenURI::HTTPError
31
27
  message = "[CMS SEEDS] No physical File \t #{file.attachment.filename}"
32
28
  Occams.logger.warn(message)
@@ -4,7 +4,7 @@ module Occams::Seeds::File
4
4
  class Importer < Occams::Seeds::Importer
5
5
  def initialize(from, to = from)
6
6
  super
7
- self.path = ::File.join(Occams.config.seeds_path, from, "files/")
7
+ self.path = ::File.join(Occams.config.seeds_path, from, 'files/')
8
8
  end
9
9
 
10
10
  def import!
@@ -12,8 +12,8 @@ module Occams::Seeds::File
12
12
  filename = ::File.basename(file_path)
13
13
 
14
14
  file = site.files.with_attached_attachment
15
- .where("active_storage_blobs.filename" => filename).references(:blob).first ||
16
- site.files.new
15
+ .where('active_storage_blobs.filename' => filename).references(:blob).first ||
16
+ site.files.new
17
17
 
18
18
  # We need to track actual file and its attributes
19
19
  fresh_file = false
@@ -22,7 +22,7 @@ module Occams::Seeds::File
22
22
  fresh_file = true
23
23
 
24
24
  attrs = YAML.safe_load(File.read(attrs_path))
25
- category_ids = category_names_to_ids(file, attrs.delete("categories"))
25
+ category_ids = category_names_to_ids(file, attrs.delete('categories'))
26
26
  file.attributes = attrs.merge(
27
27
  category_ids: category_ids
28
28
  )
@@ -53,7 +53,7 @@ module Occams::Seeds::File
53
53
  end
54
54
 
55
55
  # cleaning up
56
- site.files.where("id NOT IN (?)", seed_ids).destroy_all
56
+ site.files.where('id NOT IN (?)', seed_ids).destroy_all
57
57
  end
58
58
  end
59
59
  end