editmode 1.3.3 → 1.3.4

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: 3c2cf39ab030f4bc6d04678170c164d950a4bf947659906c6da343537f447bd4
4
- data.tar.gz: 89a6a0f4a16d51541404f1f1c0fd8ab90e0ad799b6bc176c28c48e8f653c0064
3
+ metadata.gz: 9b84d630e273ea3949b9ff1f5f0bd69f5dcf546ff33e15e92e766cd623b269ae
4
+ data.tar.gz: ce10b6c6fe4d46052f303ab4aeaddde7da8c230ae6c03a299e06e0c42f3d1d93
5
5
  SHA512:
6
- metadata.gz: d3815cd743139b4fd6a354c072d9bd2c8d010c8fa4aa2a6a6e04165f363430a5689d91a1228e5e3789b8d53a9f0434c4175a525bb3d7f85c4105bcecf81d1e96
7
- data.tar.gz: fcb8a9260a0cd706ad049c2f2dfd9406c3c3bc2ac8addcb6fa74f662709d483a00e338613136959762c5f317798cde9ad9f8d48ce0077fe63cdac323ccd063d4
6
+ metadata.gz: 24ffa6158c7b3c0d22fb4c546b521ec48a51fc2f579575608168cd7a321f103e439c6dc26bf33599483daf957215481b92b5a96bd1e9133e6342bcbba950ddad
7
+ data.tar.gz: f4d684b4d7713dee4853e304f9a61371eb982e9ce9841fbe283670c5c42176bfdd35847482dd698136e71c598a61e545be8c569f9f1177cb397984f197016e04
data/README.md CHANGED
@@ -107,6 +107,20 @@ e("cnk_16e04a02d577afb610ce", "Email Content", variables: variable_values)
107
107
  | item_class | string | `optional` Class name(s) that will be added along with "chunks-collection-item--wrapper" to all collection items |
108
108
 
109
109
 
110
+ ### Working with Image Transformation
111
+ Use `transformation` attribute to perform real-time image transformations to deliver perfect images to the end-users.
112
+
113
+ ```ruby
114
+ # This chunk should render an image with 200 x 200 dimension
115
+ = E('id-of-some-image', transformation: "w-200 h-200")
116
+
117
+ # For image inside a collection
118
+ = c('some-collection-id') do
119
+ = F('Avatar', transformation: "w-200 h-200")
120
+ ```
121
+
122
+ Please see complete list of [transformation parameters](https://editmode.com/docs#/imagekit_properties).
123
+
110
124
  ## Caching
111
125
  In order to keep your application speedy, Editmode minimizes the amount of network calls it makes by caching content where it can.
112
126
 
@@ -9,7 +9,7 @@ module Editmode
9
9
  attr_accessor :identifier, :variable_values, :branch_id,
10
10
  :variable_fallbacks, :chunk_type, :project_id,
11
11
  :url, :collection_id, :cache_identifier,
12
- :response
12
+ :response, :transformation
13
13
 
14
14
  attr_writer :content
15
15
 
@@ -22,6 +22,7 @@ module Editmode
22
22
  @raw = options[:raw].present?
23
23
  @skip_sanitize = options[:dangerously_skip_sanitization]
24
24
  @skip_cache = options[:skip_cache]
25
+ @transformation = options[:transformation]
25
26
 
26
27
  @url = "#{api_root_url}/chunks/#{identifier}"
27
28
  @cache_identifier = set_cache_identifier(identifier)
@@ -40,7 +41,7 @@ module Editmode
40
41
  if field.present?
41
42
  field_chunk = field_chunk(field)
42
43
  if field_chunk.present?
43
- result = field_chunk['content']
44
+ result = field_chunk['chunk_type'] == 'image' ? set_transformation_properties!(field_chunk['content']) : field_chunk['content']
44
45
  result = variable_parse!(result, variable_fallbacks, variable_values, @raw, @skip_sanitize)
45
46
  else
46
47
  raise no_response_received(field)
@@ -73,6 +74,20 @@ module Editmode
73
74
  end
74
75
 
75
76
  private
77
+ def set_transformation_properties!(url)
78
+ if transformation.present? && url.present?
79
+ transformation.gsub!(" ", ",")
80
+ transformation.gsub!(/\s/, '')
81
+
82
+ uri = URI(url)
83
+ uri.query = [uri.query, "tr=#{transformation}"].compact.join("&")
84
+
85
+ url = uri.to_s
86
+ end
87
+
88
+ url
89
+ end
90
+
76
91
  def allowed_tag_attributes
77
92
  %w(style href title src alt width height class target)
78
93
  end
@@ -118,6 +133,7 @@ module Editmode
118
133
  def query_params
119
134
  the_params = { 'project_id' => project_id }
120
135
  the_params['branch_id'] = branch_id if branch_id.present?
136
+ the_params['transformation'] = @transformation if @transformation.present?
121
137
 
122
138
  the_params
123
139
  end
@@ -17,7 +17,7 @@ module Editmode
17
17
  end
18
18
 
19
19
  def render_custom_field_raw(label, options={})
20
- e(@custom_field_chunk["identifier"], label, options.merge({response: @custom_field_chunk}))
20
+ e(@custom_field_chunk["identifier"], label, options.merge({response: @custom_field_chunk}))
21
21
  end
22
22
  alias_method :f, :render_custom_field_raw
23
23
 
@@ -1,3 +1,3 @@
1
1
  module Editmode
2
- VERSION = "1.3.3"
2
+ VERSION = "1.3.4"
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.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Ennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler