editmode 1.1.4 → 1.1.5
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/README.md +116 -11
- data/lib/editmode/chunk_value.rb +15 -7
- data/lib/editmode/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cd3f1671097d61c5ea8a0cec5c6dda55f9417221c712020d0aaa5e9474f6f85
|
4
|
+
data.tar.gz: c102afb1932ae31933b7e6d4d0d2361b2853c8b4d0e0c863fcf915650c509f6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b45d8499eff5c5a1864baff10963aee1dac5d2c453d99583099fcbb1ffd86d62ae8a611da3427a86e88f262927afb4f0b8182ac06300550ecdf87398858cfe20
|
7
|
+
data.tar.gz: 12d16710fdeaffde83efedc2e15fb8035b7b3bd9412296541171510b2669ca913bc47469f3b9ab65606aae24ab47ccd8a3975c32a884372bfaae18048ffeaf52
|
data/README.md
CHANGED
@@ -1,20 +1,125 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<img src="https://editmode.s3-eu-west-1.amazonaws.com/static/editmode-full-navy-bg-transparent.png" width="260" />
|
3
|
+
</p>
|
4
|
+
<br />
|
1
5
|
|
2
|
-
#
|
6
|
+
# EditMode for Rails
|
3
7
|
|
4
|
-
|
8
|
+
Editmode is a smarter way to manage copy and other content in your rails app. It's syntax is similar to i18n, but it's built for copy updates, not internationalization (yet). It's built around the idea of moving your content out of your codebase.
|
5
9
|
|
6
10
|
## Installation
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
12
|
+
#### 1. Add the gem to your Gemfile:
|
13
|
+
```ruby
|
14
|
+
gem 'editmode'
|
15
|
+
```
|
16
|
+
And run `bundle install`.
|
17
|
+
|
18
|
+
#### 2. Create an initializer with your project_id
|
19
|
+
|
20
|
+
<small>Don't have a project id? Sign up for one [here](https://editmode.com/rails?s=ghreadme)</small>
|
21
|
+
|
22
|
+
```sh
|
23
|
+
rails generate editmode:config YOUR-PROJECT-ID
|
24
|
+
```
|
25
|
+
This command produces an initializer file
|
26
|
+
```ruby
|
27
|
+
# config/initializers/editmode.rb
|
28
|
+
Editmode.setup do |config|
|
29
|
+
config.project_id={project_id}
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
That's it, you're all set up. By default Editmode will now include editmode.js in every page of your rails application, unless you disable auto-include.
|
34
|
+
<hr/>
|
35
|
+
|
36
|
+
## Rendering Content
|
37
|
+
|
38
|
+
Editmode provides helper methods for use in your rails views and controllers.
|
39
|
+
|
40
|
+
### Render the content of a chunk
|
41
|
+
```erb
|
42
|
+
<%= e('cnk_x4ts............') %> # Using a chunk identifier
|
43
|
+
<%= e('marketing_page_headline') %> # Using a content key
|
44
|
+
```
|
45
|
+
|
46
|
+
### Render an *Editable* chunk. Wait, [what?](https://editmode.com/rails)
|
47
|
+
```erb
|
48
|
+
<%= E('cnk_x4ts............') %> # Using a chunk identifier
|
49
|
+
<%= E('marketing_page_headline') %> # Using a content key
|
50
|
+
```
|
51
|
+
|
52
|
+
### Content can also be accessed in Controllers
|
53
|
+
```ruby
|
54
|
+
@page_title = e("cnk_x4ts............") # Using a chunk identifier
|
55
|
+
@page_title = e("marketing_page_seo_title") # Using a content key
|
56
|
+
```
|
57
|
+
|
58
|
+
### Directly get the value of a custom field
|
59
|
+
This works when a chunk is part of a collection.
|
60
|
+
```ruby
|
61
|
+
@email_subject = e("welcome_email","Subject")
|
62
|
+
@email_content = e("welcome_email","Content")
|
63
|
+
```
|
64
|
+
|
65
|
+
### Working with variables
|
66
|
+
```ruby
|
67
|
+
variable_values = { first_name: "Dexter", last_name: "Morgan"}
|
68
|
+
|
69
|
+
# Assume chunk content is "Hi {{first_name}} {{last_name}}"
|
70
|
+
|
71
|
+
# Single Chunk with Variables
|
72
|
+
e("cnk_d36415052285997e079b", variables: variable_values)
|
73
|
+
|
74
|
+
# Collection Field with Variables
|
75
|
+
e("cnk_16e04a02d577afb610ce", "Email Content", variables: variable_values)
|
76
|
+
|
77
|
+
# Response: "Hi Dexter Morgan"
|
78
|
+
```
|
79
|
+
|
80
|
+
### Use collections for repeatable content
|
81
|
+
```erb
|
82
|
+
<%= c('col_j8fbs...') do |chunk| %>
|
83
|
+
<div class="user-profile">
|
84
|
+
<h3 class="name">
|
85
|
+
<%= F("Name") %>
|
86
|
+
</h3>
|
87
|
+
<p class="description">
|
88
|
+
<%= f("Description") %>
|
89
|
+
</p>
|
90
|
+
</div>
|
91
|
+
<% end %>
|
92
|
+
```
|
93
|
+
|
94
|
+
|Parameter|Type|Description|
|
95
|
+
|---|---|---|
|
96
|
+
| identifier | string | The first argument of `c` takes the id of the collection you want to loop through |
|
97
|
+
| limit | int |`optional` The number of collection items you want to display |
|
98
|
+
| tags | array |`optional` Filter collection items based on tags listed in this parameter |
|
11
99
|
|
12
|
-
## Helper methods
|
13
|
-
- chunk_display
|
14
|
-
- raw_chunk
|
15
|
-
- chunk_list (coming soon)
|
16
100
|
|
17
101
|
## Caching
|
18
|
-
|
19
|
-
|
102
|
+
In order to keep your application speedy, Editmode minimizes the amount of network calls it makes by caching content where it can.
|
103
|
+
|
104
|
+
#### What's cached
|
105
|
+
- Any embedded content returned by the `e`, `E`, `f`, or `F` view helpers.
|
106
|
+
|
107
|
+
#### Expiring the cache
|
108
|
+
|
109
|
+
The editmode gem exposes a cache expiration endpoint in your application at `/editmode/clear_cache`.
|
110
|
+
|
111
|
+
1. GET `/editmode/clear_cache?identifier={chunk_id}` clears the cache for a specific chunk.
|
112
|
+
2. GET `/editmode/clear_cache?full=1` clears the full Editmode cache.
|
113
|
+
|
114
|
+
- Editmode.js will automatically hit this endpoint when you update a chunk through your frontend.
|
115
|
+
- You can configure cache expiration webhooks in Editmode.com to ensure your application is notified when content changes happen on Editmode.com
|
116
|
+
|
117
|
+
The cache expiration endpoint is currently **not** authenticated.
|
118
|
+
|
119
|
+
## Disabling editmode.js auto-include
|
120
|
+
|
121
|
+
To disable automatic insertion for a particular controller or action you can:
|
122
|
+
```ruby
|
123
|
+
skip_after_action :editmode_auto_include
|
124
|
+
```
|
20
125
|
|
data/lib/editmode/chunk_value.rb
CHANGED
@@ -3,9 +3,9 @@ module Editmode
|
|
3
3
|
include Editmode::ActionViewExtensions::EditmodeHelper
|
4
4
|
|
5
5
|
attr_accessor :identifier, :variable_values, :branch_id,
|
6
|
-
:variable_fallbacks, :chunk_type, :project_id,
|
6
|
+
:variable_fallbacks, :chunk_type, :project_id,
|
7
7
|
:response
|
8
|
-
|
8
|
+
|
9
9
|
attr_writer :content
|
10
10
|
|
11
11
|
def initialize(identifier, **options)
|
@@ -43,6 +43,14 @@ module Editmode
|
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
46
|
+
|
47
|
+
def json?(json)
|
48
|
+
JSON.parse(json)
|
49
|
+
return true
|
50
|
+
rescue JSON::ParserError => e
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
46
54
|
def get_content
|
47
55
|
branch_params = branch_id.present? ? "branch_id=#{branch_id}" : ""
|
48
56
|
url = "#{api_root_url}/chunks/#{identifier}?project_id=#{Editmode.project_id}&#{branch_params}"
|
@@ -58,16 +66,16 @@ module Editmode
|
|
58
66
|
if !cached_content_present && !response_received
|
59
67
|
raise no_response_received(identifier)
|
60
68
|
else
|
61
|
-
|
62
|
-
http_response
|
69
|
+
cached_response = Rails.cache.fetch(cache_identifier) do
|
70
|
+
http_response.to_json
|
63
71
|
end
|
64
72
|
|
73
|
+
@response = json?(cached_response) ? JSON.parse(cached_response) : cached_response
|
74
|
+
|
65
75
|
@content = response['content']
|
66
76
|
@chunk_type = response['chunk_type']
|
67
77
|
@project_id = response['project_id']
|
68
|
-
@variable_fallbacks =
|
69
|
-
response['variable_fallbacks']
|
70
|
-
end
|
78
|
+
@variable_fallbacks = response['variable_fallbacks']
|
71
79
|
end
|
72
80
|
end
|
73
81
|
|
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.5
|
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-09-
|
11
|
+
date: 2020-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|