editmode 0.0.10.14 → 1.0.21
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 +19 -16
- 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: 452e72be1c8aa82c61d586889928894d5449f69cfdaa11f80d7b6305982aa8df
|
4
|
+
data.tar.gz: 93ea8e03602162ebf4c3676e272b8febc7dfbfcd77f461847f719f9da8b9d287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a892994c140a9dc97d37b7a1bfad68698ae7a241c00483fc81a0d7c3f2698fb27458bacc8dcf067586d8dbe058758305a7ee8bbea6fe11f2ef09edd398f0df6
|
7
|
+
data.tar.gz: f9b9acb5b89db4c5b707a674aef1e49f6ed3cad428bf37d7b2de055d72b27c436e15fa568bbd024835687f60ff196f127075c3fa4ef00c2b2a7a98f0625aa76e
|
data/lib/editmode.rb
CHANGED
@@ -14,23 +14,26 @@ module Editmode
|
|
14
14
|
|
15
15
|
def chunk_collection(collection_identifier, **options)
|
16
16
|
branch_params = params[:em_branch_id].present? ? "branch_id=#{params[:em_branch_id]}" : ""
|
17
|
-
|
17
|
+
branch_id = params[:em_branch_id].presence
|
18
|
+
tags = options[:tags].presence || []
|
19
|
+
limit = options[:limit].presence
|
20
|
+
|
18
21
|
begin
|
19
|
-
|
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
|
+
|
20
33
|
response = HTTParty.get(url)
|
34
|
+
|
21
35
|
raise "No response received" unless response.code == 200
|
22
36
|
chunks = response["chunks"]
|
23
|
-
if chunks.any?
|
24
|
-
# Collection item limit
|
25
|
-
limit = options[:limit] || chunks.size
|
26
|
-
|
27
|
-
chunks = chunks.take(limit)
|
28
|
-
chunks.shuffle! if options[:shuffle]
|
29
|
-
end
|
30
|
-
|
31
|
-
if tags.any?
|
32
|
-
chunks.select!{|c| (tags - c['tags']).size < tags.size }
|
33
|
-
end
|
34
37
|
|
35
38
|
return chunks
|
36
39
|
rescue => error
|
@@ -74,7 +77,7 @@ module Editmode
|
|
74
77
|
display_type = options[:display_type] || "span"
|
75
78
|
end
|
76
79
|
|
77
|
-
chunk_data = { :chunk => chunk_identifier, :chunk_editable => false }
|
80
|
+
chunk_data = { :chunk => chunk_identifier, :chunk_editable => false, :chunk_type => chunk_type }
|
78
81
|
|
79
82
|
if options[:parent_identifier].present?
|
80
83
|
chunk_data.merge!({parent_identifier: options[:parent_identifier]})
|
@@ -83,7 +86,7 @@ module Editmode
|
|
83
86
|
case display_type
|
84
87
|
when "span"
|
85
88
|
if chunk_type == "rich_text"
|
86
|
-
content_tag("em-span", :class => css_class, :data => chunk_data ) do
|
89
|
+
content_tag("em-span", :class => "editmode-richtext-editor #{css_class}", :data => chunk_data.merge!({:chunk_editable => true}) ) do
|
87
90
|
chunk_content.html_safe
|
88
91
|
end
|
89
92
|
else
|
@@ -162,7 +165,7 @@ module Editmode
|
|
162
165
|
end
|
163
166
|
|
164
167
|
def no_response_received(id = "")
|
165
|
-
"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."
|
166
169
|
end
|
167
170
|
|
168
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.21
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|