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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91d0fd6019ba43ed0e35d1c2c0759e11faf11a2f
4
- data.tar.gz: 7c4214e800edb0c788b8bf9d8948030682262db4
3
+ metadata.gz: b661aa54deff7c406f834ddd6da31318cbb75d4f
4
+ data.tar.gz: ba0aecffc2202919bea3da0a318a98b476401b3b
5
5
  SHA512:
6
- metadata.gz: acf7f7dad35ad004caf7a2331d0d997229d1e0d0ead13ef02ab97345a0c095bc3587ddebb0c240551e5d7275acef9a76c61eca8d2689396e97ad090384c3167e
7
- data.tar.gz: 04cfb7a4d598a7ca00d21e4c380a914576dcdf8e9622ed4d4a9d834a1f6ac4050cf21f2dfc1cdcfe083b923912871a7aa42f06b764f5b779ea8f4515ad0e4329
6
+ metadata.gz: bb3cb78090badadb3370356ec4b12030e17f4ad7b991d3efadcac1d6cf928a541c9426e39add6aa9be53e80d7a83c2aaa576a8f9650ba67df7cdc7b8c3061d20
7
+ data.tar.gz: 7b08ab8b08a078073a668e63d8db3e408580cb81933924fe12603bb38f41ec14be78a4bafdeda3cf196067549ce81810c10c942d4711515469f1c72abb9e991b
data/.travis.yml CHANGED
@@ -3,3 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.4.0
5
5
  before_install: gem install bundler -v 1.14.3
6
+
7
+ notifications:
8
+ slack: fadendaten:tWoet2mtObvbwSZSyUAY93jl
9
+ email: false
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in prismicRails.gemspec
4
2
  gemspec
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/prismic-rails`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ Library to consume API-based CMS prismic.io and to display fetched content into your Rails app.
7
7
 
8
- TODO: Delete this and the text above, and describe your gem
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 'prismic-rails'
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
- Or install it yourself as:
22
+ ## Configuration
23
23
 
24
- $ gem install prismic-rails
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
- TODO: Write usage instructions here
55
+ From any view of your application we can do the followings:
29
56
 
30
- ## Development
31
57
 
32
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ #### Query the prismic type 'blog-post' and render each document as html
33
60
 
34
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- ## Contributing
69
+ #### Query the prismic type 'blog-post' in english
37
70
 
38
- Bug reports and pull requests are welcome on GitHub at https://github.com/fadendaten/prismic-rails.
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 local:
9
+ # Language machting of your app locale to prismic locale:
10
10
  # Example
11
- # config.languages do |l|
12
- # l.en = 'en-gb'
13
- # l.de = 'de-ch'
14
- # l.fr = 'fr-ch'
15
- # l.it = 'it-ch'
16
- # end
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 nif if prismic.io is down
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 primary used to establis a
50
- # got caching mechanism.
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
- # Creats a new PrismicRails::Document
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 save html
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
- # Find a fragment of a specific type in a document
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
@@ -9,7 +9,7 @@ module PrismicRails
9
9
  @fragment = fragment
10
10
  end
11
11
 
12
- # Returns the document as save html
12
+ # Returns the document as safe html
13
13
  def to_html
14
14
  @fragment.as_html(nil).html_safe
15
15
  end
@@ -9,7 +9,7 @@ module PrismicRails
9
9
  @document = ''
10
10
  end
11
11
 
12
- # Returns the document as save html, in this case simply an empty string
12
+ # Returns the document as safe html, in this case simply an empty string
13
13
  def to_html
14
14
  @document
15
15
  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 documents.
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 documents and looks for a fragment with
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 a html
12
- # <%= prismic_type 'blog-post' do |result| %>
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
- # <%= prismic_type 'blog-post', lang: 'en' do |result| %>
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
- # <%= prismic_type 'tea' do |result| %>
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
- response = PrismicRails::QueryService.type(type, options)
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 posibility to define a finer graded set of locals,
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
- # Unfortunatly Prismic does not support a wildecard query on the locals, so we
12
- # solve this problem by setting up a matching logic.
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
- # Call the PrismicRails::LanguageService with a i18n locale form rails. The
21
- # PrismicRails::LanguageService tries to match it into a prismic local.
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('block-post', {lang: 'en'}
20
+ # PrismicRails::QueryService.type('blog-post', {lang: 'en'}
21
21
  #
22
- # This returns a Prismic::Response with all the (published) documents of
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
@@ -1,5 +1,5 @@
1
1
  # :nodoc:
2
2
  module PrismicRails
3
3
  # :nodoc:
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -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.4", ">= 4.1"
25
- spec.add_runtime_dependency 'rails', '>= 4.2', '~> 5.1'
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", ">= 5.1.0"
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.2.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-06-07 00:00:00.000000000 Z
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.4'
19
+ version: '1.5'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '4.1'
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.4'
29
+ version: '1.5'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '4.1'
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: 5.1.0
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: 5.1.0
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:
Binary file