editmode 1.1.6 → 1.2.1

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: 834e252dd5d068562b8541a091e972404d759a2ae8cf9d80bedf33bdca22c167
4
- data.tar.gz: bd7d10b6264e1ddca7e219587a7c08956b3a3ff8b1636ff18c6afc0aa70f8cfa
3
+ metadata.gz: 64a20fe2b3a8ccf1cd1dafc516a2484b6f4ce6701ecdd2d4f2b8a431137959bd
4
+ data.tar.gz: 683549e7c9085dda0d1ef74ff7e2b142fa746372c1da288af5e154017b69b957
5
5
  SHA512:
6
- metadata.gz: d87b5770f58dbc06f88bece3d32f966c3ba211b537c4a3050fe72513875016cdd3898c0aeb213136595a29b5be0987d9d34bd6189d967403301c8ef7999fc2b1
7
- data.tar.gz: 793c609415a18dc4ff89f08037754b470356fe0f6cb5edf5dc680cbb8e3f934f56bd9cbd1c540112e382f1a93e6e0f798c1e21a17658f386addc0e9fe06d3f24
6
+ metadata.gz: 92953c97a18f6fb3b91389f4beab95ffc75f92bf91e4a603094a016c6673724c49442a46643259b0e9a9c4b48c855f9821eee7e19b7801cf2fca2b1d8c2cce4b
7
+ data.tar.gz: 3763c6e47edd0cd6c326a7cc80a0583b20d3a9db66d652b3416c643548a3356e45896846ea321b4a63f3b605e07a6f1df3dc6b8f070b63939d5b6b86fbb3c2a6
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 |chunk| %>
83
- <div class="user-profile">
84
- <h3 class="name">
85
- <%= F("Name") %>
86
- </h3>
87
- <p class="description">
88
- <%= f("Description") %>
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.delete("chunk_#{params[:identifier]}")
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"}
@@ -36,7 +36,7 @@ module Editmode
36
36
  begin
37
37
  Editmode::ChunkValue.new(identifier, **options )
38
38
  rescue => er
39
- raise er
39
+ puts er
40
40
  end
41
41
  end
42
42
  end
@@ -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
- yield
58
+ concat(content_tag(:div, class: "chunks-collection-item--wrapper #{item_class}") do
59
+ yield
60
+ end)
56
61
  end
57
- end
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, "&nbsp".html_safe)
58
71
  end
59
72
  end
60
73
  rescue => error
@@ -73,12 +86,17 @@ module Editmode
73
86
 
74
87
  options[:field] = custom_field_identifier
75
88
 
89
+ if parent_chunk_object[:placeholder]
90
+ custom_field_item["identifier"] = ""
91
+ custom_field_item["content"] = ""
92
+ end
93
+
76
94
  if custom_field_item.present?
77
95
  render_chunk_content(
78
96
  custom_field_item["identifier"],
79
97
  custom_field_item["content"],
80
98
  custom_field_item["chunk_type"],
81
- { parent_identifier: chunk_identifier }.merge(options)
99
+ { parent_identifier: chunk_identifier, custom_field_identifier: custom_field_identifier}.merge(options)
82
100
  )
83
101
  end
84
102
  rescue => errors
@@ -95,6 +113,7 @@ module Editmode
95
113
  chunk_content = variable_parse!(chunk_content, options[:variable_fallbacks], options[:variable_values])
96
114
 
97
115
  css_class = options[:class]
116
+ cache_id = options[:cache_identifier]
98
117
 
99
118
  if chunk_type == "image"
100
119
  display_type = "image"
@@ -104,11 +123,10 @@ module Editmode
104
123
 
105
124
  chunk_data = { :chunk => chunk_identifier, :chunk_editable => false, :chunk_type => chunk_type }
106
125
 
107
- if options[:parent_identifier].present?
108
- chunk_data.merge!({parent_identifier: options[:parent_identifier]})
109
- end
110
-
111
-
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?
129
+
112
130
  case display_type
113
131
  when "span"
114
132
  if chunk_type == "rich_text"
@@ -117,10 +135,11 @@ module Editmode
117
135
  end
118
136
  else
119
137
  content_tag("em-span", :class => css_class, :data => chunk_data.merge!({:chunk_editable => true}) ) do
120
- chunk_content
138
+ chunk_content.html_safe
121
139
  end
122
140
  end
123
141
  when "image"
142
+ chunk_content = chunk_content.blank? || chunk_content == "/images/original/missing.png" ? 'https://www.editmode.com/upload.png' : chunk_content
124
143
  image_tag(chunk_content, :data => chunk_data, :class => css_class)
125
144
  end
126
145
  rescue => errors
@@ -142,7 +161,7 @@ module Editmode
142
161
  cache_identifier = "chunk_#{identifier}#{branch_id}#{field}"
