editmode 0.0.9.127 → 0.0.10.16
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 +4 -4
- data/app/controllers/editmode_controller.rb +4 -0
- data/lib/editmode.rb +13 -28
- data/lib/editmode/action_view_extensions/editmode_helper.rb +41 -3
- data/lib/editmode/chunk_value.rb +67 -0
- data/lib/editmode/version.rb +1 -1
- data/lib/generators/editmode/config_generator.rb +26 -0
- data/lib/generators/editmode/templates/{editmode.rb → editmode.rb.erb} +1 -1
- metadata +5 -4
- data/lib/generators/editmode/install_generator.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6436b313b030cf81d23b8272298001445eb96fe03cdece2493ab493b7b03353b
|
4
|
+
data.tar.gz: d277cd2ca885fd8e082f17cde5afaab63db7cef4e67a7f131785a29d0c013006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 920b13e489ef97f223550ec25d9fe0ee6015d97cd442c448317a01ecc4d11d3c22c5bb56ae89c2e107978d4fe570385c81fb97515dcded68c70f5767808e214f
|
7
|
+
data.tar.gz: a1c1d9d60c1bfbe1f8b6bccf715aca23d03fcf14a60e3eeeb55c88a34e1110ed65f4affb37bd12d8cbdfcefd18e05f2709f744555eec7ded5bbce89a0a14f1ba
|
@@ -4,6 +4,10 @@ class EditmodeController < ApplicationController
|
|
4
4
|
if params[:full]
|
5
5
|
Rails.cache.clear
|
6
6
|
render status: 200, json: {:response => "success"}
|
7
|
+
elsif params[:variable_cache_project_id]
|
8
|
+
project_id = params[:variable_cache_project_id]
|
9
|
+
Rails.cache.delete("chunk_#{project_id}_variables")
|
10
|
+
render status: 200, json: {:response => "success"}
|
7
11
|
elsif params[:identifier]
|
8
12
|
Rails.cache.delete("chunk_#{params[:identifier]}")
|
9
13
|
Rails.cache.delete("chunk_#{params[:identifier]}_type")
|
data/lib/editmode.rb
CHANGED
@@ -3,12 +3,14 @@ require "editmode/version"
|
|
3
3
|
require 'editmode/script_tag'
|
4
4
|
require 'editmode/action_view_extensions/editmode_helper'
|
5
5
|
require 'editmode/auto_include_filter'
|
6
|
+
require 'editmode/chunk_value'
|
6
7
|
require 'editmode/railtie' if defined? Rails
|
7
8
|
require 'editmode/engine' if defined?(Rails)
|
8
|
-
|
9
|
+
# Todo: Implement RSPEC
|
9
10
|
module Editmode
|
10
11
|
class << self
|
11
12
|
include Editmode::ActionViewExtensions::EditmodeHelper
|
13
|
+
|
12
14
|
def project_id=(id)
|
13
15
|
config.project_id = id
|
14
16
|
end
|
@@ -22,8 +24,6 @@ module Editmode
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def config
|
25
|
-
# Todo: Instantiate in editmode initializer or base controllers
|
26
|
-
# Todo: Add a generator to create initializer an file?
|
27
27
|
@config ||= Configuration.new
|
28
28
|
end
|
29
29
|
|
@@ -32,36 +32,21 @@ module Editmode
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def chunk_value(identifier, **options)
|
35
|
-
body = options[:values].presence || {}
|
36
|
-
field_id = options[:field_id].presence
|
37
|
-
branch_id = options[:branch_id].presence
|
38
|
-
|
39
|
-
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
40
|
-
cache_identifier = "chunk_#{identifier}#{branch_id}"
|
41
|
-
url = "#{api_root_url}/chunks/#{identifier}?#{branch_params}"
|
42
|
-
|
43
35
|
begin
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
if !response_received
|
48
|
-
raise "No response received"
|
49
|
-
else
|
50
|
-
if field_id.present?
|
51
|
-
chunk = response["content"].detect {|f| f["custom_field_identifier"] == field_id }
|
52
|
-
chunk['content']
|
53
|
-
else
|
54
|
-
response['content']
|
55
|
-
end
|
56
|
-
end
|
57
|
-
rescue => error
|
58
|
-
# Todo: Send a log to editmode prob like sentry
|
59
|
-
return "No response received"
|
36
|
+
Editmode::ChunkValue.new(identifier, **options )
|
37
|
+
rescue => er
|
38
|
+
raise er
|
60
39
|
end
|
61
40
|
end
|
62
41
|
end
|
63
42
|
|
64
43
|
class Configuration
|
65
|
-
attr_accessor :
|
44
|
+
attr_accessor :access_token, :variable
|
45
|
+
attr_reader :project_id
|
46
|
+
|
47
|
+
def project_id=(id)
|
48
|
+
@project_id = id
|
49
|
+
|
50
|
+
end
|
66
51
|
end
|
67
52
|
end
|
@@ -12,13 +12,29 @@ module Editmode
|
|
12
12
|
ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
|
13
13
|
end
|
14
14
|
|
15
|
-
def chunk_collection(collection_identifier,
|
15
|
+
def chunk_collection(collection_identifier, **options)
|
16
16
|
branch_params = params[:em_branch_id].present? ? "branch_id=#{params[:em_branch_id]}" : ""
|
17
|
+
branch_id = params[:em_branch_id].presence
|
18
|
+
tags = options[:tags].presence || []
|
19
|
+
limit = options[:limit].presence
|
20
|
+
|
17
21
|
begin
|
18
|
-
|
22
|
+
url_params = {
|
23
|
+
:collection_identifier => collection_identifier,
|
24
|
+
:branch_id => branch_id,
|
25
|
+
:limit => limit,
|
26
|
+
:tags => tags
|
27
|
+
}.to_query
|
28
|
+
|
29
|
+
url = URI(api_root_url)
|
30
|
+
url.path = '/chunks'
|
31
|
+
url.query = url_params
|
32
|
+
|
19
33
|
response = HTTParty.get(url)
|
34
|
+
|
20
35
|
raise "No response received" unless response.code == 200
|
21
36
|
chunks = response["chunks"]
|
37
|
+
|
22
38
|
return chunks
|
23
39
|
rescue => error
|
24
40
|
puts error
|
@@ -53,7 +69,7 @@ module Editmode
|
|
53
69
|
# Always sanitize the content!!
|
54
70
|
chunk_content = ActionController::Base.helpers.sanitize(chunk_content)
|
55
71
|
|
56
|
-
css_class = options[:
|
72
|
+
css_class = options[:class]
|
57
73
|
|
58
74
|
if chunk_type == "image"
|
59
75
|
display_type = "image"
|
@@ -133,6 +149,28 @@ module Editmode
|
|
133
149
|
|
134
150
|
alias_method :chunk, :chunk_display
|
135
151
|
|
152
|
+
def variable_parse!(content, variables, values)
|
153
|
+
tokens = content.scan(/\{{(.*?)\}}/)
|
154
|
+
if tokens.any?
|
155
|
+
tokens.flatten!
|
156
|
+
tokens.each do |token|
|
157
|
+
token_value = values[token.to_sym] || variables[token] || ""
|
158
|
+
sanitized_value = ActionController::Base.helpers.sanitize(token_value)
|
159
|
+
|
160
|
+
content.gsub!("{{#{token}}}", sanitized_value)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
content
|
165
|
+
end
|
166
|
+
|
167
|
+
def no_response_received(id = "")
|
168
|
+
"Sorry, we can't find a content using this identifier: \"#{id}\""
|
169
|
+
end
|
170
|
+
|
171
|
+
def require_field_id
|
172
|
+
"Field ID or Field Name is required to retrieve a collection item"
|
173
|
+
end
|
136
174
|
end
|
137
175
|
end
|
138
176
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Editmode
|
2
|
+
class ChunkValue
|
3
|
+
include Editmode::ActionViewExtensions::EditmodeHelper
|
4
|
+
|
5
|
+
attr_accessor :identifier, :variable_values, :branch_id,
|
6
|
+
:variable_fallbacks, :chunk_type, :project_id,
|
7
|
+
:response, :content
|
8
|
+
|
9
|
+
def initialize(identifier, **options)
|
10
|
+
@identifier = identifier
|
11
|
+
@branch_id = options[:branch_id].presence
|
12
|
+
@variable_values = options[:values].presence || {}
|
13
|
+
get_content
|
14
|
+
end
|
15
|
+
|
16
|
+
def field(field = nil)
|
17
|
+
# Field ID can be a slug or field_name
|
18
|
+
if chunk_type == 'collection_item'
|
19
|
+
if field.present?
|
20
|
+
field.downcase!
|
21
|
+
field_content = content.detect {|f| f["custom_field_identifier"].downcase == field || f["custom_field_name"].downcase == field }
|
22
|
+
if field_content.present?
|
23
|
+
result = field_content['content']
|
24
|
+
result = variable_parse!(result, variable_fallbacks, variable_values)
|
25
|
+
else
|
26
|
+
raise no_response_received(field)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
raise require_field_id
|
30
|
+
end
|
31
|
+
else
|
32
|
+
raise "undefined method field for chunk_type: #{chunk_type}"
|
33
|
+
end
|
34
|
+
result ||= content
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def get_content
|
39
|
+
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
40
|
+
url = "#{api_root_url}/chunks/#{identifier}?#{branch_params}"
|
41
|
+
|
42
|
+
cache_identifier = "chunk_value_#{identifier}#{branch_id}"
|
43
|
+
cached_content_present = Rails.cache.exist?(cache_identifier)
|
44
|
+
|
45
|
+
if !cached_content_present
|
46
|
+
http_response = HTTParty.get(url)
|
47
|
+
response_received = true if http_response.code == 200
|
48
|
+
end
|
49
|
+
|
50
|
+
if !cached_content_present && !response_received
|
51
|
+
raise no_response_received(identifier)
|
52
|
+
else
|
53
|
+
@response = Rails.cache.fetch(cache_identifier) do
|
54
|
+
http_response
|
55
|
+
end
|
56
|
+
|
57
|
+
@content = response['content']
|
58
|
+
@chunk_type = response['chunk_type']
|
59
|
+
@project_id = response['project_id']
|
60
|
+
@variable_fallbacks = Rails.cache.fetch("chunk_#{project_id}_variables") do
|
61
|
+
response['variable_fallbacks']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
data/lib/editmode/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require 'rails/generators/base'
|
3
|
+
|
4
|
+
module Editmode
|
5
|
+
module Generators
|
6
|
+
class ConfigGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
|
9
|
+
argument :project_id, :desc => "Your Editmode project_id, which can be found here: https://www.editmode.com/projects"
|
10
|
+
|
11
|
+
def create_config_file
|
12
|
+
@project_id = project_id
|
13
|
+
|
14
|
+
introduction = <<-intro
|
15
|
+
Editmode will automatically insert its javascript before the closing '</body>'
|
16
|
+
tag on every page.
|
17
|
+
|
18
|
+
intro
|
19
|
+
|
20
|
+
print "#{introduction} "
|
21
|
+
|
22
|
+
template "editmode.rb.erb", "config/initializers/editmode.rb"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
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: 0.0.
|
4
|
+
version: 0.0.10.16
|
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
|
+
date: 2020-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,12 +82,13 @@ 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_value.rb
|
85
86
|
- lib/editmode/engine.rb
|
86
87
|
- lib/editmode/railtie.rb
|
87
88
|
- lib/editmode/script_tag.rb
|
88
89
|
- lib/editmode/version.rb
|
89
|
-
- lib/generators/editmode/
|
90
|
-
- lib/generators/editmode/templates/editmode.rb
|
90
|
+
- lib/generators/editmode/config_generator.rb
|
91
|
+
- lib/generators/editmode/templates/editmode.rb.erb
|
91
92
|
homepage: https://github.com/tonyennis145/editmode-rails
|
92
93
|
licenses:
|
93
94
|
- MIT
|
@@ -1,19 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rails/generators/base'
|
3
|
-
|
4
|
-
module Editmode
|
5
|
-
module Generators
|
6
|
-
class InstallGenerator < Rails::Generators::Base
|
7
|
-
source_root File.expand_path("../templates", __FILE__)
|
8
|
-
|
9
|
-
def install
|
10
|
-
copy_initializer
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
def copy_initializer
|
15
|
-
template "editmode.rb", "config/initializers/editmode.rb"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|