# HG changeset patch # User nolith # Date 1182778539 -7200 # Branch trunk # Node ID 46c838f6f25b314e8317f49eaed5f0b2509602cc # Parent ab272a2d424931073d764e7bf5d19698e3e1dce9 [svn r1046] version 1.0 diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Mon Jun 25 15:35:39 2007 +0200 @@ -0,0 +1,11 @@ += Home Dir + +This Radiant extension allow you to define ~user routes like apache userdir module. + +== Install + +Execute +
+% rake db:migrate:extensions
+% rake production db:migrate:extensions
+
\ No newline at end of file
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc Rakefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Rakefile Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,25 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the home_dir extension.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the home_dir extension.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'HomeDirExtension'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+# Load any custom rakefiles for extension
+Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
\ No newline at end of file
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc app/controllers/admin/homes_controller.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/controllers/admin/homes_controller.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,6 @@
+class Admin::HomesController < ApplicationController
+ # Remove this line if your controller should only be accessible to users
+ # that are logged in:
+ #no_login_required
+ scaffold :user_home
+end
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc app/controllers/home_redirect_controller.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/controllers/home_redirect_controller.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,18 @@
+class HomeRedirectController < ApplicationController
+ # Remove this line if your controller should only be accessible to users
+ # that are logged in:
+ no_login_required
+
+ def index
+ user = UserHome.find_by_name(params[:user].sub(/~/,''))
+ if user.nil?
+ begin
+ redirect_to :back
+ rescue ActionController::RedirectBackError
+ redirect_to "/"
+ end
+ else
+ redirect_to user.url
+ end
+ end
+end
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc app/helpers/admin/homes_helper.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/helpers/admin/homes_helper.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,2 @@
+module Admin::HomesHelper
+end
\ No newline at end of file
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc app/helpers/home_redirect_helper.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/helpers/home_redirect_helper.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,2 @@
+module HomeRedirectHelper
+end
\ No newline at end of file
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc app/models/home_dir_tags.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/models/home_dir_tags.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,21 @@
+module HomeDirTags
+ include Radiant::Taggable
+
+ desc %{
+ Create a link to the homepage defined for @name@ attribute.
+
+ *Usage:*
+
+ }
+ tag 'homelink' do |tag|
+ if name = tag.attr['name']
+ if home = UserHome.find_by_name(name)
+ %{#{home.name}}
+ else
+ raise StandardTags::TagError.new("Error in `homelink' tag, user `#{name}' does not exists")
+ end
+ else
+ raise StandardTags::TagError.new("`homelink' tag must contain `name' attribute")
+ end
+ end
+end
\ No newline at end of file
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc app/models/user_home.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/models/user_home.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,11 @@
+class UserHome < ActiveRecord::Base
+ validates_format_of :name,
+ :with => /\A\w{2,16}\Z/i, :message => "should be alfanumeric, from 2 to 16 charachter length"
+ validates_presence_of :url, :message => "can't be blank"
+
+ def validate
+ if ((self[:url] =~ /\// ) != 0)
+ errors.add(:url, "should begin with '/'")
+ end
+ end
+end
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc db/migrate/001_create_user_homes.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/db/migrate/001_create_user_homes.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,13 @@
+class CreateUserHomes < ActiveRecord::Migration
+ def self.up
+ create_table :user_homes do |t|
+ t.column :name, :string
+ t.column :url, :string
+ t.column :note, :text
+ end
+ end
+
+ def self.down
+ drop_table :user_homes
+ end
+end
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc home_dir_extension.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/home_dir_extension.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,24 @@
+# Uncomment this if you reference any of your controllers in activate
+# require_dependency 'application'
+
+class HomeDirExtension < Radiant::Extension
+ version "1.0"
+ description "Allow to redirect www.yoursite.com/~user to a specific page, like on apache userdir"
+ url "http://abisso.org/projects/home_dir"
+
+ define_routes do |map|
+ map.connect 'admin/home_dir/:action', :controller => 'admin/homes'
+ map.homes ':user', :controller => 'home_redirect', :action =>'index',
+ :requirements => { :user => /~\w{2,16}/ }
+ end
+
+ def activate
+ admin.tabs.add "Home Dir", "/admin/home_dir", :after => "Layouts", :visibility => [:all]
+ Page.send :include, HomeDirTags
+ end
+
+ def deactivate
+ admin.tabs.remove "Home Dir"
+ end
+
+end
\ No newline at end of file
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc lib/tasks/home_dir_extension_tasks.rake
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/tasks/home_dir_extension_tasks.rake Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,17 @@
+namespace :radiant do
+ namespace :extensions do
+ namespace :home_dir do
+
+ desc "Runs the migration of the Home Dir extension"
+ task :migrate => :environment do
+ require 'radiant/extension_migrator'
+ if ENV["VERSION"]
+ HomeDirExtension.migrator.migrate(ENV["VERSION"].to_i)
+ else
+ HomeDirExtension.migrator.migrate
+ end
+ end
+
+ end
+ end
+end
\ No newline at end of file
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc test/fixtures/user_homes.yml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/fixtures/user_homes.yml Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,11 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+ name: MyString
+ url: MyString
+ note: MyText
+two:
+ id: 2
+ name: MyString
+ url: MyString
+ note: MyText
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc test/functional/admin/homes_controller_test.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/functional/admin/homes_controller_test.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,17 @@
+require File.dirname(__FILE__) + '/../../test_helper'
+
+# Re-raise errors caught by the controller.
+Admin::HomesController.class_eval { def rescue_action(e) raise e end }
+
+class Admin::HomesControllerTest < Test::Unit::TestCase
+ def setup
+ @controller = Admin::HomesController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc test/functional/home_dir_extension_test.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/functional/home_dir_extension_test.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,15 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class HomeDirExtensionTest < Test::Unit::TestCase
+
+ # Replace this with your real tests.
+ def test_this_extension
+ flunk
+ end
+
+ def test_initialization
+ assert_equal File.join(File.expand_path(RAILS_ROOT), 'vendor', 'extensions', 'home_dir'), HomeDirExtension.root
+ assert_equal 'Home Dir', HomeDirExtension.extension_name
+ end
+
+end
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc test/functional/home_redirect_controller_test.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/functional/home_redirect_controller_test.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,17 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+# Re-raise errors caught by the controller.
+HomeRedirectController.class_eval { def rescue_action(e) raise e end }
+
+class HomeRedirectControllerTest < Test::Unit::TestCase
+ def setup
+ @controller = HomeRedirectController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc test/test_helper.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test_helper.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,18 @@
+# Load the the environment
+unless defined? RADIANT_ROOT
+ ENV["RAILS_ENV"] = "test"
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/boot"
+end
+require "#{RADIANT_ROOT}/test/test_helper"
+
+class Test::Unit::TestCase
+
+ # Include a helper to make testing Radius tags easier
+ test_helper :extension_tags
+
+ # Add the fixture directory to the fixture path
+ self.fixture_path << File.dirname(__FILE__) + "/fixtures"
+
+ # Add more helper methods to be used by all extension tests here...
+
+end
\ No newline at end of file
diff -r ab272a2d424931073d764e7bf5d19698e3e1dce9 -r 46c838f6f25b314e8317f49eaed5f0b2509602cc test/unit/user_home_test.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unit/user_home_test.rb Mon Jun 25 15:35:39 2007 +0200
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class UserHomeTest < Test::Unit::TestCase
+ fixtures :user_homes
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
\ No newline at end of file