occams 1.0.0 → 1.0.2
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/.rubocop.yml +23 -40
- data/CHANGELOG.md +18 -3
- data/Gemfile +17 -17
- data/LICENSE +1 -1
- data/README.md +15 -19
- data/Rakefile +1 -1
- data/TODOS.md +6 -0
- 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 +1 -3
- data/app/controllers/occams/admin/cms/base_controller.rb +10 -11
- data/app/controllers/occams/admin/cms/categories_controller.rb +0 -2
- data/app/controllers/occams/admin/cms/files_controller.rb +21 -24
- data/app/controllers/occams/admin/cms/layouts_controller.rb +8 -9
- data/app/controllers/occams/admin/cms/pages_controller.rb +28 -29
- data/app/controllers/occams/admin/cms/revisions/base_controller.rb +5 -7
- data/app/controllers/occams/admin/cms/revisions/layout_controller.rb +1 -3
- data/app/controllers/occams/admin/cms/revisions/page_controller.rb +3 -5
- data/app/controllers/occams/admin/cms/revisions/snippet_controller.rb +1 -3
- data/app/controllers/occams/admin/cms/revisions/translation_controller.rb +3 -5
- data/app/controllers/occams/admin/cms/sites_controller.rb +7 -8
- data/app/controllers/occams/admin/cms/snippets_controller.rb +7 -8
- data/app/controllers/occams/admin/cms/translations_controller.rb +26 -28
- data/app/controllers/occams/cms/assets_controller.rb +5 -7
- data/app/controllers/occams/cms/base_controller.rb +7 -14
- data/app/controllers/occams/cms/content_controller.rb +19 -16
- data/app/helpers/occams/admin/cms_helper.rb +3 -5
- data/app/helpers/occams/cms_helper.rb +13 -10
- data/app/models/concerns/occams/cms/with_categories.rb +6 -8
- data/app/models/concerns/occams/cms/with_fragments.rb +6 -8
- data/app/models/occams/cms/categorization.rb +3 -5
- data/app/models/occams/cms/category.rb +5 -7
- data/app/models/occams/cms/file.rb +10 -10
- data/app/models/occams/cms/fragment.rb +5 -6
- data/app/models/occams/cms/layout.rb +11 -12
- data/app/models/occams/cms/page.rb +20 -17
- data/app/models/occams/cms/revision.rb +1 -3
- data/app/models/occams/cms/site.rb +16 -17
- data/app/models/occams/cms/snippet.rb +5 -7
- data/app/models/occams/cms/translation.rb +5 -6
- data/app/views/layouts/occams/admin/cms/_left.html.haml +5 -0
- data/app/views/occams/admin/cms/files/_file.html.haml +1 -1
- data/config/application.rb +4 -6
- data/config/boot.rb +4 -3
- data/config/environment.rb +1 -1
- data/config/environments/development.rb +2 -2
- data/config/environments/test.rb +1 -1
- data/config/initializers/occams.rb +2 -2
- data/config.ru +1 -1
- data/lib/generators/occams/cms/assets_generator.rb +3 -5
- data/lib/generators/occams/cms/cms_generator.rb +13 -15
- data/lib/generators/occams/cms/controllers_generator.rb +2 -4
- data/lib/generators/occams/cms/models_generator.rb +2 -4
- data/lib/generators/occams/cms/views_generator.rb +2 -4
- data/lib/generators/occams/scaffold/scaffold_generator.rb +19 -20
- 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 +33 -35
- data/lib/occams/content/block.rb +0 -2
- data/lib/occams/content/params_parser.rb +12 -14
- data/lib/occams/content/renderer.rb +15 -18
- data/lib/occams/content/tag.rb +1 -3
- data/lib/occams/content/tags/asset.rb +13 -15
- data/lib/occams/content/tags/checkbox.rb +4 -6
- data/lib/occams/content/tags/date.rb +2 -4
- data/lib/occams/content/tags/datetime.rb +4 -6
- data/lib/occams/content/tags/file.rb +13 -15
- data/lib/occams/content/tags/file_link.rb +9 -10
- data/lib/occams/content/tags/files.rb +10 -12
- data/lib/occams/content/tags/fragment.rb +4 -6
- data/lib/occams/content/tags/helper.rb +6 -8
- data/lib/occams/content/tags/markdown.rb +2 -4
- data/lib/occams/content/tags/mixins/file_content.rb +4 -5
- data/lib/occams/content/tags/number.rb +1 -3
- data/lib/occams/content/tags/page_file_link.rb +9 -10
- data/lib/occams/content/tags/partial.rb +5 -7
- data/lib/occams/content/tags/snippet.rb +3 -5
- data/lib/occams/content/tags/template.rb +5 -7
- data/lib/occams/content/tags/text.rb +1 -3
- data/lib/occams/content/tags/textarea.rb +1 -3
- data/lib/occams/content/tags/wysiwyg.rb +1 -3
- data/lib/occams/content.rb +22 -22
- data/lib/occams/engine.rb +11 -13
- data/lib/occams/error.rb +0 -8
- data/lib/occams/extensions/acts_as_tree.rb +14 -20
- data/lib/occams/extensions/has_revisions.rb +7 -11
- data/lib/occams/form_builder.rb +5 -9
- data/lib/occams/render_methods.rb +11 -17
- data/lib/occams/routes/cms.rb +3 -5
- data/lib/occams/routes/cms_admin.rb +7 -9
- data/lib/occams/routing.rb +2 -4
- data/lib/occams/seeds/file/exporter.rb +7 -13
- data/lib/occams/seeds/file/importer.rb +13 -17
- data/lib/occams/seeds/layout/exporter.rb +9 -11
- data/lib/occams/seeds/layout/importer.rb +9 -11
- data/lib/occams/seeds/page/exporter.rb +19 -23
- data/lib/occams/seeds/page/importer.rb +17 -19
- data/lib/occams/seeds/snippet/exporter.rb +6 -8
- data/lib/occams/seeds/snippet/importer.rb +6 -8
- data/lib/occams/seeds.rb +6 -12
- data/lib/occams/version.rb +1 -3
- data/lib/occams/view_hooks.rb +1 -3
- data/lib/occams.rb +25 -29
- data/lib/tasks/cms_seeds.rake +4 -4
- data/occams.gemspec +22 -21
- metadata +65 -10
- data/LICENSE.comfy +0 -20
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'strscan'
|
4
4
|
|
5
5
|
# Processing content follows these stages:
|
6
6
|
#
|
@@ -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
|
@@ -51,7 +48,7 @@ class Occams::Content::Renderer
|
|
51
48
|
# @param [Boolean] allow_erb
|
52
49
|
def render(nodes, allow_erb = Occams.config.allow_erb)
|
53
50
|
if (@depth += 1) > MAX_DEPTH
|
54
|
-
raise Error,
|
51
|
+
raise Error, 'Deep tag nesting or recursive nesting detected'
|
55
52
|
end
|
56
53
|
|
57
54
|
nodes.map do |node|
|
@@ -70,7 +67,7 @@ class Occams::Content::Renderer
|
|
70
67
|
if allow_erb
|
71
68
|
string.to_s
|
72
69
|
else
|
73
|
-
string.to_s.gsub(
|
70
|
+
string.to_s.gsub('<%', '<%').gsub('%>', '%>')
|
74
71
|
end
|
75
72
|
end
|
76
73
|
|
@@ -80,12 +77,12 @@ class Occams::Content::Renderer
|
|
80
77
|
tokens = []
|
81
78
|
ss = StringScanner.new(string.to_s)
|
82
79
|
while (string = ss.scan_until(TAG_REGEX))
|
83
|
-
text = string.sub(ss[0],
|
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
|
@@ -108,22 +105,23 @@ class Occams::Content::Renderer
|
|
108
105
|
case tag_class = token[:tag_class]
|
109
106
|
|
110
107
|
# This handles {{cms:end}} tag. Stopping collecting block nodes.
|
111
|
-
when
|
108
|
+
when 'end'
|
112
109
|
if nodes.count == 1
|
113
|
-
raise SyntaxError,
|
110
|
+
raise SyntaxError, 'closing unopened block'
|
114
111
|
end
|
112
|
+
|
115
113
|
nodes.pop
|
116
114
|
|
117
115
|
else
|
118
116
|
# @type [Class<Occams::Content::Tag>]
|
119
117
|
klass = self.class.tags[tag_class] ||
|
120
|
-
|
118
|
+
raise(SyntaxError, "Unrecognized tag: #{token[:source]}")
|
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
|
|
@@ -140,10 +138,9 @@ class Occams::Content::Renderer
|
|
140
138
|
end
|
141
139
|
|
142
140
|
if nodes.count > 1
|
143
|
-
raise SyntaxError,
|
141
|
+
raise SyntaxError, 'unclosed block detected'
|
144
142
|
end
|
145
143
|
|
146
144
|
nodes.flatten
|
147
145
|
end
|
148
|
-
|
149
146
|
end
|
data/lib/occams/content/tag.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Occams::Content::Tag
|
4
|
-
|
5
4
|
class Error < StandardError; end
|
6
5
|
|
7
6
|
# @type [Occams::Cms::WithFragments]
|
@@ -39,12 +38,11 @@ class Occams::Content::Tag
|
|
39
38
|
|
40
39
|
# @return [String]
|
41
40
|
def content
|
42
|
-
raise Error,
|
41
|
+
raise Error, 'This is a base class. It holds no content'
|
43
42
|
end
|
44
43
|
|
45
44
|
# @return [String]
|
46
45
|
def render
|
47
46
|
content
|
48
47
|
end
|
49
|
-
|
50
48
|
end
|
@@ -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)
|
@@ -16,12 +15,12 @@ class Occams::Content::Tag::Asset < Occams::Content::Tag
|
|
16
15
|
|
17
16
|
options = params.extract_options!
|
18
17
|
@identifier = params[0]
|
19
|
-
@type = options[
|
20
|
-
@as = options[
|
18
|
+
@type = options['type']
|
19
|
+
@as = options['as'] || 'url'
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
return if @identifier.present?
|
22
|
+
|
23
|
+
raise Error, 'Missing layout identifier for asset tag'
|
25
24
|
end
|
26
25
|
|
27
26
|
def layout
|
@@ -29,29 +28,28 @@ class Occams::Content::Tag::Asset < Occams::Content::Tag
|
|
29
28
|
end
|
30
29
|
|
31
30
|
def content
|
32
|
-
return
|
31
|
+
return '' unless layout
|
33
32
|
|
34
|
-
base = Occams.config.public_cms_path ||
|
35
|
-
unless base.ends_with?(
|
36
|
-
base +=
|
33
|
+
base = Occams.config.public_cms_path || ''
|
34
|
+
unless base.ends_with?('/')
|
35
|
+
base += '/'
|
37
36
|
end
|
38
37
|
|
39
38
|
case @type
|
40
|
-
when
|
39
|
+
when 'css'
|
41
40
|
out = "#{base}cms-css/#{context.site.id}/#{@identifier}/#{layout.cache_buster}.css"
|
42
|
-
if @as ==
|
41
|
+
if @as == 'tag'
|
43
42
|
out = "<link href='#{out}' media='screen' rel='stylesheet' type='text/css' />"
|
44
43
|
end
|
45
44
|
out
|
46
|
-
when
|
45
|
+
when 'js'
|
47
46
|
out = "#{base}cms-js/#{context.site.id}/#{@identifier}/#{layout.cache_buster}.js"
|
48
|
-
if @as ==
|
47
|
+
if @as == 'tag'
|
49
48
|
out = "<script src='#{out}' type='text/javascript'></script>"
|
50
49
|
end
|
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
|
@@ -12,16 +11,15 @@ class Occams::Content::Tag::Checkbox < Occams::Content::Tag::Fragment
|
|
12
11
|
def form_field(object_name, view, index)
|
13
12
|
name = "#{object_name}[fragments_attributes][#{index}][boolean]"
|
14
13
|
|
15
|
-
input = view.content_tag(:div, class:
|
16
|
-
view.concat view.hidden_field_tag(name,
|
14
|
+
input = view.content_tag(:div, class: 'form-check mt-2') do
|
15
|
+
view.concat view.hidden_field_tag(name, '0', id: nil)
|
17
16
|
|
18
|
-
options = { id: form_field_id, class:
|
19
|
-
view.concat view.check_box_tag(name,
|
17
|
+
options = { id: form_field_id, class: 'form-check-input position-static' }
|
18
|
+
view.concat view.check_box_tag(name, '1', content.present?, options)
|
20
19
|
end
|
21
20
|
|
22
21
|
yield input
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
24
|
|
27
25
|
Occams::Content::Renderer.register_tag(
|
@@ -4,16 +4,14 @@
|
|
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
|
-
options = { id: form_field_id, class:
|
11
|
-
value = content.present? ? content.to_s(:db) :
|
9
|
+
options = { id: form_field_id, class: 'form-control', data: { 'cms-date' => true } }
|
10
|
+
value = content.present? ? content.to_s(:db) : ''
|
12
11
|
input = view.send(:text_field_tag, name, value, options)
|
13
12
|
|
14
13
|
yield input
|
15
14
|
end
|
16
|
-
|
17
15
|
end
|
18
16
|
|
19
17
|
Occams::Content::Renderer.register_tag(
|
@@ -6,12 +6,11 @@
|
|
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)
|
13
12
|
super
|
14
|
-
@strftime = options[
|
13
|
+
@strftime = options['strftime']
|
15
14
|
end
|
16
15
|
|
17
16
|
def content
|
@@ -19,7 +18,7 @@ class Occams::Content::Tag::Datetime < Occams::Content::Tag::Fragment
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def render
|
22
|
-
return
|
21
|
+
return '' unless renderable
|
23
22
|
|
24
23
|
if strftime.present?
|
25
24
|
content.strftime(strftime)
|
@@ -30,13 +29,12 @@ class Occams::Content::Tag::Datetime < Occams::Content::Tag::Fragment
|
|
30
29
|
|
31
30
|
def form_field(object_name, view, index)
|
32
31
|
name = "#{object_name}[fragments_attributes][#{index}][datetime]"
|
33
|
-
options = { id: form_field_id, class:
|
34
|
-
value = content.present? ? content.to_s(:db) :
|
32
|
+
options = { id: form_field_id, class: 'form-control', data: { 'cms-datetime' => true } }
|
33
|
+
value = content.present? ? content.to_s(:db) : ''
|
35
34
|
input = view.send(:text_field_tag, name, value, options)
|
36
35
|
|
37
36
|
yield input
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
41
39
|
|
42
40
|
Occams::Content::Renderer.register_tag(
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative 'mixins/file_content'
|
4
4
|
|
5
5
|
# File tag allows attaching of file to the page. This controls how files are
|
6
6
|
# uploaded and then displayed on the page. Example 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"]
|
@@ -26,31 +25,31 @@ class Occams::Content::Tag::File < Occams::Content::Tag::Fragment
|
|
26
25
|
# @param (see Occams::Content::Tag#initialize)
|
27
26
|
def initialize(context:, params: [], source: nil)
|
28
27
|
super
|
29
|
-
@as = options[
|
30
|
-
@label = options[
|
31
|
-
@class = options[
|
32
|
-
@variant_attrs = options.slice(
|
28
|
+
@as = options['as'] || 'url'
|
29
|
+
@label = options['label']
|
30
|
+
@class = options['class']
|
31
|
+
@variant_attrs = options.slice('resize', 'gravity', 'crop')
|
33
32
|
end
|
34
33
|
|
35
34
|
def form_field(object_name, view, index)
|
36
35
|
name = "#{object_name}[fragments_attributes][#{index}][files]"
|
37
|
-
input = view.send(:file_field_tag, name, id: form_field_id, class:
|
36
|
+
input = view.send(:file_field_tag, name, id: form_field_id, class: 'form-control')
|
38
37
|
|
39
38
|
attachments_partial =
|
40
39
|
if fragment.attachments
|
41
40
|
view.render(
|
42
|
-
partial:
|
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
|
52
51
|
|
53
|
-
yield view.safe_join([input, attachments_partial],
|
52
|
+
yield view.safe_join([input, attachments_partial], '')
|
54
53
|
end
|
55
54
|
|
56
55
|
protected
|
@@ -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(
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
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.
|
@@ -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.
|
@@ -31,13 +30,13 @@ class Occams::Content::Tag::FileLink < Occams::Content::Tag
|
|
31
30
|
|
32
31
|
options = params.extract_options!
|
33
32
|
@identifier = params[0]
|
34
|
-
@as = options[
|
35
|
-
@class = options[
|
36
|
-
@variant_attrs = options.slice(
|
33
|
+
@as = options['as'] || 'url'
|
34
|
+
@class = options['class']
|
35
|
+
@variant_attrs = options.slice('resize', 'gravity', 'crop')
|
36
|
+
|
37
|
+
return if @identifier.present?
|
37
38
|
|
38
|
-
|
39
|
-
raise Error, "Missing identifier for file link tag"
|
40
|
-
end
|
39
|
+
raise Error, 'Missing identifier for file link tag'
|
41
40
|
end
|
42
41
|
|
43
42
|
# @return [Occams::Cms::File]
|
@@ -52,10 +51,10 @@ class Occams::Content::Tag::FileLink < Occams::Content::Tag
|
|
52
51
|
|
53
52
|
# @return [String]
|
54
53
|
def label
|
55
|
-
return
|
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,36 +6,34 @@
|
|
6
6
|
# {{ cms:files identifier }}
|
7
7
|
#
|
8
8
|
class Occams::Content::Tag::Files < Occams::Content::Tag::File
|
9
|
-
|
10
9
|
def content
|
11
|
-
return
|
10
|
+
return '' if fragment.attachments.blank?
|
12
11
|
|
13
12
|
fragment.attachments.collect do |attachment|
|
14
13
|
super(file: attachment, label: attachment.filename)
|
15
|
-
end.join(
|
14
|
+
end.join(' ')
|
16
15
|
end
|
17
16
|
|
18
17
|
def form_field(object_name, view, index)
|
19
18
|
name = "#{object_name}[fragments_attributes][#{index}][files][]"
|
20
|
-
input = view.send(:file_field_tag, name, id: form_field_id, multiple: true, class:
|
19
|
+
input = view.send(:file_field_tag, name, id: form_field_id, multiple: true, class: 'form-control')
|
21
20
|
|
22
21
|
attachments_partial =
|
23
22
|
if fragment.attachments
|
24
23
|
view.render(
|
25
|
-
partial:
|
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
|
-
yield view.safe_join([input, attachments_partial],
|
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
|
|
@@ -26,8 +25,8 @@ class Occams::Content::Tag::Fragment < Occams::Content::Tag
|
|
26
25
|
raise Error, "Missing identifier for fragment tag: #{source}"
|
27
26
|
end
|
28
27
|
|
29
|
-
@namespace = @options[
|
30
|
-
@renderable = @options[
|
28
|
+
@namespace = @options['namespace'] || 'default'
|
29
|
+
@renderable = @options['render'].to_s.downcase != 'false'
|
31
30
|
end
|
32
31
|
|
33
32
|
# Grabs existing fragment record or spins up a new instance if there's none
|
@@ -44,7 +43,7 @@ class Occams::Content::Tag::Fragment < Occams::Content::Tag
|
|
44
43
|
# If `render: false` was passed in we won't render anything. Assuming that
|
45
44
|
# that fragment content will be rendered manually
|
46
45
|
def render
|
47
|
-
renderable ? content :
|
46
|
+
renderable ? content : ''
|
48
47
|
end
|
49
48
|
|
50
49
|
# Tag renders its own form inputs via `form_field(template, index)`
|
@@ -56,11 +55,10 @@ class Occams::Content::Tag::Fragment < Occams::Content::Tag
|
|
56
55
|
# end
|
57
56
|
# end
|
58
57
|
def form_field
|
59
|
-
raise
|
58
|
+
raise 'Form field rendering not implemented for this Tag'
|
60
59
|
end
|
61
60
|
|
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
|
@@ -17,9 +16,9 @@ class Occams::Content::Tag::Helper < Occams::Content::Tag
|
|
17
16
|
super
|
18
17
|
@method_name = params.shift
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
return if @method_name.present?
|
20
|
+
|
21
|
+
raise Error, 'Missing method name for helper tag'
|
23
22
|
end
|
24
23
|
|
25
24
|
# we output erb into rest of the content
|
@@ -31,11 +30,11 @@ class Occams::Content::Tag::Helper < Occams::Content::Tag
|
|
31
30
|
helper_params = params.map do |p|
|
32
31
|
case p
|
33
32
|
when Hash
|
34
|
-
format(
|
33
|
+
format('%<arg>s', arg: p)
|
35
34
|
else
|
36
|
-
format(
|
35
|
+
format('%<arg>p', arg: p)
|
37
36
|
end
|
38
|
-
end.join(
|
37
|
+
end.join(',')
|
39
38
|
"<%= #{method_name}(#{helper_params}) %>"
|
40
39
|
end
|
41
40
|
|
@@ -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,19 +4,17 @@
|
|
4
4
|
# {{ cms:markdown identifier }}
|
5
5
|
#
|
6
6
|
class Occams::Content::Tag::Markdown < Occams::Content::Tag::Fragment
|
7
|
-
|
8
7
|
def render
|
9
|
-
renderable ? Kramdown::Document.new(content.to_s).to_html :
|
8
|
+
renderable ? Kramdown::Document.new(content.to_s).to_html : ''
|
10
9
|
end
|
11
10
|
|
12
11
|
def form_field(object_name, view, index)
|
13
12
|
name = "#{object_name}[fragments_attributes][#{index}][content]"
|
14
|
-
options = { id: form_field_id, data: {
|
13
|
+
options = { id: form_field_id, data: { 'cms-cm-mode' => 'text/x-markdown' } }
|
15
14
|
input = view.send(:text_area_tag, name, content, options)
|
16
15
|
|
17
16
|
yield input
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
|
22
20
|
Occams::Content::Renderer.register_tag(
|
@@ -3,14 +3,13 @@
|
|
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
|
10
9
|
# @param [String] label alt text for `as: "image"`, link text for `as: "link"`
|
11
10
|
# @return [String]
|
12
11
|
def content(file: self.file, as: self.as, variant_attrs: self.variant_attrs, label: self.label)
|
13
|
-
return
|
12
|
+
return '' unless file
|
14
13
|
|
15
14
|
url_helpers = Rails.application.routes.url_helpers
|
16
15
|
|
@@ -23,9 +22,9 @@ module Occams::Content::Tag::Mixins
|
|
23
22
|
end
|
24
23
|
|
25
24
|
case as
|
26
|
-
when
|
25
|
+
when 'link'
|
27
26
|
"<a href='#{attachment_url}'#{html_class_attribute} target='_blank'>#{label}</a>"
|
28
|
-
when
|
27
|
+
when 'image'
|
29
28
|
"<img src='#{attachment_url}'#{html_class_attribute} alt='#{label}'/>"
|
30
29
|
else
|
31
30
|
attachment_url
|
@@ -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,15 +4,13 @@
|
|
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
|
-
options = { id: form_field_id, class:
|
9
|
+
options = { id: form_field_id, class: 'form-control' }
|
11
10
|
input = view.send(:number_field_tag, name, content, options)
|
12
11
|
|
13
12
|
yield input
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
17
15
|
|
18
16
|
Occams::Content::Renderer.register_tag(
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
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
|
#
|
@@ -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.
|
@@ -44,14 +43,14 @@ class Occams::Content::Tag::PageFileLink < Occams::Content::Tag
|
|
44
43
|
|
45
44
|
options = params.extract_options!
|
46
45
|
@identifier = params[0]
|
47
|
-
@as = options[
|
48
|
-
@class = options[
|
49
|
-
@variant_attrs = options.slice(
|
50
|
-
@filename = options[
|
46
|
+
@as = options['as'] || 'url'
|
47
|
+
@class = options['class']
|
48
|
+
@variant_attrs = options.slice('resize', 'gravity', 'crop')
|
49
|
+
@filename = options['filename']
|
50
|
+
|
51
|
+
return if @identifier.present?
|
51
52
|
|
52
|
-
|
53
|
-
raise Error, "Missing identifier for page file link tag"
|
54
|
-
end
|
53
|
+
raise Error, 'Missing identifier for page file link tag'
|
55
54
|
end
|
56
55
|
|
57
56
|
# @return [Occams::Cms::Fragment]
|
@@ -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(
|