editmode 1.2.7 → 1.3.2

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: aac6adb5e24a89664dc5939ddb97606ac0003f33fb329b7d00b507c98a8ebc98
4
- data.tar.gz: ae22fe6ff1b9cf07ea3a1d7761c298f856482b051a080111fa9e29a7965633ee
3
+ metadata.gz: fe9965c96f8c7fb66afae65725f82fbb536fae3981924b090643e9899735627c
4
+ data.tar.gz: 75bc30d9f5bb9575780e43a3f2f8776fc35ad55f328c7fd5c7134c9685487727
5
5
  SHA512:
6
- metadata.gz: 1264161505c4cb1ded693b68231825962f686420817244d427510e76ac71950b78ba5a4da5ab85bb02c8a163f724e012f4232b397bdaa7fcef74bedea9ea8e03
7
- data.tar.gz: 3a5afb3beac64da0120e296b3bd41747031b6a1d662aa24df1b56f82eb3e29e1f44665df76ce29a6cd87848a4ebd3e9b61df79ad6112feb7747a30bca3816b84
6
+ metadata.gz: 8ffb62bd7347c80679acdcc57fa50d3ce1c266557f3f88f27d08d0cc646b5297e8a4dceb36f6f36cb229a58888230cc9be8220f80832346607c49dfda5475c39
7
+ data.tar.gz: 0375dc9c6098596aead8445fc4d57b8f53ee57d820ccd1db2c61cf3c214171472cbee29e2f7b39b019e212c0968077702b50d99e261ef82e4722080f46d0d82b
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in chunks.gemspec
4
+ gem 'pry-rails'
5
+ gem 'rails', '~> 5.2.0'
4
6
  gemspec
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
2
3
 
4
+ task :test do
5
+ Dir['test/*_test.rb'].each do |testfile|
6
+ load testfile
7
+ end
8
+ end
9
+
10
+ task :default => :test
@@ -1,15 +1,25 @@
1
1
  require 'editmode/helper'
2
+ require 'action_view'
3
+ require 'httparty'
2
4
 
3
5
  module Editmode
4
6
  module ActionViewExtensions
5
7
  module EditmodeHelper
6
- require 'httparty'
8
+ include ::ActionView::Helpers::TagHelper
9
+ include ::ActionView::Helpers::TextHelper
10
+ include ::ActionView::Helpers::AssetTagHelper
11
+ include ::ActionView::Context
7
12
  include Editmode::Helper
8
13
 
14
+
9
15
  def api_version
10
16
  # Todo Add Header Version
11
17
  end
12
18
 
19
+ def allowed_tag_attributes
20
+ [:style, :href, :title, :src, :alt, :width, :height]
21
+ end
22
+
13
23
  def api_root_url
14
24
  ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
15
25
  end
@@ -104,7 +114,7 @@ module Editmode
104
114
  end
105
115
  end
106
116
 
107
- def render_chunk_content(chunk_identifier, chunk_content, chunk_type,options = {})
117
+ def render_chunk_content(chunk_identifier, chunk_content, chunk_type, options = {})
108
118
  begin
109
119
  css_class = options[:class]
110
120
  cache_id = options[:cache_identifier]
@@ -126,17 +136,17 @@ module Editmode
126
136
  case display_type
127
137
  when "span"
128
138
  if chunk_type == "rich_text"
129
- 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
130
140
  chunk_content.html_safe
131
141
  end
132
142
  else
133
- 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
134
144
  chunk_content.html_safe
135
145
  end
136
146
  end
137
147
  when "image"
138
148
  chunk_content = chunk_content.blank? || chunk_content == "/images/original/missing.png" ? 'https://www.editmode.com/upload.png' : chunk_content
139
- 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))
140
150
  end
141
151
  rescue => errors
142
152
  puts errors
@@ -153,7 +163,7 @@ module Editmode
153
163
  # prevent the page from loading.
154
164
  begin
155
165
  field = options[:field].presence || ""
156
-
166
+ options[:referrer] = request.url
157
167
  chunk_value = Editmode::ChunkValue.new(identifier, options)
158
168
 
159
169
  if field.present? && chunk_value.chunk_type == 'collection_item'
@@ -1,3 +1,6 @@
1
+ require 'action_view'
2
+ require 'active_support'
3
+
1
4
  module Editmode
2
5
  class ChunkValue
3
6
  include ActionView::Helpers::TagHelper
@@ -14,6 +17,7 @@ module Editmode
14
17
  @identifier = identifier
15
18
  @branch_id = options[:branch_id].presence
16
19
  @project_id = project_id
20
+ @referrer = options[:referrer].presence || ""
17
21
  @variable_values = options[:variables].presence || {}
18
22
  @raw = options[:raw].present?
19
23
  @skip_sanitize = options[:dangerously_skip_sanitization]
