# Effective Pages Content pages, bootstrap3 menu builder and page-specific header tag helpers for your Rails app. Create content pages ontop of one or more templates -- just regular Rails views -- that you define and control. Edit menus with a WYSIWYG drag-and-drop bootstrap3-strict menu builder. Use this gem to create a fully-functional CMS that provides full or restricted editing for your end users. Built ontop of effective_regions. Rails 3.2.x and 4.x ## Getting Started Please first install the [effective_regions](https://github.com/code-and-effect/effective_regions) and [effective_datatables](https://github.com/code-and-effect/effective_datatables) gems. Please download and install [Twitter Bootstrap3](http://getbootstrap.com) Add to your Gemfile: ```ruby gem 'effective_pages' ``` Run the bundle command to install it: ```console bundle install ``` Then run the generator: ```ruby rails generate effective_pages:install ``` The generator will install an initializer which describes all configuration options and creates a database migration. If you want to tweak the table name (to use something other than the default 'pages', 'menus', 'menu_items'), manually adjust both the configuration file and the migration now. Then migrate the database: ```ruby rake db:migrate ``` Add the following helper to your application layout in the `..` section. This will properly create `` and `<meta description>` tags based on the Effective::Page and the controller instance variables `@page_title` and `@meta_description` for non Effective::Page routes. ```ruby = effective_pages_header_tags ``` There are no required javascript or stylesheet includes. ### Post Installation Once the above Getting Started tasks have been completed, there are still a few small things that need to be initialized and configured. The documentation for these post-installation tasks is split up into the following Pages and Menus sections. ## Pages To create your first content page, visit `/admin/pages` and click `New Page`. This first page will be created with the provided `example` page view template and allow you to immediately jump into the effective_regions editor when you click `Save and Edit Content`. This page will be available on your website at a route matching the slugified title. ### View Template and Layout Every Effective::Page is rendered by a regular Rails view file and layout. The same as any standard Rails #show action. When creating a Page, if the `app/views/layouts/` directory contains more than one layout file, you will be able to choose which layout to use when displaying this Page. If your Rails app contains only the default `application` layout then this layout will be used. As well, when creating your Effective::Page object, if the `app/views/effective/pages/` directory contains more than one view file, you will be able to choose which view is used to display this Page. When this gem's installation generator is run, the `app/views/effective/pages/example.html.haml` page view template is created. To add additional page view templates, just create more views in this directory. An example of a two-column layout I like to create is as follows: ```haml %h1 = simple_effective_region page, :header do = page.title .row .col-sm-6 = effective_region page, :left do %p this is default left column content .col-sm-6 = effective_region page, :right do %p this is default right column content ``` You can add anything to these page views. The views are not required to contain any effective_regions, but then they wouldn't be user-editable. ### Routes All Effective::Page pages are immediately available to your application at a url matching the slugified title. This gem's page routes are evaluated last, after all your existing routes. This may cause an issue if you create an Effective::Page titled `Events` but you already have a route matching `/events` such as `resources :events`. You can edit the Effective::Page object and set the slug to a value that does not conflict. To find the path for an Effective::Page object: ```ruby page = Effective::Page.find_by_title('My Page') effective_pages.page_path(page) effective_pages.page_url(page) ``` If you would like to use an Effective::Page for your home/root page, add the following to your routes.rb: Rails 3 Syntax: ```ruby root :to => 'Effective::Pages#show', :id => 'home' ``` Rails 4 Syntax: ```ruby root :to => 'effective/pages#show', :id => 'home' ``` and make sure a page with slug 'home' exists. ### Header Tags Your layout needs to be configured to set the appropriate html `<title>` and `<meta>` tags. In your application layout and any additional layouts files, add the following to the `<head>` section: ```ruby = effective_pages_header_tags ``` This helper inserts a `<title>...` html tag based on the `@page_title` instance variable, which you can set anywhere on your non-effective controllers, and whose value is set to the `@page.title` value when displaying an `Effective::Page`. This helper also inserts a `` html tag based on the `@meta_description` instance variable, which you can set anywhere on your non-effective controllers, and whose value is set to the `@page.meta_description` value when displaying an `Effective::Page`. This tag provides the content that search engines use to display their search results. This value will automatically be truncated to 150 characters. This helper will also warn about missing `@page_title` and `@meta_description` variables. You can turn off the warnings in the config file. This helper is entirely optional and in no way required for effective_pages to work. ### Body Tag Classes Another optional helper. Add the following to your `` tag: ```haml %body{:class => effective_pages_body_classes} ``` to apply the following html classes: `params[:controller]`, `params[:action]`, `signed-in` / `not-signed-in`, `@page.template` and any thing set in the `@body_classes` instance variable. This provides a mechanism to easily target CSS styles for specific pages. This helper is entirely optional and in no way required for effective_pages to work. ### Permissions When creating a Page, if you've also installed the [effective_roles](https://github.com/code-and-effect/effective_roles) gem, you will be able to configure user access on a per-page basis. Use this functionality to create member-only type pages. ## Menus The menus rendered by this gem output strict bootstrap3 (v3.3.2) html. It is intended for bootstrap3 navbars as well as footer menus, sidebar menus and more. It outputs the ul tag and all contained li items: ```html ``` The bootstrap3 `.active` class will be added to the appropriate li item based on the current page. ### Create a menu Each Effective::Menu object is referred to by its title. The title is unique, so only one `'main menu'` can exist. To display our first menu, we must create an Effective::Menu object and then render it in the Rails application layout or appropriate view. To create your first menu, either: - Visit `/admin/menus` and click `New Menu`. Give it a title: `'main menu'`. or - Run `bundle exec rake effective_pages:seed` to create a menu called `'main menu'` with some placeholder menu items. then add it to your application layout where you would normally display your site's menu: ```html = render_menu('main menu') ``` or with some additional custom classes rendered on the opening `