143
162
  url = "#{api_root_url}/chunks/#{identifier}?project_id=#{Editmode.project_id}&#{branch_params}"
144
163
  cached_content_present = Rails.cache.exist?(cache_identifier)
145
-
164
+ parent_identifier = identifier if field.present?
146
165
  if !cached_content_present
147
166
  response = HTTParty.get(url)
148
167
  response_received = true if response.code == 200
@@ -156,7 +175,9 @@ module Editmode
156
175
  if field_content
157
176
  content = field_content["content"]
158
177
  type = field_content["chunk_type"]
159
- identifier = field_content["identifier"]
178
+ identifier = Rails.cache.fetch("#{cache_identifier}_field_identifier") do
179
+ field_content["identifier"]
180
+ end
160
181
  end
161
182
  end
162
183
 
@@ -172,11 +193,16 @@ module Editmode
172
193
  type.presence || response['chunk_type']
173
194
  end
174
195
 
196
+ identifier = Rails.cache.fetch("#{cache_identifier}_field_identifier") do
197
+ identifier
198
+ end
199
+
175
200
  options[:variable_fallbacks] = variable_fallbacks
176
- options[:variable_values] = options[:variables]
201
+ options[:variable_values] = options[:variables].presence || {}
202
+
203
+ options[:cache_identifier] = parent_identifier.presence || identifier
177
204
 
178
205
  render_chunk_content(identifier,chunk_content,chunk_type, options)
179
-
180
206
  end
181
207
 
182
208
  rescue => error
@@ -206,7 +232,7 @@ module Editmode
206
232
  alias_method :E, :render_chunk
207
233
 
208
234
 
209
- def variable_parse!(content, variables = {}, values = {})
235
+ def variable_parse!(content, variables = {}, values = {}, raw = false)
210
236
  tokens = content.scan(/\{{(.*?)\}}/)
211
237
  if tokens.any?
212
238
  tokens.flatten!
@@ -214,6 +240,12 @@ module Editmode
214
240
  token_value = values[token.to_sym] || variables[token] || ""
215
241
  sanitized_value = ActionController::Base.helpers.sanitize(token_value)
216
242
 
243
+ unless raw
244
+ sanitized_value = content_tag("em-var", :data => {chunk_variable: token, chunk_variable_value: sanitized_value}) do
245
+ sanitized_value
246
+ end
247
+ end
248
+
217
249
  content.gsub!("{{#{token}}}", sanitized_value)
218
250
  end
219
251
  end
@@ -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?
@@ -23,7 +23,7 @@ module Editmode
23
23
  field_content = @content.detect {|f| f["custom_field_identifier"].downcase == field || f["custom_field_name"].downcase == field }
24
24
  if field_content.present?
25
25
  result = field_content['content']
26
- result = variable_parse!(result, variable_fallbacks, variable_values)
26
+ result = variable_parse!(result, variable_fallbacks, variable_values, true)
27
27
  else
28
28
  raise no_response_received(field)
29
29
  end
@@ -31,15 +31,17 @@ module Editmode
31
31
  raise require_field_id
32
32
  end
33
33
  else
34
- raise NoMethodError.new "undefined method 'field` for chunk_type: #{chunk_type} \n"
34
+ raise "undefined method 'field` for chunk_type: #{chunk_type} \n"
35
35
  end
36
- result || @content
36
+ result ||= @content
37
+ result.try(:html_safe)
37
38
  end
38
39
 
39
40
  def content
40
- raise NoMethodError.new "undefined method 'content` for chunk_type: collection_item \nDid you mean? field" if chunk_type == 'collection_item'
41
+ raise "undefined method 'content` for chunk_type: collection_item \nDid you mean? field" if chunk_type == 'collection_item'
41
42
 
42
- variable_parse!(@content, variable_fallbacks, variable_values)
43
+ result = variable_parse!(@content, variable_fallbacks, variable_values, true)
44
+ result.try(:html_safe)
43
45
  end
44
46
 
45
47
  private
@@ -75,7 +77,7 @@ module Editmode
75
77
  @content = response['content']
76
78
  @chunk_type = response['chunk_type']
77
79
  @project_id = response['project_id']
78
- @variable_fallbacks = response['variable_fallbacks']
80
+ @variable_fallbacks = response['variable_fallbacks'].presence || {}
79
81
  end
80
82
  end
81
83
 
@@ -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
- raise er
15
+ puts er
16
16
  end
17
17
  end
18
18
 
@@ -1,3 +1,3 @@
1
1
  module Editmode
2
- VERSION = "1.1.6"
2
+ VERSION = "1.2.1"
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: 1.1.6
4
+ version: 1.2.1
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-30 00:00:00.000000000 Z
11
+ date: 2020-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler