editmode 1.2.3 → 1.2.8

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: 78dda874aecacc9edfdf0e96598019e7dad8cc44693336d94511083238b55a91
4
- data.tar.gz: d111ab02c60c737e5711139473e7be988f02ffdb3a8ed01a7876174348bf5d83
3
+ metadata.gz: 68357d9af1673886733d966a8c6bad378f2f0a9242b810b9e61560ab8b793b75
4
+ data.tar.gz: d7f45153fe466bb03b68a7b1428cc245883fbd033a4a0e9e449133a14c4480d5
5
5
  SHA512:
6
- metadata.gz: e896421ca91061b25d28bc0ea217a2891df5f06d109b00301364ad67c3813caf2de47219f0be1b13ac335b6a8b76bcdaa5dc10b5ad4a9308722e90939613cbaf
7
- data.tar.gz: 9ad90b4008998f64e52cfe34c73c74db62633b468764f0939df16ffb4fbeb1a9acbbdee0acfe053e793ff66b316f9c8ecde7bb64544b81013828e61383995f69
6
+ metadata.gz: cf0d706724b4d3fd92b7e3926af60e491adc248b3ac1b36b1913f3bf22eac78e82e8967182b29c8ba86984a0c5ce8b3124fecce2b8695e79fca0b098c72d9d77
7
+ data.tar.gz: a2af19294f5625257a5d94239a16bbb68035863404c951f9aa1d2728d0e16e57071f00ac1cecc1c560950505e2b8c9552d802fd16dbaaf6312403cc8db8302aa
data/README.md CHANGED
@@ -50,6 +50,12 @@ Editmode provides helper methods for use in your rails views and controllers.
50
50
  <%= E('cnk_x4ts...', class: "a-css-class") %> # Render a chunk with inline css class
51
51
  ```
52
52
 
53
+ ### Working with multiple projects in the same codebase
54
+ If you want to include content from a different project to the one you've specified in the initializer, you can pass the project id in to the view helper.
55
+ ```erb
56
+ <%= E("cnk_16e04a02d577afb610ce", project_id: "prj_02d577afb617hdb") %>
57
+ ```
58
+
53
59
  ### Content can also be accessed in Controllers
54
60
  ```ruby
55
61
  @page_title = e("cnk_x4ts............") # Using a chunk identifier
@@ -78,6 +84,8 @@ e("cnk_16e04a02d577afb610ce", "Email Content", variables: variable_values)
78
84
  # Response: "Hi Dexter Morgan"
79
85
  ```
80
86
 
87
+
88
+
81
89
  ### Use collections for repeatable content
82
90
  ```erb
83
91
  <%= c('col_j8fbs...', class: "profiles-container", item_class: "profile-item") do %>
@@ -56,14 +56,14 @@ module Editmode
56
56
  chunks.each do |chunk|
57
57
  @custom_field_chunk = chunk
58
58
  concat(content_tag(:div, class: "chunks-collection-item--wrapper #{item_class}") do
59
- yield
59
+ yield(@custom_field_chunk)
60
60
  end)
61
61
  end
62
62
 
63
63
  # Placeholder element for new collection item
64
64
  @custom_field_chunk = chunks.first.merge!({placeholder: true})
65
65
  concat(content_tag(:div, class: "chunks-hide chunks-col-placeholder-wrapper") do
66
- yield
66
+ yield(@custom_field_chunk)
67
67
  end)
68
68
  end
69
69
  else
@@ -10,12 +10,14 @@ module Editmode
10
10
 
11
11
  attr_writer :content
12
12
 
13
- def initialize(identifier, **options)
13
+ def initialize(identifier, project_id: Editmode.project_id, **options)
14
14
  @identifier = identifier
15
15
  @branch_id = options[:branch_id].presence
16
- @project_id = Editmode.project_id
16
+ @project_id = project_id
17
17
  @variable_values = options[:variables].presence || {}
18
18
  @raw = options[:raw].present?
19
+ @skip_sanitize = options[:dangerously_skip_sanitization]
20
+ @skip_cache = options[:skip_cache]
19
21
 
20
22
  @url = "#{api_root_url}/chunks/#{identifier}"
21
23
  @cache_identifier = set_cache_identifier(identifier)
@@ -35,7 +37,7 @@ module Editmode
35
37
  field_chunk = field_chunk(field)
36
38
  if field_chunk.present?
37
39
  result = field_chunk['content']
38
- result = variable_parse!(result, variable_fallbacks, variable_values, @raw)
40
+ result = variable_parse!(result, variable_fallbacks, variable_values, @raw, @skip_sanitize)
39
41
  else
40
42
  raise no_response_received(field)
41
43
  end
@@ -57,7 +59,7 @@ module Editmode
57
59
  def content
58
60
  raise "undefined method 'content' for chunk_type: collection_item \nDid you mean? field" if chunk_type == 'collection_item'
59
61
 
60
- result = variable_parse!(@content, variable_fallbacks, variable_values, @raw)
62
+ result = variable_parse!(@content, variable_fallbacks, variable_values, @raw, @skip_sanitize)
61
63
  result.try(:html_safe)
62
64
  end
63
65
 
@@ -79,8 +81,7 @@ module Editmode
79
81
  return false
80
82
  end
81
83
 
82
- def variable_parse!(content, variables = {}, values = {}, raw = true)
83
- content = ActionController::Base.helpers.sanitize(content)
84
+ def variable_parse!(content, variables = {}, values = {}, raw = true, skip_sanitize=false)
84
85
  tokens = content.scan(/\{{(.*?)\}}/)
85
86
  if tokens.any?
86
87
  tokens.flatten!
@@ -98,10 +99,12 @@ module Editmode
98
99
  end
99
100
  end
100
101
 
101
- content
102
+ content = ActionController::Base.helpers.sanitize(content) unless skip_sanitize
103
+ return content
102
104
  end
103
105
 
104
106
  def cached?
107
+ return false if @skip_cache
105
108
  Rails.cache.exist?(cache_identifier)
106
109
  end
107
110
 
@@ -113,6 +116,7 @@ module Editmode
113
116
  end
114
117
 
115
118
  def get_content
119
+
116
120
  if !cached?
117
121
  http_response = HTTParty.get(url, query: query_params)
118
122
  response_received = true if http_response.code == 200
@@ -121,9 +125,8 @@ module Editmode
121
125
  if !cached? && !response_received
122
126
  raise no_response_received(identifier)
123
127
  else
124
- cached_response = Rails.cache.fetch(cache_identifier) do
125
- http_response.to_json
126
- end
128
+ Rails.cache.write(cache_identifier, http_response.to_json) if http_response.present?
129
+ cached_response = Rails.cache.fetch(cache_identifier)
127
130
 
128
131
  @response = json?(cached_response) ? JSON.parse(cached_response) : cached_response
129
132
  set_response_attributes!
@@ -1,3 +1,3 @@
1
1
  module Editmode
2
- VERSION = "1.2.3"
3
- end
2
+ VERSION = "1.2.8"
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.2.3
4
+ version: 1.2.8
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-23 00:00:00.000000000 Z
11
+ date: 2020-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler