editmode 1.1.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -10
- data/app/controllers/editmode_controller.rb +1 -2
- data/lib/editmode.rb +1 -1
- data/lib/editmode/action_view_extensions/editmode_helper.rb +71 -17
- data/lib/editmode/chunk_value.rb +4 -4
- data/lib/editmode/helper.rb +2 -2
- data/lib/editmode/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c56cee03d73400139003e5a7b643e5ba0cc87827dd8373f973e4e5bbbf41e234
|
4
|
+
data.tar.gz: 5cc247b0737cf3a34a7b7507895ff5b6b67d14363bd4ef328ab0630155ac8cd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 909f2860b00987679e572d4c7c3202fe208fc7cc99ae75df7b698e5371b97f90861f65598193a0882fd924ec653978c0547d57bdc66ec2ad76651b6d1358aff1
|
7
|
+
data.tar.gz: 6ccc29e44f1cd14ad281c182a78904f74a199b1b9fc22fe5cf7757753b24b3ac5eeb9a0db2098e34662b0e1448a49831e9bc99db7f78ff931485ae64cded024b
|
data/README.md
CHANGED
@@ -47,6 +47,7 @@ Editmode provides helper methods for use in your rails views and controllers.
|
|
47
47
|
```erb
|
48
48
|
<%= E('cnk_x4ts............') %> # Using a chunk identifier
|
49
49
|
<%= E('marketing_page_headline') %> # Using a content key
|
50
|
+
<%= E('cnk_x4ts...', class: "a-css-class") %> # Render a chunk with inline css class
|
50
51
|
```
|
51
52
|
|
52
53
|
### Content can also be accessed in Controllers
|
@@ -79,23 +80,23 @@ e("cnk_16e04a02d577afb610ce", "Email Content", variables: variable_values)
|
|
79
80
|
|
80
81
|
### Use collections for repeatable content
|
81
82
|
```erb
|
82
|
-
<%= c('col_j8fbs...') do
|
83
|
-
<
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
</p>
|
90
|
-
</div>
|
83
|
+
<%= c('col_j8fbs...', class: "profiles-container", item_class: "profile-item") do %>
|
84
|
+
<h3 class="name">
|
85
|
+
<%= F("Name", class: "profile-name") %>
|
86
|
+
</h3>
|
87
|
+
<p class="description">
|
88
|
+
<%= f("Description"), class: "profile-description" %>
|
89
|
+
</p>
|
91
90
|
<% end %>
|
92
91
|
```
|
93
92
|
|
94
93
|
|Parameter|Type|Description|
|
95
94
|
|---|---|---|
|
96
95
|
| identifier | string | The first argument of `c` takes the id of the collection you want to loop through |
|
97
|
-
| limit | int |`optional` The number of collection items you want to display |
|
96
|
+
| limit | int/string |`optional` The number of collection items you want to display |
|
98
97
|
| tags | array |`optional` Filter collection items based on tags listed in this parameter |
|
98
|
+
| class | string | `optional` Class name(s) that will be added along with "chunks-collection-wrapper" to the main collection `<div>` element |
|
99
|
+
| item_class | string | `optional` Class name(s) that will be added along with "chunks-collection-item--wrapper" to all collection items |
|
99
100
|
|
100
101
|
|
101
102
|
## Caching
|
@@ -13,8 +13,7 @@ class EditmodeController < ApplicationController
|
|
13
13
|
Rails.cache.delete("chunk_#{project_id}_variables")
|
14
14
|
render status: 200, json: {:response => "success"}
|
15
15
|
elsif params[:identifier]
|
16
|
-
Rails.cache.
|
17
|
-
Rails.cache.delete("chunk_#{params[:identifier]}_type")
|
16
|
+
Rails.cache.delete_matched("#{params[:identifier]}")
|
18
17
|
render status: 200, json: {:response => "success"}
|
19
18
|
else
|
20
19
|
render status: 404, json: {:response => "no identifier specified"}
|
data/lib/editmode.rb
CHANGED
@@ -19,6 +19,9 @@ module Editmode
|
|
19
19
|
branch_id = params[:em_branch_id].presence
|
20
20
|
tags = options[:tags].presence || []
|
21
21
|
limit = options[:limit].presence
|
22
|
+
|
23
|
+
parent_class = options[:class] || ""
|
24
|
+
item_class = options[:item_class] || ""
|
22
25
|
|
23
26
|
begin
|
24
27
|
url_params = {
|
@@ -49,12 +52,22 @@ module Editmode
|
|
49
52
|
end
|
50
53
|
|
51
54
|
if chunks.any?
|
52
|
-
content_tag :div, class: "chunks-collection-wrapper", data: {chunk_collection_identifier: collection_identifier} do
|
55
|
+
content_tag :div, class: "chunks-collection-wrapper #{parent_class}", data: {chunk_collection_identifier: collection_identifier} do
|
53
56
|
chunks.each do |chunk|
|
54
57
|
@custom_field_chunk = chunk
|
55
|
-
|
58
|
+
concat(content_tag(:div, class: "chunks-collection-item--wrapper #{item_class}") do
|
59
|
+
yield
|
60
|
+
end)
|
56
61
|
end
|
57
|
-
|
62
|
+
|
63
|
+
# Placeholder element for new collection item
|
64
|
+
@custom_field_chunk = chunks.first.merge!({placeholder: true})
|
65
|
+
concat(content_tag(:div, class: "chunks-hide chunks-col-placeholder-wrapper") do
|
66
|
+
yield
|
67
|
+
end)
|
68
|
+
end
|
69
|
+
else
|
70
|
+
content_tag(:span, " ".html_safe)
|
58
71
|
end
|
59
72
|
end
|
60
73
|
rescue => error
|
@@ -67,14 +80,23 @@ module Editmode
|
|
67
80
|
def chunk_field_value(parent_chunk_object, custom_field_identifier, options = {})
|
68
81
|
begin
|
69
82
|
chunk_identifier = parent_chunk_object["identifier"]
|
70
|
-
custom_field_item = parent_chunk_object["content"].detect
|
83
|
+
custom_field_item = parent_chunk_object["content"].detect do |f|
|
84
|
+
f["custom_field_identifier"].try(:downcase) == custom_field_identifier.try(:downcase) || f["custom_field_name"].try(:downcase) == custom_field_identifier.try(:downcase)
|
85
|
+
end
|
86
|
+
|
87
|
+
options[:field] = custom_field_identifier
|
71
88
|
|
89
|
+
if parent_chunk_object[:placeholder]
|
90
|
+
custom_field_item["identifier"] = ""
|
91
|
+
custom_field_item["content"] = ""
|
92
|
+
end
|
93
|
+
|
72
94
|
if custom_field_item.present?
|
73
95
|
render_chunk_content(
|
74
96
|
custom_field_item["identifier"],
|
75
97
|
custom_field_item["content"],
|
76
98
|
custom_field_item["chunk_type"],
|
77
|
-
{ parent_identifier: chunk_identifier }.merge(options)
|
99
|
+
{ parent_identifier: chunk_identifier, custom_field_identifier: custom_field_identifier}.merge(options)
|
78
100
|
)
|
79
101
|
end
|
80
102
|
rescue => errors
|
@@ -88,8 +110,10 @@ module Editmode
|
|
88
110
|
begin
|
89
111
|
# Always sanitize the content!!
|
90
112
|
chunk_content = ActionController::Base.helpers.sanitize(chunk_content) unless chunk_type == 'rich_text'
|
113
|
+
chunk_content = variable_parse!(chunk_content, options[:variable_fallbacks], options[:variable_values])
|
91
114
|
|
92
115
|
css_class = options[:class]
|
116
|
+
cache_id = options[:cache_identifier]
|
93
117
|
|
94
118
|
if chunk_type == "image"
|
95
119
|
display_type = "image"
|
@@ -99,9 +123,9 @@ module Editmode
|
|
99
123
|
|
100
124
|
chunk_data = { :chunk => chunk_identifier, :chunk_editable => false, :chunk_type => chunk_type }
|
101
125
|
|
102
|
-
if options[:parent_identifier].present?
|
103
|
-
|
104
|
-
|
126
|
+
chunk_data.merge!({parent_identifier: options[:parent_identifier]}) if options[:parent_identifier].present?
|
127
|
+
chunk_data.merge!({custom_field_identifier: options[:custom_field_identifier]}) if options[:custom_field_identifier].present?
|
128
|
+
chunk_data.merge!({chunk_cache_id: cache_id}) if cache_id.present?
|
105
129
|
|
106
130
|
case display_type
|
107
131
|
when "span"
|
@@ -115,6 +139,7 @@ module Editmode
|
|
115
139
|
end
|
116
140
|
end
|
117
141
|
when "image"
|
142
|
+
chunk_content = chunk_content.blank? || chunk_content == "/images/original/missing.png" ? 'https://www.editmode.com/upload.png' : chunk_content
|
118
143
|
image_tag(chunk_content, :data => chunk_data, :class => css_class)
|
119
144
|
end
|
120
145
|
rescue => errors
|
@@ -132,9 +157,11 @@ module Editmode
|
|
132
157
|
# prevent the page from loading.
|
133
158
|
begin
|
134
159
|
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
135
|
-
|
160
|
+
field = options[:field].presence || ""
|
161
|
+
cache_identifier = "chunk_#{identifier}#{branch_id}#{field}"
|
136
162
|
url = "#{api_root_url}/chunks/#{identifier}?project_id=#{Editmode.project_id}&#{branch_params}"
|
137
163
|
cached_content_present = Rails.cache.exist?(cache_identifier)
|
164
|
+
parent_identifier = identifier if field.present?
|
138
165
|
|
139
166
|
if !cached_content_present
|
140
167
|
response = HTTParty.get(url)
|
@@ -144,17 +171,39 @@ module Editmode
|
|
144
171
|
if !cached_content_present && !response_received
|
145
172
|
raise "No response received"
|
146
173
|
else
|
147
|
-
|
174
|
+
if field.present? && response.present?
|
175
|
+
field_content = response["content"].detect {|f| f["custom_field_identifier"].downcase == field.downcase || f["custom_field_name"].downcase == field.downcase }
|
176
|
+
if field_content
|
177
|
+
content = field_content["content"]
|
178
|
+
type = field_content["chunk_type"]
|
179
|
+
identifier = Rails.cache.fetch("#{cache_identifier}_field_identifier") do
|
180
|
+
field_content["identifier"]
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
variable_fallbacks = Rails.cache.fetch("#{cache_identifier}_variables") do
|
186
|
+
response['variable_fallbacks'].presence || {}
|
187
|
+
end
|
188
|
+
|
148
189
|
chunk_content = Rails.cache.fetch(cache_identifier) do
|
149
|
-
response[
|
190
|
+
content.presence || response["content"]
|
150
191
|
end
|
151
192
|
|
152
193
|
chunk_type = Rails.cache.fetch("#{cache_identifier}_type") do
|
153
|
-
response['chunk_type']
|
194
|
+
type.presence || response['chunk_type']
|
154
195
|
end
|
155
196
|
|
156
|
-
|
197
|
+
identifier = Rails.cache.fetch("#{cache_identifier}_field_identifier") do
|
198
|
+
identifier
|
199
|
+
end
|
157
200
|
|
201
|
+
options[:variable_fallbacks] = variable_fallbacks
|
202
|
+
options[:variable_values] = options[:variables].presence || {}
|
203
|
+
|
204
|
+
options[:cache_identifier] = parent_identifier.presence || identifier
|
205
|
+
|
206
|
+
render_chunk_content(identifier,chunk_content,chunk_type, options)
|
158
207
|
end
|
159
208
|
|
160
209
|
rescue => error
|
@@ -168,18 +217,23 @@ module Editmode
|
|
168
217
|
alias_method :chunk, :chunk_display
|
169
218
|
|
170
219
|
|
171
|
-
def render_custom_field(
|
172
|
-
|
220
|
+
def render_custom_field(field_name, options={})
|
221
|
+
options[:variable_fallbacks] = @custom_field_chunk["variable_fallbacks"] || {}
|
222
|
+
options[:variable_values] = options[:variables] || {}
|
223
|
+
|
224
|
+
chunk_field_value(@custom_field_chunk, field_name, options)
|
173
225
|
end
|
174
226
|
alias_method :F, :render_custom_field
|
175
227
|
|
176
|
-
def render_chunk(identifier,
|
228
|
+
def render_chunk(identifier, *args, &block)
|
229
|
+
field, options = parse_arguments(args)
|
230
|
+
options[:field] = field
|
177
231
|
chunk_display('label', identifier, options, &block)
|
178
232
|
end
|
179
233
|
alias_method :E, :render_chunk
|
180
234
|
|
181
235
|
|
182
|
-
def variable_parse!(content, variables, values)
|
236
|
+
def variable_parse!(content, variables = {}, values = {})
|
183
237
|
tokens = content.scan(/\{{(.*?)\}}/)
|
184
238
|
if tokens.any?
|
185
239
|
tokens.flatten!
|
data/lib/editmode/chunk_value.rb
CHANGED
@@ -15,7 +15,7 @@ module Editmode
|
|
15
15
|
get_content
|
16
16
|
end
|
17
17
|
|
18
|
-
def field(field = nil)
|
18
|
+
def field(field = nil)
|
19
19
|
# Field ID can be a slug or field_name
|
20
20
|
if chunk_type == 'collection_item'
|
21
21
|
if field.present?
|
@@ -31,13 +31,13 @@ module Editmode
|
|
31
31
|
raise require_field_id
|
32
32
|
end
|
33
33
|
else
|
34
|
-
raise
|
34
|
+
raise "undefined method 'field` for chunk_type: #{chunk_type} \n"
|
35
35
|
end
|
36
36
|
result || @content
|
37
37
|
end
|
38
38
|
|
39
39
|
def content
|
40
|
-
raise
|
40
|
+
raise "undefined method 'content` for chunk_type: collection_item \nDid you mean? field" if chunk_type == 'collection_item'
|
41
41
|
|
42
42
|
variable_parse!(@content, variable_fallbacks, variable_values)
|
43
43
|
end
|
@@ -75,7 +75,7 @@ module Editmode
|
|
75
75
|
@content = response['content']
|
76
76
|
@chunk_type = response['chunk_type']
|
77
77
|
@project_id = response['project_id']
|
78
|
-
@variable_fallbacks = response['variable_fallbacks']
|
78
|
+
@variable_fallbacks = response['variable_fallbacks'].presence || {}
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
data/lib/editmode/helper.rb
CHANGED
@@ -5,14 +5,14 @@ module Editmode
|
|
5
5
|
field, options = parse_arguments(args)
|
6
6
|
begin
|
7
7
|
chunk = Editmode::ChunkValue.new(identifier, options)
|
8
|
-
|
8
|
+
|
9
9
|
if chunk.chunk_type == 'collection_item'
|
10
10
|
chunk.field(field)
|
11
11
|
else
|
12
12
|
chunk.content
|
13
13
|
end
|
14
14
|
rescue => er
|
15
|
-
|
15
|
+
puts er
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/lib/editmode/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: editmode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Ennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|