From 34d0b8fac1edda43d51dedde74c6f976db5b24a2 Mon Sep 17 00:00:00 2001
From: Kaito
Date: Wed, 10 Aug 2011 17:28:10 +0800
Subject: [PATCH] complete new parser for layout_part
---
app/controllers/admin/snippets_controller.rb | 2 ++
app/models/layout.rb | 9 +++++++-
app/models/layout_part.rb | 7 ++++--
app/views/admin/designs/_form.html.erb | 3 +--
lib/parser.rb | 23 ++++++++++++++++++--
5 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/app/controllers/admin/snippets_controller.rb b/app/controllers/admin/snippets_controller.rb
index 7e7e4413..4473ad5b 100644
--- a/app/controllers/admin/snippets_controller.rb
+++ b/app/controllers/admin/snippets_controller.rb
@@ -5,6 +5,8 @@ class Admin::SnippetsController < ApplicationController
before_filter :find_parent_item
before_filter :is_admin?
+ #Snippet is a object admin user can define his own tag and being used later on in parser
+
def show
#TODO
end
diff --git a/app/models/layout.rb b/app/models/layout.rb
index 6b540378..0502e761 100644
--- a/app/models/layout.rb
+++ b/app/models/layout.rb
@@ -1,5 +1,5 @@
class Layout < DesignFile
-
+ include Parser
embedded_in :design
attr_reader :content
@@ -8,7 +8,14 @@ class Layout < DesignFile
def content
self.file.read
end
+
def self.exist_one?
Layout.count > 0
end
+
+ after_save:parse_layout
+
+ def parse_layout
+ parse_layout_layout_part(self)
+ end
end
diff --git a/app/models/layout_part.rb b/app/models/layout_part.rb
index 063e1b38..49baf943 100644
--- a/app/models/layout_part.rb
+++ b/app/models/layout_part.rb
@@ -3,9 +3,12 @@ class LayoutPart
include Mongoid::Document
include Mongoid::Timestamps
- field :name
+ field :name_tag
+ field :id_tag
+ field :editable_tag
+ field :class_tag
field :content
belongs_to :layout
-end
\ No newline at end of file
+end
diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb
index 9c4bce40..7e1282c4 100644
--- a/app/views/admin/designs/_form.html.erb
+++ b/app/views/admin/designs/_form.html.erb
@@ -4,7 +4,6 @@
<%= f.label :title, t('admin.title') %>
<%= f.text_field :title, :class => 'text' %>
-
<%= f.label :author, t('admin.author') %>
<%= f.text_field :author, :class => 'text' %>
@@ -31,7 +30,7 @@
<% if @design.structure_css.blank? %>
<%= f.file_field :structure_css %>
<% else%>
- <%= File.basename (Design.all.last.structure_css.url) %>
+ <%= File.basename (@design.structure_css.url) %>
<% end %>
diff --git a/lib/parser.rb b/lib/parser.rb
index 08616dfe..fe9467a0 100644
--- a/lib/parser.rb
+++ b/lib/parser.rb
@@ -206,7 +206,27 @@ module Parser
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)
context = parser_context_update_code(page, page_content)
parser = Radius::Parser.new(context, :tag_prefix => 'r')
@@ -279,7 +299,6 @@ module Parser
def self.included(base)
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_code if base.respond_to? :helper_method
end
end