editmode 1.1.3 → 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 +46 -16
- data/lib/editmode/chunk_value.rb +2 -2
- data/lib/editmode/engine.rb +6 -4
- data/lib/editmode/helper.rb +36 -0
- data/lib/editmode/script_tag.rb +1 -1
- data/lib/editmode/version.rb +1 -1
- metadata +3 -2
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,10 +81,9 @@ 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!!
|
@@ -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
@@ -11,7 +11,7 @@ module Editmode
|
|
11
11
|
def initialize(identifier, **options)
|
12
12
|
@identifier = identifier
|
13
13
|
@branch_id = options[:branch_id].presence
|
14
|
-
@variable_values = options[:
|
14
|
+
@variable_values = options[:variables].presence || {}
|
15
15
|
get_content
|
16
16
|
end
|
17
17
|
|
@@ -45,7 +45,7 @@ module Editmode
|
|
45
45
|
private
|
46
46
|
def get_content
|
47
47
|
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
48
|
-
url = "#{api_root_url}/chunks/#{identifier}
|
48
|
+
url = "#{api_root_url}/chunks/#{identifier}?project_id=#{Editmode.project_id}&#{branch_params}"
|
49
49
|
|
50
50
|
cache_identifier = "chunk_value_#{identifier}#{branch_id}"
|
51
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
@@ -27,7 +27,7 @@ module Editmode
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def script_url
|
30
|
-
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"
|
31
31
|
end
|
32
32
|
|
33
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.1.
|
4
|
+
version: 1.1.4
|
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-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
|