Modifications in Layout
In the layout file we can have "contents" (for editable content) and "layout_parts" (for when the layout is created from scratch)
This commit is contained in:
parent
b2c0047d0f
commit
f4b1d1e182
|
@ -70,12 +70,15 @@ class Design
|
|||
end
|
||||
|
||||
def procs_embedded_objects
|
||||
[[self.layout], self.javascripts, self.images].each do |objects|
|
||||
[self.javascripts, self.images].each do |objects|
|
||||
objects.each do |object|
|
||||
process_object(object)
|
||||
end
|
||||
end
|
||||
self.layout.parse_urls
|
||||
if self.layout.to_save
|
||||
self.layout.save
|
||||
self.layout.parse_urls
|
||||
end
|
||||
self.themes.each do |theme|
|
||||
to_parse_url = theme.to_save ? true : false
|
||||
process_object(theme)
|
||||
|
|
|
@ -12,19 +12,20 @@ class Layout < DesignFile
|
|||
after_save :parse_layout
|
||||
|
||||
def content
|
||||
self.file.read
|
||||
self.file.read.force_encoding("UTF-8")
|
||||
end
|
||||
|
||||
def self.exist_one?
|
||||
Layout.count > 0
|
||||
end
|
||||
|
||||
def parse_layout
|
||||
parse_layout_layout_part(self)
|
||||
def parse_layout
|
||||
debugger
|
||||
parse_layout_contents(self)
|
||||
end
|
||||
|
||||
def parse_urls
|
||||
orig_content = content = self.file.read.force_encoding("UTF-8")
|
||||
orig_content = content = self.content
|
||||
self.remove_file!
|
||||
self.remove_file_orig!
|
||||
names = []
|
||||
|
@ -52,7 +53,7 @@ class Layout < DesignFile
|
|||
temp_file.write content.force_encoding("UTF-8")
|
||||
self.file = temp_file
|
||||
|
||||
Layout.without_callback(:save) do
|
||||
Layout.without_callback(:save, :after, :parse_layout) do
|
||||
self.save
|
||||
end
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@ class LayoutPart
|
|||
|
||||
field :name
|
||||
field :id_tag
|
||||
field :editable
|
||||
field :editable, :type => Boolean
|
||||
field :class_tag
|
||||
field :content
|
||||
|
||||
embedded_in :layout
|
||||
|
||||
def editable?
|
||||
self.editable.eql?('true')
|
||||
self.editable
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,22 +15,19 @@
|
|||
<body>
|
||||
<!-- example -->
|
||||
<div id="header_top" class="header">
|
||||
<r:layout_part id='header_top' class='header' name='header_1'>
|
||||
</r:layout_part>
|
||||
This is the first level of header
|
||||
</div>
|
||||
<div id="header_bottom" class="header">
|
||||
<r:layout_part id='header_bottom' class='header' name='header_2'>
|
||||
</r:layout_part>
|
||||
This is the second level of header
|
||||
</div>
|
||||
|
||||
<div id="main_content" class="content">
|
||||
<r:layout_part id="main_content" class='content' name='block_1' editable="true">
|
||||
</r:layout_part>
|
||||
<r:content name='content_1'>
|
||||
</r:content>
|
||||
</div>
|
||||
|
||||
<div id="footer" class="footer">
|
||||
<r:layout_part id="footer" class='footer' name='footer_1'>
|
||||
</r:layout_part>
|
||||
This is the footer
|
||||
</div>
|
||||
<!-- END example -->
|
||||
</body>
|
||||
|
|
|
@ -88,11 +88,11 @@ module Parser
|
|||
end
|
||||
c.define_tag 'layout_part' do |tag|
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil
|
||||
if part
|
||||
part.content
|
||||
else
|
||||
tag.expand
|
||||
end
|
||||
part.content
|
||||
end
|
||||
c.define_tag 'content' do |tag|
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil
|
||||
part.content
|
||||
end
|
||||
c.define_tag 'link' do |tag|
|
||||
item = Item.first(:conditions => { :full_name => tag.attr['name'] })
|
||||
|
@ -186,20 +186,20 @@ module Parser
|
|||
end
|
||||
c.define_tag 'layout_part' do |tag|
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
|
||||
if part
|
||||
ret = ''
|
||||
ret << "<div id='#{tag.attr['name']}'"
|
||||
ret << " part_id='#{part.id}'"
|
||||
ret << " class='editable'"
|
||||
ret << " style='border:solid 1px; margin:5px; padding:5px;'>"
|
||||
ret << "<div class='edit_link' style='display:none'>"
|
||||
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>"
|
||||
ret << '</div>'
|
||||
ret << part.i18n_variable[I18n.locale.to_s] rescue ''
|
||||
ret << '</div>'
|
||||
else
|
||||
tag.expand
|
||||
end
|
||||
ret = ''
|
||||
ret << "<div id='#{tag.attr['name']}' part_id='#{part.id}'>"
|
||||
ret << tag.expand
|
||||
ret << '</div>'
|
||||
end
|
||||
c.define_tag 'content' do |tag|
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
|
||||
ret = ''
|
||||
ret << "<div id='#{tag.attr['name']}' part_id='#{part.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>"
|
||||
ret << "<div class='edit_link' style='display:none'>"
|
||||
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>"
|
||||
ret << '</div>'
|
||||
ret << part.i18n_variable[I18n.locale.to_s] rescue ''
|
||||
ret << '</div>'
|
||||
end
|
||||
c.define_tag 'link' do |tag|
|
||||
item = Item.first(:conditions => { :full_name => tag.attr['name'] })
|
||||
|
@ -250,14 +250,14 @@ module Parser
|
|||
end
|
||||
|
||||
#=============
|
||||
def parse_layout_layout_part(layout)
|
||||
def parse_layout_contents(layout)
|
||||
content = layout.content.force_encoding('UTF-8')
|
||||
context = parser_layout_layout_part(layout)
|
||||
context = parser_layout_contents(layout)
|
||||
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
||||
parser.parse(content)
|
||||
end
|
||||
|
||||
def parser_layout_layout_part(layout )
|
||||
def parser_layout_contents(layout )
|
||||
Radius::Context.new do |c|
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
end
|
||||
|
@ -271,14 +271,8 @@ module Parser
|
|||
layout.menu.save
|
||||
tag.expand
|
||||
end
|
||||
c.define_tag 'layout_part' do |tag|
|
||||
data={}
|
||||
data[:class_tag]=tag.attr['class'].to_s
|
||||
data[:id_tag]=tag.attr['id'].to_s
|
||||
data[:name]=tag.attr['name'].to_s
|
||||
data[:editable]=tag.attr['editable'].to_s
|
||||
data[:content] = tag.expand.force_encoding('UTF-8') if !(tag.attr['editable'].eql?('true'))
|
||||
layout.layout_parts.create(data)
|
||||
c.define_tag 'content' do |tag|
|
||||
layout.layout_parts.create(:name => tag.attr['name'], :editable => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace :dev do
|
|||
|
||||
|
||||
home = Page.create!( :i18n_variable_id => var_10.id, :design_id => design_1.id, :name => 'home', :is_published => true, :theme_id => theme.id )
|
||||
home.page_parts.create!( :name => 'header_1', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id )
|
||||
home.page_parts.create!( :name => 'content_1', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id )
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue