Modification of the page model
This commit is contained in:
parent
4399804e19
commit
3d97c5bfda
|
@ -54,9 +54,9 @@ module ApplicationHelper
|
||||||
if node
|
if node
|
||||||
case node._type
|
case node._type
|
||||||
when 'Page'
|
when 'Page'
|
||||||
dest = admin_page_path(:id => node.id)
|
dest = admin_page_path(node)
|
||||||
when 'Link'
|
when 'Link'
|
||||||
dest = admin_link_path(:id => node.id)
|
dest = admin_link_path(node)
|
||||||
end
|
end
|
||||||
ret << "<li>"
|
ret << "<li>"
|
||||||
ret << (link_to node.name, dest)
|
ret << (link_to node.name, dest)
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
class Layout
|
class Layout
|
||||||
|
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
field :name, :index => true
|
field :name, :index => true
|
||||||
field :description
|
field :description
|
||||||
field :content
|
field :content
|
||||||
|
|
||||||
references_many :children, :class_name => "Item"
|
references_many :children, :class_name => "Item"
|
||||||
|
has_many :layout_parts
|
||||||
|
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
|
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
|
|
||||||
def self.exist_one?
|
def self.exist_one?
|
||||||
Layout.count > 0
|
Layout.count > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
class LayoutPart
|
||||||
|
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
field :name
|
||||||
|
field :content
|
||||||
|
|
||||||
|
belongs_to :layout
|
||||||
|
|
||||||
|
end
|
|
@ -9,6 +9,7 @@ class Page < Item
|
||||||
validates_presence_of :layout_name, :layout_id
|
validates_presence_of :layout_name, :layout_id
|
||||||
|
|
||||||
referenced_in :layout
|
referenced_in :layout
|
||||||
|
has_many :page_parts
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
class PagePart
|
||||||
|
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
field :name
|
||||||
|
field :content
|
||||||
|
|
||||||
|
belongs_to :page
|
||||||
|
|
||||||
|
end
|
|
@ -1,10 +1,7 @@
|
||||||
module Parser
|
module Parser
|
||||||
|
|
||||||
def parser_context(page_content, attributes = {})
|
def parser_context(page, attributes = {})
|
||||||
Radius::Context.new do |c|
|
Radius::Context.new do |c|
|
||||||
c.define_tag 'content' do |tag|
|
|
||||||
page_content
|
|
||||||
end
|
|
||||||
c.define_tag 'snippet' do |tag|
|
c.define_tag 'snippet' do |tag|
|
||||||
snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
|
snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
|
||||||
if snippet
|
if snippet
|
||||||
|
@ -72,6 +69,13 @@ module Parser
|
||||||
res << '>'
|
res << '>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
c.define_tag 'layout_part' do |tag|
|
||||||
|
ret = ''
|
||||||
|
ret << "<div id='#{tag.attr['name']}'>"
|
||||||
|
ret << (page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }).content rescue ''
|
||||||
|
ret << tag.expand
|
||||||
|
ret << '</div>'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,11 +87,11 @@ module Parser
|
||||||
|
|
||||||
def parse_page(page)
|
def parse_page(page)
|
||||||
if page._type == 'Page'
|
if page._type == 'Page'
|
||||||
layout_content = (page.layout)? page.layout.content : "<r:content />"
|
layout_content = page.layout.content
|
||||||
context = parser_context(page.content)
|
context = parser_context(page)
|
||||||
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
||||||
parser.parse(parser.parse(layout_content))
|
parser.parse(parser.parse(layout_content))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
|
|
|
@ -32,6 +32,8 @@ namespace :dev do
|
||||||
var_11 = I18nVariable.create!( :document_class => 'Page', :key => 'about', :en => 'About', :zh_tw => '關於我們' )
|
var_11 = I18nVariable.create!( :document_class => 'Page', :key => 'about', :en => 'About', :zh_tw => '關於我們' )
|
||||||
var_12 = I18nVariable.create!( :document_class => 'Link', :key => 'google', :en => 'Google', :zh_tw => 'Google' )
|
var_12 = I18nVariable.create!( :document_class => 'Link', :key => 'google', :en => 'Google', :zh_tw => 'Google' )
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: modify for the new model
|
||||||
urm_1 = UserRoleModel.new( :key => 'teacher', :i18n_variable_id => var_1.id, :built_in => true )
|
urm_1 = UserRoleModel.new( :key => 'teacher', :i18n_variable_id => var_1.id, :built_in => true )
|
||||||
urm_1.attribute_models.build( :key => 'discipline', :locale => true, :i18n_variable_id => var_2.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
urm_1.attribute_models.build( :key => 'discipline', :locale => true, :i18n_variable_id => var_2.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
||||||
urm_1.attribute_models.build( :key => 'department', :locale => true, :i18n_variable_id => var_3.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
urm_1.attribute_models.build( :key => 'department', :locale => true, :i18n_variable_id => var_3.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
||||||
|
@ -45,11 +47,17 @@ namespace :dev do
|
||||||
uim_1.attribute_models.build( :key => 'first_name', :locale => true, :i18n_variable_id => var_9.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
uim_1.attribute_models.build( :key => 'first_name', :locale => true, :i18n_variable_id => var_9.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
||||||
uim_1.save!
|
uim_1.save!
|
||||||
|
|
||||||
|
|
||||||
layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{RAILS_ROOT}/lib/template/root.layout").read )
|
layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{RAILS_ROOT}/lib/template/root.layout").read )
|
||||||
|
layout.layout_parts.create!( :name => 'header', :content => "<r:language_bar /><r:snippet name='nav' />" )
|
||||||
|
layout.layout_parts.create!( :name => 'main_content' )
|
||||||
|
layout.layout_parts.create!( :name => 'footer', :content => "<r:snippet name='footer' />" )
|
||||||
|
|
||||||
home = Page.create!( :i18n_variable_id => var_10.id, :layout_id => layout.id, :name => 'home', :is_published => true, :content => File.open("#{RAILS_ROOT}/lib/template/root.home").read )
|
home = Page.create!( :i18n_variable_id => var_10.id, :layout_id => layout.id, :name => 'home', :is_published => true )
|
||||||
|
home.page_parts.create!( :name => 'main_content', :content => "<r:locale en='This is the homepage' zh_tw='這是首頁' />" )
|
||||||
|
|
||||||
Page.create!( :i18n_variable_id => var_11.id, :layout_id => layout.id, :name => 'about', :is_published => true, :parent_id => home.id, :content => File.open("#{RAILS_ROOT}/lib/template/about.page").read )
|
about = Page.create!( :i18n_variable_id => var_11.id, :layout_id => layout.id, :name => 'about', :is_published => true, :parent_id => home.id )
|
||||||
|
about.page_parts.create!( :name => 'main_content', :content => "This is about" )
|
||||||
|
|
||||||
Link.create!( :i18n_variable_id => var_12.id, :name => 'google', :is_published => true, :parent_id => home.id, :url => 'www.google.com' )
|
Link.create!( :i18n_variable_id => var_12.id, :name => 'google', :is_published => true, :parent_id => home.id, :url => 'www.google.com' )
|
||||||
|
|
||||||
|
|
|
@ -8,18 +8,17 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="header">
|
<r:layout_part name='header'>
|
||||||
<r:language_bar />
|
<r:language_bar />
|
||||||
<r:snippet name='nav' />
|
<r:snippet name='nav' />
|
||||||
</div>
|
</r:layout_part>
|
||||||
|
|
||||||
<div id="container">
|
<r:layout_part name="main_content">
|
||||||
<r:content />
|
</r:layout_part>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="footer">
|
<r:layout_part name="footer">
|
||||||
<r:snippet name='footer' />
|
<r:snippet name='footer' />
|
||||||
</div>
|
</r:layout_part>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Reference in New Issue