Library to consume API-based CMS prismic.io and to display fetched content into your Rails app.
This gem uses prismicio/ruby-kit gem to consume Prismic API.
Add this line to your application's Gemfile:
gem 'prismic_rails', git: 'git@github.com:fadendaten/prismic_rails.git'
And then execute:
$ bundle
Copy the initializer file by running
$ rails g prismic_rails:install
And then set the ENV variables you got from prismic.io.
prismic.io supports finer graded set of locals. To work with that we need to map Rails locale to the locale prismic.io recognise. Define the language hash as following:
config.languages = {
'en' => 'en-gb',
'de' => 'de-ch',
'fr' => 'fr-ch',
'it' => 'it-ch',
}
No need to configure language hash if you don't want I18n support. English will be used by default.
PrismicRails uses Rails caching to fasten the query process. You can choose to usse it or not to use it.
$ config.caching = true
From any view of your application we can do the followings:
<%= prismic_type 'blog-post' do |result| %>
<%- result.documents.each do |document| %>
<%= document.to_html %>
<% end %>
<% end %>
<%= prismic_type 'blog-post', lang: 'en' do |result| %>
<%- result.documents.each do |document| %>
<%= document.to_html %>
<% end %>
<% end %>
<%= prismic_type 'tea' do |result| %>
<%= result.find_fragment('title').to_html %>
<% end %>
You can use to_text
is case you want only the text.
The gem is available as open source under the terms of the MIT License.