editmode 1.2.9 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3c6615ff35d91086eb0774d03d3d5e90070f1f52456563b883b947c42182bdf
4
- data.tar.gz: 067ea9cb9d9227d12cda1aa825fbce9987731ee720e9882386a9a1d6cdbb4e4c
3
+ metadata.gz: 9b84d630e273ea3949b9ff1f5f0bd69f5dcf546ff33e15e92e766cd623b269ae
4
+ data.tar.gz: ce10b6c6fe4d46052f303ab4aeaddde7da8c230ae6c03a299e06e0c42f3d1d93
5
5
  SHA512:
6
- metadata.gz: e3da11757cc4d252bd5222533c4e4fee807623a50c6913d968dec1ded22e3a653199b3b5b858f138440d62391e64048d22e1062837689c082b523c62beb82170
7
- data.tar.gz: 367aace629ffe1363a1938a6bdec061976eeb2dda597916378f4c6385ee57e7dfa7a8e0efda7d873d8d1aafbb0cb5875a4328e478540b4abba775728e177c05f
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
 
data/lib/editmode.rb CHANGED
@@ -6,7 +6,8 @@ require 'editmode/auto_include_filter'
6
6
  require 'editmode/chunk_value'
7
7
  require 'editmode/railtie' if defined? Rails
8
8
  require 'editmode/engine' if defined?(Rails)
9
- # Todo: Implement RSPEC
9
+ require 'editmode/monkey_patches'
10
+ require 'editmode/logger'
10
11
  module Editmode
11
12
  class << self
12
13
  include Editmode::ActionViewExtensions::EditmodeHelper
@@ -20,6 +21,18 @@ module Editmode
20
21
  config.project_id
21
22
  end
22
23
 
24
+ def logger
25
+ config.logger
26
+ end
27
+
28
+ def log_level
29
+ config.log_level
30
+ end
31
+
32
+ def log_level=(level)
33
+ config.log_level = level
34
+ end
35
+
23
36
  def access_token
24
37
  config.access_token
25
38
  end
@@ -43,11 +56,19 @@ module Editmode
43
56
 
44
57
  class Configuration
45
58
  attr_accessor :access_token, :variable
46
- attr_reader :project_id
59
+ attr_reader :project_id, :log_level
60
+
61
+ def logger
62
+ @logger ||= Editmode::Logger.new
63
+ end
47
64
 
48
65
  def project_id=(id)
49
66
  @project_id = id
67
+ end
50
68
 
69
+ def log_level=(level)
70
+ @log_level = level
71
+ logger.log_level = level
51
72
  end
52
73
  end
53
74
  end
@@ -16,6 +16,10 @@ module Editmode
16
16
  # Todo Add Header Version
17
17
  end
18
18
 
19
+ def allowed_tag_attributes
20
+ [:style, :href, :title, :src, :alt, :width, :height]
21
+ end
22
+
19
23
  def api_root_url
20
24
  ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
21
25
  end
@@ -110,7 +114,7 @@ module Editmode
110
114
  end
111
115
  end
112
116
 
113
- def render_chunk_content(chunk_identifier, chunk_content, chunk_type,options = {})
117
+ def render_chunk_content(chunk_identifier, chunk_content, chunk_type, options = {})
114
118
  begin
115
119
  css_class = options[:class]
116
120
  cache_id = options[:cache_identifier]
@@ -132,17 +136,17 @@ module Editmode
132
136
  case display_type
133
137
  when "span"
134
138
  if chunk_type == "rich_text"
135
- content = content_tag("em-span", :class => "editmode-richtext-editor #{css_class}", :data => chunk_data.merge!({:chunk_editable => true}) ) do
139
+ content = content_tag("em-span", :class => "editmode-richtext-editor #{css_class}", :data => chunk_data.merge!({:chunk_editable => true}), **options.slice(*allowed_tag_attributes) ) do
136
140
  chunk_content.html_safe
137
141
  end
138
142
  else
139
- content_tag("em-span", :class => css_class, :data => chunk_data.merge!({:chunk_editable => true}) ) do
143
+ content_tag("em-span", :class => css_class, :data => chunk_data.merge!({:chunk_editable => true}), **options.slice(*allowed_tag_attributes) ) do
140
144
  chunk_content.html_safe
141
145
  end
142
146
  end
143
147
  when "image"
144
148
  chunk_content = chunk_content.blank? || chunk_content == "/images/original/missing.png" ? 'https://www.editmode.com/upload.png' : chunk_content
145
- image_tag(chunk_content, :data => chunk_data, :class => css_class)
149
+ image_tag(chunk_content, :data => chunk_data, :class => css_class, **options.slice(*allowed_tag_attributes))
146
150
  end
147
151
  rescue => errors
148
152
  puts errors
@@ -159,7 +163,7 @@ module Editmode
159
163
  # prevent the page from loading.
