complete new parser for layout_part

This commit is contained in:
Kaito 2011-08-10 17:28:10 +08:00
parent 278938a52d
commit 34d0b8fac1
5 changed files with 37 additions and 7 deletions

View File

@ -5,6 +5,8 @@ class Admin::SnippetsController < ApplicationController
before_filter :find_parent_item before_filter :find_parent_item
before_filter :is_admin? before_filter :is_admin?
#Snippet is a object admin user can define his own tag and being used later on in parser
def show def show
#TODO #TODO
end end

View File

@ -1,5 +1,5 @@
class Layout < DesignFile class Layout < DesignFile
include Parser
embedded_in :design embedded_in :design
attr_reader :content attr_reader :content
@ -8,7 +8,14 @@ class Layout < DesignFile
def content def content
self.file.read self.file.read
end end
def self.exist_one? def self.exist_one?
Layout.count > 0 Layout.count > 0
end end
after_save:parse_layout
def parse_layout
parse_layout_layout_part(self)
end
end end

View File

@ -3,7 +3,10 @@ class LayoutPart
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
field :name field :name_tag
field :id_tag
field :editable_tag
field :class_tag
field :content field :content
belongs_to :layout belongs_to :layout

View File

@ -4,7 +4,6 @@
<%= f.label :title, t('admin.title') %> <%= f.label :title, t('admin.title') %>
<%= f.text_field :title, :class => 'text' %> <%= f.text_field :title, :class => 'text' %>
</p> </p>
<p> <p>
<%= f.label :author, t('admin.author') %> <%= f.label :author, t('admin.author') %>
<%= f.text_field :author, :class => 'text' %> <%= f.text_field :author, :class => 'text' %>
@ -31,7 +30,7 @@
<% if @design.structure_css.blank? %> <% if @design.structure_css.blank? %>
<%= f.file_field :structure_css %> <%= f.file_field :structure_css %>
<% else%> <% else%>
<%= File.basename (Design.all.last.structure_css.url) %> <%= File.basename (@design.structure_css.url) %>
<% end %> <% end %>
</p> </p>
<p> <p>

View File

@ -206,7 +206,27 @@ module Parser
end end
end end
end end
#=============
def parse_layout_layout_part(layout)
content = layout.content
context = parser_layout_layout_part(layout)
parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(content)
end
def parser_layout_layout_part(layout )
Radius::Context.new do |c|
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]=tag.attr['name'].to_s
data[:editable_tag]=tag.attr['editable'].to_s
layout.layout_parts.create(data)
end
end
end
#============
def parse_content_update_code(page, page_content) def parse_content_update_code(page, page_content)
context = parser_context_update_code(page, page_content) context = parser_context_update_code(page, page_content)
parser = Radius::Parser.new(context, :tag_prefix => 'r') parser = Radius::Parser.new(context, :tag_prefix => 'r')
@ -279,7 +299,6 @@ module Parser
def self.included(base) def self.included(base)
base.send :helper_method, :parse_page if base.respond_to? :helper_method base.send :helper_method, :parse_page if base.respond_to? :helper_method
base.send :helper_method, :parse_page_edit if base.respond_to? :helper_method base.send :helper_method, :parse_page_edit if base.respond_to? :helper_method
base.send :helper_method, :parse_page_code if base.respond_to? :helper_method
end end
end end