Modification of the page model
This commit is contained in:
1 parent
4399804e19
commit
3d97c5bfda
9 files changed
+71
-36
No files matched your search
+13
-9
@@ -1,10 +1,7 @@
|
||||
module Parser
|
||||
|
||||
def parser_context(page_content, attributes = {})
|
||||
def parser_context(page, attributes = {})
|
||||
Radius::Context.new do |c|
|
||||
c.define_tag 'content' do |tag|
|
||||
page_content
|
||||
end
|
||||
c.define_tag 'snippet' do |tag|
|
||||
snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
|
||||
if snippet
|
||||
@@ -72,6 +69,13 @@ module Parser
|
||||
res << '>'
|
||||
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
|
||||
|
||||
@@ -83,11 +87,11 @@ module Parser
|
||||
|
||||
def parse_page(page)
|
||||
if page._type == 'Page'
|
||||
layout_content = (page.layout)? page.layout.content : "<r:content />"
|
||||
context = parser_context(page.content)
|
||||
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
||||
parser.parse(parser.parse(layout_content))
|
||||
end
|
||||
layout_content = page.layout.content
|
||||
context = parser_context(page)
|
||||
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
||||
parser.parse(parser.parse(layout_content))
|
||||
end
|
||||
end
|
||||
|
||||
def self.included(base)
|
||||
|
||||
+11
-3
@@ -32,6 +32,8 @@ namespace :dev do
|
||||
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' )
|
||||
|
||||
|
||||
# TODO: modify for the new model
|
||||
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 => '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.save!
|
||||
|
||||
layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{RAILS_ROOT}/lib/template/root.layout").read )
|
||||
|
||||
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 )
|
||||
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' />" )
|
||||
|
||||
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 )
|
||||
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='這是首頁' />" )
|
||||
|
||||
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' )
|
||||
|
||||
|
||||
File renamed without changes.
@@ -8,18 +8,17 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="header">
|
||||
<r:layout_part name='header'>
|
||||
<r:language_bar />
|
||||
<r:snippet name='nav' />
|
||||
</div>
|
||||
</r:layout_part>
|
||||
|
||||
<div id="container">
|
||||
<r:content />
|
||||
</div>
|
||||
<r:layout_part name="main_content">
|
||||
</r:layout_part>
|
||||
|
||||
<div id="footer">
|
||||
<r:layout_part name="footer">
|
||||
<r:snippet name='footer' />
|
||||
</div>
|
||||
</r:layout_part>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user