160
164
  begin
161
165
  field = options[:field].presence || ""
162
-
166
+ options[:referrer] = request.url
163
167
  chunk_value = Editmode::ChunkValue.new(identifier, options)
164
168
 
165
169
  if field.present? && chunk_value.chunk_type == 'collection_item'
@@ -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
 
@@ -17,10 +17,12 @@ module Editmode
17
17
  @identifier = identifier
18
18
  @branch_id = options[:branch_id].presence
19
19
  @project_id = project_id
20
+ @referrer = options[:referrer].presence || ""
20
21
  @variable_values = options[:variables].presence || {}
21
22
  @raw = options[:raw].present?
22
23
  @skip_sanitize = options[:dangerously_skip_sanitization]
23
24
  @skip_cache = options[:skip_cache]
25
+ @transformation = options[:transformation]
24
26
 
25
27
  @url = "#{api_root_url}/chunks/#{identifier}"
26
28
  @cache_identifier = set_cache_identifier(identifier)
@@ -39,7 +41,7 @@ module Editmode
39
41
  if field.present?
40
42
  field_chunk = field_chunk(field)
41
43
  if field_chunk.present?
42
- result = field_chunk['content']
44
+ result = field_chunk['chunk_type'] == 'image' ? set_transformation_properties!(field_chunk['content']) : field_chunk['content']
43
45
  result = variable_parse!(result, variable_fallbacks, variable_values, @raw, @skip_sanitize)
44
46
  else
45
47
  raise no_response_received(field)
@@ -72,6 +74,23 @@ module Editmode
72
74
  end
73
75
 
74
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
+
91
+ def allowed_tag_attributes
92
+ %w(style href title src alt width height class target)
93
+ end
75
94
 
76
95
  # Todo: Transfer to helper utils
77
96
  def api_root_url
@@ -107,21 +126,21 @@ module Editmode
107
126
  end
108
127
  end
109
128
 
110
- content = ActionController::Base.helpers.sanitize(content) unless skip_sanitize
129
+ content = ActionController::Base.helpers.sanitize(content, attributes: allowed_tag_attributes) unless skip_sanitize
111
130
  return content
112
131
  end
113
132
 
114
133
  def query_params
115
134
  the_params = { 'project_id' => project_id }
116
135
  the_params['branch_id'] = branch_id if branch_id.present?
136
+ the_params['transformation'] = @transformation if @transformation.present?
117
137
 
118
138
  the_params
119
139
  end
120
140
 
121
141
  def get_content
122
-
123
142
  if !cached?
124
- http_response = HTTParty.get(url, query: query_params)
143
+ http_response = HTTParty.get(url, query: query_params, headers: {referrer: @referrer})
125
144
  response_received = true if http_response.code == 200
126
145
  end
127
146
 
@@ -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
 
@@ -0,0 +1,28 @@
1
+ require 'active_support'
2
+
3
+ module Editmode
4
+ class Logger
5
+ attr_accessor :httparty_subscription
6
+
7
+ def log_level=(level)
8
+ if level == :normal
9
+ # Add more subscription here
10
+ enable_httparty!
11
+ end
12
+ end
13
+
14
+ def enable_httparty!
15
+ @httparty_subscription = ActiveSupport::Notifications.subscribe('request.httparty') do |name, start, ending, transaction_id, payload|
16
+ event = ActiveSupport::Notifications::Event.new(name, start, ending, transaction_id, payload)
17
+ Rails.logger.info " HTTParty -- " + "#{event.payload[:method]} #{event.payload[:url]} (Duration: #{event.duration}ms)"
18
+ Thread.current[:http_runtime] ||= 0
19
+ Thread.current[:http_runtime] += event.duration
20
+ payload[:http_runtime] = event.duration
21
+ end
22
+ end
23
+
24
+ def unsubscribe(subscriber)
25
+ ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber.present?
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ require 'httparty'
2
+
3
+ # Support logging on httparty requests
4
+ module HTTParty
5
+ class Request
6
+ alias_method :_original_perform, :perform
7
+ def perform(&block)
8
+ payload = {
9
+ method: http_method.const_get(:METHOD),
10
+ url: uri
11
+ }
12
+ ActiveSupport::Notifications.instrument 'request.httparty', payload do
13
+ _original_perform(&block)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Editmode
2
- VERSION = "1.2.9"
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.2.9
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-01-14 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
@@ -85,6 +85,8 @@ files:
85
85
  - lib/editmode/chunk_value.rb
86
86
  - lib/editmode/engine.rb
87
87
  - lib/editmode/helper.rb
88
+ - lib/editmode/logger.rb
89
+ - lib/editmode/monkey_patches.rb
88
90
  - lib/editmode/railtie.rb
89
91
  - lib/editmode/script_tag.rb
90
92
  - lib/editmode/version.rb