editmode 1.0.21 → 1.1.4
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 +1 -0
- data/lib/editmode/action_view_extensions/editmode_helper.rb +49 -19
- data/lib/editmode/chunk_value.rb +14 -6
- data/lib/editmode/engine.rb +6 -4
- data/lib/editmode/helper.rb +36 -0
- data/lib/editmode/script_tag.rb +2 -1
- data/lib/editmode/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d4e7090d2da1935453260320513e82439c6815295621646a1ebdc7378895abe
|
4
|
+
data.tar.gz: 8e96d36c0c479a4ebd89c4efb74896270c3cbae9ea75353adf491e00fdd51943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28475295b70e1e65c3472f74d0b3ee4a5765bb52727843dc478c1239f9fd09fe399d43fd0db2c63814e14623f5f225344aea474421e3c73ff6feba3ec84123e6
|
7
|
+
data.tar.gz: d3d787c71c390a115b9470c06f2e48cdd5089fb7a788dc03e862d6090453b0a41a75a41812297b4a66dddae77b86a59e7415a8145245a0edebd72740c79ae1df
|
@@ -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[:collection]
|
8
|
+
cache_id = "collection_#{params[:identifier]}"
|
9
|
+
Rails.cache.delete_matched("#{cache_id}*")
|
10
|
+
render status: 200, json: {:response => "success"}
|
7
11
|
elsif params[:variable_cache_project_id]
|
8
12
|
project_id = params[:variable_cache_project_id]
|
9
13
|
Rails.cache.delete("chunk_#{project_id}_variables")
|
data/lib/editmode.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'editmode/helper'
|
2
|
+
|
1
3
|
module Editmode
|
2
4
|
module ActionViewExtensions
|
3
5
|
module EditmodeHelper
|
4
|
-
|
5
6
|
require 'httparty'
|
7
|
+
include Editmode::Helper
|
6
8
|
|
7
9
|
def api_version
|
8
10
|
# Todo Add Header Version
|
@@ -12,12 +14,12 @@ module Editmode
|
|
12
14
|
ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
|
13
15
|
end
|
14
16
|
|
15
|
-
def chunk_collection(collection_identifier, **options)
|
17
|
+
def chunk_collection(collection_identifier, **options, &block)
|
16
18
|
branch_params = params[:em_branch_id].present? ? "branch_id=#{params[:em_branch_id]}" : ""
|
17
19
|
branch_id = params[:em_branch_id].presence
|
18
20
|
tags = options[:tags].presence || []
|
19
21
|
limit = options[:limit].presence
|
20
|
-
|
22
|
+
|
21
23
|
begin
|
22
24
|
url_params = {
|
23
25
|
:collection_identifier => collection_identifier,
|
@@ -30,24 +32,43 @@ module Editmode
|
|
30
32
|
url.path = '/chunks'
|
31
33
|
url.query = url_params
|
32
34
|
|
33
|
-
|
35
|
+
cache_identifier = "collection_#{collection_identifier}#{branch_id}#{limit}#{tags.join}"
|
36
|
+
cached_content_present = Rails.cache.exist?(cache_identifier)
|
37
|
+
|
38
|
+
if !cached_content_present
|
39
|
+
response = HTTParty.get(url)
|
40
|
+
response_received = true if response.code == 200
|
41
|
+
end
|
42
|
+
|
43
|
+
if !cached_content_present && !response_received
|
44
|
+
raise "No response received"
|
45
|
+
else
|
34
46
|
|
35
|
-
|
36
|
-
|
47
|
+
chunks = Rails.cache.fetch(cache_identifier) do
|
48
|
+
response['chunks']
|
49
|
+
end
|
37
50
|
|
38
|
-
|
51
|
+
if chunks.any?
|
52
|
+
content_tag :div, class: "chunks-collection-wrapper", data: {chunk_collection_identifier: collection_identifier} do
|
53
|
+
chunks.each do |chunk|
|
54
|
+
@custom_field_chunk = chunk
|
55
|
+
yield
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
39
60
|
rescue => error
|
40
61
|
puts error
|
41
62
|
return []
|
42
63
|
end
|
43
64
|
end
|
65
|
+
alias_method :c, :chunk_collection
|
44
66
|
|
45
|
-
def chunk_field_value(parent_chunk_object, custom_field_identifier,options={})
|
46
|
-
|
67
|
+
def chunk_field_value(parent_chunk_object, custom_field_identifier, options = {})
|
47
68
|
begin
|
48
69
|
chunk_identifier = parent_chunk_object["identifier"]
|
49
|
-
custom_field_item = parent_chunk_object["content"].detect {|f| f["custom_field_identifier"] == custom_field_identifier }
|
50
|
-
|
70
|
+
custom_field_item = parent_chunk_object["content"].detect {|f| f["custom_field_identifier"] == custom_field_identifier || f["custom_field_name"] == custom_field_identifier }
|
71
|
+
|
51
72
|
if custom_field_item.present?
|
52
73
|
render_chunk_content(
|
53
74
|
custom_field_item["identifier"],
|
@@ -60,15 +81,14 @@ module Editmode
|
|
60
81
|
puts errors
|
61
82
|
content_tag(:span, " ".html_safe)
|
62
83
|
end
|
63
|
-
|
64
84
|
end
|
65
85
|
|
66
|
-
def render_chunk_content(chunk_identifier,chunk_content,chunk_type,options={})
|
86
|
+
def render_chunk_content(chunk_identifier, chunk_content, chunk_type,options = {})
|
67
87
|
|
68
88
|
begin
|
69
89
|
# Always sanitize the content!!
|
70
|
-
chunk_content = ActionController::Base.helpers.sanitize(chunk_content)
|
71
|
-
|
90
|
+
chunk_content = ActionController::Base.helpers.sanitize(chunk_content) unless chunk_type == 'rich_text'
|
91
|
+
|
72
92
|
css_class = options[:class]
|
73
93
|
|
74
94
|
if chunk_type == "image"
|
@@ -86,7 +106,7 @@ module Editmode
|
|
86
106
|
case display_type
|
87
107
|
when "span"
|
88
108
|
if chunk_type == "rich_text"
|
89
|
-
content_tag("em-span", :class => "editmode-richtext-editor #{css_class}", :data => chunk_data.merge!({:chunk_editable => true}) ) do
|
109
|
+
content = content_tag("em-span", :class => "editmode-richtext-editor #{css_class}", :data => chunk_data.merge!({:chunk_editable => true}) ) do
|
90
110
|
chunk_content.html_safe
|
91
111
|
end
|
92
112
|
else
|
@@ -104,7 +124,7 @@ module Editmode
|
|
104
124
|
|
105
125
|
end
|
106
126
|
|
107
|
-
def chunk_display(label,identifier,options={}
|
127
|
+
def chunk_display(label, identifier, options = {}, &block)
|
108
128
|
branch_id = params[:em_branch_id]
|
109
129
|
# This method should never show an error.
|
110
130
|
# If anything goes wrong fetching content
|
@@ -113,7 +133,7 @@ module Editmode
|
|
113
133
|
begin
|
114
134
|
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
115
135
|
cache_identifier = "chunk_#{identifier}#{branch_id}"
|
116
|
-
url = "#{api_root_url}/chunks/#{identifier}
|
136
|
+
url = "#{api_root_url}/chunks/#{identifier}?project_id=#{Editmode.project_id}&#{branch_params}"
|
117
137
|
cached_content_present = Rails.cache.exist?(cache_identifier)
|
118
138
|
|
119
139
|
if !cached_content_present
|
@@ -144,10 +164,20 @@ module Editmode
|
|
144
164
|
# maintain layout
|
145
165
|
content_tag("em-span", " ".html_safe)
|
146
166
|
end
|
167
|
+
end
|
168
|
+
alias_method :chunk, :chunk_display
|
169
|
+
|
147
170
|
|
171
|
+
def render_custom_field(label, options={})
|
172
|
+
chunk_field_value(@custom_field_chunk, label, options)
|
148
173
|
end
|
174
|
+
alias_method :F, :render_custom_field
|
175
|
+
|
176
|
+
def render_chunk(identifier, options = {}, &block)
|
177
|
+
chunk_display('label', identifier, options, &block)
|
178
|
+
end
|
179
|
+
alias_method :E, :render_chunk
|
149
180
|
|
150
|
-
alias_method :chunk, :chunk_display
|
151
181
|
|
152
182
|
def variable_parse!(content, variables, values)
|
153
183
|
tokens = content.scan(/\{{(.*?)\}}/)
|
data/lib/editmode/chunk_value.rb
CHANGED
@@ -4,12 +4,14 @@ module Editmode
|
|
4
4
|
|
5
5
|
attr_accessor :identifier, :variable_values, :branch_id,
|
6
6
|
:variable_fallbacks, :chunk_type, :project_id,
|
7
|
-
:response
|
7
|
+
:response
|
8
|
+
|
9
|
+
attr_writer :content
|
8
10
|
|
9
11
|
def initialize(identifier, **options)
|
10
12
|
@identifier = identifier
|
11
13
|
@branch_id = options[:branch_id].presence
|
12
|
-
@variable_values = options[:
|
14
|
+
@variable_values = options[:variables].presence || {}
|
13
15
|
get_content
|
14
16
|
end
|
15
17
|
|
@@ -18,7 +20,7 @@ module Editmode
|
|
18
20
|
if chunk_type == 'collection_item'
|
19
21
|
if field.present?
|
20
22
|
field.downcase!
|
21
|
-
field_content = content.detect {|f| f["custom_field_identifier"].downcase == field || f["custom_field_name"].downcase == field }
|
23
|
+
field_content = @content.detect {|f| f["custom_field_identifier"].downcase == field || f["custom_field_name"].downcase == field }
|
22
24
|
if field_content.present?
|
23
25
|
result = field_content['content']
|
24
26
|
result = variable_parse!(result, variable_fallbacks, variable_values)
|
@@ -29,15 +31,21 @@ module Editmode
|
|
29
31
|
raise require_field_id
|
30
32
|
end
|
31
33
|
else
|
32
|
-
raise "undefined method field for chunk_type: #{chunk_type}"
|
34
|
+
raise NoMethodError.new "undefined method 'field` for chunk_type: #{chunk_type} \n"
|
33
35
|
end
|
34
|
-
result
|
36
|
+
result || @content
|
37
|
+
end
|
38
|
+
|
39
|
+
def content
|
40
|
+
raise NoMethodError.new "undefined method 'content` for chunk_type: collection_item \nDid you mean? field" if chunk_type == 'collection_item'
|
41
|
+
|
42
|
+
variable_parse!(@content, variable_fallbacks, variable_values)
|
35
43
|
end
|
36
44
|
|
37
45
|
private
|
38
46
|
def get_content
|
39
47
|
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
40
|
-
url = "#{api_root_url}/chunks/#{identifier}
|
48
|
+
url = "#{api_root_url}/chunks/#{identifier}?project_id=#{Editmode.project_id}&#{branch_params}"
|
41
49
|
|
42
50
|
cache_identifier = "chunk_value_#{identifier}#{branch_id}"
|
43
51
|
cached_content_present = Rails.cache.exist?(cache_identifier)
|
data/lib/editmode/engine.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Editmode
|
2
|
+
module Helper
|
3
|
+
# Render non-editable content
|
4
|
+
def e(identifier, *args)
|
5
|
+
field, options = parse_arguments(args)
|
6
|
+
begin
|
7
|
+
chunk = Editmode::ChunkValue.new(identifier, options)
|
8
|
+
|
9
|
+
if chunk.chunk_type == 'collection_item'
|
10
|
+
chunk.field(field)
|
11
|
+
else
|
12
|
+
chunk.content
|
13
|
+
end
|
14
|
+
rescue => er
|
15
|
+
raise er
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def render_custom_field_raw(label, options={})
|
20
|
+
e(@custom_field_chunk["identifier"], label, options)
|
21
|
+
end
|
22
|
+
alias_method :f, :render_custom_field_raw
|
23
|
+
|
24
|
+
def parse_arguments(args)
|
25
|
+
field = nil
|
26
|
+
options = {}
|
27
|
+
if args[0].class.name == 'String'
|
28
|
+
field = args[0]
|
29
|
+
options = args[1] || {}
|
30
|
+
elsif args[0].class.name == 'Hash'
|
31
|
+
options = args[0] || {}
|
32
|
+
end
|
33
|
+
return field, options
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/editmode/script_tag.rb
CHANGED
@@ -18,6 +18,7 @@ module Editmode
|
|
18
18
|
|
19
19
|
str = <<-EDITMODE_SCRIPT
|
20
20
|
<script>window.chunksProjectIdentifier = '#{Editmode.project_id}'</script>
|
21
|
+
<script>window.editmodeENV = '#{ENV["EDITMODE_ENV"] || 'production'}'</script>
|
21
22
|
<script src="#{script_url}" async ></script>
|
22
23
|
EDITMODE_SCRIPT
|
23
24
|
|
@@ -26,7 +27,7 @@ module Editmode
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def script_url
|
29
|
-
ENV["EDITMODE_OVERRIDE_SCRIPT_URL"] || "https://static.editmode.com/editmode@
|
30
|
+
ENV["EDITMODE_OVERRIDE_SCRIPT_URL"] || "https://static.editmode.com/editmode@2.0.0/dist/editmode.js"
|
30
31
|
end
|
31
32
|
|
32
33
|
end
|
data/lib/editmode/version.rb
CHANGED
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.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Ennis
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/editmode/auto_include_filter.rb
|
85
85
|
- lib/editmode/chunk_value.rb
|
86
86
|
- lib/editmode/engine.rb
|
87
|
+
- lib/editmode/helper.rb
|
87
88
|
- lib/editmode/railtie.rb
|
88
89
|
- lib/editmode/script_tag.rb
|
89
90
|
- lib/editmode/version.rb
|
@@ -93,7 +94,7 @@ homepage: https://github.com/tonyennis145/editmode-rails
|
|
93
94
|
licenses:
|
94
95
|
- MIT
|
95
96
|
metadata: {}
|
96
|
-
post_install_message:
|
97
|
+
post_install_message:
|
97
98
|
rdoc_options: []
|
98
99
|
require_paths:
|
99
100
|
- lib
|
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
112
|
rubygems_version: 3.0.8
|
112
|
-
signing_key:
|
113
|
+
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: Editmode allows you to turn plain text in your rails app into easily inline-editable
|
115
116
|
bits of content that can be managed by anyone with no technical knowledge
|