Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tb_cms

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tb_cms

  • 1.3.6
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

TB CMS

TB CMS is a content managment engine intended for use with Rails and Twice Baked.

Installation

First, it is recommended you run the steps listed in the "Installation/Usage" section of the TB Core README file. Then, perform the following steps:

  1. Add the following to your Gemfile

     gem 'tb_cms'
    
  2. Run bundle install

  3. Copy in database migrations to your new rails project

     bundle exec rake railties:install:migrations
     rake db:migrate
    
  4. Restart your application

Configuration

TB CMS accepts the following configuration options.

Spud::Cms.configure do |config|
  config.menus_enabled = true
end

Defining Layouts

By default, CMS pages will use your standard application.html.erb layout. Chances are you will eventually want to specify different layouts for different pages. This is where page layouts come in handy.

A page layout is essentially a plain old Rails layout file with a little bit of metadata inserted at the top. The following example defines a layout with two content blocks, Left and Right.

<%
#template_name: Two Column
#html: Left
#html: Right
%>
<%= content_for :body do %>
  <div class="left">
    <%= yield :left %>
  </div>
  <div class="right">
    <%= yield :right %>
  </div>
<% end %>
<%= render :template => "/layouts/application" %>

You may also use the spud:cms:layout generator to quickly generate a layout file.

rails g spud:cms:layout two_column left right

Layout Actions

Layout actions provide a mechanism for running custom Ruby code when a given layout is hit. For example, suppose you have an About layout that needs to show an array of Employee records. Let's also imagine you want to show a different list of employees for get and post requests.

Create a controller concern at app/controllers/concerns/spud_cms_layout_actions.rb with the following code.

module SpudCmsLayoutActions
  extend ActiveSupport::Concern

  def about_action(method)
    if method == :post
      @employees = Employee.where(:secret_agent => true).order('first_name asc')
    else
      @employees = Employee.where(:is_cool => true).order('first_name asc')
    end  
  end

end

If you ran the spud:cms:layout generator described earlier, the concern and empty action would have been created for you automatically.

Using Menus

A lot of cms engines allow you to render your navigation links in a ul block by using your page tree structure. In a lot of cases this is insufficient as some sites have urls that redirect to pages outside of your cms. This is where menus come in. They can be built in the admin control panel. In your application layout file or any erb template you can render a ul block like so

<%= sp_list_menu({:id => "navigation",:name => "Main"}) %>

This will output a

    block for the menu you created in admin named "Main"

    Testing

    TB CMS uses RSpec for testing. Get the tests running with a few short commands:

    1. Create and migrate the databases:

       rake db:create
       rake db:migrate
      
    2. Load the schema in to the test database:

       rake app:db:test:prepare
      
    3. Run the tests with RSpec

       rspec spec
      

    After the tests have completed the current code coverage stats is available by opening /coverage/index.html in a browser.

    FAQs

    Package last updated on 06 Jan 2021

    Did you know?

    Socket

    Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

    Install

    Related posts

    SocketSocket SOC 2 Logo

    Product

    • Package Alerts
    • Integrations
    • Docs
    • Pricing
    • FAQ
    • Roadmap
    • Changelog

    Packages

    npm

    Stay in touch

    Get open source security insights delivered straight into your inbox.


    • Terms
    • Privacy
    • Security

    Made with ⚡️ by Socket Inc