editmode 1.3.5 → 1.3.6

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: e15d8405884179d972f91d11fa4bb20097577371dc6daee29935c26530fed7a3
4
- data.tar.gz: 7819de17f3f5a4da995adb11855c0aba118a3da2a89c3a74762e9e36aa687af1
3
+ metadata.gz: 32d49f4215168d36260f8b3f363c12d7ba6948fd7e9f97e8dae1e1b58ddb7ef8
4
+ data.tar.gz: ed1cf4a9c60ae63973ed9e3f98b5c2a7e66eb4b273e1a392509574aa7ae3f86a
5
5
  SHA512:
6
- metadata.gz: fa7861dfa13bb0e4c680fbf943a30486be2d2519322afe0dfe898d91bae1e929cca214d2e36b693bd8e9016bb2ce4954c7889baede5605b4aa17ca31d837410e
7
- data.tar.gz: 10291830bd61bd79720a77fbddf4b88e3dbd909eee66e1236915f757bb958f264b93ad20b2fbb232ab055e3e3ab025e01906e05b8e6e348b66f3709c5cf6c626
6
+ metadata.gz: b2036241a90a7d9eff95d2da0553918d278f37c5336b181bcf62d076bb7a4184f87b8dac5a286026dc88f5beaf46e54db5020f6228877d88b0a72592bd85ee2c
7
+ data.tar.gz: 6f0354be4a33de404b01f0b1611a87e95c4916b59f0034356cc647192b99f77b113424c5b463d1542c6e405306c959a4477c93949d92392e382c9f7fa98000f1
data/README.md CHANGED
@@ -119,7 +119,7 @@ Use `transformation` attribute to perform real-time image transformations to del
119
119
  = F('Avatar', transformation: "w-200 h-200")
120
120
  ```
121
121
 
122
- Please see complete list of [transformation parameters](https://editmode.com/docs#/imagekit_properties).
122
+ Please see the complete list of [transformation parameters](https://editmode.com/docs#/imagekit_properties).
123
123
 
124
124
  ## Caching
125
125
  In order to keep your application speedy, Editmode minimizes the amount of network calls it makes by caching content where it can.
@@ -139,6 +139,8 @@ The editmode gem exposes a cache expiration endpoint in your application at `/ed
139
139
 
140
140
  The cache expiration endpoint is currently **not** authenticated.
141
141
 
142
+ ?> We are using a method called `delete_matched` to purge your caches when a content gets updated, and this method isn't supported in `memcached`. We highly recommend using `redis_store` or `file_store`.
143
+
142
144
  ## Disabling editmode.js auto-include
143
145
 
144
146
  To disable automatic insertion for a particular controller or action you can:
data/lib/editmode.rb CHANGED
@@ -8,11 +8,17 @@ require 'editmode/railtie' if defined? Rails
8
8
  require 'editmode/engine' if defined?(Rails)
9
9
  require 'editmode/monkey_patches'
10
10
  require 'editmode/logger'
11
+ require 'editmode/chunk'
12
+
11
13
  module Editmode
12
14
  class << self
13
15
  include Editmode::ActionViewExtensions::EditmodeHelper
14
16
  include Editmode::Helper
15
17
 
18
+ def api_root_url
19
+ ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
20
+ end
21
+
16
22
  def project_id=(id)
17
23
  config.project_id = id
18
24
  end
@@ -52,11 +58,30 @@ module Editmode
52
58
  puts er
53
59
  end
54
60
  end
61
+
62
+ def cache_all!(chunks)
63
+ chunks.each do |chunk|
64
+ project_id = chunk["project_id"]
65
+ identifier = chunk["identifier"]
66
+ content_key = chunk["content_key"]
67
+ json_data = chunk.to_json
68
+ Rails.cache.write("chunk_#{project_id}#{identifier}", json_data)
69
+ Rails.cache.write("chunk_#{project_id}#{content_key}", json_data) if content_key.present?
70
+ end
71
+ end
55
72
  end
56
73
 
57
74
  class Configuration
58
75
  attr_accessor :access_token, :variable
59
- attr_reader :project_id, :log_level
76
+ attr_reader :project_id, :log_level, :preload
77
+
78
+ def preload=(bool)
79
+ @preload = bool
80
+ if bool
81
+ chunks = Editmode::Chunk.retrieve
82
+ Editmode.cache_all!(chunks)
83
+ end
84
+ end
60
85
 
61
86
  def logger
62
87
  @logger ||= Editmode::Logger.new
@@ -64,6 +89,10 @@ module Editmode
64
89
 
65
90
  def project_id=(id)
66
91
  @project_id = id
92
+ if preload
93
+ chunks = Editmode::Chunk.retrieve(id)
94
+ Editmode.cache_all!(chunks)
95
+ end
67
96
  end
68
97
 
69
98
  def log_level=(level)
@@ -0,0 +1,26 @@
1
+ class Editmode::Chunk
2
+ def initialize
3
+ end
4
+
5
+ class << self
6
+ def retrieve(project_id = Editmode.project_id, options = {})
7
+ begin
8
+ root_url = Editmode.api_root_url
9
+ chunk_id = options[:identifier] || options[:content_key]
10
+
11
+ url = "#{root_url}/chunks/#{chunk_id}?project_id=#{project_id}"
12
+ response = HTTParty.get(url)
13
+
14
+ if chunk_id.present?
15
+ return response
16
+ else
17
+ chunks = response.try(:[], "chunks")
18
+ chunks ||= []
19
+ end
20
+ rescue => er
21
+ Rails.logger.info er
22
+ []
23
+ end
24
+ end
25
+ end
26
+ end
@@ -133,7 +133,6 @@ module Editmode
133
133
  def query_params
134
134
  the_params = { 'project_id' => project_id }
135
135
  the_params['branch_id'] = branch_id if branch_id.present?
136
- the_params['transformation'] = @transformation if @transformation.present?
137
136
 
138
137
  the_params
139
138
  end
@@ -158,8 +157,9 @@ module Editmode
158
157
  end
159
158
 
160
159
  def set_response_attributes!
161
- @content = response['content']
162
160
  @chunk_type = response['chunk_type']
161
+
162
+ @content = @chunk_type == 'image' ? set_transformation_properties!(response['content']) : response['content']
163
163
  @variable_fallbacks = response['variable_fallbacks'].presence || {}
164
164
  @collection_id = response["collection"]["identifier"] if chunk_type == 'collection_item'
165
165
  @branch_id = response['branch_id']
@@ -1,3 +1,3 @@
1
1
  module Editmode
2
- VERSION = "1.3.5"
2
+ VERSION = "1.3.6"
3
3
  end
@@ -1,5 +1,11 @@
1
1
  Editmode.setup do |config|
2
- # Replace TodoProjectId with your Editmode Project ID,
3
- # visit https://editmode.com/projects
4
2
  config.project_id = "<%= @project_id %>"
3
+
4
+ # Enables logging on every API request
5
+ # config.log_level = :silence
6
+
7
+ # Preload contents - this will take all the contents
8
+ # from the project specified in config.project_id
9
+ # and store it to your Application cache.
10
+ # config.preload = true
5
11
  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.5
4
+ version: 1.3.6
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-12 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,6 +82,7 @@ files:
82
82
  - lib/editmode.rb
83
83
  - lib/editmode/action_view_extensions/editmode_helper.rb
84
84
  - lib/editmode/auto_include_filter.rb
85
+ - lib/editmode/chunk.rb
85
86
  - lib/editmode/chunk_value.rb
86
87
  - lib/editmode/engine.rb
87
88
  - lib/editmode/helper.rb