occams 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/issue_template.md +2 -4
- data/CHANGELOG.md +10 -3
- data/README.md +0 -1
- data/app/controllers/application_controller.rb +0 -2
- data/app/controllers/concerns/occams/paginate.rb +0 -2
- data/app/controllers/concerns/occams/reorder_action.rb +0 -2
- data/app/controllers/occams/admin/base_controller.rb +0 -2
- data/app/controllers/occams/admin/cms/base_controller.rb +3 -4
- data/app/controllers/occams/admin/cms/categories_controller.rb +0 -2
- data/app/controllers/occams/admin/cms/files_controller.rb +4 -7
- data/app/controllers/occams/admin/cms/layouts_controller.rb +1 -2
- data/app/controllers/occams/admin/cms/pages_controller.rb +4 -5
- data/app/controllers/occams/admin/cms/revisions/base_controller.rb +0 -2
- data/app/controllers/occams/admin/cms/revisions/layout_controller.rb +0 -2
- data/app/controllers/occams/admin/cms/revisions/page_controller.rb +0 -2
- data/app/controllers/occams/admin/cms/revisions/snippet_controller.rb +0 -2
- data/app/controllers/occams/admin/cms/revisions/translation_controller.rb +0 -2
- data/app/controllers/occams/admin/cms/sites_controller.rb +1 -2
- data/app/controllers/occams/admin/cms/snippets_controller.rb +1 -2
- data/app/controllers/occams/admin/cms/translations_controller.rb +3 -5
- data/app/controllers/occams/cms/assets_controller.rb +0 -2
- data/app/controllers/occams/cms/base_controller.rb +0 -2
- data/app/controllers/occams/cms/content_controller.rb +5 -6
- data/app/helpers/occams/admin/cms_helper.rb +0 -2
- data/app/helpers/occams/cms_helper.rb +5 -2
- data/app/models/concerns/occams/cms/with_categories.rb +5 -7
- data/app/models/concerns/occams/cms/with_fragments.rb +7 -9
- data/app/models/occams/cms/categorization.rb +2 -4
- data/app/models/occams/cms/category.rb +4 -6
- data/app/models/occams/cms/file.rb +9 -9
- data/app/models/occams/cms/fragment.rb +3 -4
- data/app/models/occams/cms/layout.rb +6 -7
- data/app/models/occams/cms/page.rb +16 -13
- data/app/models/occams/cms/revision.rb +0 -2
- data/app/models/occams/cms/site.rb +8 -9
- data/app/models/occams/cms/snippet.rb +4 -6
- data/app/models/occams/cms/translation.rb +4 -5
- data/app/views/layouts/occams/admin/cms/_left.html.haml +4 -0
- data/app/views/occams/admin/cms/files/_file.html.haml +1 -1
- data/config/application.rb +0 -2
- data/config.ru +1 -1
- data/lib/generators/occams/cms/assets_generator.rb +0 -2
- data/lib/generators/occams/cms/cms_generator.rb +3 -5
- data/lib/generators/occams/cms/controllers_generator.rb +0 -2
- data/lib/generators/occams/cms/models_generator.rb +0 -2
- data/lib/generators/occams/cms/views_generator.rb +0 -2
- data/lib/generators/occams/scaffold/scaffold_generator.rb +1 -2
- data/lib/occams/access_control/admin_authentication.rb +0 -2
- data/lib/occams/access_control/admin_authorization.rb +0 -2
- data/lib/occams/access_control/public_authentication.rb +0 -2
- data/lib/occams/access_control/public_authorization.rb +0 -2
- data/lib/occams/configuration.rb +21 -23
- data/lib/occams/content/block.rb +0 -2
- data/lib/occams/content/params_parser.rb +9 -11
- data/lib/occams/content/renderer.rb +7 -10
- data/lib/occams/content/tag.rb +0 -2
- data/lib/occams/content/tags/asset.rb +0 -2
- data/lib/occams/content/tags/checkbox.rb +0 -2
- data/lib/occams/content/tags/date.rb +0 -2
- data/lib/occams/content/tags/datetime.rb +0 -2
- data/lib/occams/content/tags/file.rb +5 -7
- data/lib/occams/content/tags/file_link.rb +1 -2
- data/lib/occams/content/tags/files.rb +5 -7
- data/lib/occams/content/tags/fragment.rb +0 -2
- data/lib/occams/content/tags/helper.rb +0 -2
- data/lib/occams/content/tags/markdown.rb +0 -2
- data/lib/occams/content/tags/mixins/file_content.rb +1 -2
- data/lib/occams/content/tags/number.rb +0 -2
- data/lib/occams/content/tags/page_file_link.rb +1 -2
- data/lib/occams/content/tags/partial.rb +0 -2
- data/lib/occams/content/tags/snippet.rb +0 -2
- data/lib/occams/content/tags/template.rb +0 -2
- data/lib/occams/content/tags/text.rb +0 -2
- data/lib/occams/content/tags/textarea.rb +0 -2
- data/lib/occams/content/tags/wysiwyg.rb +0 -2
- data/lib/occams/engine.rb +1 -3
- data/lib/occams/error.rb +0 -8
- data/lib/occams/extensions/acts_as_tree.rb +14 -20
- data/lib/occams/extensions/has_revisions.rb +5 -9
- data/lib/occams/form_builder.rb +2 -6
- data/lib/occams/render_methods.rb +9 -15
- data/lib/occams/routes/cms.rb +0 -2
- data/lib/occams/routes/cms_admin.rb +1 -3
- data/lib/occams/routing.rb +0 -2
- data/lib/occams/seeds/file/exporter.rb +2 -4
- data/lib/occams/seeds/file/importer.rb +9 -13
- data/lib/occams/seeds/layout/exporter.rb +2 -4
- data/lib/occams/seeds/layout/importer.rb +3 -5
- data/lib/occams/seeds/page/exporter.rb +7 -9
- data/lib/occams/seeds/page/importer.rb +3 -5
- data/lib/occams/seeds/snippet/exporter.rb +3 -5
- data/lib/occams/seeds/snippet/importer.rb +1 -3
- data/lib/occams/seeds.rb +1 -7
- data/lib/occams/version.rb +1 -3
- data/lib/occams/view_hooks.rb +0 -2
- data/lib/occams.rb +0 -4
- data/lib/tasks/cms_seeds.rake +2 -2
- data/occams.gemspec +13 -13
- metadata +62 -8
@@ -15,17 +15,15 @@ require "strscan"
|
|
15
15
|
# Resulting list is flattened and joined into a final rendered string.
|
16
16
|
#
|
17
17
|
class Occams::Content::Renderer
|
18
|
-
|
19
18
|
class SyntaxError < StandardError; end
|
20
19
|
class Error < StandardError; end
|
21
20
|
|
22
21
|
MAX_DEPTH = 100
|
23
22
|
|
24
23
|
# tags are in this format: {{ cms:tag_class params }}
|
25
|
-
TAG_REGEX = %r{\{\{\s*?cms:(?<class>\w+)(?<params>.*?)\}\}}
|
24
|
+
TAG_REGEX = %r{\{\{\s*?cms:(?<class>\w+)(?<params>.*?)\}\}}.freeze
|
26
25
|
|
27
26
|
class << self
|
28
|
-
|
29
27
|
# @return [Hash<String, Class<Occams::Content::Tag>>]
|
30
28
|
def tags
|
31
29
|
@tags ||= {}
|
@@ -36,7 +34,6 @@ class Occams::Content::Renderer
|
|
36
34
|
def register_tag(name, klass)
|
37
35
|
tags[name.to_s] = klass
|
38
36
|
end
|
39
|
-
|
40
37
|
end
|
41
38
|
|
42
39
|
# @param [Occams::Cms::WithFragments, nil] context
|
@@ -83,9 +80,9 @@ class Occams::Content::Renderer
|
|
83
80
|
text = string.sub(ss[0], "")
|
84
81
|
tokens << text unless text.empty?
|
85
82
|
tokens << {
|
86
|
-
tag_class:
|
83
|
+
tag_class: ss[:class],
|
87
84
|
tag_params: ss[:params].strip,
|
88
|
-
source:
|
85
|
+
source: ss[0]
|
89
86
|
}
|
90
87
|
end
|
91
88
|
text = ss.rest
|
@@ -112,6 +109,7 @@ class Occams::Content::Renderer
|
|
112
109
|
if nodes.count == 1
|
113
110
|
raise SyntaxError, "closing unopened block"
|
114
111
|
end
|
112
|
+
|
115
113
|
nodes.pop
|
116
114
|
|
117
115
|
else
|
@@ -121,9 +119,9 @@ class Occams::Content::Renderer
|
|
121
119
|
|
122
120
|
# @type [Occams::Content::Tag]
|
123
121
|
tag = klass.new(
|
124
|
-
context:
|
125
|
-
params:
|
126
|
-
source:
|
122
|
+
context: @context,
|
123
|
+
params: Occams::Content::ParamsParser.new(token[:tag_params]).params,
|
124
|
+
source: token[:source]
|
127
125
|
)
|
128
126
|
nodes.last << tag
|
129
127
|
|
@@ -145,5 +143,4 @@ class Occams::Content::Renderer
|
|
145
143
|
|
146
144
|
nodes.flatten
|
147
145
|
end
|
148
|
-
|
149
146
|
end
|
data/lib/occams/content/tag.rb
CHANGED
@@ -8,7 +8,6 @@
|
|
8
8
|
# `as` - url (default) | tag - output url or wrap it in the appropriate tag
|
9
9
|
#
|
10
10
|
class Occams::Content::Tag::Asset < Occams::Content::Tag
|
11
|
-
|
12
11
|
attr_reader :identifier, :type, :as
|
13
12
|
|
14
13
|
def initialize(context:, params: [], source: nil)
|
@@ -51,7 +50,6 @@ class Occams::Content::Tag::Asset < Occams::Content::Tag
|
|
51
50
|
out
|
52
51
|
end
|
53
52
|
end
|
54
|
-
|
55
53
|
end
|
56
54
|
|
57
55
|
Occams::Content::Renderer.register_tag(
|
@@ -4,7 +4,6 @@
|
|
4
4
|
# {{ cms:checkbox identifier }}
|
5
5
|
#
|
6
6
|
class Occams::Content::Tag::Checkbox < Occams::Content::Tag::Fragment
|
7
|
-
|
8
7
|
def content
|
9
8
|
fragment.boolean
|
10
9
|
end
|
@@ -21,7 +20,6 @@ class Occams::Content::Tag::Checkbox < Occams::Content::Tag::Fragment
|
|
21
20
|
|
22
21
|
yield input
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
24
|
|
27
25
|
Occams::Content::Renderer.register_tag(
|
@@ -4,7 +4,6 @@
|
|
4
4
|
# {{ cms:date identifier }}
|
5
5
|
#
|
6
6
|
class Occams::Content::Tag::Date < Occams::Content::Tag::Datetime
|
7
|
-
|
8
7
|
def form_field(object_name, view, index)
|
9
8
|
name = "#{object_name}[fragments_attributes][#{index}][datetime]"
|
10
9
|
options = { id: form_field_id, class: "form-control", data: { "cms-date" => true } }
|
@@ -13,7 +12,6 @@ class Occams::Content::Tag::Date < Occams::Content::Tag::Datetime
|
|
13
12
|
|
14
13
|
yield input
|
15
14
|
end
|
16
|
-
|
17
15
|
end
|
18
16
|
|
19
17
|
Occams::Content::Renderer.register_tag(
|
@@ -6,7 +6,6 @@
|
|
6
6
|
# `strftime` - Format datetime string during rendering
|
7
7
|
#
|
8
8
|
class Occams::Content::Tag::Datetime < Occams::Content::Tag::Fragment
|
9
|
-
|
10
9
|
attr_reader :strftime
|
11
10
|
|
12
11
|
def initialize(context:, params: [], source: nil)
|
@@ -36,7 +35,6 @@ class Occams::Content::Tag::Datetime < Occams::Content::Tag::Fragment
|
|
36
35
|
|
37
36
|
yield input
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
41
39
|
|
42
40
|
Occams::Content::Renderer.register_tag(
|
@@ -14,7 +14,6 @@ require_relative "./mixins/file_content"
|
|
14
14
|
# `class` - any html classes that you want on the result link or image tag. For example "class1 class2"
|
15
15
|
#
|
16
16
|
class Occams::Content::Tag::File < Occams::Content::Tag::Fragment
|
17
|
-
|
18
17
|
include Occams::Content::Tag::Mixins::FileContent
|
19
18
|
|
20
19
|
# @type ["url", "link", "image"]
|
@@ -41,11 +40,11 @@ class Occams::Content::Tag::File < Occams::Content::Tag::Fragment
|
|
41
40
|
view.render(
|
42
41
|
partial: "occams/admin/cms/fragments/form_fragment_attachments",
|
43
42
|
locals: {
|
44
|
-
object_name:
|
45
|
-
index:
|
46
|
-
attachments:
|
47
|
-
fragment_id:
|
48
|
-
multiple:
|
43
|
+
object_name: object_name,
|
44
|
+
index: index,
|
45
|
+
attachments: fragment.attachments,
|
46
|
+
fragment_id: identifier,
|
47
|
+
multiple: false
|
49
48
|
}
|
50
49
|
)
|
51
50
|
end
|
@@ -64,7 +63,6 @@ protected
|
|
64
63
|
def label
|
65
64
|
@label || file&.filename
|
66
65
|
end
|
67
|
-
|
68
66
|
end
|
69
67
|
|
70
68
|
Occams::Content::Renderer.register_tag(
|
@@ -14,7 +14,6 @@ require_relative "./mixins/file_content"
|
|
14
14
|
# `class` - any html classes that you want on the result link or image tag. For example "class1 class2"
|
15
15
|
#
|
16
16
|
class Occams::Content::Tag::FileLink < Occams::Content::Tag
|
17
|
-
|
18
17
|
include Occams::Content::Tag::Mixins::FileContent
|
19
18
|
|
20
19
|
# @return [String] A {Occams::Cms::Site#files} ID.
|
@@ -53,9 +52,9 @@ class Occams::Content::Tag::FileLink < Occams::Content::Tag
|
|
53
52
|
# @return [String]
|
54
53
|
def label
|
55
54
|
return "" if file_record.nil?
|
55
|
+
|
56
56
|
file_record.label.presence || file.filename.to_s
|
57
57
|
end
|
58
|
-
|
59
58
|
end
|
60
59
|
|
61
60
|
Occams::Content::Renderer.register_tag(
|
@@ -6,7 +6,6 @@
|
|
6
6
|
# {{ cms:files identifier }}
|
7
7
|
#
|
8
8
|
class Occams::Content::Tag::Files < Occams::Content::Tag::File
|
9
|
-
|
10
9
|
def content
|
11
10
|
return "" if fragment.attachments.blank?
|
12
11
|
|
@@ -24,18 +23,17 @@ class Occams::Content::Tag::Files < Occams::Content::Tag::File
|
|
24
23
|
view.render(
|
25
24
|
partial: "occams/admin/cms/fragments/form_fragment_attachments",
|
26
25
|
locals: {
|
27
|
-
object_name:
|
28
|
-
index:
|
29
|
-
attachments:
|
30
|
-
fragment_id:
|
31
|
-
multiple:
|
26
|
+
object_name: object_name,
|
27
|
+
index: index,
|
28
|
+
attachments: fragment.attachments,
|
29
|
+
fragment_id: identifier,
|
30
|
+
multiple: true
|
32
31
|
}
|
33
32
|
)
|
34
33
|
end
|
35
34
|
|
36
35
|
yield view.safe_join([input, attachments_partial], "")
|
37
36
|
end
|
38
|
-
|
39
37
|
end
|
40
38
|
|
41
39
|
Occams::Content::Renderer.register_tag(
|
@@ -9,7 +9,6 @@
|
|
9
9
|
# Just a string that allows grouping of form elements in the admin area
|
10
10
|
#
|
11
11
|
class Occams::Content::Tag::Fragment < Occams::Content::Tag
|
12
|
-
|
13
12
|
attr_accessor :renderable
|
14
13
|
attr_reader :identifier, :namespace
|
15
14
|
|
@@ -62,5 +61,4 @@ class Occams::Content::Tag::Fragment < Occams::Content::Tag
|
|
62
61
|
def form_field_id
|
63
62
|
"fragment-#{@identifier}"
|
64
63
|
end
|
65
|
-
|
66
64
|
end
|
@@ -8,7 +8,6 @@
|
|
8
8
|
# By default there's a blacklist of methods that should not be called.
|
9
9
|
#
|
10
10
|
class Occams::Content::Tag::Helper < Occams::Content::Tag
|
11
|
-
|
12
11
|
BLACKLIST = %w[eval class_eval instance_eval render].freeze
|
13
12
|
|
14
13
|
attr_reader :method_name
|
@@ -47,7 +46,6 @@ class Occams::Content::Tag::Helper < Occams::Content::Tag
|
|
47
46
|
content unless BLACKLIST.member?(method_name)
|
48
47
|
end
|
49
48
|
end
|
50
|
-
|
51
49
|
end
|
52
50
|
|
53
51
|
Occams::Content::Renderer.register_tag(
|
@@ -4,7 +4,6 @@
|
|
4
4
|
# {{ cms:markdown identifier }}
|
5
5
|
#
|
6
6
|
class Occams::Content::Tag::Markdown < Occams::Content::Tag::Fragment
|
7
|
-
|
8
7
|
def render
|
9
8
|
renderable ? Kramdown::Document.new(content.to_s).to_html : ""
|
10
9
|
end
|
@@ -16,7 +15,6 @@ class Occams::Content::Tag::Markdown < Occams::Content::Tag::Fragment
|
|
16
15
|
|
17
16
|
yield input
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
|
22
20
|
Occams::Content::Renderer.register_tag(
|
@@ -3,7 +3,6 @@
|
|
3
3
|
# A mixin for tags that returns the file as their content.
|
4
4
|
module Occams::Content::Tag::Mixins
|
5
5
|
module FileContent
|
6
|
-
|
7
6
|
# @param [ActiveStorage::Blob] file
|
8
7
|
# @param ["link", "image", "url"] as
|
9
8
|
# @param [{String => String}] variant_attrs ImageMagick variant attributes
|
@@ -36,8 +35,8 @@ module Occams::Content::Tag::Mixins
|
|
36
35
|
|
37
36
|
def html_class_attribute
|
38
37
|
return if @class.blank?
|
38
|
+
|
39
39
|
" class='#{@class}'"
|
40
40
|
end
|
41
|
-
|
42
41
|
end
|
43
42
|
end
|
@@ -4,7 +4,6 @@
|
|
4
4
|
# {{ cms:number identifier }}
|
5
5
|
#
|
6
6
|
class Occams::Content::Tag::Number < Occams::Content::Tag::Fragment
|
7
|
-
|
8
7
|
def form_field(object_name, view, index)
|
9
8
|
name = "#{object_name}[fragments_attributes][#{index}][content]"
|
10
9
|
options = { id: form_field_id, class: "form-control" }
|
@@ -12,7 +11,6 @@ class Occams::Content::Tag::Number < Occams::Content::Tag::Fragment
|
|
12
11
|
|
13
12
|
yield input
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
17
15
|
|
18
16
|
Occams::Content::Renderer.register_tag(
|
@@ -23,7 +23,6 @@ require_relative "./mixins/file_content"
|
|
23
23
|
# `class` - any html classes that you want on the result link or image tag. For example "class1 class2"
|
24
24
|
#
|
25
25
|
class Occams::Content::Tag::PageFileLink < Occams::Content::Tag
|
26
|
-
|
27
26
|
include Occams::Content::Tag::Mixins::FileContent
|
28
27
|
|
29
28
|
# @return [String] A `cms:file(s)` identifier.
|
@@ -74,9 +73,9 @@ class Occams::Content::Tag::PageFileLink < Occams::Content::Tag
|
|
74
73
|
# @return [String]
|
75
74
|
def label
|
76
75
|
return if file.nil?
|
76
|
+
|
77
77
|
file.filename.to_s
|
78
78
|
end
|
79
|
-
|
80
79
|
end
|
81
80
|
|
82
81
|
Occams::Content::Renderer.register_tag(
|
@@ -7,7 +7,6 @@
|
|
7
7
|
# Whitelist is can be used to control what partials are renderable.
|
8
8
|
#
|
9
9
|
class Occams::Content::Tag::Partial < Occams::Content::Tag
|
10
|
-
|
11
10
|
attr_reader :path, :locals
|
12
11
|
|
13
12
|
def initialize(context:, params: [], source: nil)
|
@@ -41,7 +40,6 @@ class Occams::Content::Tag::Partial < Occams::Content::Tag
|
|
41
40
|
content
|
42
41
|
end
|
43
42
|
end
|
44
|
-
|
45
43
|
end
|
46
44
|
|
47
45
|
Occams::Content::Renderer.register_tag(
|
@@ -5,7 +5,6 @@
|
|
5
5
|
# Snippets may have more tags in them like fragments, so they may be expanded too.
|
6
6
|
#
|
7
7
|
class Occams::Content::Tag::Snippet < Occams::Content::Tag
|
8
|
-
|
9
8
|
attr_reader :identifier
|
10
9
|
|
11
10
|
def initialize(context:, params: [], source: nil)
|
@@ -30,7 +29,6 @@ class Occams::Content::Tag::Snippet < Occams::Content::Tag
|
|
30
29
|
context.site.snippets.detect { |s| s.identifier == identifier } ||
|
31
30
|
context.site.snippets.build(identifier: identifier)
|
32
31
|
end
|
33
|
-
|
34
32
|
end
|
35
33
|
|
36
34
|
Occams::Content::Renderer.register_tag(
|
@@ -7,7 +7,6 @@
|
|
7
7
|
# Whitelist is can be used to control what templates are available.
|
8
8
|
#
|
9
9
|
class Occams::Content::Tag::Template < Occams::Content::Tag
|
10
|
-
|
11
10
|
attr_reader :path
|
12
11
|
|
13
12
|
def initialize(context:, params: [], source: nil)
|
@@ -36,7 +35,6 @@ class Occams::Content::Tag::Template < Occams::Content::Tag
|
|
36
35
|
content
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
41
39
|
|
42
40
|
Occams::Content::Renderer.register_tag(
|
@@ -4,7 +4,6 @@
|
|
4
4
|
# {{ cms:text identifier }}
|
5
5
|
#
|
6
6
|
class Occams::Content::Tag::Text < Occams::Content::Tag::Fragment
|
7
|
-
|
8
7
|
def form_field(object_name, view, index)
|
9
8
|
name = "#{object_name}[fragments_attributes][#{index}][content]"
|
10
9
|
options = { id: form_field_id, class: "form-control" }
|
@@ -12,7 +11,6 @@ class Occams::Content::Tag::Text < Occams::Content::Tag::Fragment
|
|
12
11
|
|
13
12
|
yield input
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
17
15
|
|
18
16
|
Occams::Content::Renderer.register_tag(
|
@@ -4,7 +4,6 @@
|
|
4
4
|
# {{ cms:textarea identifier }}
|
5
5
|
#
|
6
6
|
class Occams::Content::Tag::TextArea < Occams::Content::Tag::Fragment
|
7
|
-
|
8
7
|
def form_field(object_name, view, index)
|
9
8
|
name = "#{object_name}[fragments_attributes][#{index}][content]"
|
10
9
|
options = { id: form_field_id, data: { "cms-cm-mode" => "text/html" } }
|
@@ -12,7 +11,6 @@ class Occams::Content::Tag::TextArea < Occams::Content::Tag::Fragment
|
|
12
11
|
|
13
12
|
yield input
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
17
15
|
|
18
16
|
Occams::Content::Renderer.register_tag(
|
@@ -6,14 +6,12 @@
|
|
6
6
|
#
|
7
7
|
#
|
8
8
|
class Occams::Content::Tag::Wysiwyg < Occams::Content::Tag::Fragment
|
9
|
-
|
10
9
|
def form_field(object_name, view, index)
|
11
10
|
name = "#{object_name}[fragments_attributes][#{index}][content]"
|
12
11
|
options = { id: form_field_id, data: { "cms-rich-text" => true } }
|
13
12
|
input = view.send(:text_area_tag, name, content, options)
|
14
13
|
yield input
|
15
14
|
end
|
16
|
-
|
17
15
|
end
|
18
16
|
|
19
17
|
Occams::Content::Renderer.register_tag(
|
data/lib/occams/engine.rb
CHANGED
@@ -12,7 +12,6 @@ require "sassc-rails"
|
|
12
12
|
|
13
13
|
module Occams
|
14
14
|
class Engine < ::Rails::Engine
|
15
|
-
|
16
15
|
initializer "occams.setup_assets" do
|
17
16
|
::Occams::Engine.config.assets.precompile += %w[
|
18
17
|
occams/admin/cms/application.js
|
@@ -22,10 +21,9 @@ module Occams
|
|
22
21
|
end
|
23
22
|
|
24
23
|
config.to_prepare do
|
25
|
-
Dir.glob(Rails.root
|
24
|
+
Dir.glob("#{Rails.root}app/decorators/occams/*_decorator*.rb").each do |c|
|
26
25
|
require_dependency(c)
|
27
26
|
end
|
28
27
|
end
|
29
|
-
|
30
28
|
end
|
31
29
|
end
|
data/lib/occams/error.rb
CHANGED
@@ -1,32 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Occams
|
4
|
-
|
5
4
|
class Error < StandardError
|
6
5
|
end
|
7
6
|
|
8
7
|
class MissingSite < Occams::Error
|
9
|
-
|
10
8
|
def initialize(identifier)
|
11
9
|
super "Cannot find CMS Site with identifier: #{identifier}"
|
12
10
|
end
|
13
|
-
|
14
11
|
end
|
15
12
|
|
16
13
|
class MissingLayout < Occams::Error
|
17
|
-
|
18
14
|
def initialize(identifier)
|
19
15
|
super "Cannot find CMS Layout with identifier: #{identifier}"
|
20
16
|
end
|
21
|
-
|
22
17
|
end
|
23
18
|
|
24
19
|
class MissingPage < Occams::Error
|
25
|
-
|
26
20
|
def initialize(path)
|
27
21
|
super "Cannot find CMS Page at #{path}"
|
28
22
|
end
|
29
|
-
|
30
23
|
end
|
31
|
-
|
32
24
|
end
|
@@ -1,35 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Occams::ActsAsTree
|
4
|
-
|
5
4
|
def self.included(base)
|
6
5
|
base.extend(ClassMethods)
|
7
6
|
end
|
8
7
|
|
9
8
|
module ClassMethods
|
10
|
-
|
11
9
|
def cms_acts_as_tree(options = {})
|
12
10
|
configuration = {
|
13
|
-
foreign_key:
|
14
|
-
order:
|
15
|
-
counter_cache:
|
16
|
-
dependent:
|
17
|
-
touch:
|
11
|
+
foreign_key: "parent_id",
|
12
|
+
order: nil,
|
13
|
+
counter_cache: nil,
|
14
|
+
dependent: :destroy,
|
15
|
+
touch: false
|
18
16
|
}
|
19
17
|
configuration.update(options) if options.is_a?(Hash)
|
20
18
|
|
21
19
|
belongs_to :parent,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
optional: true,
|
21
|
+
class_name: name,
|
22
|
+
foreign_key: configuration[:foreign_key],
|
23
|
+
counter_cache: configuration[:counter_cache],
|
24
|
+
touch: configuration[:touch]
|
27
25
|
|
28
26
|
has_many :children,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
-> { order(configuration[:order]) },
|
28
|
+
class_name: name,
|
29
|
+
foreign_key: configuration[:foreign_key],
|
30
|
+
dependent: configuration[:dependent]
|
33
31
|
|
34
32
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
35
33
|
include Occams::ActsAsTree::InstanceMethods
|
@@ -54,11 +52,9 @@ module Occams::ActsAsTree
|
|
54
52
|
end
|
55
53
|
RUBY
|
56
54
|
end
|
57
|
-
|
58
55
|
end
|
59
56
|
|
60
57
|
module InstanceMethods
|
61
|
-
|
62
58
|
# Returns list of ancestors, starting from parent until root.
|
63
59
|
#
|
64
60
|
# subchild1.ancestors # => [child1, root]
|
@@ -110,9 +106,7 @@ module Occams::ActsAsTree
|
|
110
106
|
def parent_id=(id)
|
111
107
|
self.parent = self.class.find_by(id: id)
|
112
108
|
end
|
113
|
-
|
114
109
|
end
|
115
|
-
|
116
110
|
end
|
117
111
|
|
118
112
|
ActiveSupport.on_load :active_record do
|
@@ -1,22 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Occams::HasRevisions
|
4
|
-
|
5
4
|
def self.included(base)
|
6
5
|
base.send :extend, ClassMethods
|
7
6
|
end
|
8
7
|
|
9
8
|
module ClassMethods
|
10
|
-
|
11
9
|
def cms_has_revisions_for(*fields)
|
12
10
|
include Occams::HasRevisions::InstanceMethods
|
13
11
|
|
14
12
|
attr_accessor :revision_data
|
15
13
|
|
16
14
|
has_many :revisions,
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
as: :record,
|
16
|
+
dependent: :destroy,
|
17
|
+
class_name: "Occams::Cms::Revision"
|
20
18
|
|
21
19
|
before_save :prepare_revision
|
22
20
|
after_save :create_revision
|
@@ -25,14 +23,13 @@ module Occams::HasRevisions
|
|
25
23
|
fields.collect(&:to_s)
|
26
24
|
end
|
27
25
|
end
|
28
|
-
|
29
26
|
end
|
30
27
|
|
31
28
|
module InstanceMethods
|
32
|
-
|
33
29
|
# Preparing revision data. A bit of a special thing to grab page blocks
|
34
30
|
def prepare_revision
|
35
31
|
return if new_record?
|
32
|
+
|
36
33
|
if (respond_to?(:fragments_attributes_changed) && fragments_attributes_changed) ||
|
37
34
|
!(changed & revision_fields).empty?
|
38
35
|
self.revision_data = revision_fields.each_with_object({}) do |field, c|
|
@@ -60,11 +57,10 @@ module Occams::HasRevisions
|
|
60
57
|
# Assigning whatever is found in revision data and attempting to save the object
|
61
58
|
def restore_from_revision(revision)
|
62
59
|
return unless revision.record == self
|
60
|
+
|
63
61
|
update!(revision.data)
|
64
62
|
end
|
65
|
-
|
66
63
|
end
|
67
|
-
|
68
64
|
end
|
69
65
|
|
70
66
|
ActiveSupport.on_load :active_record do
|
data/lib/occams/form_builder.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Occams::FormBuilder < ComfyBootstrapForm::FormBuilder
|
4
|
-
|
5
4
|
# Renders form input for a fragment
|
6
5
|
#
|
7
6
|
# @param [Occams::Cms::Page] record
|
@@ -32,16 +31,13 @@ class Occams::FormBuilder < ComfyBootstrapForm::FormBuilder
|
|
32
31
|
# = form.form_actions do
|
33
32
|
# = form.submit
|
34
33
|
#
|
35
|
-
def form_actions
|
34
|
+
def form_actions(&block)
|
36
35
|
content_tag(:div, class: "form-actions row bg-light") do
|
37
36
|
content_tag(:div, class: "col-lg-8 offset-lg-2") do
|
38
37
|
content_tag(:div, class: "form-group row mb-0") do
|
39
|
-
content_tag(:div, class: "col-sm-10 offset-sm-2")
|
40
|
-
yield
|
41
|
-
end
|
38
|
+
content_tag(:div, class: "col-sm-10 offset-sm-2", &block)
|
42
39
|
end
|
43
40
|
end
|
44
41
|
end
|
45
42
|
end
|
46
|
-
|
47
43
|
end
|