Class: DcDesign
- Inherits:
-
Object
- Object
- DcDesign
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/dc_design.rb
Overview
Schema information
Collection name: dc_design : Designs
_id BSON::ObjectId _id
created_at Time created_at
updated_at Time updated_at
description String Short description of design
body String Body of design which will be rendered like any Rails view
params String Parameters used by design
css String CSS for design
rails_view String Rails view (file) name which will be used to render design
author String Creater if design
active Mongoid::Boolean Is the design active
created_by BSON::ObjectId created_by
updated_by BSON::ObjectId Last updated by
site_id BSON::ObjectId Select site name if this design belongs to singe site
dc_parts Embedded:DcPart Parts of design
Designs are essential parts of DRG CMS. Every DcPage document must have its design document defined. If DcPage documents are anchors for url addresses, DcDesign documents define how will page data be rendered in browser.
DcDesign documents define what would normally be written into Rails view file. The code is saved in the body field of DcDesign document. If you prefere Rails way, enter view file name into rails_view field and put your code into file into views directory (ex. designs/home_page for ../views/designs/home_page.html.erb file).
If you choose to save code to Rails view file you must add one top and bottom line to every source file. Top line will provide CMS edit menu, bottom line will provide additional CSS and javascript code scooped when renderers are called.
Example (as written in body of dc_design):
<div id="site">
<div id="site-top-bg">
<div id="site-top"><div id="logo"><%= dc_render(:dc_piece, name: 'site-top') %></div>
<div id="login"><%= dc_render(:common, method: 'login') %></div>
</div>
<%= dc_render(:dc_menu, name: 'test-menu') %>
</div>
<div id="page"><%= dc_render(:dc_page) %></div>
</div>
<div id="site-bottom"><%= dc_render(:dc_piece, name: 'site-bottom') %></div>
Example (as written in Rails view file):
<!-- Pay attention on lines added at the top and bottom of file -->
<%= render partial: 'cmsedit/edit_stuff' if session[:edit_mode] > 0 %>
<div id="site">
<div id="site-top-bg">
<div id="site-top"><div id="logo"><%= dc_render(:dc_piece, name: 'site-top') %></div>
<div id="login"><%= dc_render(:common, method: 'login') %></div>
</div>
<%= dc_render(:dc_menu, name: 'test-menu') %>
</div>
<div id="page"><%= dc_render(:dc_page) %></div>
</div>
<div id="site-bottom"><%= dc_render(:dc_piece, name: 'site-bottom') %></div>
<style type="text/css"><%= @css.html_safe %></style><%= javascript_tag @js %>
Class Method Summary collapse
-
.choices4_design(site) ⇒ Object
Return choices for select for design_id.
Instance Method Summary collapse
-
#cache_clear ⇒ Object
Clear cache if cache is configured.
Class Method Details
.choices4_design(site) ⇒ Object
Return choices for select for design_id.
If site is passed as parameter, only designs which belong to site or do not have site assigned will be selected. Too much designs to select often confuses end user.
127 128 129 130 131 132 |
# File 'app/models/dc_design.rb', line 127 def self.choices4_design(site) (site.blank? ? where(active: true) : where(:site_id.in => [nil, BSON::ObjectId.from_string(site) ], active: true)) .only(:id, :description) .order_by(description: 1) .map { |design| [design.description, design.id] } end |
Instance Method Details
#cache_clear ⇒ Object
Clear cache if cache is configured
116 117 118 |
# File 'app/models/dc_design.rb', line 116 def cache_clear DrgCms.cache_clear(:dc_design) end |