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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e17da0620f2d013a83300d7984ace6b9badd0716bc3187b1125fe7497e8c99a0
4
- data.tar.gz: 39e552edd8fc95c2ba238b0fe7575432603b4e6f7e7e46328c5ff5836987ce31
3
+ metadata.gz: 4ae0438c959f508fa801802027178522476c93f3f4484f48693ecbc2719d879a
4
+ data.tar.gz: 3cc41e671a7c2c21b4a37b324163ff24494ca88d6381b1779aee14fc79386594
5
5
  SHA512:
6
- metadata.gz: ff2bd59f92ff2389577e23888d092f1097daebc95e4f6e8cd56c3ce5df1e2dd6221705849301a0b6865a3fac8709530d6198d4a04137e9496720bac6b715f376
7
- data.tar.gz: 69e56b6950e2e8c2f1907b7fd4a2c9626cf5b4777ddceadc720a002efbc15d1a6b3ae041117841e7b8c3351c3af825d12fcd558345ac5a8d49e53e727caf235d
6
+ metadata.gz: a1fa2d9118f2d4e9e47aedb3ec0b65dd0c88a5cc3becd945414103380de431f34b0010531fe64a23cc32b39e52bba0d57fef0e2b80cf406402b552c388c5924f
7
+ data.tar.gz: 329caa75d6c8a8fe11fabaf5d3a7a182da3b6112e04dd4831a5f96fb7f28c7125b3250144ab0a5b60bd59187353566bd28c656007f625c66437366dd92971389
@@ -33,7 +33,6 @@ module Editmode
33
33
 
34
34
  def chunk_value(identifier, **options)
35
35
  begin
36
- options.merge!(project_id: project_id)
37
36
  Editmode::ChunkValue.new(identifier, **options )
38
37
  rescue => er
39
38
  raise er
@@ -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,has_tags=[])
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
- url = "#{api_root_url}/chunks?collection_identifier=#{collection_identifier}&#{branch_params}"
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[:css_class]
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 content using this identifier: \"#{id}\""
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
@@ -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
- field_content = content.detect {|f| f["custom_field_identifier"] == field || f["custom_field_name"] == field }
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 = "chunk_#{identifier}#{branch_id}"
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
- response = HTTParty.get(url)
48
- response_received = true if response.code == 200
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
- @content = Rails.cache.fetch(cache_identifier) do
55
- response['content']
53
+ @response = Rails.cache.fetch(cache_identifier) do
54
+ http_response
56
55
  end
57
56
 
58
- @chunk_type = Rails.cache.fetch("#{cache_identifier}_type") do
59
- response['chunk_type']
60
- end
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
@@ -1,3 +1,3 @@
1
1
  module Editmode
2
- VERSION = "0.0.10.12"
2
+ VERSION = "1.0.18"
3
3
  end
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: 0.0.10.12
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-06-25 00:00:00.000000000 Z
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler