资源说明:Comfortable Mexican Sofa
= Comfortable Mexican Sofa ComfortableMexicanSofa is a CMS engine that provides CMS functionality to any Rails app. It is not intended for users that would put <% ActiveRecord::Base.connection.execute('DROP DATABASE;') %> as content of a page. == Install From local gem: rake manifest && rake install In your Rails project: # config/environment.rb config.gem 'comfortable_mexican_sofa' Run the follwing in your console to generate migrations and update your database: script/generate cms rake db:migrate Navigate to the following address to access CMS admin page: http://your_application/cms-admin == Sample CMS Configuration ComfortableMexicanSofa.config do |config| config.http_auth_username = 'username' config.http_auth_password = 'secret_password' end == Setting Up Layouts and Writing CMS Content Here's some available type of tags that allow construction and insertion of page content: cms_page_block - block that gets rendered in the actual content of the page cms_block - block that is not automatically rendered cms_snippet - it's a snippet, a small reusable piece you can put around your site. not tied to a page. cms_helper - it's a helper method of some sort, ill-defined at this point. cms_partial - renders a Rails partial into the page. Layouts define the input fields a user will see when editing a page that uses that template. For example, your primary layout uses the 'application' Rails layout and has as content: {{cms_block:meta_title:string}} {{cms_page_block:main_content:code}} {{cms_block:date_stamp:date}} This will give you a single-line text field, a text area, and a date field with day/month/year. Only the main_content will be rendered to the page. You can use cms_block's to add attributes to pages that aren't necessarily rendered into the final output. Here are the different formats for page blocks and what they will generate in the CMS page editing form: string - a single-line text input text - a textarea datetime - a date field rich_text - if TinyMCE is installed in the app, this will generate a TinyMCE enhanced textarea code - if CodeMirror is installed in the app, this will generate a CodeMirror editor with syntax highlighting for HTML, JavaScript and CSS == Layout inheritance There must be at least one layout. Layouts can inherit input fields from their parents. If the parent layout defines one textarea and its child defines a timestamp field, then a page that uses the child layout will have two input fields - the textare and the timestamp. However, the layouts DO NOT nest their Rails layouts. The child Rails layout will not be nested inside the parent Rails layout. Also, both layouts can use the SAME Rails layout, if you wish. == Snippets Once you have a bunch of snippets defined, you can render them into your layouts however you'd like. In your Rails layouts, put in : CmsSnippet.content_for('the-slug-of-the-snippet') == Installing CodeMirror Support Download CodeMirror from: http://marijn.haverbeke.nl/codemirror To get CodeMirror support properly working, you need to place the CodeMirror files in specific folders in your app. The JavaScript initializer expects the CodeMirror .js files to be at /public/javascripts/codemirrror/ and the CSS files at /public/stylesheets/codemirror/. To properly generate the .sass files, use the following command: css2sass -a file.css > file.sass == Adding Categorization Support for Plugins 1. Add acts_as_categorized to the model definition # app/models/cms_model_name.rb class CmsModelName < ActiveRecord::Base acts_as_categorized # The rest of the actual model definition goes here end 2. Create the join model # app/models/cms_model_name_categorizations.rb class CmsModelNameCategorization < ActiveRecord::Base acts_as_categorization end 3. Modify the migration generator # generators/cms_plugin_name/migrations/create_cms_plugin_name.rb class CreateCmsPluginName < ActiveRecord::Migration def self.up # migrations ups for actual plugin go here create_table :cms_model_name_categorizations do |t| t.integer :cms_category_id t.integer :cms_model_name_id t.timestamps end add_index :cms_model_name_categorizations, [:cms_category_id, :cms_attachment_id], :unique => true, :name => 'index_model_name_cats_on_cat_id_and_model_name_id' end def self.down # migration downs for actual plugin go here drop_table :cms_model_name_categorizations end end 4. Add a module to update CmsCategory to connect it to your plugin # lib/add_to_category.rb # makes sure this is required either in init.rb or somewhere else in lib module AddToCategory module InstanceMethods def apply_model_name_methods has_many :cms_model_name_categorizations has_many :cms_model_names, :through => :cms_model_name_categorizations end end end CmsCategory.extend(AddToCategory::InstanceMethods) CmsCategory.apply_mode_name_methods 5. Add css/sass for the category show view / generators/cms_plugin_name/templates/stylesheets/cms_plugin_name.sass #cms_admin_categories_show h3 .model_name margin-bottom: 15px overflow: hidden a.model_name width: 150px float: left height: 30px padding-left: 35px font: 14px/30px Georgia, serif color: #000 margin: 0px 5px 5px 0px background: url(/images/cms/icon_model_name.gif) left center no-repeat 6. Add subform for inline category editing # views/cms_admin/controller_name/_form.html.haml = render :partial => 'cms_admin/categories/category_subform', :locals => { :item => @cms_page }
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。