prismic_rails 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +0 -2
- data/README.md +59 -11
- data/lib/generators/templates/prismic_rails.rb +7 -7
- data/lib/prismic_rails.rb +11 -5
- data/lib/prismic_rails/content/document.rb +8 -4
- data/lib/prismic_rails/content/fragment.rb +1 -1
- data/lib/prismic_rails/content/nil_document.rb +1 -1
- data/lib/prismic_rails/content/result.rb +2 -2
- data/lib/prismic_rails/helpers/view_helpers.rb +5 -6
- data/lib/prismic_rails/services/language_service.rb +5 -5
- data/lib/prismic_rails/services/query_service.rb +6 -5
- data/lib/prismic_rails/version.rb +1 -1
- data/prismic_rails.gemspec +4 -3
- metadata +22 -15
- data/prismic_rails-0.1.21.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b661aa54deff7c406f834ddd6da31318cbb75d4f
|
4
|
+
data.tar.gz: ba0aecffc2202919bea3da0a318a98b476401b3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb3cb78090badadb3370356ec4b12030e17f4ad7b991d3efadcac1d6cf928a541c9426e39add6aa9be53e80d7a83c2aaa576a8f9650ba67df7cdc7b8c3061d20
|
7
|
+
data.tar.gz: 7b08ab8b08a078073a668e63d8db3e408580cb81933924fe12603bb38f41ec14be78a4bafdeda3cf196067549ce81810c10c942d4711515469f1c72abb9e991b
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,40 +3,88 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/fadendaten/prismic_rails.svg?branch=master)](https://travis-ci.org/fadendaten/prismic_rails)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/fadendaten/prismic_rails.png)](https://codeclimate.com/github/fadendaten/prismic_rails)
|
5
5
|
|
6
|
-
|
6
|
+
Library to consume API-based CMS prismic.io and to display fetched content into your Rails app.
|
7
7
|
|
8
|
-
|
8
|
+
This gem uses [prismicio/ruby-kit](https://github.com/prismicio/ruby-kit) gem to consume Prismic API.
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
12
|
Add this line to your application's Gemfile:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem '
|
15
|
+
gem 'prismic_rails', git: 'git@github.com:fadendaten/prismic_rails.git'
|
16
16
|
```
|
17
17
|
|
18
18
|
And then execute:
|
19
19
|
|
20
20
|
$ bundle
|
21
21
|
|
22
|
-
|
22
|
+
## Configuration
|
23
23
|
|
24
|
-
|
24
|
+
Copy the initializer file by running
|
25
|
+
|
26
|
+
$ rails g prismic_rails:install
|
27
|
+
|
28
|
+
And then set the ENV variables you got from prismic.io.
|
29
|
+
|
30
|
+
#### I18n Support
|
31
|
+
|
32
|
+
prismic.io supports finer graded set of locals. To work with that we need to map
|
33
|
+
Rails locale to the locale prismic.io recognise.
|
34
|
+
Define the language hash as following:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
config.languages = {
|
38
|
+
'en' => 'en-gb',
|
39
|
+
'de' => 'de-ch',
|
40
|
+
'fr' => 'fr-ch',
|
41
|
+
'it' => 'it-ch',
|
42
|
+
}
|
43
|
+
```
|
44
|
+
No need to configure language hash if you don't want I18n support. English will be used by default.
|
45
|
+
|
46
|
+
|
47
|
+
#### Caching
|
48
|
+
|
49
|
+
PrismicRails uses Rails caching to fasten the query process. You can choose to usse it or not to use it.
|
50
|
+
|
51
|
+
$ config.caching = true
|
25
52
|
|
26
53
|
## Usage
|
27
54
|
|
28
|
-
|
55
|
+
From any view of your application we can do the followings:
|
29
56
|
|
30
|
-
## Development
|
31
57
|
|
32
|
-
|
58
|
+
|
59
|
+
#### Query the prismic type 'blog-post' and render each document as html
|
33
60
|
|
34
|
-
|
61
|
+
```ruby
|
62
|
+
<%= prismic_type 'blog-post' do |result| %>
|
63
|
+
<%- result.documents.each do |document| %>
|
64
|
+
<%= document.to_html %>
|
65
|
+
<% end %>
|
66
|
+
<% end %>
|
67
|
+
```
|
35
68
|
|
36
|
-
|
69
|
+
#### Query the prismic type 'blog-post' in english
|
37
70
|
|
38
|
-
|
71
|
+
```ruby
|
72
|
+
<%= prismic_type 'blog-post', lang: 'en' do |result| %>
|
73
|
+
<%- result.documents.each do |document| %>
|
74
|
+
<%= document.to_html %>
|
75
|
+
<% end %>
|
76
|
+
<% end %>
|
77
|
+
```
|
78
|
+
|
79
|
+
#### Query only the title of the type 'blog-post
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
<%= prismic_type 'tea' do |result| %>
|
83
|
+
<%= result.find_fragment('title').to_html %>
|
84
|
+
<% end %>
|
85
|
+
```
|
39
86
|
|
87
|
+
You can use `to_text` is case you want only the text.
|
40
88
|
|
41
89
|
## License
|
42
90
|
|
@@ -6,14 +6,14 @@ PrismicRails.configure do |config|
|
|
6
6
|
# Set the access token of prismic if you have one
|
7
7
|
config.token = ENV["PRISMIC_ACCESS_TOKEN"]
|
8
8
|
|
9
|
-
# Language machting of your app locale to prismic
|
9
|
+
# Language machting of your app locale to prismic locale:
|
10
10
|
# Example
|
11
|
-
# config.languages
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
11
|
+
# config.languages = {
|
12
|
+
# 'en' => 'en-gb',
|
13
|
+
# 'de' => 'de-ch',
|
14
|
+
# 'fr' => 'fr-ch',
|
15
|
+
# 'it' => 'it-ch'
|
16
|
+
# }
|
17
17
|
#
|
18
18
|
# Set if PrismicRails should use rails caching
|
19
19
|
# config.caching = true
|
data/lib/prismic_rails.rb
CHANGED
@@ -33,7 +33,7 @@ module PrismicRails
|
|
33
33
|
yield self.config
|
34
34
|
end
|
35
35
|
|
36
|
-
# Returns the Prismic::API Object or
|
36
|
+
# Returns the Prismic::API Object or nil if prismic.io is down
|
37
37
|
def self.api
|
38
38
|
begin
|
39
39
|
@api = Prismic.api(self.config.url, self.config.token)
|
@@ -46,8 +46,8 @@ module PrismicRails
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
# Get the master ref of prismic account. This is
|
50
|
-
#
|
49
|
+
# Get the master ref of prismic account. This is primarily used to establish a
|
50
|
+
# caching mechanism.
|
51
51
|
def self.ref
|
52
52
|
if caching_enabled?
|
53
53
|
get_cached_ref
|
@@ -61,8 +61,6 @@ module PrismicRails
|
|
61
61
|
PrismicRails.config.caching
|
62
62
|
end
|
63
63
|
|
64
|
-
private
|
65
|
-
|
66
64
|
# Get the master ref out of the rails cache if prismic is not available
|
67
65
|
def self.get_cached_ref
|
68
66
|
if api.nil?
|
@@ -79,4 +77,12 @@ module PrismicRails
|
|
79
77
|
api.master_ref.ref
|
80
78
|
end
|
81
79
|
|
80
|
+
def self.find(document_type, fragment_id, options = {})
|
81
|
+
if options[:lang]
|
82
|
+
PrismicRails::QueryService.type(document_type, lang: options[:lang]).find_fragment(fragment_id)
|
83
|
+
else
|
84
|
+
PrismicRails::QueryService.type(document_type).find_fragment(fragment_id)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
82
88
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# :nodoc:
|
2
2
|
module PrismicRails
|
3
3
|
# The PrismicRails::Document is a wrapper class around Prismic::Document to
|
4
|
-
# support custom features like to_html and to handle nil documents.
|
4
|
+
# support custom features like to_html, to_text and to handle nil documents.
|
5
5
|
class Document
|
6
6
|
|
7
|
-
#
|
7
|
+
# Creates a new PrismicRails::Document
|
8
8
|
# ====
|
9
9
|
# +document+ A Prismic::Document
|
10
10
|
def initialize(document)
|
11
11
|
@document = document || PrismicRails::NilDocument.new
|
12
12
|
end
|
13
13
|
|
14
|
-
# Returns the document as
|
14
|
+
# Returns the document as safe html
|
15
15
|
def to_html
|
16
16
|
@document.as_html(nil).html_safe
|
17
17
|
end
|
@@ -21,13 +21,17 @@ module PrismicRails
|
|
21
21
|
@document.as_text
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
24
|
+
# Finds a fragment of a specific type in a document
|
25
|
+
# ====
|
26
|
+
# +type+ 'text', 'image' etc
|
25
27
|
def find_fragment(type)
|
26
28
|
fragment = @document.fragments[type]
|
27
29
|
return PrismicRails::Fragment.new(fragment) || NilDocument.new
|
28
30
|
end
|
29
31
|
|
30
32
|
# Tests if the document has the type type.
|
33
|
+
# ====
|
34
|
+
# +type+ 'text', 'image' etc
|
31
35
|
def is_type? type
|
32
36
|
type == @document.type
|
33
37
|
end
|
@@ -22,12 +22,12 @@ module PrismicRails
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
# Find a specific fragment in the list of all
|
25
|
+
# Find a specific fragment in the list of all document.
|
26
26
|
#
|
27
27
|
# ==== Examples
|
28
28
|
#
|
29
29
|
# PrismicRails::Result.find_fragment('image')
|
30
|
-
# This call walks through all the
|
30
|
+
# This call walks through all the document and looks for a fragment with
|
31
31
|
# the type 'image'.
|
32
32
|
def find_fragment(type)
|
33
33
|
@documents.each do |document|
|
@@ -8,15 +8,15 @@ module PrismicRails
|
|
8
8
|
# Query prismic for a specific type
|
9
9
|
#
|
10
10
|
# ==== Examples:
|
11
|
-
# Query the prismic type 'blog-post' and render each document
|
12
|
-
#
|
11
|
+
# Query the prismic type 'blog-post' and render each document as html
|
12
|
+
# <% prismic_type 'blog-post' do |result| %>
|
13
13
|
# <%- result.documents.each do |document| %>
|
14
14
|
# <%= document.to_html %>
|
15
15
|
# <% end %>
|
16
16
|
# <% end %>
|
17
17
|
#
|
18
18
|
# Query the prismic type 'blog-post' in english
|
19
|
-
#
|
19
|
+
# <% prismic_type 'blog-post', lang: 'en' do |result| %>
|
20
20
|
# <%- result.documents.each do |document| %>
|
21
21
|
# <%= document.to_html %>
|
22
22
|
# <% end %>
|
@@ -24,7 +24,7 @@ module PrismicRails
|
|
24
24
|
#
|
25
25
|
# Query only the title of the type 'blog-post
|
26
26
|
#
|
27
|
-
#
|
27
|
+
# <% prismic_type 'tea' do |result| %>
|
28
28
|
# <%= result.find_fragment('title').to_html %>
|
29
29
|
# <% end %>
|
30
30
|
#
|
@@ -33,8 +33,7 @@ module PrismicRails
|
|
33
33
|
def prismic_type(type, options = {}, &block)
|
34
34
|
|
35
35
|
query = Proc.new do
|
36
|
-
|
37
|
-
result = PrismicRails::Result.new(response)
|
36
|
+
result = PrismicRails::QueryService.type(type, options)
|
38
37
|
capture(result, &block)
|
39
38
|
end
|
40
39
|
|
@@ -6,10 +6,10 @@ module PrismicRails
|
|
6
6
|
# E.g. If your rails app support the locales :en, :de and :fr and you want to
|
7
7
|
# support this locales with your prismic content you have to match this
|
8
8
|
# locals.
|
9
|
-
# In Prismic you have the
|
9
|
+
# In Prismic you have the possibility to define a finer graded set of locals,
|
10
10
|
# e.g. 'en-gb', 'en-us', 'de-de', 'de-ch' and so on.
|
11
|
-
#
|
12
|
-
#
|
11
|
+
# Unfortunately Prismic does not support a wildcard query on the locals, so we
|
12
|
+
# have solved this problem by setting up a matching logic.
|
13
13
|
#
|
14
14
|
# You can define the matching logic in your PrismicRails configureation.
|
15
15
|
class LanguageService
|
@@ -17,8 +17,8 @@ module PrismicRails
|
|
17
17
|
# Stores the given locale
|
18
18
|
attr_accessor :locale
|
19
19
|
|
20
|
-
#
|
21
|
-
# PrismicRails::LanguageService tries to match it into a prismic
|
20
|
+
# Calls the PrismicRails::LanguageService with a i18n locale form rails. The
|
21
|
+
# PrismicRails::LanguageService tries to match it into a prismic locale.
|
22
22
|
def self.call(locale)
|
23
23
|
new(locale).match()
|
24
24
|
end
|
@@ -12,19 +12,20 @@ module PrismicRails
|
|
12
12
|
|
13
13
|
# Query the Prismic API with a type
|
14
14
|
# ==== Examples
|
15
|
-
# PrismicRails::QueryService('blog-post')
|
15
|
+
# PrismicRails::QueryService.type('blog-post')
|
16
16
|
#
|
17
17
|
# This returns a Prismic::Response with all the (published) documents of
|
18
18
|
# the type 'blog-post'
|
19
19
|
#
|
20
|
-
# PrismicRails::QueryService('
|
20
|
+
# PrismicRails::QueryService.type('blog-post', {lang: 'en'}
|
21
21
|
#
|
22
|
-
# This
|
23
|
-
# the type 'blog-post' in english
|
22
|
+
# This gets all the (published) documents of
|
23
|
+
# the type 'blog-post' in english as a Prismic::Response and wraps it around with a PrismicRails::Result
|
24
24
|
#
|
25
25
|
def type(type, options = {})
|
26
26
|
match_language options if options[:lang]
|
27
|
-
query(predicates(type), options)
|
27
|
+
response = query(predicates(type), options)
|
28
|
+
PrismicRails::Result.new(response)
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
data/prismic_rails.gemspec
CHANGED
@@ -21,16 +21,17 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_runtime_dependency "prismic.io", "~> 1.
|
25
|
-
spec.add_runtime_dependency
|
24
|
+
spec.add_runtime_dependency "prismic.io", "~> 1.5", ">= 1.5"
|
25
|
+
spec.add_runtime_dependency "rails", ">= 4.2"
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.14"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
30
|
|
31
31
|
spec.add_development_dependency "rdoc", "~> 5.1", ">= 5.1"
|
32
|
-
spec.add_development_dependency "vcr", "~> 3.0.3", ">=
|
32
|
+
spec.add_development_dependency "vcr", "~> 3.0.3", ">= 3.0.3"
|
33
33
|
spec.add_development_dependency "dotenv", "~> 2.2", ">= 2.2.1"
|
34
34
|
spec.add_development_dependency "webmock", "~> 3.0", ">= 3.0.1"
|
35
35
|
spec.add_development_dependency 'simplecov', "~> 0.14", ">= 0.14.1"
|
36
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
36
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prismic_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Langenegger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prismic.io
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.5'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '1.5'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
29
|
+
version: '1.5'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '1.5'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rails
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -37,9 +37,6 @@ dependencies:
|
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '4.2'
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '5.1'
|
43
40
|
type: :runtime
|
44
41
|
prerelease: false
|
45
42
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -47,9 +44,6 @@ dependencies:
|
|
47
44
|
- - ">="
|
48
45
|
- !ruby/object:Gem::Version
|
49
46
|
version: '4.2'
|
50
|
-
- - "~>"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '5.1'
|
53
47
|
- !ruby/object:Gem::Dependency
|
54
48
|
name: bundler
|
55
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +115,7 @@ dependencies:
|
|
121
115
|
version: 3.0.3
|
122
116
|
- - ">="
|
123
117
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
118
|
+
version: 3.0.3
|
125
119
|
type: :development
|
126
120
|
prerelease: false
|
127
121
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -131,7 +125,7 @@ dependencies:
|
|
131
125
|
version: 3.0.3
|
132
126
|
- - ">="
|
133
127
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
128
|
+
version: 3.0.3
|
135
129
|
- !ruby/object:Gem::Dependency
|
136
130
|
name: dotenv
|
137
131
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +186,20 @@ dependencies:
|
|
192
186
|
- - ">="
|
193
187
|
- !ruby/object:Gem::Version
|
194
188
|
version: 0.14.1
|
189
|
+
- !ruby/object:Gem::Dependency
|
190
|
+
name: pry
|
191
|
+
requirement: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - "~>"
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: 0.10.4
|
196
|
+
type: :development
|
197
|
+
prerelease: false
|
198
|
+
version_requirements: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - "~>"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: 0.10.4
|
195
203
|
description: With PrismicRails it is simple to query the prismic.io API for a defined
|
196
204
|
custom type. By providing rails helpers the integration in your rails view is much
|
197
205
|
easier as before.
|
@@ -223,7 +231,6 @@ files:
|
|
223
231
|
- lib/prismic_rails/services/language_service.rb
|
224
232
|
- lib/prismic_rails/services/query_service.rb
|
225
233
|
- lib/prismic_rails/version.rb
|
226
|
-
- prismic_rails-0.1.21.gem
|
227
234
|
- prismic_rails.gemspec
|
228
235
|
homepage: https://github.com/fadendaten/prismic_rails
|
229
236
|
licenses:
|
data/prismic_rails-0.1.21.gem
DELETED
Binary file
|