Change "NewBlog" folders into "new_blog" in assets
Modify routes and pages handling for clean front-end urls
This commit is contained in:
parent
6a196c5d3d
commit
783eae4597
|
@ -43,9 +43,9 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
# Render the page
|
||||
def render_page(url = nil)
|
||||
def render_page(id = nil)
|
||||
if @item
|
||||
render :text => parse_page(@item,url)
|
||||
render :text => parse_page(@item, id)
|
||||
else
|
||||
render :text => '404 Not Found'
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class PagesController < ApplicationController
|
||||
|
||||
before_filter :get_item, :only => [:index_from_link, :show_from_link]
|
||||
|
||||
def index
|
||||
@item = Page.find_by_name('home')
|
||||
if @item
|
||||
|
@ -9,22 +11,13 @@ class PagesController < ApplicationController
|
|||
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
|
||||
#begin
|
||||
item = Item.first(:conditions => {:full_name => params[:page_name]})
|
||||
case item._type
|
||||
when 'Page'
|
||||
@item = item
|
||||
render_page ((params[:app_url]+'?inner='+"true" if params[:app_url]))
|
||||
render_page(params[:id])
|
||||
when 'Link'
|
||||
redirect_to "http://#{item[:url]}"
|
||||
end
|
||||
|
@ -33,4 +26,19 @@ class PagesController < ApplicationController
|
|||
#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
|
||||
|
|
|
@ -78,7 +78,11 @@ PrototypeR4::Application.routes.draw do
|
|||
resources :users
|
||||
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")
|
||||
}
|
||||
|
||||
match '/panel/:app_name/front_end/:app_action' => 'pages#index_from_link', :constraints => lambda { |request|
|
||||
!request.query_string.include?("inner=true")
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ module ParserBackEnd
|
|||
c.define_tag 'content' do |tag|
|
||||
ret = ''
|
||||
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
|
||||
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;'>"
|
||||
|
|
|
@ -2,7 +2,7 @@ module ParserFrontEnd
|
|||
require 'radius'
|
||||
include ParserCommon
|
||||
|
||||
def parser_context(page, attributes = {},appfront_url = nil)
|
||||
def parser_context(page, attributes = {}, id = nil)
|
||||
Radius::Context.new do |c|
|
||||
c.define_tag 'snippet' do |tag|
|
||||
snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
|
||||
|
@ -101,7 +101,9 @@ module ParserFrontEnd
|
|||
c.define_tag 'content' do |tag|
|
||||
ret = ''
|
||||
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
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil
|
||||
ret << part.content rescue nil
|
||||
|
@ -123,10 +125,10 @@ module ParserFrontEnd
|
|||
end
|
||||
end
|
||||
|
||||
def parse_page(page ,appfront_url)
|
||||
def parse_page(page, id = nil)
|
||||
if page._type == 'Page'
|
||||
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.parse(parser.parse(layout_content))
|
||||
end
|
||||
|
|
|
@ -9,8 +9,8 @@ Rails.application.routes.draw do
|
|||
end
|
||||
namespace :front_end do
|
||||
root :to => "posts#index"
|
||||
match "show/:id" => "posts#show" ,:as => :post
|
||||
match "comments" => "comments#create",:as => :comments
|
||||
resources :posts
|
||||
resources :comments
|
||||
end
|
||||
namespace :widget do
|
||||
root :to => "posts#index"
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"title": "NewBlog",
|
||||
"title": "new_blog",
|
||||
"version": "0.1",
|
||||
"organization": "Rulingcom",
|
||||
"author": "RD dep",
|
||||
"intro": "A simple blog……",
|
||||
"update_info": "Some info",
|
||||
"create_date": "11-11-2011",
|
||||
"app_pages": ["/panel/new_blog/front_end/"],
|
||||
"widgets": ["/panel/new_blog/widget/latest_post","/panel/new_blog/widget/"],
|
||||
"enable_frontend": false
|
||||
"app_pages": ["posts"],
|
||||
"widgets": ["/latest_post","/"],
|
||||
"enable_frontend": true
|
||||
}
|
||||
|
|
Reference in New Issue