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: ce997b779bf5eaa50e09fe58d37f34e8af99c84563bc924f96383cd122444480
4
- data.tar.gz: a5a6a81f255a310da5d3903ad23f08a5d388a831304ffda5ec90a0be995abb89
3
+ metadata.gz: 26f96a0bfe674f27bb92438c188449cb788da1c848ca42188ad55b08215b5282
4
+ data.tar.gz: 82929aa1471f71a6f93c80fa1f987735c0fe85efce664adb4244f46a2234af44
5
5
  SHA512:
6
- metadata.gz: 4c00859b98407d53afd1b3bd1dec620a0d2c8bdb72a38331fb28ae2cd765412f39f1450f28194ef30a3c29bace62290b4ad418d3134cd722834490851bf4597d
7
- data.tar.gz: 3dd0c905ea7eb2356387c70eeac7cca415de719c5080ed2c753a7c26044bf449c2c572d45992e2006f15eb73fc11775f8d00e8f54edf7f3d3058cd0e12953ab4
6
+ metadata.gz: 6f4352a5e5cfa504e5f3fe3cdc0d0bbc62ea472b580751b4415ece76ab431902ea2cb06e82f8cb408551c6df1d7c2f056313b6cd22893fe472874e0854394cdd
7
+ data.tar.gz: 95f1ccb5fe2b1b83b257eae7bb96cd280720ca5093fafbbdce1819e2998c808a963e84c9adf3b96b926aaa2fee3db56bfb8bc100cc26c58ddf3446dc3c81956d
@@ -1,7 +1,6 @@
1
1
  class EditmodeController < ApplicationController
2
2
 
3
3
  def clear_cache
4
-
5
4
 
6
5
  if params[:identifier]
7
6
  Rails.cache.delete("chunk_#{params[:identifier]}")
@@ -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 chunk_property(chunk_info,custom_field_identifier=nil,options={})
33
-
34
- chunk_identifier = chunk_info["identifier"]
32
+ def chunk_field_value(parent_chunk_object,custom_field_identifier,options={})
35
33
 
36
- if custom_field_identifier
37
- custom_field_info = chunk_info["custom_fields"].select{|custom_field| custom_field["custom_field_identifier"] == custom_field_identifier }[0]
38
- if custom_field_info.present?
39
- chunk_display("",chunk_identifier,options,custom_field_info)
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
- else
42
- chunk_display("",chunk_identifier,options)
46
+ rescue => errors
47
+ puts errors
48
+ content_tag(:span, "&nbsp".html_safe)
43
49
  end
50
+
44
51
  end
45
52
 
46
- def chunk_display(label,identifier,options={},custom_field_info={})
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
- end
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 content_type == "rich"
95
- content_tag(:span, :class => css_class, :data => {:chunk => identifier, :chunk_editable => false}.merge(additional_data_properties) ) do
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 => identifier, :chunk_editable => true}.merge(additional_data_properties)) do
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 => identifier, :chunk_editable => false}.merge(additional_data_properties)) do
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
- rescue => error
111
- puts error
112
- end
83
+ rescue => errors
84
+ puts errors
85
+ content_tag(:span, "&nbsp".html_safe)
86
+ end
113
87
 
114
88
  end
115
89
 
116
- def bit(label,identifier,options={})
117
- chunk_display(label,identifier,options)
118
- end
90
+ def chunk_display(label,identifier,options={},&block)
119
91
 
120
- def chunk(label,identifier,options={})
121
- chunk_display(label,identifier,options)
122
- end
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, "&nbsp".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
@@ -1,3 +1,3 @@
1
1
  module EditModeRails
2
- VERSION = "0.0.9.61"
2
+ VERSION = "0.0.9.72"
3
3
  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.61
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-03-17 00:00:00.000000000 Z
11
+ date: 2020-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler