Add Pig to your Gemfile:
gem 'pig', git: "https://#{ENV['GITHUB_PIG_TOKEN']}:x-oauth-basic@github.com/yoomee/pig.git", tag: '0.0.7.0'
Run the bundle command to install it.
To install it simply run:
rails g pig:install
rake db:migrate
rake pig:db:seed
Now you're up and trotting! 🐖
If you take a look in your config/routes.rb
file you should now see the Pig mounted, the default route for all pig admin functionality is /admin
, this may be modified by editing:
# config/initializers/pig.rb
config.mount_path = 'admin'
To use the pig factories in the specs of your project add the following to your RSpec configuration (usually found in spec/rails_helper.rb
):
config.before(:suite) do
FactoryGirl.reset_configuration
FactoryGirl.register_default_strategies
FactoryGirl.register_default_callbacks
FactoryGirl.definition_file_paths << Pig.factory_path
FactoryGirl.find_definitions
end
Note: the config above has been tested with factory_girl
, not factory_girl_rails
.
To configure Pig to display google analytics info when editing a page the following steps are required.
Set the analytics tracking code in config/initializers/pig.rb
config.ga_code = 'UA-xxxxxxxx-1'
We then have to give Pig the permission to access to the Google analytics API
- Login to the Google developer console
- Click Create Project
- Give the project a name
- Click the newly created project name
- Enable the Analytics Api from the APIs & auth -> APIs
- Click the newly created project name
- Click Add Credentials and choose Sevice Account from the dropdown
- Choose P12 and click Create
- Copy the downloaded *.p12 file to the project root
-
Create a new ga_config.yml file in the root of your project
-
Populate it with the following
service_account_email: <Service account email> key_file: <The name of the keyfile downloaded in the previous step (Including .p12)> key_secret: notasecret profileID: <GA tracking code> application_name: <The name given to the service account> application_version: 1.0
- Navigate to Google Analytics
- Click the admin tab
- Choose the relevant account from the drop down
- Add the service account email to the user management with Read & analyze privileges
Sometimes the predefined field types in Pig (Single line of text, rich text, boolean, etc) aren't enough. The following steps allow creation of custom types.
Add the following line to the Pig config initializer
config.content_types = { my_custom_field: 'Display name' }
Create 2 new files in your application, the first file defines how the custom field will be rendered when editing the page. Pig uses formtastic for all its inputs.
# /app/inputs/my_custom_field_input.rb
class StoryTagsInput < FormtasticBootstrap::Inputs::SelectInput
def input_html_options
super.merge(class: "my-custom-input")
end
end
The second file defines get/set
for the value of the field.
# /app/types/pig/my_custom_field_type.rb
module Pig
class MyCustomFieldType < Type
def get(content_package)
super(content_package).do_custom_stuff
end
end
end
To run the cucumber tests you will need phantomjs, if you're on OSX it can be installed with:
brew install phantomjs
To deploy a site using Pig ensure the following in addition to the usual Rails deploy process:
-
A mail service is present, and if required any configuration for that service. We currently recommend the SendGrid add-on when using Heroku.
-
An email address is set in the
SITE_NOREPLY_EMAIL
environment variable. -
The
GITHUB_PIG_TOKEN
variable is also present. -
If you wish to use the embeddable content type with youtube and display video thumbnails add the
YOUTUBE_API_KEY
environment variable.