editmode 1.1.5 → 1.1.6
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/lib/editmode/action_view_extensions/editmode_helper.rb +38 -11
- 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: 834e252dd5d068562b8541a091e972404d759a2ae8cf9d80bedf33bdca22c167
|
4
|
+
data.tar.gz: bd7d10b6264e1ddca7e219587a7c08956b3a3ff8b1636ff18c6afc0aa70f8cfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d87b5770f58dbc06f88bece3d32f966c3ba211b537c4a3050fe72513875016cdd3898c0aeb213136595a29b5be0987d9d34bd6189d967403301c8ef7999fc2b1
|
7
|
+
data.tar.gz: 793c609415a18dc4ff89f08037754b470356fe0f6cb5edf5dc680cbb8e3f934f56bd9cbd1c540112e382f1a93e6e0f798c1e21a17658f386addc0e9fe06d3f24
|
@@ -67,7 +67,11 @@ module Editmode
|
|
67
67
|
def chunk_field_value(parent_chunk_object, custom_field_identifier, options = {})
|
68
68
|
begin
|
69
69
|
chunk_identifier = parent_chunk_object["identifier"]
|
70
|
-
custom_field_item = parent_chunk_object["content"].detect
|
70
|
+
custom_field_item = parent_chunk_object["content"].detect do |f|
|
71
|
+
f["custom_field_identifier"].try(:downcase) == custom_field_identifier.try(:downcase) || f["custom_field_name"].try(:downcase) == custom_field_identifier.try(:downcase)
|
72
|
+
end
|
73
|
+
|
74
|
+
options[:field] = custom_field_identifier
|
71
75
|
|
72
76
|
if custom_field_item.present?
|
73
77
|
render_chunk_content(
|
@@ -88,6 +92,7 @@ module Editmode
|
|
88
92
|
begin
|
89
93
|
# Always sanitize the content!!
|
90
94
|
chunk_content = ActionController::Base.helpers.sanitize(chunk_content) unless chunk_type == 'rich_text'
|
95
|
+
chunk_content = variable_parse!(chunk_content, options[:variable_fallbacks], options[:variable_values])
|
91
96
|
|
92
97
|
css_class = options[:class]
|
93
98
|
|
@@ -102,7 +107,8 @@ module Editmode
|
|
102
107
|
if options[:parent_identifier].present?
|
103
108
|
chunk_data.merge!({parent_identifier: options[:parent_identifier]})
|
104
109
|
end
|
105
|
-
|
110
|
+
|
111
|
+
|
106
112
|
case display_type
|
107
113
|
when "span"
|
108
114
|
if chunk_type == "rich_text"
|
@@ -132,10 +138,11 @@ module Editmode
|
|
132
138
|
# prevent the page from loading.
|
133
139
|
begin
|
134
140
|
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
135
|
-
|
141
|
+
field = options[:field].presence || ""
|
142
|
+
cache_identifier = "chunk_#{identifier}#{branch_id}#{field}"
|
136
143
|
url = "#{api_root_url}/chunks/#{identifier}?project_id=#{Editmode.project_id}&#{branch_params}"
|
137
144
|
cached_content_present = Rails.cache.exist?(cache_identifier)
|
138
|
-
|
145
|
+
|
139
146
|
if !cached_content_present
|
140
147
|
response = HTTParty.get(url)
|
141
148
|
response_received = true if response.code == 200
|
@@ -144,15 +151,30 @@ module Editmode
|
|
144
151
|
if !cached_content_present && !response_received
|
145
152
|
raise "No response received"
|
146
153
|
else
|
147
|
-
|
154
|
+
if field.present? && response.present?
|
155
|
+
field_content = response["content"].detect {|f| f["custom_field_identifier"].downcase == field.downcase || f["custom_field_name"].downcase == field.downcase }
|
156
|
+
if field_content
|
157
|
+
content = field_content["content"]
|
158
|
+
type = field_content["chunk_type"]
|
159
|
+
identifier = field_content["identifier"]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
variable_fallbacks = Rails.cache.fetch("#{cache_identifier}_variables") do
|
164
|
+
response['variable_fallbacks'].presence || {}
|
165
|
+
end
|
166
|
+
|
148
167
|
chunk_content = Rails.cache.fetch(cache_identifier) do
|
149
|
-
response[
|
168
|
+
content.presence || response["content"]
|
150
169
|
end
|
151
170
|
|
152
171
|
chunk_type = Rails.cache.fetch("#{cache_identifier}_type") do
|
153
|
-
response['chunk_type']
|
172
|
+
type.presence || response['chunk_type']
|
154
173
|
end
|
155
174
|
|
175
|
+
options[:variable_fallbacks] = variable_fallbacks
|
176
|
+
options[:variable_values] = options[:variables]
|
177
|
+
|
156
178
|
render_chunk_content(identifier,chunk_content,chunk_type, options)
|
157
179
|
|
158
180
|
end
|
@@ -168,18 +190,23 @@ module Editmode
|
|
168
190
|
alias_method :chunk, :chunk_display
|
169
191
|
|
170
192
|
|
171
|
-
def render_custom_field(
|
172
|
-
|
193
|
+
def render_custom_field(field_name, options={})
|
194
|
+
options[:variable_fallbacks] = @custom_field_chunk["variable_fallbacks"] || {}
|
195
|
+
options[:variable_values] = options[:variables] || {}
|
196
|
+
|
197
|
+
chunk_field_value(@custom_field_chunk, field_name, options)
|
173
198
|
end
|
174
199
|
alias_method :F, :render_custom_field
|
175
200
|
|
176
|
-
def render_chunk(identifier,
|
201
|
+
def render_chunk(identifier, *args, &block)
|
202
|
+
field, options = parse_arguments(args)
|
203
|
+
options[:field] = field
|
177
204
|
chunk_display('label', identifier, options, &block)
|
178
205
|
end
|
179
206
|
alias_method :E, :render_chunk
|
180
207
|
|
181
208
|
|
182
|
-
def variable_parse!(content, variables, values)
|
209
|
+
def variable_parse!(content, variables = {}, values = {})
|
183
210
|
tokens = content.scan(/\{{(.*?)\}}/)
|
184
211
|
if tokens.any?
|
185
212
|
tokens.flatten!
|
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.1.
|
4
|
+
version: 1.1.6
|
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-09-
|
11
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|