editmode 0.0.9.61 → 0.0.9.72
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26f96a0bfe674f27bb92438c188449cb788da1c848ca42188ad55b08215b5282
|
4
|
+
data.tar.gz: 82929aa1471f71a6f93c80fa1f987735c0fe85efce664adb4244f46a2234af44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f4352a5e5cfa504e5f3fe3cdc0d0bbc62ea472b580751b4415ece76ab431902ea2cb06e82f8cb408551c6df1d7c2f056313b6cd22893fe472874e0854394cdd
|
7
|
+
data.tar.gz: 95f1ccb5fe2b1b83b257eae7bb96cd280720ca5093fafbbdce1819e2998c808a963e84c9adf3b96b926aaa2fee3db56bfb8bc100cc26c58ddf3446dc3c81956d
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module EditModeRails
|
2
|
-
|
3
2
|
module ActionViewExtensions
|
4
3
|
module EditModeHelper
|
5
4
|
|
@@ -21,111 +20,118 @@ module EditModeRails
|
|
21
20
|
begin
|
22
21
|
url = "#{versioned_api_url}/chunks?collection_identifier=#{collection_identifier}"
|
23
22
|
response = HTTParty.get(url)
|
23
|
+
raise "No response received" unless response.code == 200
|
24
24
|
chunks = response["chunks"]
|
25
25
|
return chunks
|
26
26
|
rescue => error
|
27
27
|
puts error
|
28
|
-
[]
|
28
|
+
return []
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
34
|
-
chunk_identifier = chunk_info["identifier"]
|
32
|
+
def chunk_field_value(parent_chunk_object,custom_field_identifier,options={})
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
begin
|
35
|
+
chunk_identifier = parent_chunk_object["identifier"]
|
36
|
+
custom_field_item = parent_chunk_object["content"].detect {|f| f[custom_field_identifier].present? }
|
37
|
+
|
38
|
+
if custom_field_item.present?
|
39
|
+
properties = custom_field_item[custom_field_identifier]
|
40
|
+
render_chunk_content(
|
41
|
+
properties["identifier"],
|
42
|
+
properties["content"],
|
43
|
+
properties["chunk_type"]
|
44
|
+
)
|
40
45
|
end
|
41
|
-
|
42
|
-
|
46
|
+
rescue => errors
|
47
|
+
puts errors
|
48
|
+
content_tag(:span, " ".html_safe)
|
43
49
|
end
|
50
|
+
|
44
51
|
end
|
45
52
|
|
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
|
53
|
+
def render_chunk_content(chunk_identifier,chunk_content,chunk_type,options={})
|
68
54
|
|
69
|
-
|
55
|
+
begin
|
56
|
+
# Always sanitize the content!!
|
57
|
+
chunk_content = ActionController::Base.helpers.sanitize(chunk_content)
|
58
|
+
|
59
|
+
css_class = options[:css_class]
|
70
60
|
|
71
61
|
if chunk_type == "image"
|
72
62
|
display_type = "image"
|
73
63
|
else
|
74
64
|
display_type = options[:display_type] || "span"
|
75
65
|
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
|
-
|
90
|
-
additional_data_properties = custom_field_info.present? ? { :custom_field_identifier => custom_field_info["custom_field_identifier"] } : {}
|
91
66
|
|
92
67
|
case display_type
|
93
68
|
when "span"
|
94
|
-
if
|
95
|
-
content_tag(:span, :class => css_class, :data => {:chunk =>
|
96
|
-
chunk_content
|
69
|
+
if chunk_type == "rich_text"
|
70
|
+
content_tag(:span, :class => css_class, :data => {:chunk => chunk_identifier, :chunk_editable => false} ) do
|
71
|
+
chunk_content.html_safe
|
97
72
|
end
|
98
73
|
else
|
99
|
-
content_tag(:span, :class => css_class, :data => {:chunk =>
|
74
|
+
content_tag(:span, :class => css_class, :data => {:chunk => chunk_identifier, :chunk_editable => true} ) do
|
100
75
|
chunk_content
|
101
76
|
end
|
102
77
|
end
|
103
|
-
when "raw"
|
104
|
-
chunk_content
|
105
78
|
when "image"
|
106
|
-
content_tag(:span, :data => {:chunk =>
|
79
|
+
content_tag(:span, :data => {:chunk => chunk_identifier, :chunk_editable => false} ) do
|
107
80
|
image_tag(chunk_content, :class => css_class)
|
108
81
|
end
|
109
82
|
end
|
110
|
-
|
111
|
-
|
112
|
-
|
83
|
+
rescue => errors
|
84
|
+
puts errors
|
85
|
+
content_tag(:span, " ".html_safe)
|
86
|
+
end
|
113
87
|
|
114
88
|
end
|
115
89
|
|
116
|
-
def
|
117
|
-
chunk_display(label,identifier,options)
|
118
|
-
end
|
90
|
+
def chunk_display(label,identifier,options={},&block)
|
119
91
|
|
120
|
-
|
121
|
-
|
122
|
-
|
92
|
+
# This method should never show an error.
|
93
|
+
# If anything goes wrong fetching content
|
94
|
+
# We should just show blank content, not
|
95
|
+
# prevent the page from loading.
|
96
|
+
begin
|
97
|
+
|
98
|
+
cache_identifier = "chunk_#{identifier}"
|
99
|
+
url = "#{versioned_api_url}/chunks/#{identifier}"
|
100
|
+
cached_content_present = Rails.cache.exist?(cache_identifier)
|
101
|
+
|
102
|
+
if !cached_content_present
|
103
|
+
response = HTTParty.get(url)
|
104
|
+
response_received = true if response.code == 200
|
105
|
+
end
|
106
|
+
|
107
|
+
if !cached_content_present && !response_received
|
108
|
+
raise "No response received"
|
109
|
+
else
|
110
|
+
|
111
|
+
chunk_content = Rails.cache.fetch(cache_identifier) do
|
112
|
+
response['content']
|
113
|
+
end
|
114
|
+
|
115
|
+
chunk_type = Rails.cache.fetch("#{cache_identifier}_type") do
|
116
|
+
response['chunk_type']
|
117
|
+
end
|
118
|
+
|
119
|
+
render_chunk_content(identifier,chunk_content,chunk_type)
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
rescue => error
|
124
|
+
# Show fallback content by default
|
125
|
+
return content_tag(:span, &block) if block_given?
|
126
|
+
# Otherwise show a span with no content to
|
127
|
+
# maintain layout
|
128
|
+
content_tag(:span, " ".html_safe)
|
129
|
+
end
|
123
130
|
|
124
|
-
def raw_chunk(label,identifier,options={})
|
125
|
-
chunk_display(label,identifier,options.merge(:display_type => "raw"))
|
126
131
|
end
|
127
|
-
|
132
|
+
|
133
|
+
alias_method :chunk, :chunk_display
|
134
|
+
|
128
135
|
end
|
129
136
|
end
|
130
|
-
|
131
137
|
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.72
|
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-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|