editmode 0.0.10.12 → 1.0.18
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.rb +0 -1
- data/lib/editmode/action_view_extensions/editmode_helper.rb +21 -5
- data/lib/editmode/chunk_value.rb +11 -15
- 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: 4ae0438c959f508fa801802027178522476c93f3f4484f48693ecbc2719d879a
|
4
|
+
data.tar.gz: 3cc41e671a7c2c21b4a37b324163ff24494ca88d6381b1779aee14fc79386594
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1fa2d9118f2d4e9e47aedb3ec0b65dd0c88a5cc3becd945414103380de431f34b0010531fe64a23cc32b39e52bba0d57fef0e2b80cf406402b552c388c5924f
|
7
|
+
data.tar.gz: 329caa75d6c8a8fe11fabaf5d3a7a182da3b6112e04dd4831a5f96fb7f28c7125b3250144ab0a5b60bd59187353566bd28c656007f625c66437366dd92971389
|
data/lib/editmode.rb
CHANGED
@@ -12,13 +12,29 @@ module Editmode
|
|
12
12
|
ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
|
13
13
|
end
|
14
14
|
|
15
|
-
def chunk_collection(collection_identifier,
|
15
|
+
def chunk_collection(collection_identifier, **options)
|
16
16
|
branch_params = params[:em_branch_id].present? ? "branch_id=#{params[:em_branch_id]}" : ""
|
17
|
+
branch_id = params[:em_branch_id].presence
|
18
|
+
tags = options[:tags].presence || []
|
19
|
+
limit = options[:limit].presence
|
20
|
+
|
17
21
|
begin
|
18
|
-
|
22
|
+
url_params = {
|
23
|
+
:collection_identifier => collection_identifier,
|
24
|
+
:branch_id => branch_id,
|
25
|
+
:limit => limit,
|
26
|
+
:tags => tags
|
27
|
+
}.to_query
|
28
|
+
|
29
|
+
url = URI(api_root_url)
|
30
|
+
url.path = '/chunks'
|
31
|
+
url.query = url_params
|
32
|
+
|
19
33
|
response = HTTParty.get(url)
|
34
|
+
|
20
35
|
raise "No response received" unless response.code == 200
|
21
36
|
chunks = response["chunks"]
|
37
|
+
|
22
38
|
return chunks
|
23
39
|
rescue => error
|
24
40
|
puts error
|
@@ -53,7 +69,7 @@ module Editmode
|
|
53
69
|
# Always sanitize the content!!
|
54
70
|
chunk_content = ActionController::Base.helpers.sanitize(chunk_content)
|
55
71
|
|
56
|
-
css_class = options[:
|
72
|
+
css_class = options[:class]
|
57
73
|
|
58
74
|
if chunk_type == "image"
|
59
75
|
display_type = "image"
|
@@ -61,7 +77,7 @@ module Editmode
|
|
61
77
|
display_type = options[:display_type] || "span"
|
62
78
|
end
|
63
79
|
|
64
|
-
chunk_data = { :chunk => chunk_identifier, :chunk_editable => false }
|
80
|
+
chunk_data = { :chunk => chunk_identifier, :chunk_editable => false, :chunk_type => chunk_type }
|
65
81
|
|
66
82
|
if options[:parent_identifier].present?
|
67
83
|
chunk_data.merge!({parent_identifier: options[:parent_identifier]})
|
@@ -149,7 +165,7 @@ module Editmode
|
|
149
165
|
end
|
150
166
|
|
151
167
|
def no_response_received(id = "")
|
152
|
-
"Sorry, we can't find a
|
168
|
+
"Sorry, we can't find a chunk using this identifier: \"#{id}\". This can happen if you've deleted a chunk on editmode.com or if your local cache is out of date. If it persists, try running Rails.cache clear."
|
153
169
|
end
|
154
170
|
|
155
171
|
def require_field_id
|
data/lib/editmode/chunk_value.rb
CHANGED
@@ -4,12 +4,11 @@ module Editmode
|
|
4
4
|
|
5
5
|
attr_accessor :identifier, :variable_values, :branch_id,
|
6
6
|
:variable_fallbacks, :chunk_type, :project_id,
|
7
|
-
:content
|
7
|
+
:response, :content
|
8
8
|
|
9
9
|
def initialize(identifier, **options)
|
10
10
|
@identifier = identifier
|
11
11
|
@branch_id = options[:branch_id].presence
|
12
|
-
@project_id = options[:project_id].presence
|
13
12
|
@variable_values = options[:values].presence || {}
|
14
13
|
get_content
|
15
14
|
end
|
@@ -18,7 +17,8 @@ module Editmode
|
|
18
17
|
# Field ID can be a slug or field_name
|
19
18
|
if chunk_type == 'collection_item'
|
20
19
|
if field.present?
|
21
|
-
|
20
|
+
field.downcase!
|
21
|
+
field_content = content.detect {|f| f["custom_field_identifier"].downcase == field || f["custom_field_name"].downcase == field }
|
22
22
|
if field_content.present?
|
23
23
|
result = field_content['content']
|
24
24
|
result = variable_parse!(result, variable_fallbacks, variable_values)
|
@@ -39,28 +39,24 @@ module Editmode
|
|
39
39
|
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
40
40
|
url = "#{api_root_url}/chunks/#{identifier}?#{branch_params}"
|
41
41
|
|
42
|
-
cache_identifier = "
|
42
|
+
cache_identifier = "chunk_value_#{identifier}#{branch_id}"
|
43
43
|
cached_content_present = Rails.cache.exist?(cache_identifier)
|
44
|
-
cached_content_present = Rails.cache.exist?("chunk_#{project_id}_variables") if cached_content_present
|
45
44
|
|
46
45
|
if !cached_content_present
|
47
|
-
|
48
|
-
response_received = true if
|
46
|
+
http_response = HTTParty.get(url)
|
47
|
+
response_received = true if http_response.code == 200
|
49
48
|
end
|
50
49
|
|
51
50
|
if !cached_content_present && !response_received
|
52
51
|
raise no_response_received(identifier)
|
53
52
|
else
|
54
|
-
@
|
55
|
-
|
53
|
+
@response = Rails.cache.fetch(cache_identifier) do
|
54
|
+
http_response
|
56
55
|
end
|
57
56
|
|
58
|
-
@
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
# Since variables are defined in the project level,
|
63
|
-
# We use project_id as cache identifier
|
57
|
+
@content = response['content']
|
58
|
+
@chunk_type = response['chunk_type']
|
59
|
+
@project_id = response['project_id']
|
64
60
|
@variable_fallbacks = Rails.cache.fetch("chunk_#{project_id}_variables") do
|
65
61
|
response['variable_fallbacks']
|
66
62
|
end
|
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:
|
4
|
+
version: 1.0.18
|
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-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|