Skip to content

Commit

Permalink
added meta redirect to external link
Browse files Browse the repository at this point in the history
  • Loading branch information
Junya Ogura committed Jun 19, 2009
1 parent 0f885d0 commit 130cbf2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/controllers/redirect_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
class RedirectController < ApplicationController
unloadable

def index
@target = params[:url].join('/')
@target = @target + '/' if /(\/$)/ =~ request.path

if @target =~ /^https?:\/\/.+/i
@meta = true
end

render :file=>"#{RAILS_ROOT}/public/404.html", :status => '404 Not Found' and return if @target.length == 0
render :layout => false
end
end
2 changes: 2 additions & 0 deletions app/helpers/redirect_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module RedirectHelper
end
12 changes: 12 additions & 0 deletions app/views/redirect/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title>redirecting...</title>
<% if @meta -%>
<meta http-equiv="refresh" content="0;url=<%=h @target %>"/>
<% end -%>
</head>
<body>
<p>Redirecting to <a href="<%= @target %>"><%= @target %></a></p>
</body>
</html>

4 changes: 3 additions & 1 deletion lib/redmine_markdown_extra_formatter/wiki_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
require 'bluefeather'

module RedmineMarkdownExtraFormatter
Expand All @@ -7,7 +8,8 @@ def initialize(text)
end

def to_html(&block)
BlueFeather.parse(@text)
BlueFeather.parse(@text.gsub(/\[(.+)\]\((https?:\/\/.+)\)/, '[\1](/redirect/\2)'))
# BlueFeather.parse(@text).gsub(/href=(["'])(.+)(["'])/i, 'href=\1/redirect/\2\3')
rescue => e
return("<pre>problem parsing wiki text: #{e.message}\n"+
"original text: \n"+
Expand Down
1 change: 1 addition & 0 deletions routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
map.connect 'redirect/*url', :controller => 'redirect', :action => 'index'
8 changes: 8 additions & 0 deletions test/functional/redirect_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require File.dirname(__FILE__) + '/../test_helper'

class RedirectControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

0 comments on commit 130cbf2

Please sign in to comment.