renderful 0.2.0 → 0.3.0
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/.circleci/config.yml +4 -1
- data/.gitignore +1 -0
- data/.rubocop-https---relaxed-ruby-style-rubocop-yml +3 -24
- data/CHANGELOG.md +36 -12
- data/README.md +99 -158
- data/lib/renderful.rb +10 -7
- data/lib/renderful/cache/base.rb +31 -0
- data/lib/renderful/cache/null.rb +31 -0
- data/lib/renderful/cache/redis.rb +17 -4
- data/lib/renderful/client.rb +30 -19
- data/lib/renderful/component/base.rb +18 -0
- data/lib/renderful/content_entry.rb +24 -0
- data/lib/renderful/error/base.rb +7 -0
- data/lib/renderful/error/entry_not_found_error.rb +15 -0
- data/lib/renderful/error/no_component_error.rb +15 -0
- data/lib/renderful/provider/base.rb +25 -0
- data/lib/renderful/provider/contentful.rb +55 -0
- data/lib/renderful/provider/prismic.rb +46 -0
- data/lib/renderful/version.rb +1 -1
- data/renderful.gemspec +9 -3
- metadata +131 -28
- data/lib/renderful/cache.rb +0 -21
- data/lib/renderful/cache_invalidator.rb +0 -26
- data/lib/renderful/no_renderer_error.rb +0 -13
- data/lib/renderful/renderer.rb +0 -36
- data/lib/renderful/renderer/rails.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8b21d6a36339a25124f85dc7a61596b84307b23d3931d163d72f543a592ae90
|
4
|
+
data.tar.gz: bca04f50852ace266b6ce965159f0d1d9d681ada34727551e9ae3faa404d4aaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c2e0367a4297cf75dc9851122b77628321959d398c8cf5354af3a6d683462cdbf94d0225d58fa6eca7355a5c7451fe097204f25c96c7613e1dbbc9d0874bd4d
|
7
|
+
data.tar.gz: 41fe4c2e8aadff79edad156da04ba42832f3443c2456aa45f969f3d52165ede301d88dc9d6bef5293341b2c119070c0a91880729cff7cc0f6b9c3f9e367f11d5
|
data/.circleci/config.yml
CHANGED
@@ -14,8 +14,11 @@ jobs:
|
|
14
14
|
- renderful-v1-{{ .Branch }}
|
15
15
|
- renderful-v1-
|
16
16
|
- run:
|
17
|
-
name: Bundle
|
17
|
+
name: Bundle install
|
18
18
|
command: bundle check || bundle install
|
19
|
+
- run:
|
20
|
+
name: Appraisal install
|
21
|
+
command: bundle exec appraisal install
|
19
22
|
- save_cache:
|
20
23
|
key: renderful-v1-{{ .Branch }}-{{ .Revision }}
|
21
24
|
paths:
|
data/.gitignore
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Relaxed.Ruby.Style
|
2
|
-
## Version 2.
|
2
|
+
## Version 2.5
|
3
3
|
|
4
4
|
Style/Alias:
|
5
5
|
Enabled: false
|
@@ -145,30 +145,9 @@ Lint/AssignmentInCondition:
|
|
145
145
|
Enabled: false
|
146
146
|
StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
|
147
147
|
|
148
|
-
|
148
|
+
Layout/LineLength:
|
149
149
|
Enabled: false
|
150
150
|
|
151
|
-
Metrics
|
152
|
-
Enabled: false
|
153
|
-
|
154
|
-
Metrics/ClassLength:
|
155
|
-
Enabled: false
|
156
|
-
|
157
|
-
Metrics/ModuleLength:
|
158
|
-
Enabled: false
|
159
|
-
|
160
|
-
Metrics/CyclomaticComplexity:
|
161
|
-
Enabled: false
|
162
|
-
|
163
|
-
Metrics/LineLength:
|
164
|
-
Enabled: false
|
165
|
-
|
166
|
-
Metrics/MethodLength:
|
167
|
-
Enabled: false
|
168
|
-
|
169
|
-
Metrics/ParameterLists:
|
170
|
-
Enabled: false
|
171
|
-
|
172
|
-
Metrics/PerceivedComplexity:
|
151
|
+
Metrics:
|
173
152
|
Enabled: false
|
174
153
|
|
data/CHANGELOG.md
CHANGED
@@ -1,23 +1,47 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
3
|
+
## [Unreleased](https://github.com/nebulab/renderful/tree/HEAD)
|
4
4
|
|
5
|
-
|
6
|
-
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
5
|
+
[Full Changelog](https://github.com/nebulab/renderful/compare/v0.2.0...HEAD)
|
7
6
|
|
8
|
-
|
7
|
+
**Closed issues:**
|
9
8
|
|
10
|
-
|
9
|
+
- Normalize field values [\#21](https://github.com/nebulab/renderful/issues/21)
|
10
|
+
- Expose customer helpers to ERB views [\#15](https://github.com/nebulab/renderful/issues/15)
|
11
|
+
- \[Contentful\] Render entities embedded in rich text? [\#14](https://github.com/nebulab/renderful/issues/14)
|
12
|
+
- Generate a UI component library [\#13](https://github.com/nebulab/renderful/issues/13)
|
13
|
+
- Write an end-to-end integration test [\#12](https://github.com/nebulab/renderful/issues/12)
|
14
|
+
- Remove rails from the gemspec [\#8](https://github.com/nebulab/renderful/issues/8)
|
15
|
+
- Remove redis from the gemspec [\#7](https://github.com/nebulab/renderful/issues/7)
|
16
|
+
- Move issues from the upstream here [\#3](https://github.com/nebulab/renderful/issues/3)
|
17
|
+
- Adopt ActionView::Component for rendering [\#2](https://github.com/nebulab/renderful/issues/2)
|
18
|
+
- Add support for Prismic [\#1](https://github.com/nebulab/renderful/issues/1)
|
11
19
|
|
12
|
-
|
20
|
+
**Merged pull requests:**
|
13
21
|
|
14
|
-
|
22
|
+
- Raise error when entry not found [\#24](https://github.com/nebulab/renderful/pull/24) ([filippoliverani](https://github.com/filippoliverani))
|
23
|
+
- Add support for \#render\_in and ViewComponent [\#19](https://github.com/nebulab/renderful/pull/19) ([aldesantis](https://github.com/aldesantis))
|
24
|
+
- Fix a typo and trim whitespace in the README [\#18](https://github.com/nebulab/renderful/pull/18) ([elia](https://github.com/elia))
|
25
|
+
- Prismic integration [\#17](https://github.com/nebulab/renderful/pull/17) ([aldesantis](https://github.com/aldesantis))
|
26
|
+
- Support for multiple providers [\#16](https://github.com/nebulab/renderful/pull/16) ([aldesantis](https://github.com/aldesantis))
|
15
27
|
|
16
|
-
|
28
|
+
## [v0.2.0](https://github.com/nebulab/renderful/tree/v0.2.0) (2020-01-17)
|
17
29
|
|
18
|
-
|
30
|
+
[Full Changelog](https://github.com/nebulab/renderful/compare/v0.1.0...v0.2.0)
|
19
31
|
|
20
|
-
|
32
|
+
**Closed issues:**
|
21
33
|
|
22
|
-
[
|
23
|
-
|
34
|
+
- Add Rails 6 support [\#4](https://github.com/nebulab/renderful/issues/4)
|
35
|
+
|
36
|
+
**Merged pull requests:**
|
37
|
+
|
38
|
+
- Update linting and testing infrastructure [\#6](https://github.com/nebulab/renderful/pull/6) ([aldesantis](https://github.com/aldesantis))
|
39
|
+
- Add support for Rails 6 [\#5](https://github.com/nebulab/renderful/pull/5) ([aldesantis](https://github.com/aldesantis))
|
40
|
+
|
41
|
+
## [v0.1.0](https://github.com/nebulab/renderful/tree/v0.1.0) (2019-05-02)
|
42
|
+
|
43
|
+
[Full Changelog](https://github.com/nebulab/renderful/compare/579c7801e5937dc02d789cc0fa4877ae43a60e70...v0.1.0)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Renderful
|
2
2
|
|
3
|
-
[](https://circleci.com/gh/nebulab/renderful)
|
4
4
|
|
5
|
-
Welcome! Renderful is a rendering engine for
|
6
|
-
|
5
|
+
Welcome! Renderful is a rendering engine for headless CMSs. It allows you to map your content types
|
6
|
+
to Ruby objects that take care of rendering your content.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -28,154 +28,81 @@ $ gem install renderful
|
|
28
28
|
Once you have installed the gem, you can configure it like this:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
RenderfulClient = Renderful::Client.new(
|
32
|
+
provider: Renderful::Provider::DummyCms.new(api_key: 'secretApiKey'), # see "Providers"
|
33
|
+
components: {
|
34
|
+
'jumbotron' => JumbotronComponent,
|
35
|
+
},
|
34
36
|
)
|
35
|
-
|
36
|
-
renderful = Renderful.new(
|
37
|
-
contentful: contentful,
|
38
|
-
renderers: {
|
39
|
-
'jumbotron' => JumbotronRenderer,
|
40
|
-
}
|
41
|
-
)
|
42
|
-
```
|
37
|
+
```
|
43
38
|
|
44
39
|
## Usage
|
45
40
|
|
46
41
|
Suppose you have the `jumbotron` content type in your Contentful space. This content type has the
|
47
42
|
`title` and `content` fields, both strings.
|
48
43
|
|
49
|
-
Let's create the `app/
|
44
|
+
Let's create the `app/components/jumbotron_component.rb` file:
|
50
45
|
|
51
46
|
```ruby
|
52
|
-
class
|
47
|
+
class JumbotronComponent < Renderful::Component
|
53
48
|
def render
|
54
49
|
<<~HTML
|
55
50
|
<div class="jumbotron">
|
56
|
-
<h1 class="display-4"
|
57
|
-
<p class="lead"
|
51
|
+
<h1 class="display-4">#{ entry.title }</h1>
|
52
|
+
<p class="lead">#{ entry.content }</p>
|
58
53
|
</div>
|
59
54
|
HTML
|
60
55
|
end
|
61
56
|
end
|
62
57
|
```
|
63
58
|
|
64
|
-
You can now render
|
65
|
-
|
66
|
-
```ruby
|
67
|
-
entry = contentful.entry('jumbotron_entry_id')
|
68
|
-
renderful.render(entry)
|
69
|
-
```
|
70
|
-
|
71
|
-
### Rich text rendering
|
72
|
-
|
73
|
-
If you have rich-text fields, you can leverage Contentful's [rich_text_renderer](https://github.com/contentful/rich-text-renderer.rb)
|
74
|
-
along with a custom local variable:
|
59
|
+
You can now render the component like this:
|
75
60
|
|
76
61
|
```ruby
|
77
|
-
|
78
|
-
def html_body
|
79
|
-
RichTextRenderer::Renderer.new.render(entry.body)
|
80
|
-
end
|
81
|
-
|
82
|
-
def locals
|
83
|
-
{ html_body: html_body }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
```
|
87
|
-
|
88
|
-
Then, just reference the `html_body` variable as usual:
|
89
|
-
|
90
|
-
```erb
|
91
|
-
<%# app/views/renderful/_text_block.html.erb %>
|
92
|
-
<%= raw html_body %>
|
93
|
-
```
|
94
|
-
|
95
|
-
### Nested components
|
96
|
-
|
97
|
-
What if you want to have a `Grid` component that can contain references to other components? It's
|
98
|
-
actually quite simple! Simply create a _References_ field for your content, then recursively render
|
99
|
-
all of the content entries contained in that field:
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
# app/components/grid.rb
|
103
|
-
class Grid < Renderful::Renderer
|
104
|
-
# This will define a `resolved_blocks` method that reads external references
|
105
|
-
# from the `blocks` fields and turns them into Contentful::Entry instances
|
106
|
-
resolve :blocks
|
107
|
-
|
108
|
-
def render
|
109
|
-
entries = blocks.map do |block|
|
110
|
-
# `client` can be used to access the Renderful::Client instance
|
111
|
-
<<~HTML
|
112
|
-
<div class="grid-entry">
|
113
|
-
#{client.render(block)}
|
114
|
-
</div>
|
115
|
-
HTML
|
116
|
-
end
|
117
|
-
|
118
|
-
<<~HTML
|
119
|
-
<div class="grid">#{entries}</div>
|
120
|
-
HTML
|
121
|
-
end
|
122
|
-
end
|
62
|
+
RenderfulClient.render('my_entry_id')
|
123
63
|
```
|
124
64
|
|
125
65
|
### Caching
|
126
66
|
|
127
|
-
You can easily cache the output of your
|
128
|
-
|
129
|
-
|
130
|
-
- `#read(key)`
|
131
|
-
- `#write(key, value)`
|
132
|
-
- `#delete(key)`
|
133
|
-
- `#exist?(key)`
|
134
|
-
|
135
|
-
A Redis cache implementation is included out of the box. Here's an example:
|
67
|
+
You can easily cache the output of your components. A Redis cache implementation is included out of
|
68
|
+
the box. Here's an example:
|
136
69
|
|
137
70
|
```ruby
|
138
|
-
|
139
|
-
contentful: contentful,
|
71
|
+
RenderfulClient = Renderful.new(
|
140
72
|
cache: Renderful::Cache::Redis.new(Redis.new(url: 'redis://localhost:6379')),
|
141
|
-
|
142
|
-
'jumbotron' => JumbotronRenderer
|
143
|
-
}
|
73
|
+
# ...
|
144
74
|
)
|
145
|
-
```
|
75
|
+
```
|
146
76
|
|
147
77
|
If you are using Rails and want to use the Rails cache store for Renderful, you can simply pass
|
148
78
|
`Rails.cache`, which responds to the expected interface:
|
149
79
|
|
150
80
|
```ruby
|
151
|
-
|
152
|
-
contentful: contentful,
|
81
|
+
RenderfulClient = Renderful.new(ful,
|
153
82
|
cache: Rails.cache,
|
154
|
-
|
155
|
-
'jumbotron' => JumbotronRenderer
|
156
|
-
}
|
83
|
+
# ...
|
157
84
|
)
|
158
|
-
```
|
85
|
+
```
|
159
86
|
|
160
87
|
#### Cache invalidation
|
161
88
|
|
162
|
-
The best way to invalidate the cache is through [
|
89
|
+
The best way to invalidate the cache is through [webhooks](https://www.contentful.com/developers/docs/concepts/webhooks/).
|
163
90
|
|
164
91
|
Renderful ships with a framework-agnostic webhook processor you can use to automatically invalidate
|
165
92
|
the cache for all updated content:
|
166
93
|
|
167
94
|
```ruby
|
168
|
-
|
95
|
+
RenderfulClient.invalidate_cache_from_webhook(json_body)
|
169
96
|
```
|
170
97
|
|
171
98
|
This is how you could use it in a Rails controller:
|
172
99
|
|
173
100
|
```ruby
|
174
|
-
class
|
101
|
+
class WebhooksController < ApplicationController
|
175
102
|
skip_before_action :verify_authenticity_token
|
176
103
|
|
177
104
|
def create
|
178
|
-
|
105
|
+
RenderfulClient.invalidate_cache_from_webhook(request.raw_post)
|
179
106
|
head :no_content
|
180
107
|
end
|
181
108
|
end
|
@@ -186,96 +113,109 @@ also for any entries linking to it, so that they are re-rendered. This is very u
|
|
186
113
|
if you have a `Page` entry type that contains references to many UI components - when one of the
|
187
114
|
components is updated, you want the page to be re-rendered.
|
188
115
|
|
189
|
-
###
|
116
|
+
### ViewComponent support
|
190
117
|
|
191
|
-
|
192
|
-
|
118
|
+
Renderful integrates nicely with [ViewComponent](https://github.com/github/view_component) for
|
119
|
+
rendering your components:
|
193
120
|
|
194
121
|
```ruby
|
195
|
-
|
196
|
-
|
122
|
+
RenderfulClient = Renderful::Client.new(
|
123
|
+
components: {
|
124
|
+
'jumbotron' => JumbotronComponent, # JumbotronComponent inherits from ViewComponent::Base
|
125
|
+
},
|
126
|
+
)
|
127
|
+
```
|
128
|
+
|
129
|
+
However, keep in mind you will now have to pass a view context when rendering them:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
RenderfulClient.render('my_entry_id', view_context: view_context)
|
197
133
|
```
|
198
134
|
|
199
|
-
|
135
|
+
## Providers
|
200
136
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
137
|
+
### Contentful
|
138
|
+
|
139
|
+
In order to integrate with Contentful, you will first need to add the `contentful` gem to your
|
140
|
+
Gemfile:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
gem 'contentful'
|
206
144
|
```
|
207
145
|
|
208
|
-
|
146
|
+
Now make sure to install it:
|
209
147
|
|
210
|
-
|
148
|
+
```console
|
149
|
+
$ bundle install
|
150
|
+
```
|
211
151
|
|
212
|
-
|
213
|
-
using your own helpers in components. If you want to use a different renderer instead, you can
|
214
|
-
override the `renderer` method:
|
152
|
+
Finally, initialize Renderful with the Contentful provider:
|
215
153
|
|
216
154
|
```ruby
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
155
|
+
RenderfulClient = Renderful::Client.new(
|
156
|
+
provider: Renderful::Provider::Contentful.new(
|
157
|
+
contentful: Contentful::Client.new(
|
158
|
+
space: 'cfexampleapi',
|
159
|
+
access_token: 'b4c0n73n7fu1',
|
160
|
+
)
|
161
|
+
)
|
162
|
+
)
|
163
|
+
```
|
164
|
+
|
165
|
+
You can now render your Contentful entries via Renderful:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
RenderfulClient.render('your_entry_id')
|
169
|
+
```
|
223
170
|
|
224
|
-
|
171
|
+
### Prismic
|
225
172
|
|
226
|
-
|
173
|
+
In order to integrate with Prismic, you will first need to add the `prismic.io` gem to your Gemfile:
|
227
174
|
|
228
175
|
```ruby
|
229
|
-
|
230
|
-
def locals
|
231
|
-
italian_title = entry.title.gsub(/hello/, 'ciao')
|
232
|
-
{ italian_title: italian_title }
|
233
|
-
end
|
234
|
-
end
|
176
|
+
gem 'prismic.io', require: 'prismic'
|
235
177
|
```
|
236
178
|
|
237
|
-
|
179
|
+
Now make sure to install it:
|
238
180
|
|
239
|
-
```
|
240
|
-
|
241
|
-
<h1 class="display-4">
|
242
|
-
<%= entry.title %>
|
243
|
-
(<%= italian_title %>)
|
244
|
-
</h1>
|
245
|
-
<p class="lead"><%= entry.content %></p>
|
246
|
-
</div>
|
181
|
+
```console
|
182
|
+
$ bundle install
|
247
183
|
```
|
248
184
|
|
249
|
-
|
185
|
+
Finally, initialize Renderful with the Prismic provider:
|
250
186
|
|
251
|
-
|
252
|
-
|
187
|
+
```ruby
|
188
|
+
RenderfulClient = Renderful::Client.new(
|
189
|
+
provider: Renderful::Provider::Prismic.new(
|
190
|
+
prismic: Prismic.api('https://yourendpoint.prismic.io/api', 'your_access_token')
|
191
|
+
)
|
192
|
+
)
|
193
|
+
```
|
253
194
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
<div class="grid-entry">
|
259
|
-
<%= client.render(block) %>
|
260
|
-
</div>
|
261
|
-
<% end %>
|
262
|
-
</div>
|
195
|
+
You can now render your Prismic documents via Renderful:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
RenderfulClient.render('your_entry_id')
|
263
199
|
```
|
264
200
|
|
201
|
+
NOTE: Due to limitations in Prismic's API, cache invalidation for Prismic will invalidate all your
|
202
|
+
components. Depending on how often you update your content, you may want to disable caching entirely
|
203
|
+
if you are using Prismic.
|
204
|
+
|
265
205
|
## Development
|
266
206
|
|
267
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run
|
268
|
-
the tests. You can also run `bin/console` for an interactive prompt that will allow you to
|
207
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run
|
208
|
+
the tests. You can also run `bin/console` for an interactive prompt that will allow you to
|
269
209
|
experiment.
|
270
210
|
|
271
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new
|
272
|
-
version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
|
273
|
-
will create a git tag for the version, push git commits and tags, and push the `.gem` file to
|
211
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new
|
212
|
+
version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
|
213
|
+
will create a git tag for the version, push git commits and tags, and push the `.gem` file to
|
274
214
|
[rubygems.org](https://rubygems.org).
|
275
215
|
|
276
216
|
## Contributing
|
277
217
|
|
278
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
218
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nebulab/renderful.
|
279
219
|
|
280
220
|
## License
|
281
221
|
|
@@ -283,4 +223,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
283
223
|
|
284
224
|
## Credits
|
285
225
|
|
286
|
-
Renderful
|
226
|
+
Renderful was originally developed by [Nebulab](https://nebulab.it) and sponsored by
|
227
|
+
[Bolt Threads](https://www.boltthreads.com). It is currently maintained by Nebulab.
|