editmode 0.0.9.75 → 0.0.10.12
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 +8 -2
- data/lib/editmode.rb +48 -9
- data/lib/{editmode-rails → editmode}/action_view_extensions/editmode_helper.rb +52 -29
- 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 +3 -2
- 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 +12 -9
- 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: e17da0620f2d013a83300d7984ace6b9badd0716bc3187b1125fe7497e8c99a0
|
4
|
+
data.tar.gz: 39e552edd8fc95c2ba238b0fe7575432603b4e6f7e7e46328c5ff5836987ce31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff2bd59f92ff2389577e23888d092f1097daebc95e4f6e8cd56c3ce5df1e2dd6221705849301a0b6865a3fac8709530d6198d4a04137e9496720bac6b715f376
|
7
|
+
data.tar.gz: 69e56b6950e2e8c2f1907b7fd4a2c9626cf5b4777ddceadc720a002efbc15d1a6b3ae041117841e7b8c3351c3af825d12fcd558345ac5a8d49e53e727caf235d
|
@@ -1,8 +1,14 @@
|
|
1
1
|
class EditmodeController < ApplicationController
|
2
2
|
|
3
3
|
def clear_cache
|
4
|
-
|
5
|
-
|
4
|
+
if params[:full]
|
5
|
+
Rails.cache.clear
|
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"}
|
11
|
+
elsif params[:identifier]
|
6
12
|
Rails.cache.delete("chunk_#{params[:identifier]}")
|
7
13
|
Rails.cache.delete("chunk_#{params[:identifier]}_type")
|
8
14
|
render status: 200, json: {:response => "success"}
|
data/lib/editmode.rb
CHANGED
@@ -1,14 +1,53 @@
|
|
1
1
|
require "active_support/dependencies"
|
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
|
11
|
+
class << self
|
12
|
+
include Editmode::ActionViewExtensions::EditmodeHelper
|
2
13
|
|
3
|
-
|
14
|
+
def project_id=(id)
|
15
|
+
config.project_id = id
|
16
|
+
end
|
4
17
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
require 'editmode-rails/railtie' if defined? Rails
|
18
|
+
def project_id
|
19
|
+
config.project_id
|
20
|
+
end
|
9
21
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
22
|
+
def access_token
|
23
|
+
config.access_token
|
24
|
+
end
|
13
25
|
|
14
|
-
|
26
|
+
def config
|
27
|
+
@config ||= Configuration.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup
|
31
|
+
yield config
|
32
|
+
end
|
33
|
+
|
34
|
+
def chunk_value(identifier, **options)
|
35
|
+
begin
|
36
|
+
options.merge!(project_id: project_id)
|
37
|
+
Editmode::ChunkValue.new(identifier, **options )
|
38
|
+
rescue => er
|
39
|
+
raise er
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Configuration
|
45
|
+
attr_accessor :access_token, :variable
|
46
|
+
attr_reader :project_id
|
47
|
+
|
48
|
+
def project_id=(id)
|
49
|
+
@project_id = id
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,24 +1,21 @@
|
|
1
|
-
module
|
1
|
+
module Editmode
|
2
2
|
module ActionViewExtensions
|
3
|
-
module
|
3
|
+
module EditmodeHelper
|
4
4
|
|
5
5
|
require 'httparty'
|
6
6
|
|
7
7
|
def api_version
|
8
|
-
|
8
|
+
# Todo Add Header Version
|
9
9
|
end
|
10
10
|
|
11
11
|
def api_root_url
|
12
|
-
ENV["EDITMODE_OVERRIDE_API_URL"] || "https://
|
12
|
+
ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
|
13
13
|
end
|
14
14
|
|
15
|
-
def versioned_api_url
|
16
|
-
"#{api_root_url}/#{api_version}"
|
17
|
-
end
|
18
|
-
|
19
15
|
def chunk_collection(collection_identifier,has_tags=[])
|
16
|
+
branch_params = params[:em_branch_id].present? ? "branch_id=#{params[:em_branch_id]}" : ""
|
20
17
|
begin
|
21
|
-
url = "#{
|
18
|
+
url = "#{api_root_url}/chunks?collection_identifier=#{collection_identifier}&#{branch_params}"
|
22
19
|
response = HTTParty.get(url)
|
23
20
|
raise "No response received" unless response.code == 200
|
24
21
|
chunks = response["chunks"]
|
@@ -29,18 +26,18 @@ module EditModeRails
|
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
32
|
-
def chunk_field_value(parent_chunk_object,custom_field_identifier,options={})
|
29
|
+
def chunk_field_value(parent_chunk_object, custom_field_identifier,options={})
|
33
30
|
|
34
31
|
begin
|
35
32
|
chunk_identifier = parent_chunk_object["identifier"]
|
36
|
-
custom_field_item = parent_chunk_object["content"].detect {|f| f[custom_field_identifier]
|
33
|
+
custom_field_item = parent_chunk_object["content"].detect {|f| f["custom_field_identifier"] == custom_field_identifier }
|
37
34
|
|
38
35
|
if custom_field_item.present?
|
39
|
-
properties = custom_field_item[custom_field_identifier]
|
40
36
|
render_chunk_content(
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
custom_field_item["identifier"],
|
38
|
+
custom_field_item["content"],
|
39
|
+
custom_field_item["chunk_type"],
|
40
|
+
{ parent_identifier: chunk_identifier }.merge(options)
|
44
41
|
)
|
45
42
|
end
|
46
43
|
rescue => errors
|
@@ -64,39 +61,43 @@ module EditModeRails
|
|
64
61
|
display_type = options[:display_type] || "span"
|
65
62
|
end
|
66
63
|
|
64
|
+
chunk_data = { :chunk => chunk_identifier, :chunk_editable => false }
|
65
|
+
|
66
|
+
if options[:parent_identifier].present?
|
67
|
+
chunk_data.merge!({parent_identifier: options[:parent_identifier]})
|
68
|
+
end
|
69
|
+
|
67
70
|
case display_type
|
68
71
|
when "span"
|
69
72
|
if chunk_type == "rich_text"
|
70
|
-
content_tag(
|
73
|
+
content_tag("em-span", :class => css_class, :data => chunk_data ) do
|
71
74
|
chunk_content.html_safe
|
72
75
|
end
|
73
76
|
else
|
74
|
-
content_tag(
|
77
|
+
content_tag("em-span", :class => css_class, :data => chunk_data.merge!({:chunk_editable => true}) ) do
|
75
78
|
chunk_content
|
76
79
|
end
|
77
80
|
end
|
78
81
|
when "image"
|
79
|
-
|
80
|
-
image_tag(chunk_content, :class => css_class)
|
81
|
-
end
|
82
|
+
image_tag(chunk_content, :data => chunk_data, :class => css_class)
|
82
83
|
end
|
83
84
|
rescue => errors
|
84
85
|
puts errors
|
85
|
-
content_tag(
|
86
|
+
content_tag("em-span", " ".html_safe)
|
86
87
|
end
|
87
88
|
|
88
89
|
end
|
89
90
|
|
90
91
|
def chunk_display(label,identifier,options={},&block)
|
91
|
-
|
92
|
+
branch_id = params[:em_branch_id]
|
92
93
|
# This method should never show an error.
|
93
94
|
# If anything goes wrong fetching content
|
94
95
|
# We should just show blank content, not
|
95
96
|
# prevent the page from loading.
|
96
|
-
begin
|
97
|
-
|
98
|
-
cache_identifier = "chunk_#{identifier}"
|
99
|
-
url = "#{
|
97
|
+
begin
|
98
|
+
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
99
|
+
cache_identifier = "chunk_#{identifier}#{branch_id}"
|
100
|
+
url = "#{api_root_url}/chunks/#{identifier}?#{branch_params}"
|
100
101
|
cached_content_present = Rails.cache.exist?(cache_identifier)
|
101
102
|
|
102
103
|
if !cached_content_present
|
@@ -116,22 +117,44 @@ module EditModeRails
|
|
116
117
|
response['chunk_type']
|
117
118
|
end
|
118
119
|
|
119
|
-
render_chunk_content(identifier,chunk_content,chunk_type)
|
120
|
+
render_chunk_content(identifier,chunk_content,chunk_type, options)
|
120
121
|
|
121
122
|
end
|
122
123
|
|
123
124
|
rescue => error
|
124
125
|
# Show fallback content by default
|
125
|
-
return content_tag(
|
126
|
+
return content_tag("em-span", &block) if block_given?
|
126
127
|
# Otherwise show a span with no content to
|
127
128
|
# maintain layout
|
128
|
-
content_tag(
|
129
|
+
content_tag("em-span", " ".html_safe)
|
129
130
|
end
|
130
131
|
|
131
132
|
end
|
132
133
|
|
133
134
|
alias_method :chunk, :chunk_display
|
134
135
|
|
136
|
+
def variable_parse!(content, variables, values)
|
137
|
+
tokens = content.scan(/\{{(.*?)\}}/)
|
138
|
+
if tokens.any?
|
139
|
+
tokens.flatten!
|
140
|
+
tokens.each do |token|
|
141
|
+
token_value = values[token.to_sym] || variables[token] || ""
|
142
|
+
sanitized_value = ActionController::Base.helpers.sanitize(token_value)
|
143
|
+
|
144
|
+
content.gsub!("{{#{token}}}", sanitized_value)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
content
|
149
|
+
end
|
150
|
+
|
151
|
+
def no_response_received(id = "")
|
152
|
+
"Sorry, we can't find a content using this identifier: \"#{id}\""
|
153
|
+
end
|
154
|
+
|
155
|
+
def require_field_id
|
156
|
+
"Field ID or Field Name is required to retrieve a collection item"
|
157
|
+
end
|
135
158
|
end
|
136
159
|
end
|
137
160
|
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
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Editmode
|
2
2
|
|
3
3
|
class ScriptTag
|
4
4
|
|
@@ -17,6 +17,7 @@ module EditModeRails
|
|
17
17
|
def output
|
18
18
|
|
19
19
|
str = <<-EDITMODE_SCRIPT
|
20
|
+
<script>window.chunksProjectIdentifier = '#{Editmode.project_id}'</script>
|
20
21
|
<script src="#{script_url}" async ></script>
|
21
22
|
EDITMODE_SCRIPT
|
22
23
|
|
@@ -25,7 +26,7 @@ module EditModeRails
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def script_url
|
28
|
-
ENV["EDITMODE_OVERRIDE_SCRIPT_URL"] || "https://
|
29
|
+
ENV["EDITMODE_OVERRIDE_SCRIPT_URL"] || "https://static.editmode.com/editmode@1.0.0/dist/editmode.js"
|
29
30
|
end
|
30
31
|
|
31
32
|
end
|
@@ -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.12
|
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-06-25 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
|
@@ -105,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
108
|
- !ruby/object:Gem::Version
|
106
109
|
version: '0'
|
107
110
|
requirements: []
|
108
|
-
rubygems_version: 3.0.
|
111
|
+
rubygems_version: 3.0.8
|
109
112
|
signing_key:
|
110
113
|
specification_version: 4
|
111
114
|
summary: Editmode allows you to turn plain text in your rails app into easily inline-editable
|