editmode 0.0.9.112 → 0.0.10.15
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 +22 -36
- data/lib/{editmode-rails → editmode}/action_view_extensions/editmode_helper.rb +43 -5
- data/lib/{editmode-rails → editmode}/auto_include_filter.rb +3 -3
- data/lib/editmode/chunk_value.rb +71 -0
- data/lib/{editmode-rails → editmode}/engine.rb +1 -1
- data/lib/{editmode-rails → editmode}/railtie.rb +3 -3
- data/lib/{editmode-rails → editmode}/script_tag.rb +1 -1
- data/lib/editmode/version.rb +3 -0
- data/lib/generators/editmode/config_generator.rb +26 -0
- data/lib/generators/editmode/templates/editmode.rb.erb +5 -0
- metadata +11 -8
- data/lib/editmode-rails/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: feb3922328fd985e4aec3156ba98021dbd194c3fdf58a9b51b63de2b7f7dc535
|
4
|
+
data.tar.gz: f52847ef24647300e4bde80f71a90f557e67e7caa40b55ded07fe1276ca759e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573b7952ccdb805057e3cdeffe11f9d19af12fc578d166916a95f14e0d3508b868b8c4f37348a2550bc1563abba2bd218b53d416f628c9422a19db6c08e656c2
|
7
|
+
data.tar.gz: 3a690c5d2a0427596f29fdf1154f1715da067611c27ad95dbe86a8ef4c5a296e5cbc6c96e170ce0442f9f32c9fea835233ab276a5cc28be98e7f7caa2e84c8ee
|
@@ -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
@@ -1,14 +1,16 @@
|
|
1
1
|
require "active_support/dependencies"
|
2
|
-
require "editmode
|
3
|
-
require 'editmode
|
4
|
-
require 'editmode
|
5
|
-
require 'editmode
|
6
|
-
require 'editmode
|
7
|
-
require 'editmode
|
8
|
-
|
9
|
-
|
2
|
+
require "editmode/version"
|
3
|
+
require 'editmode/script_tag'
|
4
|
+
require 'editmode/action_view_extensions/editmode_helper'
|
5
|
+
require 'editmode/auto_include_filter'
|
6
|
+
require 'editmode/chunk_value'
|
7
|
+
require 'editmode/railtie' if defined? Rails
|
8
|
+
require 'editmode/engine' if defined?(Rails)
|
9
|
+
# Todo: Implement RSPEC
|
10
|
+
module Editmode
|
10
11
|
class << self
|
11
|
-
include ::
|
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 @@ class 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,22 @@ class 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
|
-
|
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
|
+
options.merge!(project_id: project_id)
|
37
|
+
Editmode::ChunkValue.new(identifier, **options )
|
38
|
+
rescue => er
|
39
|
+
raise er
|
60
40
|
end
|
61
41
|
end
|
62
42
|
end
|
63
43
|
|
64
44
|
class Configuration
|
65
|
-
attr_accessor :
|
45
|
+
attr_accessor :access_token, :variable
|
46
|
+
attr_reader :project_id
|
47
|
+
|
48
|
+
def project_id=(id)
|
49
|
+
@project_id = id
|
50
|
+
|
51
|
+
end
|
66
52
|
end
|
67
53
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module Editmode
|
2
2
|
module ActionViewExtensions
|
3
|
-
module
|
3
|
+
module EditmodeHelper
|
4
4
|
|
5
5
|
require 'httparty'
|
6
6
|
|
@@ -12,13 +12,29 @@ module EditModeRails
|
|
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 EditModeRails
|
|
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 EditModeRails
|
|
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
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module
|
1
|
+
module Editmode
|
2
2
|
|
3
3
|
module AutoInclude
|
4
4
|
|
5
5
|
module Method
|
6
6
|
def editmode_auto_include
|
7
|
-
|
7
|
+
Editmode::AutoInclude::Filter.filter(self)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -49,7 +49,7 @@ module EditModeRails
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def editmode_script_tag
|
52
|
-
@script_tag ||=
|
52
|
+
@script_tag ||= Editmode::ScriptTag.new()
|
53
53
|
end
|
54
54
|
|
55
55
|
def enabled_for_environment?
|
@@ -0,0 +1,71 @@
|
|
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
|
+
:content
|
8
|
+
|
9
|
+
def initialize(identifier, **options)
|
10
|
+
@identifier = identifier
|
11
|
+
@branch_id = options[:branch_id].presence
|
12
|
+
@project_id = options[:project_id].presence
|
13
|
+
@variable_values = options[:values].presence || {}
|
14
|
+
get_content
|
15
|
+
end
|
16
|
+
|
17
|
+
def field(field = nil)
|
18
|
+
# Field ID can be a slug or field_name
|
19
|
+
if chunk_type == 'collection_item'
|
20
|
+
if field.present?
|
21
|
+
field_content = content.detect {|f| f["custom_field_identifier"] == field || f["custom_field_name"] == 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_#{identifier}#{branch_id}"
|
43
|
+
cached_content_present = Rails.cache.exist?(cache_identifier)
|
44
|
+
cached_content_present = Rails.cache.exist?("chunk_#{project_id}_variables") if cached_content_present
|
45
|
+
|
46
|
+
if !cached_content_present
|
47
|
+
response = HTTParty.get(url)
|
48
|
+
response_received = true if response.code == 200
|
49
|
+
end
|
50
|
+
|
51
|
+
if !cached_content_present && !response_received
|
52
|
+
raise no_response_received(identifier)
|
53
|
+
else
|
54
|
+
@content = Rails.cache.fetch(cache_identifier) do
|
55
|
+
response['content']
|
56
|
+
end
|
57
|
+
|
58
|
+
@chunk_type = Rails.cache.fetch("#{cache_identifier}_type") do
|
59
|
+
response['chunk_type']
|
60
|
+
end
|
61
|
+
|
62
|
+
# Since variables are defined in the project level,
|
63
|
+
# We use project_id as cache identifier
|
64
|
+
@variable_fallbacks = Rails.cache.fetch("chunk_#{project_id}_variables") do
|
65
|
+
response['variable_fallbacks']
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module Editmode
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
-
initializer "editmode
|
3
|
+
initializer "editmode" do |app|
|
4
4
|
|
5
5
|
ActiveSupport.on_load :action_view do
|
6
|
-
include
|
6
|
+
include Editmode::ActionViewExtensions::EditmodeHelper
|
7
7
|
end
|
8
8
|
ActiveSupport.on_load :action_controller do
|
9
9
|
include AutoInclude::Method
|
@@ -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.15
|
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-06-
|
11
|
+
date: 2020-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -79,13 +79,16 @@ files:
|
|
79
79
|
- Rakefile
|
80
80
|
- app/controllers/editmode_controller.rb
|
81
81
|
- config/routes.rb
|
82
|
-
- lib/editmode-rails/action_view_extensions/editmode_helper.rb
|
83
|
-
- lib/editmode-rails/auto_include_filter.rb
|
84
|
-
- lib/editmode-rails/engine.rb
|
85
|
-
- lib/editmode-rails/railtie.rb
|
86
|
-
- lib/editmode-rails/script_tag.rb
|
87
|
-
- lib/editmode-rails/version.rb
|
88
82
|
- lib/editmode.rb
|
83
|
+
- lib/editmode/action_view_extensions/editmode_helper.rb
|
84
|
+
- lib/editmode/auto_include_filter.rb
|
85
|
+
- lib/editmode/chunk_value.rb
|
86
|
+
- lib/editmode/engine.rb
|
87
|
+
- lib/editmode/railtie.rb
|
88
|
+
- lib/editmode/script_tag.rb
|
89
|
+
- lib/editmode/version.rb
|
90
|
+
- lib/generators/editmode/config_generator.rb
|
91
|
+
- lib/generators/editmode/templates/editmode.rb.erb
|
89
92
|
homepage: https://github.com/tonyennis145/editmode-rails
|
90
93
|
licenses:
|
91
94
|
- MIT
|