Change "NewBlog" folders into "new_blog" in assets

Modify routes and pages handling for clean front-end urls
This commit is contained in:
Christophe Vilayphiou 2012-01-24 18:16:58 +08:00
parent 6a196c5d3d
commit 783eae4597
12 changed files with 40 additions and 26 deletions

View File

@ -43,9 +43,9 @@ class ApplicationController < ActionController::Base
end end
# Render the page # Render the page
def render_page(url = nil) def render_page(id = nil)
if @item if @item
render :text => parse_page(@item,url) render :text => parse_page(@item, id)
else else
render :text => '404 Not Found' render :text => '404 Not Found'
end end

View File

@ -1,5 +1,7 @@
class PagesController < ApplicationController class PagesController < ApplicationController
before_filter :get_item, :only => [:index_from_link, :show_from_link]
def index def index
@item = Page.find_by_name('home') @item = Page.find_by_name('home')
if @item if @item
@ -9,22 +11,13 @@ class PagesController < ApplicationController
end end
end end
def appfront
pre_uri = URI.split request.env['HTTP_REFERER']
pre_item_fullname = pre_uri[5][1..-1]
@item = Item.first(:conditions => {:full_name => pre_item_fullname})
redirect_to (request.env['HTTP_REFERER'].partition("?")[0]+"?app_url=#{request.fullpath}")
end
def show def show
#begin #begin
item = Item.first(:conditions => {:full_name => params[:page_name]}) item = Item.first(:conditions => {:full_name => params[:page_name]})
case item._type case item._type
when 'Page' when 'Page'
@item = item @item = item
render_page ((params[:app_url]+'?inner='+"true" if params[:app_url])) render_page(params[:id])
when 'Link' when 'Link'
redirect_to "http://#{item[:url]}" redirect_to "http://#{item[:url]}"
end end
@ -32,5 +25,20 @@ class PagesController < ApplicationController
# render :file => "#{Rails.root}/public/404.html", :status => :not_found # render :file => "#{Rails.root}/public/404.html", :status => :not_found
#end #end
end end
def index_from_link
redirect_to "/#{@item.full_name}"
end
def show_from_link
redirect_to "/#{@item.full_name}?id=#{params[:id]}"
end
protected
def get_item
module_app = ModuleApp.first(:conditions => {:title => params[:app_name]})
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action]})
end
end end

View File

@ -77,10 +77,14 @@ PrototypeR4::Application.routes.draw do
namespace :panel do namespace :panel do
resources :users resources :users
end end
match '/panel/:app_name/front_end/*page_name' => 'pages#appfront', :via => "get",:constraints => lambda { |request| match '/panel/:app_name/front_end/:app_action/:id' => 'pages#show_from_link', :constraints => lambda { |request|
!request.query_string.include?("inner=true") !request.query_string.include?("inner=true")
} }
match '/panel/:app_name/front_end/:app_action' => 'pages#index_from_link', :constraints => lambda { |request|
!request.query_string.include?("inner=true")
}
# routes for gridfs files # routes for gridfs files
match "/gridfs/*path" => "gridfs#serve" match "/gridfs/*path" => "gridfs#serve"

View File

@ -84,7 +84,7 @@ module ParserBackEnd
c.define_tag 'content' do |tag| c.define_tag 'content' do |tag|
ret = '' ret = ''
if (tag.attributes["main"] == "true" && !page.module_app.nil?) if (tag.attributes["main"] == "true" && !page.module_app.nil?)
ret << "<div id='appfrontend' class='dymanic_load' path='#{page.app_frontend_url}'></div>" ret << "<div id='appfrontend' class='dymanic_load' path='/panel/#{page.module_app.title}/front_end/#{page.app_frontend_url}'></div>"
else else
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
ret << "<div id='#{tag.attr['name']}' part_id='#{part.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>" ret << "<div id='#{tag.attr['name']}' part_id='#{part.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>"

View File

@ -2,7 +2,7 @@ module ParserFrontEnd
require 'radius' require 'radius'
include ParserCommon include ParserCommon
def parser_context(page, attributes = {},appfront_url = nil) def parser_context(page, attributes = {}, id = nil)
Radius::Context.new do |c| Radius::Context.new do |c|
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']})
@ -101,7 +101,9 @@ module ParserFrontEnd
c.define_tag 'content' do |tag| c.define_tag 'content' do |tag|
ret = '' ret = ''
if (tag.attributes["main"] == "true" && !page.module_app.nil?) if (tag.attributes["main"] == "true" && !page.module_app.nil?)
ret << "<div id='appfrontend' class='dymanic_load' path='#{appfront_url.nil?? page.app_frontend_url : appfront_url}'></div>" ret << "<div id='appfrontend' class='dymanic_load' path='/panel/#{page.module_app.title}/front_end/#{page.app_frontend_url}"
ret << "/#{id}" if id
ret << "?inner=true'></div>"
else else
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil
ret << part.content rescue nil ret << part.content rescue nil
@ -123,10 +125,10 @@ module ParserFrontEnd
end end
end end
def parse_page(page ,appfront_url) def parse_page(page, id = nil)
if page._type == 'Page' if page._type == 'Page'
layout_content = page.design.layout.content.force_encoding('UTF-8') rescue '' layout_content = page.design.layout.content.force_encoding('UTF-8') rescue ''
context = parser_context(page,{}, appfront_url) context = parser_context(page, {}, id)
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

View File

@ -9,8 +9,8 @@ Rails.application.routes.draw do
end end
namespace :front_end do namespace :front_end do
root :to => "posts#index" root :to => "posts#index"
match "show/:id" => "posts#show" ,:as => :post resources :posts
match "comments" => "comments#create",:as => :comments resources :comments
end end
namespace :widget do namespace :widget do
root :to => "posts#index" root :to => "posts#index"

View File

@ -1,12 +1,12 @@
{ {
"title": "NewBlog", "title": "new_blog",
"version": "0.1", "version": "0.1",
"organization": "Rulingcom", "organization": "Rulingcom",
"author": "RD dep", "author": "RD dep",
"intro": "A simple blog……", "intro": "A simple blog……",
"update_info": "Some info", "update_info": "Some info",
"create_date": "11-11-2011", "create_date": "11-11-2011",
"app_pages": ["/panel/new_blog/front_end/"], "app_pages": ["posts"],
"widgets": ["/panel/new_blog/widget/latest_post","/panel/new_blog/widget/"], "widgets": ["/latest_post","/"],
"enable_frontend": false "enable_frontend": true
} }