editmode 0.0.9.61 → 0.0.9.112
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 -3
- data/lib/editmode-rails/action_view_extensions/editmode_helper.rb +84 -77
- data/lib/editmode-rails/auto_include_filter.rb +1 -1
- data/lib/editmode-rails/script_tag.rb +2 -1
- data/lib/editmode-rails/version.rb +1 -1
- data/lib/editmode.rb +59 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c06ee068c329efaa3dba8ccf03bc2c83cf32d6ef753cacd87b2b0d8117ae7a9f
|
4
|
+
data.tar.gz: c9433d98aff266e7f16bfeacf7ece3fd03bd373159aac702868f2231d392696c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcee3061b99a16e7d7a6c172899b15d271ccd27e97c0c09eec240d6922a67be01a2d8845940ca30d78b3538fc585178c6ea9b7b523cf4373e3f273cbb7e9cf6d
|
7
|
+
data.tar.gz: b91a78c606b9579fec2388fe9e5b21cbd6fa5fe01e8d509b7090700f88f31a615b57edf41061abe2bd56f739e6c959eace3872a712b20b4fe5f4f408d3ec440e
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class EditmodeController < ApplicationController
|
2
2
|
|
3
3
|
def clear_cache
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
if params[:full]
|
5
|
+
Rails.cache.clear
|
6
|
+
render status: 200, json: {:response => "success"}
|
7
|
+
elsif params[:identifier]
|
7
8
|
Rails.cache.delete("chunk_#{params[:identifier]}")
|
8
9
|
Rails.cache.delete("chunk_#{params[:identifier]}_type")
|
9
10
|
render status: 200, json: {:response => "success"}
|
@@ -1,131 +1,138 @@
|
|
1
1
|
module EditModeRails
|
2
|
-
|
3
2
|
module ActionViewExtensions
|
4
3
|
module EditModeHelper
|
5
4
|
|
6
5
|
require 'httparty'
|
7
6
|
|
8
7
|
def api_version
|
9
|
-
|
8
|
+
# Todo Add Header Version
|
10
9
|
end
|
11
10
|
|
12
11
|
def api_root_url
|
13
|
-
ENV["EDITMODE_OVERRIDE_API_URL"] || "https://
|
12
|
+
ENV["EDITMODE_OVERRIDE_API_URL"] || "https://api.editmode.com"
|
14
13
|
end
|
15
14
|
|
16
|
-
def versioned_api_url
|
17
|
-
"#{api_root_url}/#{api_version}"
|
18
|
-
end
|
19
|
-
|
20
15
|
def chunk_collection(collection_identifier,has_tags=[])
|
16
|
+
branch_params = params[:em_branch_id].present? ? "branch_id=#{params[:em_branch_id]}" : ""
|
21
17
|
begin
|
22
|
-
url = "#{
|
18
|
+
url = "#{api_root_url}/chunks?collection_identifier=#{collection_identifier}&#{branch_params}"
|
23
19
|
response = HTTParty.get(url)
|
20
|
+
raise "No response received" unless response.code == 200
|
24
21
|
chunks = response["chunks"]
|
25
22
|
return chunks
|
26
23
|
rescue => error
|
27
24
|
puts error
|
28
|
-
[]
|
25
|
+
return []
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
32
|
-
def
|
29
|
+
def chunk_field_value(parent_chunk_object, custom_field_identifier,options={})
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if
|
39
|
-
|
31
|
+
begin
|
32
|
+
chunk_identifier = parent_chunk_object["identifier"]
|
33
|
+
custom_field_item = parent_chunk_object["content"].detect {|f| f["custom_field_identifier"] == custom_field_identifier }
|
34
|
+
|
35
|
+
if custom_field_item.present?
|
36
|
+
render_chunk_content(
|
37
|
+
custom_field_item["identifier"],
|
38
|
+
custom_field_item["content"],
|
39
|
+
custom_field_item["chunk_type"],
|
40
|
+
{ parent_identifier: chunk_identifier }.merge(options)
|
41
|
+
)
|
40
42
|
end
|
41
|
-
|
42
|
-
|
43
|
+
rescue => errors
|
44
|
+
puts errors
|
45
|
+
content_tag(:span, " ".html_safe)
|
43
46
|
end
|
47
|
+
|
44
48
|
end
|
45
49
|
|
46
|
-
def
|
47
|
-
|
48
|
-
begin
|
49
|
-
|
50
|
-
if custom_field_info.present?
|
51
|
-
chunk_content = custom_field_info["value"]
|
52
|
-
else
|
53
|
-
|
54
|
-
cache_identifier = "chunk_#{identifier}"
|
55
|
-
url = "#{versioned_api_url}/bits/#{identifier}"
|
56
|
-
|
57
|
-
if !Rails.cache.exist?(cache_identifier)
|
58
|
-
response = HTTParty.get(url)
|
59
|
-
end
|
60
|
-
|
61
|
-
chunk_content = Rails.cache.fetch(cache_identifier) do
|
62
|
-
response['content']
|
63
|
-
end
|
64
|
-
|
65
|
-
chunk_type = Rails.cache.fetch("#{cache_identifier}_type") do
|
66
|
-
response['chunk_type']
|
67
|
-
end
|
50
|
+
def render_chunk_content(chunk_identifier,chunk_content,chunk_type,options={})
|
68
51
|
|
69
|
-
|
52
|
+
begin
|
53
|
+
# Always sanitize the content!!
|
54
|
+
chunk_content = ActionController::Base.helpers.sanitize(chunk_content)
|
55
|
+
|
56
|
+
css_class = options[:css_class]
|
70
57
|
|
71
58
|
if chunk_type == "image"
|
72
59
|
display_type = "image"
|
73
60
|
else
|
74
61
|
display_type = options[:display_type] || "span"
|
75
62
|
end
|
76
|
-
css_class = options[:css_class]
|
77
|
-
content_type = "plain"
|
78
|
-
|
79
|
-
# Simple check to see if returned chunk contains html. Regex will need to be improved
|
80
|
-
if /<[a-z][\s\S]*>/i.match(chunk_content)
|
81
|
-
content_type = "rich"
|
82
|
-
chunk_content = sanitize chunk_content.html_safe
|
83
|
-
elsif chunk_content.include? "\n"
|
84
|
-
content_type = "rich"
|
85
|
-
renderer = Redcarpet::Render::HTML.new(no_links: true, hard_wrap: true)
|
86
|
-
markdown = Redcarpet::Markdown.new(renderer, extensions = {})
|
87
|
-
chunk_content = markdown.render(chunk_content).html_safe
|
88
|
-
end
|
89
63
|
|
90
|
-
|
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
|
91
69
|
|
92
70
|
case display_type
|
93
71
|
when "span"
|
94
|
-
if
|
95
|
-
content_tag(
|
96
|
-
chunk_content
|
72
|
+
if chunk_type == "rich_text"
|
73
|
+
content_tag("em-span", :class => css_class, :data => chunk_data ) do
|
74
|
+
chunk_content.html_safe
|
97
75
|
end
|
98
76
|
else
|
99
|
-
content_tag(
|
77
|
+
content_tag("em-span", :class => css_class, :data => chunk_data.merge!({:chunk_editable => true}) ) do
|
100
78
|
chunk_content
|
101
79
|
end
|
102
80
|
end
|
103
|
-
when "raw"
|
104
|
-
chunk_content
|
105
81
|
when "image"
|
106
|
-
|
107
|
-
image_tag(chunk_content, :class => css_class)
|
108
|
-
end
|
82
|
+
image_tag(chunk_content, :data => chunk_data, :class => css_class)
|
109
83
|
end
|
110
|
-
|
111
|
-
|
112
|
-
|
84
|
+
rescue => errors
|
85
|
+
puts errors
|
86
|
+
content_tag("em-span", " ".html_safe)
|
87
|
+
end
|
113
88
|
|
114
89
|
end
|
115
90
|
|
116
|
-
def
|
117
|
-
|
118
|
-
|
91
|
+
def chunk_display(label,identifier,options={},&block)
|
92
|
+
branch_id = params[:em_branch_id]
|
93
|
+
# This method should never show an error.
|
94
|
+
# If anything goes wrong fetching content
|
95
|
+
# We should just show blank content, not
|
96
|
+
# prevent the page from loading.
|
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}"
|
101
|
+
cached_content_present = Rails.cache.exist?(cache_identifier)
|
102
|
+
|
103
|
+
if !cached_content_present
|
104
|
+
response = HTTParty.get(url)
|
105
|
+
response_received = true if response.code == 200
|
106
|
+
end
|
119
107
|
|
120
|
-
|
121
|
-
|
122
|
-
|
108
|
+
if !cached_content_present && !response_received
|
109
|
+
raise "No response received"
|
110
|
+
else
|
111
|
+
|
112
|
+
chunk_content = Rails.cache.fetch(cache_identifier) do
|
113
|
+
response['content']
|
114
|
+
end
|
115
|
+
|
116
|
+
chunk_type = Rails.cache.fetch("#{cache_identifier}_type") do
|
117
|
+
response['chunk_type']
|
118
|
+
end
|
119
|
+
|
120
|
+
render_chunk_content(identifier,chunk_content,chunk_type, options)
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
rescue => error
|
125
|
+
# Show fallback content by default
|
126
|
+
return content_tag("em-span", &block) if block_given?
|
127
|
+
# Otherwise show a span with no content to
|
128
|
+
# maintain layout
|
129
|
+
content_tag("em-span", " ".html_safe)
|
130
|
+
end
|
123
131
|
|
124
|
-
def raw_chunk(label,identifier,options={})
|
125
|
-
chunk_display(label,identifier,options.merge(:display_type => "raw"))
|
126
132
|
end
|
127
|
-
|
133
|
+
|
134
|
+
alias_method :chunk, :chunk_display
|
135
|
+
|
128
136
|
end
|
129
137
|
end
|
130
|
-
|
131
138
|
end
|
@@ -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
|
data/lib/editmode.rb
CHANGED
@@ -1,14 +1,67 @@
|
|
1
1
|
require "active_support/dependencies"
|
2
|
-
|
3
2
|
require "editmode-rails/version"
|
4
|
-
|
5
3
|
require 'editmode-rails/script_tag'
|
6
4
|
require 'editmode-rails/action_view_extensions/editmode_helper'
|
7
5
|
require 'editmode-rails/auto_include_filter'
|
8
6
|
require 'editmode-rails/railtie' if defined? Rails
|
7
|
+
require 'editmode-rails/engine' if defined?(Rails)
|
8
|
+
|
9
|
+
class Editmode
|
10
|
+
class << self
|
11
|
+
include ::EditModeRails::ActionViewExtensions::EditModeHelper
|
12
|
+
def project_id=(id)
|
13
|
+
config.project_id = id
|
14
|
+
end
|
15
|
+
|
16
|
+
def project_id
|
17
|
+
config.project_id
|
18
|
+
end
|
19
|
+
|
20
|
+
def access_token
|
21
|
+
config.access_token
|
22
|
+
end
|
23
|
+
|
24
|
+
def config
|
25
|
+
# Todo: Instantiate in editmode initializer or base controllers
|
26
|
+
# Todo: Add a generator to create initializer an file?
|
27
|
+
@config ||= Configuration.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup
|
31
|
+
yield config
|
32
|
+
end
|
33
|
+
|
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
|
+
begin
|
44
|
+
response = HTTParty.get(url, query: body)
|
45
|
+
response_received = true if response.code == 200
|
9
46
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
13
63
|
|
14
|
-
|
64
|
+
class Configuration
|
65
|
+
attr_accessor :project_id, :access_token
|
66
|
+
end
|
67
|
+
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.9.
|
4
|
+
version: 0.0.9.112
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
|
-
rubygems_version: 3.0.
|
108
|
+
rubygems_version: 3.0.8
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Editmode allows you to turn plain text in your rails app into easily inline-editable
|