prismic_rails 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +1 -0
- data/bin/console +14 -3
- data/lib/generators/templates/prismic_rails.rb +4 -4
- data/lib/prismic_rails/content/document.rb +8 -4
- data/lib/prismic_rails/content/fragment.rb +3 -3
- data/lib/prismic_rails/content/nil_document.rb +6 -2
- data/lib/prismic_rails/content/result.rb +12 -3
- data/lib/prismic_rails/helpers/view_helpers.rb +1 -1
- data/lib/prismic_rails/railtie.rb +0 -2
- data/lib/prismic_rails/services/language_service.rb +2 -0
- data/lib/prismic_rails/services/query_service.rb +21 -19
- data/lib/prismic_rails/version.rb +1 -1
- data/lib/prismic_rails.rb +4 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020d3bd11b1873d59943f9bd97178578c350b53a
|
4
|
+
data.tar.gz: 00b2e319e63e1f4550d443ee960dfee32375d85c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16594c30edb833d0b6a835680da5cc35ec818a41ff9ec0ae69fec7504ddbf1d139d7dbf5d3e521a821b98e74ba9a45ce687c8c86429ce1594e7d607f289c938f
|
7
|
+
data.tar.gz: 1279b6f79edd3aef343c6e3e740127d15c63db142a0a017b97d677ebae2cb901706c22f257e6266c6c280063434058a03ae5153ccd9b93e74c3001933e5df08b
|
data/.env
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'dotenv'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'pry'
|
6
|
+
require 'rails'
|
7
|
+
require 'prismic_rails'
|
5
8
|
|
6
9
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
10
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +13,13 @@ require "prismicRails"
|
|
10
13
|
# require "pry"
|
11
14
|
# Pry.start
|
12
15
|
|
13
|
-
|
16
|
+
Dotenv.load
|
17
|
+
|
18
|
+
PrismicRails.configure do |config|
|
19
|
+
config.url = ENV.fetch("PRISMIC_API_URL", "")
|
20
|
+
config.token = ENV.fetch("PRISMIC_ACCESS_TOKEN", nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'irb'
|
14
24
|
IRB.start(__FILE__)
|
25
|
+
|
@@ -6,15 +6,15 @@ 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
|
-
|
9
|
+
## Language machting of your app locale to prismic locale:
|
10
10
|
# Example
|
11
11
|
# config.languages = {
|
12
|
-
# 'en' => 'en-
|
12
|
+
# 'en' => 'en-us',
|
13
13
|
# 'de' => 'de-ch',
|
14
14
|
# 'fr' => 'fr-ch',
|
15
15
|
# 'it' => 'it-ch'
|
16
16
|
# }
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
## Set if PrismicRails should use rails caching
|
19
19
|
# config.caching = true
|
20
20
|
end
|
@@ -12,12 +12,12 @@ module PrismicRails
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# Returns the document as safe html
|
15
|
-
def
|
16
|
-
@document.as_html(
|
15
|
+
def as_html(serializer = nil)
|
16
|
+
@document.as_html(serializer)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Returns only the text of a document
|
20
|
-
def
|
20
|
+
def as_text
|
21
21
|
@document.as_text
|
22
22
|
end
|
23
23
|
|
@@ -26,7 +26,11 @@ module PrismicRails
|
|
26
26
|
# +type+ 'text', 'image' etc
|
27
27
|
def find_fragment(type)
|
28
28
|
fragment = @document.fragments[type]
|
29
|
-
|
29
|
+
if fragment
|
30
|
+
PrismicRails::Fragment.new(fragment)
|
31
|
+
else
|
32
|
+
NilDocument.new
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
# Tests if the document has the type type.
|
@@ -10,12 +10,12 @@ module PrismicRails
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Returns the document as safe html
|
13
|
-
def
|
14
|
-
@fragment.as_html(
|
13
|
+
def as_html(serializer = nil)
|
14
|
+
@fragment.as_html(serializer)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Returns only the text of a document
|
18
|
-
def
|
18
|
+
def as_text
|
19
19
|
@fragment.as_text
|
20
20
|
end
|
21
21
|
|
@@ -10,15 +10,19 @@ module PrismicRails
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Returns the document as safe html, in this case simply an empty string
|
13
|
-
def
|
13
|
+
def as_html(serializer = nil)
|
14
14
|
@document
|
15
15
|
end
|
16
16
|
|
17
17
|
# Returns the document as text, in this case simply an empty string
|
18
|
-
def
|
18
|
+
def as_text
|
19
19
|
@document
|
20
20
|
end
|
21
21
|
|
22
|
+
def find_fragment(type)
|
23
|
+
PrismicRails::Fragment.new(PrismicRails::NilDocument.new)
|
24
|
+
end
|
25
|
+
|
22
26
|
# Returns the type nil of the NilDocument
|
23
27
|
def type
|
24
28
|
nil
|
@@ -13,12 +13,13 @@ module PrismicRails
|
|
13
13
|
# ==== Attributes
|
14
14
|
# +response+ The response of the Prismic API query
|
15
15
|
def initialize(response)
|
16
|
-
if response.results
|
16
|
+
if response && response.results && !response.results.empty?
|
17
17
|
@documents = response.results.map do |document|
|
18
18
|
PrismicRails::Document.new(document)
|
19
19
|
end
|
20
|
-
else #Handles the case if the response is nil
|
21
|
-
|
20
|
+
else #Handles the case if the response is nil or empty
|
21
|
+
nil_document = PrismicRails::NilDocument.new
|
22
|
+
@documents = [nil_document]
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
@@ -35,5 +36,13 @@ module PrismicRails
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
39
|
+
def first
|
40
|
+
@documents.first
|
41
|
+
end
|
42
|
+
|
43
|
+
def last
|
44
|
+
@documents.last
|
45
|
+
end
|
46
|
+
|
38
47
|
end
|
39
48
|
end
|
@@ -14,8 +14,6 @@ module PrismicRails
|
|
14
14
|
PrismicRails.configure do |config|
|
15
15
|
config.url = app.config.prismic_rails[:url]
|
16
16
|
config.token = app.config.prismic_rails[:token]
|
17
|
-
config.client_id = app.config.prismic_rails[:client_id]
|
18
|
-
config.client_secret = app.config.prismic_rails[:client_secret]
|
19
17
|
config.languages = app.config.prismic_rails[:languages]
|
20
18
|
config.caching = app.config.prismic_rails[:caching]
|
21
19
|
end
|
@@ -7,10 +7,7 @@ module PrismicRails
|
|
7
7
|
# :nodoc:
|
8
8
|
class << self
|
9
9
|
|
10
|
-
#
|
11
|
-
DOCUMENT_TYPE = 'document.type'.freeze
|
12
|
-
|
13
|
-
# Query the Prismic API with a type
|
10
|
+
# Query the Prismic API by type
|
14
11
|
# ==== Examples
|
15
12
|
# PrismicRails::QueryService.type('blog-post')
|
16
13
|
#
|
@@ -21,25 +18,30 @@ module PrismicRails
|
|
21
18
|
#
|
22
19
|
# This gets all the (published) documents of
|
23
20
|
# the type 'blog-post' in english as a Prismic::Response and wraps it around with a PrismicRails::Result
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
def by_type(type, options = {})
|
22
|
+
type_query = {'document.type': type}
|
23
|
+
if options[:q]
|
24
|
+
options[:q].merge(type_query)
|
25
|
+
else
|
26
|
+
options[:q] = type_query
|
27
|
+
end
|
28
|
+
query(options)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
# Query the Prismic API
|
32
|
+
def query(options = {})
|
33
|
+
match_language(options) if options[:lang]
|
34
|
+
predicates = []
|
35
|
+
if q = options.delete(:q)
|
36
|
+
q.each do |key, value|
|
37
|
+
predicates << Prismic::Predicates.at(key, value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
response = api.query(predicates, options)
|
41
|
+
PrismicRails::Result.new(response)
|
37
42
|
end
|
38
43
|
|
39
|
-
|
40
|
-
def predicates type
|
41
|
-
Prismic::Predicates.at(DOCUMENT_TYPE, type)
|
42
|
-
end
|
44
|
+
private
|
43
45
|
|
44
46
|
# Returns the Prismic::Api object
|
45
47
|
def api
|
data/lib/prismic_rails.rb
CHANGED
@@ -13,11 +13,12 @@ require "prismic_rails/content/nil_document.rb"
|
|
13
13
|
# :nodoc:
|
14
14
|
module PrismicRails
|
15
15
|
|
16
|
+
class NoPrismicAPIConnection < StandardError; end
|
17
|
+
|
16
18
|
# A simple Config class that holds the config objects
|
17
19
|
class Config
|
18
20
|
attr_accessor :url, # Prismic API URL
|
19
|
-
:token, # Prismic API Token
|
20
|
-
:client_id, # Client ID
|
21
|
+
:token, # Prismic API Token :client_id, # Client ID
|
21
22
|
:client_secret, # Client Secret
|
22
23
|
:languages, # Language maching hash
|
23
24
|
:caching # Changing enabled?
|
@@ -42,7 +43,7 @@ module PrismicRails
|
|
42
43
|
Prismic::API::PrismicWSAuthError,
|
43
44
|
SocketError,
|
44
45
|
Net::OpenTimeout
|
45
|
-
|
46
|
+
raise NoPrismicAPIConnection
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -77,12 +78,4 @@ module PrismicRails
|
|
77
78
|
api.master_ref.ref
|
78
79
|
end
|
79
80
|
|
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
|
-
|
88
81
|
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: 1.0.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:
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prismic.io
|