editmode 1.2.2 → 1.2.3

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: 2beab37962d65855d3ecfd66b6d9731fd4f1826eac260d97a30d8c1b022b9ff8
4
- data.tar.gz: b05b7f2425a796262ec31e2d8cc447405d9bb2ed339b37a6f71cc2d52cd10ad7
3
+ metadata.gz: 78dda874aecacc9edfdf0e96598019e7dad8cc44693336d94511083238b55a91
4
+ data.tar.gz: d111ab02c60c737e5711139473e7be988f02ffdb3a8ed01a7876174348bf5d83
5
5
  SHA512:
6
- metadata.gz: 75944607fde64c8da7a99751a421d43fbc473b7f0c0c7ce34297b16d70869d2d393de8731fed85dfd6387ba22977ef3e92ae892370b07a13a9ed41bad7d6472b
7
- data.tar.gz: c2109b7ca239fce3ddb025348bc534201002d6396a18e4eec9357fdc992f64489efed095e4568db984148e5ff45aafad70b1026cf93111d9c04aa20bed329924
6
+ metadata.gz: e896421ca91061b25d28bc0ea217a2891df5f06d109b00301364ad67c3813caf2de47219f0be1b13ac335b6a8b76bcdaa5dc10b5ad4a9308722e90939613cbaf
7
+ data.tar.gz: 9ad90b4008998f64e52cfe34c73c74db62633b468764f0939df16ffb4fbeb1a9acbbdee0acfe053e793ff66b316f9c8ecde7bb64544b81013828e61383995f69
@@ -3,10 +3,10 @@ module Editmode
3
3
  include ActionView::Helpers::TagHelper
4
4
  include ActionView::Context
5
5
 
6
- attr_accessor :identifier, :variable_values, :branch_id,
7
- :variable_fallbacks, :chunk_type, :project_id,
8
- :url, :collection_id, :cache_identifier,
9
- :response
6
+ attr_accessor :identifier, :variable_values, :branch_id,
7
+ :variable_fallbacks, :chunk_type, :project_id,
8
+ :url, :collection_id, :cache_identifier,
9
+ :response
10
10
 
11
11
  attr_writer :content
12
12
 
@@ -17,8 +17,7 @@ module Editmode
17
17
  @variable_values = options[:variables].presence || {}
18
18
  @raw = options[:raw].present?
19
19
 
20
- branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
21
- @url = "#{api_root_url}/chunks/#{identifier}?project_id=#{project_id}&#{branch_params}"
20
+ @url = "#{api_root_url}/chunks/#{identifier}"
22
21
  @cache_identifier = set_cache_identifier(identifier)
23
22
 
24
23
  if options[:response].present?
@@ -29,7 +28,7 @@ module Editmode
29
28
  end
30
29
  end
31
30
 
32
- def field(field = nil)
31
+ def field(field = nil)
33
32
  # Field ID can be a slug or field_name
34
33
  if chunk_type == 'collection_item'
35
34
  if field.present?
@@ -56,13 +55,14 @@ module Editmode
56
55
  end
57
56
 
58
57
  def content
59
- raise "undefined method 'content` for chunk_type: collection_item \nDid you mean? field" if chunk_type == 'collection_item'
60
-
58
+ 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
61
  result.try(:html_safe)
63
62
  end
64
63
 
65
64
  private
65
+
66
66
  # Todo: Transfer to helper utils
67
67
  def api_root_url
68
68
  ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
@@ -83,7 +83,7 @@ module Editmode
83
83
  content = ActionController::Base.helpers.sanitize(content)
84
84
  tokens = content.scan(/\{{(.*?)\}}/)
85
85
  if tokens.any?
86
- tokens.flatten!
86
+ tokens.flatten!
87
87
  tokens.each do |token|
88
88
  token_value = values[token.to_sym] || variables[token] || ""
89
89
  sanitized_value = ActionController::Base.helpers.sanitize(token_value)
@@ -93,7 +93,7 @@ module Editmode
93
93
  sanitized_value
94
94
  end
95
95
  end
96
-
96
+
97
97
  content.gsub!("{{#{token}}}", sanitized_value)
98
98
  end
99
99
  end
@@ -105,9 +105,16 @@ module Editmode
105
105
  Rails.cache.exist?(cache_identifier)
106
106
  end
107
107
 
108
+ def query_params
109
+ the_params = { 'project_id' => project_id }
110
+ the_params['branch_id'] = branch_id if branch_id.present?
111
+
112
+ the_params
113
+ end
114
+
108
115
  def get_content
109
116
  if !cached?
110
- http_response = HTTParty.get(url)
117
+ http_response = HTTParty.get(url, query: query_params)
111
118
  response_received = true if http_response.code == 200
112
119
  end
113
120
 
@@ -128,7 +135,8 @@ module Editmode
128
135
  @chunk_type = response['chunk_type']
129
136
  @variable_fallbacks = response['variable_fallbacks'].presence || {}
130
137
  @collection_id = response["collection"]["identifier"] if chunk_type == 'collection_item'
138
+ @branch_id = response['branch_id']
131
139
  end
132
140
 
133
141
  end
134
- end
142
+ end
@@ -1,3 +1,3 @@
1
1
  module Editmode
2
- VERSION = "1.2.2"
3
- end
2
+ VERSION = "1.2.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.2.2
4
+ version: 1.2.3
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-09 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler