Butter CMS for Rails

www.buttercms.com

**Why Butter?**

Butter makes setting up a professional company blog on Rails insanely easy. It’s built for developers to save us from hosting, DB setup, themeing, maintaining yet another Wordpress install. It’s designed to be quickly integrated to an existing Rails project.

Butter provides a user friendly blogging UI, hosted on buttercms.com, and exposes content created via an API.

This package provides a Rails Engine that interacts with the Butter API to get you up and running in seconds.

Installation


Add buttercms gem to your Gemfile and install it.

.. code-block

ruby

# In Gemfile
gem 'buttercms'
.. code-block

bash

$ gem install buttercms

Mount the Buttercms engine in your config/routes.rb and define your blog path.

.. code-block

ruby

# In config/routes.rb
mount Buttercms::Engine => "/blog"

Grab your API token from buttercms.com/api_token

.. code

ruby

# In config/secrets.yml
# Add your BUTTER_CMS_TOKEN to both development: and production:
BUTTER_CMS_TOKEN: <your_api_token>

Nice job. You’ve now got a blog running natively in your Rails project. Nothing but Ruby goodness. (No PHP scripts here ;))

Check it out: localhost:3000/blog

Log into buttercms.com/ to start blogging!

Specify the Blog Layout


We’ve provided a default layout but we expect you’ll want the blog to appear your branded layout so we’ve made this as simple as defining config.blog_layout.

.. code

ruby

# In application.rb (or an initializer like constants.rb)
config.blog_layout = "<your_blog_layout>"

Note that an ideal layout simply defines the header and footer for the page and <%= yields %> the main body. Restart the server and go to localhost:3000/blog and you’ll see your new branded blog!

Add comments to blog post template


If you want to customize the blog post template (for example to add ‘Disqus <disqus.com/>`_ comments at the bottom), it’s simple:

First create your template. We recommend putting it in ‘views/blog/post.html.erb`

.. code

html

<div class="post-preview">
    <h2 class="post-title">
        <%= @post['title'] %>
    </h2>

    <p class="post-meta">
    Posted by 
    <%= link_to("#{@post['author']['first_name']} #{@post['author']['last_name']}", blog_author_path(:author_slug => @post['author']['slug'])) %>
     on <%= @post['created'] %>

    <% @post['categories'].each do |category| %>
    <span class="label label-default">
    <%= link_to(category['name'], blog_category_path(:category_slug => category['slug'])) %>
    </span>
    <% end %>
    </p>

    <p class="post-body">
        <%= @post['body'].html_safe %>
    </p>
</div>

<hr>

<!-- Paste your Disqus embed code here --->

Then tell Butter about this template:

.. code

ruby

# In application.rb
config.blog_post_template = "blog/post"

Customize other templates


You can customize other parts of the blog as well by following the same pattern. A full list of page types + settings is below:

.. code

ruby

# In application.rb
config.blog_home_template = "blog/home"
config.blog_post_template = "blog/post"
config.blog_author_template = "blog/author"
config.blog_category_template = "blog/category"