editmode 1.2.4 → 1.2.9
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/Gemfile +2 -0
- data/README.md +8 -0
- data/Rakefile +9 -1
- data/lib/editmode/action_view_extensions/editmode_helper.rb +9 -3
- data/lib/editmode/chunk_value.rb +22 -12
- data/lib/editmode/engine.rb +2 -1
- data/lib/editmode/helper.rb +1 -1
- data/lib/editmode/railtie.rb +1 -0
- data/lib/editmode/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3c6615ff35d91086eb0774d03d3d5e90070f1f52456563b883b947c42182bdf
|
4
|
+
data.tar.gz: 067ea9cb9d9227d12cda1aa825fbce9987731ee720e9882386a9a1d6cdbb4e4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3da11757cc4d252bd5222533c4e4fee807623a50c6913d968dec1ded22e3a653199b3b5b858f138440d62391e64048d22e1062837689c082b523c62beb82170
|
7
|
+
data.tar.gz: 367aace629ffe1363a1938a6bdec061976eeb2dda597916378f4c6385ee57e7dfa7a8e0efda7d873d8d1aafbb0cb5875a4328e478540b4abba775728e177c05f
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -50,6 +50,12 @@ Editmode provides helper methods for use in your rails views and controllers.
|
|
50
50
|
<%= E('cnk_x4ts...', class: "a-css-class") %> # Render a chunk with inline css class
|
51
51
|
```
|
52
52
|
|
53
|
+
### Working with multiple projects in the same codebase
|
54
|
+
If you want to include content from a different project to the one you've specified in the initializer, you can pass the project id in to the view helper.
|
55
|
+
```erb
|
56
|
+
<%= E("cnk_16e04a02d577afb610ce", project_id: "prj_02d577afb617hdb") %>
|
57
|
+
```
|
58
|
+
|
53
59
|
### Content can also be accessed in Controllers
|
54
60
|
```ruby
|
55
61
|
@page_title = e("cnk_x4ts............") # Using a chunk identifier
|
@@ -78,6 +84,8 @@ e("cnk_16e04a02d577afb610ce", "Email Content", variables: variable_values)
|
|
78
84
|
# Response: "Hi Dexter Morgan"
|
79
85
|
```
|
80
86
|
|
87
|
+
|
88
|
+
|
81
89
|
### Use collections for repeatable content
|
82
90
|
```erb
|
83
91
|
<%= c('col_j8fbs...', class: "profiles-container", item_class: "profile-item") do %>
|
data/Rakefile
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
require 'editmode/helper'
|
2
|
+
require 'action_view'
|
3
|
+
require 'httparty'
|
2
4
|
|
3
5
|
module Editmode
|
4
6
|
module ActionViewExtensions
|
5
7
|
module EditmodeHelper
|
6
|
-
|
8
|
+
include ::ActionView::Helpers::TagHelper
|
9
|
+
include ::ActionView::Helpers::TextHelper
|
10
|
+
include ::ActionView::Helpers::AssetTagHelper
|
11
|
+
include ::ActionView::Context
|
7
12
|
include Editmode::Helper
|
8
13
|
|
14
|
+
|
9
15
|
def api_version
|
10
16
|
# Todo Add Header Version
|
11
17
|
end
|
@@ -56,14 +62,14 @@ module Editmode
|
|
56
62
|
chunks.each do |chunk|
|
57
63
|
@custom_field_chunk = chunk
|
58
64
|
concat(content_tag(:div, class: "chunks-collection-item--wrapper #{item_class}") do
|
59
|
-
yield
|
65
|
+
yield(@custom_field_chunk)
|
60
66
|
end)
|
61
67
|
end
|
62
68
|
|
63
69
|
# Placeholder element for new collection item
|
64
70
|
@custom_field_chunk = chunks.first.merge!({placeholder: true})
|
65
71
|
concat(content_tag(:div, class: "chunks-hide chunks-col-placeholder-wrapper") do
|
66
|
-
yield
|
72
|
+
yield(@custom_field_chunk)
|
67
73
|
end)
|
68
74
|
end
|
69
75
|
else
|
data/lib/editmode/chunk_value.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'active_support'
|
3
|
+
|
1
4
|
module Editmode
|
2
5
|
class ChunkValue
|
3
6
|
include ActionView::Helpers::TagHelper
|
@@ -10,13 +13,14 @@ module Editmode
|
|
10
13
|
|
11
14
|
attr_writer :content
|
12
15
|
|
13
|
-
def initialize(identifier, **options)
|
16
|
+
def initialize(identifier, project_id: Editmode.project_id, **options)
|
14
17
|
@identifier = identifier
|
15
18
|
@branch_id = options[:branch_id].presence
|
16
|
-
@project_id =
|
19
|
+
@project_id = project_id
|
17
20
|
@variable_values = options[:variables].presence || {}
|
18
21
|
@raw = options[:raw].present?
|
19
22
|
@skip_sanitize = options[:dangerously_skip_sanitization]
|
23
|
+
@skip_cache = options[:skip_cache]
|
20
24
|
|
21
25
|
@url = "#{api_root_url}/chunks/#{identifier}"
|
22
26
|
@cache_identifier = set_cache_identifier(identifier)
|
@@ -62,6 +66,11 @@ module Editmode
|
|
62
66
|
result.try(:html_safe)
|
63
67
|
end
|
64
68
|
|
69
|
+
def cached?
|
70
|
+
return false if @skip_cache
|
71
|
+
Rails.cache.exist?(cache_identifier)
|
72
|
+
end
|
73
|
+
|
65
74
|
private
|
66
75
|
|
67
76
|
# Todo: Transfer to helper utils
|
@@ -81,7 +90,6 @@ module Editmode
|
|
81
90
|
end
|
82
91
|
|
83
92
|
def variable_parse!(content, variables = {}, values = {}, raw = true, skip_sanitize=false)
|
84
|
-
content = ActionController::Base.helpers.sanitize(content) unless skip_sanitize
|
85
93
|
tokens = content.scan(/\{{(.*?)\}}/)
|
86
94
|
if tokens.any?
|
87
95
|
tokens.flatten!
|
@@ -99,11 +107,8 @@ module Editmode
|
|
99
107
|
end
|
100
108
|
end
|
101
109
|
|
102
|
-
content
|
103
|
-
|
104
|
-
|
105
|
-
def cached?
|
106
|
-
Rails.cache.exist?(cache_identifier)
|
110
|
+
content = ActionController::Base.helpers.sanitize(content) unless skip_sanitize
|
111
|
+
return content
|
107
112
|
end
|
108
113
|
|
109
114
|
def query_params
|
@@ -114,17 +119,19 @@ module Editmode
|
|
114
119
|
end
|
115
120
|
|
116
121
|
def get_content
|
122
|
+
|
117
123
|
if !cached?
|
118
124
|
http_response = HTTParty.get(url, query: query_params)
|
119
125
|
response_received = true if http_response.code == 200
|
120
126
|
end
|
121
127
|
|
122
128
|
if !cached? && !response_received
|
123
|
-
|
129
|
+
message = http_response.try(:[], 'message') || no_response_received(identifier)
|
130
|
+
|
131
|
+
raise message
|
124
132
|
else
|
125
|
-
|
126
|
-
|
127
|
-
end
|
133
|
+
Rails.cache.write(cache_identifier, http_response.to_json) if http_response.present?
|
134
|
+
cached_response = Rails.cache.fetch(cache_identifier)
|
128
135
|
|
129
136
|
@response = json?(cached_response) ? JSON.parse(cached_response) : cached_response
|
130
137
|
set_response_attributes!
|
@@ -139,5 +146,8 @@ module Editmode
|
|
139
146
|
@branch_id = response['branch_id']
|
140
147
|
end
|
141
148
|
|
149
|
+
def no_response_received(id = "")
|
150
|
+
"Sorry, we can't find a chunk using this identifier: \"#{id}\". This can happen if you've deleted a chunk on editmode.com or if your local cache is out of date. If it persists, try running Rails.cache clear."
|
151
|
+
end
|
142
152
|
end
|
143
153
|
end
|
data/lib/editmode/engine.rb
CHANGED
data/lib/editmode/helper.rb
CHANGED
data/lib/editmode/railtie.rb
CHANGED
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.2.
|
4
|
+
version: 1.2.9
|
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:
|
11
|
+
date: 2021-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,7 @@ homepage: https://github.com/tonyennis145/editmode-rails
|
|
94
94
|
licenses:
|
95
95
|
- MIT
|
96
96
|
metadata: {}
|
97
|
-
post_install_message:
|
97
|
+
post_install_message:
|
98
98
|
rdoc_options: []
|
99
99
|
require_paths:
|
100
100
|
- lib
|
@@ -109,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
113
|
-
signing_key:
|
112
|
+
rubygems_version: 3.2.4
|
113
|
+
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Editmode allows you to turn plain text in your rails app into easily inline-editable
|
116
116
|
bits of content that can be managed by anyone with no technical knowledge
|