@@ -63,7 +67,15 @@ module Editmode
63
67
  result.try(:html_safe)
64
68
  end
65
69
 
70
+ def cached?
71
+ return false if @skip_cache
72
+ Rails.cache.exist?(cache_identifier)
73
+ end
74
+
66
75
  private
76
+ def allowed_tag_attributes
77
+ %w(style href title src alt width height class target)
78
+ end
67
79
 
68
80
  # Todo: Transfer to helper utils
69
81
  def api_root_url
@@ -99,15 +111,10 @@ module Editmode
99
111
  end
100
112
  end
101
113
 
102
- content = ActionController::Base.helpers.sanitize(content) unless skip_sanitize
114
+ content = ActionController::Base.helpers.sanitize(content, attributes: allowed_tag_attributes) unless skip_sanitize
103
115
  return content
104
116
  end
105
117
 
106
- def cached?
107
- return false if @skip_cache
108
- Rails.cache.exist?(cache_identifier)
109
- end
110
-
111
118
  def query_params
112
119
  the_params = { 'project_id' => project_id }
113
120
  the_params['branch_id'] = branch_id if branch_id.present?
@@ -116,14 +123,15 @@ module Editmode
116
123
  end
117
124
 
118
125
  def get_content
119
-
120
126
  if !cached?
121
- http_response = HTTParty.get(url, query: query_params)
127
+ http_response = HTTParty.get(url, query: query_params, headers: {referrer: @referrer})
122
128
  response_received = true if http_response.code == 200
123
129
  end
124
130
 
125
131
  if !cached? && !response_received
126
- raise no_response_received(identifier)
132
+ message = http_response.try(:[], 'message') || no_response_received(identifier)
133
+
134
+ raise message
127
135
  else
128
136
  Rails.cache.write(cache_identifier, http_response.to_json) if http_response.present?
129
137
  cached_response = Rails.cache.fetch(cache_identifier)
@@ -141,5 +149,8 @@ module Editmode
141
149
  @branch_id = response['branch_id']
142
150
  end
143
151
 
152
+ def no_response_received(id = "")
153
+ "Sorry, we can't find a chunk using this identifier: \"#{id}\". This can happen if you've deleted a chunk on editmode.com or if your local cache is out of date. If it persists, try running Rails.cache clear."
154
+ end
144
155
  end
145
156
  end
@@ -1,4 +1,5 @@
1
- require 'editmode/chunk_value'
1
+ require 'rails/engine'
2
+ require 'action_controller'
2
3
  require 'editmode/helper'
3
4
 
4
5
  module Editmode
@@ -5,34 +5,17 @@ module Editmode
5
5
  field, options = parse_arguments(args)
6
6
  begin
7
7
  chunk = Editmode::ChunkValue.new(identifier, options.merge({raw: true}))
8
- render_noneditable_chunk(chunk, field, options)
8
+
9
+ if chunk.chunk_type == 'collection_item'
10
+ chunk.field(field)
11
+ else
12
+ chunk.content
13
+ end
9
14
  rescue => er
10
- puts er
15
+ Rails.logger.info "#{er}: We can't render content for #{identifier}"
11
16
  end
12
17
  end
13
18
 
14
- def render_noneditable_chunk(chunk, field=nil, options=nil)
15
- return render_collection_item(chunk, field, options) if chunk.chunk_type == 'collection_item'
16
-
17
- render_content(chunk, options)
18
- end
19
-
20
- def render_collection_item(chunk, field=nil, options=nil)
21
- return render_image(chunk.field(field), options[:class]) if chunk.field_chunk(field)['chunk_type'] == 'image'
22
-
23
- chunk.field(field)
24
- end
25
-
26
- def render_content(chunk, options=nil)
27
- return render_image(chunk.content, options[:class]) if chunk.chunk_type == 'image'
28
-
29
- chunk.content
30
- end
31
-
32
- def render_image(content, css_class=nil)
33
- image_tag(content, class: css_class)
34
- end
35
-
36
19
  def render_custom_field_raw(label, options={})
37
20
  e(@custom_field_chunk["identifier"], label, options.merge({response: @custom_field_chunk}))
38
21
  end
@@ -50,4 +33,4 @@ module Editmode
50
33
  return field, options
51
34
  end
52
35
  end
53
- end
36
+ end
@@ -1,3 +1,4 @@
1
+ require 'rails/railtie'
1
2
  module Editmode
2
3
  class Railtie < Rails::Railtie
3
4
  initializer "editmode" do |app|
@@ -1,3 +1,3 @@
1
1
  module Editmode
2
- VERSION = "1.2.7"
2
+ VERSION = "1.3.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.7
4
+ version: 1.3.2
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-12-22 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.0.8
112
+ rubygems_version: 3.2.4
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Editmode allows you to turn plain text in your rails app into easily inline-editable