Merge branch 'routing-filter'
This commit is contained in:
commit
00d9f060cc
29 changed files with 282 additions and 260 deletions
37
lib/foodcoop_filter.rb
Normal file
37
lib/foodcoop_filter.rb
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
require 'routing_filter/base'
|
||||
|
||||
module RoutingFilter
|
||||
class Foodcoop < Base
|
||||
def around_recognize(path, env, &block)
|
||||
token = extract_token!(path) # remove the token from the beginning of the path
|
||||
returning yield do |params| # invoke the given block (calls more filters and finally routing)
|
||||
params[:foodcoop] = token if token # set recognized token to the resulting params hash
|
||||
end
|
||||
end
|
||||
|
||||
def around_generate(*args, &block)
|
||||
token = args.extract_options!.delete(:foodcoop) # extract the passed :token option
|
||||
token = Foodsoft.env if token.nil? # default to Foodsoft.env
|
||||
|
||||
returning yield do |result|
|
||||
if token
|
||||
url = result.is_a?(Array) ? result.first : result
|
||||
prepend_token!(url, token)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def extract_token!(path)
|
||||
foodcoop = nil
|
||||
path.sub! %r(^/([a-zA-Z0-9]*)(?=/|$)) do foodcoop = $1; '' end
|
||||
foodcoop
|
||||
end
|
||||
|
||||
def prepend_token!(url, token)
|
||||
url.sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{token}#{$2}" }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,23 +1,21 @@
|
|||
class Wikilink < WikiCloth::WikiLinkHandler
|
||||
|
||||
def url_for(page, parent = nil)
|
||||
if parent
|
||||
"/pages/new?title=#{page}&parent=#{parent}"
|
||||
else
|
||||
"/wiki/#{page}"
|
||||
end
|
||||
end
|
||||
|
||||
include ActionController::UrlWriter # To use named routes
|
||||
|
||||
def link_attributes_for(page)
|
||||
permalink = Page.permalink(page)
|
||||
url_options = {:host => Foodsoft.config[:host], :protocol => Foodsoft.config[:protocol]}
|
||||
url_options.merge!({:port => Foodsoft.config[:port]}) if Foodsoft.config[:port]
|
||||
|
||||
if Page.exists?(:permalink => permalink)
|
||||
{ :href => url_for(permalink) }
|
||||
{ :href => url_for(url_options.merge({:controller => "pages", :action => "show",
|
||||
:permalink => permalink, :use_route => :wiki_page})) }
|
||||
else
|
||||
{ :href => url_for(page, params[:referer]), :class => "new_wiki_link"}
|
||||
{ :href => url_for(url_options.merge({:controller => "pages", :action => "new",
|
||||
:title => page, :parent => params[:referer]})), :class => "new_wiki_link"}
|
||||
end
|
||||
end
|
||||
|
||||
def section_link(section)
|
||||
""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue