Repository URL to install this package:
|
Version:
4.1.0beta1 ▾
|
| app |
| config |
| db |
| lib |
| vendor |
| README.md |
| Rakefile |
This is the basic Marketing Pages Rails Engine by Neoteric Design, Inc.
# Gemfile gem 'evergreen', '~> 4.0.0'
$ bundle install
$ rails g evergreen:install
$ rake db:migrate db:test:prepare
Set your base class
Out of the box, you get a Page model and a PagesController configured to use "evergreen"
class Page < Evergreen::Page # Any model can do this, and doesn't need a table created for it def base_path # if you have more than one Page class, override this method with a string # of the desired root end end class PagesController < ApplicationController evergreen end
@page = Page.find('slug or id') @page = Page.find_by! cached_path: 'about/the-team' @page.title #=> 'The page title' @page.hidden? #=> For keeping the page out of navigation menus @page.drafted? #=> For the editorial process (page will not be accessible to the public) @page.meta_description #=> For the <meta name="description" content="CONTENT GOES HERE"> in your website's <head> Page.published #=> All non-drafted pages, including hidden pages Page.visible #=> All published pages, excluding hidden pages
collectiveidea/awesome_nested_set
home? #=> true if request.path == '/' browser_title #=> use in HTML > HEAD > TITLE <head> <title><%= browser_title %></title> </head> browser_title('Website Title') #=> 'Website Title' browser_title('Website Title', @page.title) #=> 'The Page Title - Website Title' #=> it also strips HTML while preserving ascii characters top_ancestor_for(@page) #=> Returns the given page's top-most ancestor in the NestedSet tree #=> Returns @page if @page has no parents active_if_selected('something') #=> 'active' if request.path =~ /something/ active_if_selected('/') #=> 'active' if request.path == '/' active_if_selected('home') #=> 'active' if request.path == '/' #=> nil if the request.path !=~ /given-string/ # you can restrain the search scope # useful for highlighting ancestor items in other navigation menus active_if_selected('something', :starts) #=> 'active' if request.path =~ /^something/ active_if_selected('something', :ends) #=> 'active' if request.path =~ /something$/ #=> :includes is the default search scope ### as demonstrated above # used primarily in Admin UI drafted_label(@page) #=> "<span class='state-label drafted'>Drafted</span>" if @page.drafted? hidden_label(@page) #=> "<span class='state-label hidden'>Hidden</span>" if @page.hidden?
class AnyNameController < ApplicationController evergreen # any controller can do this end # provides 2 actions # page_class is discovered based on controller_name def home @page = page_class.home_page end def show @page = page_class.visible.find_by! cached_path: trimmed_request_path end # Extensions to ApplicationController def not_found # renders a not found page for active record not founds or missing templates end def server_error # renders a server error page for when you rescue out of a 500 class error end # helper methods ancestors children # each scoped to the respective action's @page
You must have ActiveAdmin installed and generated first
$ rails g evergreen:active_admin
$ rails g evergreen:resource ModelName
create app/models/model_name.rb
create app/controllers/model_names_controller.rb
create app/views/model_names/index.html.erb
create app/views/model_names/show.html.erb
create app/views/model_names/_model_name.html.erb
create spec/models/model_name_spec.rb
route resources :model_names, :only => [:index, :show], :path => 'model-names'
Note: the JavaScript variable admin_actions is globally available to all UJS files.
Add to your form:
<%= render 'admin/toolbar/templates', :f => f %>
Add create.js.erb and update.js.erb with the following:
<%= render 'admin/toolbar/response' %>
_default_actions.html.erb_toolbar.js.erb_errors.js.erb_default_actions.html.erb should be a list of li's.
<li>
<%= f.submit 'Save' %>
</li>
<li>
<%= f.submit 'Preview', :name => 'preview',
:class => 'preview',
:data => {
:path => eval("live_preview_admin_#{plural_model_name}_path")
} %>
</li>
Remove compass from admin CSS Add generating of routing test for post-install