From 2352ff7f2673ff33591b96238fb81adfbeea6f01 Mon Sep 17 00:00:00 2001 From: Alex Coles Date: Tue, 26 Feb 2008 19:35:03 +0100 Subject: [PATCH] Renamed controllers classes. Created route rules in router.rb --- Rakefile | 18 +-- .../abstract_models.rb} | 2 +- app/controllers/admin/export.rb | 7 ++ .../extensions.rb} | 2 +- .../{layout_controller.rb => admin/layouts.rb} | 2 +- .../{page_controller.rb => admin/pages.rb} | 2 +- app/controllers/admin/snippets.rb | 3 + .../{user_controller.rb => admin/users.rb} | 2 +- .../{welcome_controller.rb => admin/welcome.rb} | 2 +- .../{radiant_application.rb => application.rb} | 6 +- app/controllers/export_controller.rb | 5 - app/controllers/{site_controller.rb => site.rb} | 2 +- app/controllers/snippet_controller.rb | 3 - config/radiant_routes.rb | 74 ------------ config/router.rb | 124 +++++++++++++++------ 15 files changed, 119 insertions(+), 135 deletions(-) rename app/controllers/{abstract_model_controller.rb => admin/abstract_models.rb} (98%) create mode 100644 app/controllers/admin/export.rb rename app/controllers/{extension_controller.rb => admin/extensions.rb} (72%) rename app/controllers/{layout_controller.rb => admin/layouts.rb} (90%) rename app/controllers/{page_controller.rb => admin/pages.rb} (98%) create mode 100644 app/controllers/admin/snippets.rb rename app/controllers/{user_controller.rb => admin/users.rb} (95%) rename app/controllers/{welcome_controller.rb => admin/welcome.rb} (94%) rename app/controllers/{radiant_application.rb => application.rb} (91%) delete mode 100644 app/controllers/export_controller.rb rename app/controllers/{site_controller.rb => site.rb} (97%) delete mode 100644 app/controllers/snippet_controller.rb delete mode 100644 config/radiant_routes.rb rewrite config/router.rb (62%) diff --git a/Rakefile b/Rakefile index afc1a34..ee05bc3 100644 --- a/Rakefile +++ b/Rakefile @@ -9,15 +9,15 @@ module MerbRadiant end -Hoe.new('merb_radiant', MerbRadiant::VERSION) do |p| - p.rubyforge_name = 'merb_radiant' - p.author = 'Stephane Busso' - p.email = 'stephane.busso@gmail.com' - p.summary = 'A try of Radiant on Merb' - p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n") - p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1] - p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n") -end +#Hoe.new('merb_radiant', MerbRadiant::VERSION) do |p| +# p.rubyforge_name = 'merb_radiant' +# p.author = 'Stephane Busso' +# p.email = 'stephane.busso@gmail.com' +# p.summary = 'A try of Radiant on Merb' +# p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n") +# p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1] +# p.changes = p.paragraphs_of('CHANGELOG.txt', 0..1).join("\n\n") +#end # vim: syntax=Ruby diff --git a/app/controllers/abstract_model_controller.rb b/app/controllers/admin/abstract_models.rb similarity index 98% rename from app/controllers/abstract_model_controller.rb rename to app/controllers/admin/abstract_models.rb index ffa94ff..ceb7cdb 100644 --- a/app/controllers/abstract_model_controller.rb +++ b/app/controllers/admin/abstract_models.rb @@ -1,4 +1,4 @@ -class AbstractModelController < Application +class Admin::AbstractModels < Application attr_accessor :cache def self.model_class(model_class = nil) diff --git a/app/controllers/admin/export.rb b/app/controllers/admin/export.rb new file mode 100644 index 0000000..5602eca --- /dev/null +++ b/app/controllers/admin/export.rb @@ -0,0 +1,7 @@ +module Admin + class Export < Application + def yaml + render :text => Radiant::Exporter.export, :content_type => "text/yaml" + end + end +end \ No newline at end of file diff --git a/app/controllers/extension_controller.rb b/app/controllers/admin/extensions.rb similarity index 72% rename from app/controllers/extension_controller.rb rename to app/controllers/admin/extensions.rb index a350b6d..605e037 100644 --- a/app/controllers/extension_controller.rb +++ b/app/controllers/admin/extensions.rb @@ -1,4 +1,4 @@ -class ExtensionController < Application +class Admin::Extensions < Application def index @extensions = Radiant::Extension.descendants.sort_by { |e| e.extension_name } end diff --git a/app/controllers/layout_controller.rb b/app/controllers/admin/layouts.rb similarity index 90% rename from app/controllers/layout_controller.rb rename to app/controllers/admin/layouts.rb index 1246b05..31577b0 100644 --- a/app/controllers/layout_controller.rb +++ b/app/controllers/admin/layouts.rb @@ -1,4 +1,4 @@ -class LayoutController < AbstractModelController +class Admin::Layouts < AbstractModelController #model_class Layout attr_accessor :cache diff --git a/app/controllers/page_controller.rb b/app/controllers/admin/pages.rb similarity index 98% rename from app/controllers/page_controller.rb rename to app/controllers/admin/pages.rb index fe81af5..d2859e5 100644 --- a/app/controllers/page_controller.rb +++ b/app/controllers/admin/pages.rb @@ -1,4 +1,4 @@ -class PageController < AbstractModelController +class Admin::Pages < AbstractModelController #model_class Page before :initialize_meta_rows_and_buttons, :only => [:new, :edit] attr_accessor :cache diff --git a/app/controllers/admin/snippets.rb b/app/controllers/admin/snippets.rb new file mode 100644 index 0000000..4ea01ee --- /dev/null +++ b/app/controllers/admin/snippets.rb @@ -0,0 +1,3 @@ +class Admin::Snippets < AbstractModelController + #model_class Snippet +end \ No newline at end of file diff --git a/app/controllers/user_controller.rb b/app/controllers/admin/users.rb similarity index 95% rename from app/controllers/user_controller.rb rename to app/controllers/admin/users.rb index 70b6694..e54512c 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/admin/users.rb @@ -1,4 +1,4 @@ -class UserController < AbstractModelController +class Admin::Users < AbstractModelController #model_class User only_allow_access_to :index, :new, :edit, :remove, diff --git a/app/controllers/welcome_controller.rb b/app/controllers/admin/welcome.rb similarity index 94% rename from app/controllers/welcome_controller.rb rename to app/controllers/admin/welcome.rb index ef583ad..c22e99e 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/admin/welcome.rb @@ -1,4 +1,4 @@ -class WelcomeController < Application +class Admin::Welcome < Application no_login_required def index diff --git a/app/controllers/radiant_application.rb b/app/controllers/application.rb similarity index 91% rename from app/controllers/radiant_application.rb rename to app/controllers/application.rb index d0b8a84..6aa5504 100644 --- a/app/controllers/radiant_application.rb +++ b/app/controllers/application.rb @@ -1,6 +1,7 @@ require_dependency 'radiant' -class ApplicationController < Merb::Controller #FIXME before Action::ApplicationController::Base +class Application < Merb::Controller + include LoginSystem filter_parameter_logging :password, :password_confirmation @@ -45,4 +46,5 @@ class ApplicationController < Merb::Controller #FIXME before Action::Application @stylesheets = %w(admin/main) @javascripts = %w(prototype string effects tabcontrol ruledtable admin) end -end + +end \ No newline at end of file diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb deleted file mode 100644 index 4a2157f..0000000 --- a/app/controllers/export_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ExportController < Application - def yaml - render :text => Radiant::Exporter.export, :content_type => "text/yaml" - end -end diff --git a/app/controllers/site_controller.rb b/app/controllers/site.rb similarity index 97% rename from app/controllers/site_controller.rb rename to app/controllers/site.rb index 5033a0f..faf3896 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site.rb @@ -1,4 +1,4 @@ -class SiteController < Application +class Site < Application session :off no_login_required diff --git a/app/controllers/snippet_controller.rb b/app/controllers/snippet_controller.rb deleted file mode 100644 index a17f3a9..0000000 --- a/app/controllers/snippet_controller.rb +++ /dev/null @@ -1,3 +0,0 @@ -class SnippetController < AbstractModelController - #model_class Snippet -end \ No newline at end of file diff --git a/config/radiant_routes.rb b/config/radiant_routes.rb deleted file mode 100644 index 50c97d3..0000000 --- a/config/radiant_routes.rb +++ /dev/null @@ -1,74 +0,0 @@ -# FIXME move routes to router.rb - -# ActionController::Routing::Routes.draw do |map| -# -# # Admin Routes -# map.with_options(:controller => 'admin/welcome') do |welcome| -# welcome.admin 'admin', :action => 'index' -# welcome.welcome 'admin/welcome', :action => 'index' -# welcome.login 'admin/login', :action => 'login' -# welcome.logout 'admin/logout', :action => 'logout' -# end -# -# # Export Routes -# map.with_options(:controller => 'admin/export') do |export| -# export.export 'admin/export', :action => 'yaml' -# export.export_yaml 'admin/export/yaml', :action => 'yaml' -# end -# -# # Page Routes -# map.with_options(:controller => 'admin/page') do |page| -# page.page_index 'admin/pages', :action => 'index' -# page.page_edit 'admin/pages/edit/:id', :action => 'edit' -# page.page_new 'admin/pages/:parent_id/child/new', :action => 'new' -# page.homepage_new 'admin/pages/new/homepage', :action => 'new', :slug => '/', :breadcrumb => 'Home' -# page.page_remove 'admin/pages/remove/:id', :action => 'remove' -# page.page_add_part 'admin/ui/pages/part/add', :action => 'add_part' -# page.page_children 'admin/ui/pages/children/:id/:level', :action => 'children', :level => '1' -# page.tag_reference 'admin/ui/pages/tag_reference', :action => 'tag_reference' -# page.filter_reference 'admin/ui/pages/filter_reference', :action => 'filter_reference' -# page.clear_cache 'admin/pages/cache/clear', :action => 'clear_cache' -# end -# -# # Layouts Routes -# map.with_options(:controller => 'admin/layout') do |layout| -# layout.layout_index 'admin/layouts', :action => 'index' -# layout.layout_edit 'admin/layouts/edit/:id', :action => 'edit' -# layout.layout_new 'admin/layouts/new', :action => 'new' -# layout.layout_remove 'admin/layouts/remove/:id', :action => 'remove' -# end -# -# # Snippets Routes -# map.with_options(:controller => 'admin/snippet') do |snippet| -# snippet.snippet_index 'admin/snippets', :action => 'index' -# snippet.snippet_edit 'admin/snippets/edit/:id', :action => 'edit' -# snippet.snippet_new 'admin/snippets/new', :action => 'new' -# snippet.snippet_remove 'admin/snippets/remove/:id', :action => 'remove' -# end -# -# # Users Routes -# map.with_options(:controller => 'admin/user') do |user| -# user.user_index 'admin/users', :action => 'index' -# user.user_edit 'admin/users/edit/:id', :action => 'edit' -# user.user_new 'admin/users/new', :action => 'new' -# user.user_remove 'admin/users/remove/:id', :action => 'remove' -# user.user_preferences 'admin/preferences', :action => 'preferences' -# end -# -# # Extension Routes -# map.with_options(:controller => 'admin/extension') do |extension| -# extension.extension_index 'admin/extensions', :action => 'index' -# extension.extension_update 'admin/extensions/update', :action => 'update' -# end -# -# # Site URLs -# map.with_options(:controller => 'site') do |site| -# site.homepage '', :action => 'show_page', :url => '/' -# site.not_found 'error/404', :action => 'not_found' -# site.error 'error/500', :action => 'error' -# -# # Everything else -# site.connect '*url', :action => 'show_page' -# end -# -# end \ No newline at end of file diff --git a/config/router.rb b/config/router.rb dissimilarity index 62% index 2a3a696..7c770dc 100644 --- a/config/router.rb +++ b/config/router.rb @@ -1,35 +1,89 @@ -# Merb::Router is the request routing mapper for the merb framework. -# -# You can route a specific URL to a controller / action pair: -# -# r.match("/contact"). -# to(:controller => "info", :action => "contact") -# -# You can define placeholder parts of the url with the :symbol notation. These -# placeholders will be available in the params hash of your controllers. For example: -# -# r.match("/books/:book_id/:action"). -# to(:controller => "books") -# -# Or, use placeholders in the "to" results for more complicated routing, e.g.: -# -# r.match("/admin/:module/:controller/:action/:id"). -# to(:controller => ":module/:controller") -# -# You can also use regular expressions, deferred routes, and many other options. -# See merb/specs/merb/router.rb for a fairly complete usage sample. - -puts "Compiling routes.." -Merb::Router.prepare do |r| - # RESTful routes - # r.resources :posts - - # This is the default route for /:controller/:action/:id - # This is fine for most cases. If you're heavily using resource-based - # routes, you may want to comment/remove this line to prevent - # clients from calling your create or destroy actions with a GET - r.default_routes - - # Change this for your home page to be available at / - # r.match('/').to(:controller => 'whatever', :action =>'index') -end \ No newline at end of file +puts "Compiling routes.." + +Merb::Router.prepare do |r| + + # Admin Routes + r.namespace :admin do |admin| + + admin.match "admin", :controller => 'admin/welcome' do |w| + w.match('/').to(:action => 'index').name('admin') + w.match('/welcome').to(:action => 'index').name('welcome') + w.match('/login').to(:action => 'login').name('login') + w.match('/logout').to(:action => 'logout').name('logout') + end + + # Export Routes + admin.match "admin", :controller => 'admin/export' do |ex| + ex.match('/export').to(:action => 'yaml').name('export') + ex.match('/export/yaml').to(:action => 'yaml').name('export_yaml') + end + + # Page Routes + admin.match "admin", :controller => 'admin/page' do |pag| + pag.match('/pages').to(:action => 'index') + pag.match('/pages/edit/:id').to(:action => 'edit') + pag.match('/pages/:parent_id/child/new').to(:action => 'new') + pag.match('/pages/new/homepage').to(:action => 'new', :slug => '/', :breadcrumb => 'Home') + pag.match('/pages/remove/:id').to(:action => 'remove') + pag.match('/ui/pages/part/add').to(:action => 'add_part') + pag.match('/ui/pages/children/:id/:level').to(:action => 'children', :level => '1') + pag.match('/ui/pages/tag_reference').to(:action => 'tag_reference') + pag.match('/ui/pages/filter_reference').to(:action => 'filter_reference') + pag.match('/pages/cache/clear').to(:action => 'clear_cache') + end + + # Layouts Routes + admin.match "admin", :controller => 'admin/layout' do |lay| + lay.match('/layouts').to(:action => 'index') + lay.match('/layouts/edit/:id').to(:action => 'edit') + lay.match('/layouts/new').to(:action => 'new') + lay.match('/layouts/remove/:id').to(:action => 'remove') + end + + # Snippets Routes + admin.match "admin", :controller => 'admin/snippet' do |snp| + snp.match('/snippets').to(:action => 'index') + snp.match('/snippets/edit/:id').to(:action => 'edit') + snp.match('/snippets/new').to(:action => 'new') + snp.match('/snippets/remove/:id').to(:action => 'remove') + end + + # Users Routes + admin.match "admin", :controller => 'admin/user' do |usr| + usr.match('/users').to(:action => 'index') + usr.match('/users/edit/:id').to(:action => 'edit') + usr.match('/users/new').to(:action => 'new') + usr.match('/users/remove/:id').to(:action => 'remove') + usr.match('/preferences').to(:action => 'preferences') + end + + # Extension Routes + admin.match "welcome", :controller => '' do |ext| + ext.match('extensions').to(:action => 'index') + ext.match('extensions/update').to(:action => 'update') + end + + end + + # Site URLs + r.match "welcome", :controller => 'site' do |sit| + sit.match('').to(:action => 'show_page', :url = '/').name('homepage') + sit.match('error/404').to(:action => 'not_found').name('not_found') + sit.match('error/500').to(:action => 'error').name('error') + + # Everything else + sit.match('*url', :action => 'show_page') + end + + # RESTful routes + # r.resources :posts + + # This is the default route for /:controller/:action/:id + # This is fine for most cases. If you're heavily using resource-based + # routes, you may want to comment/remove this line to prevent + # clients from calling your create or destroy actions with a GET + # r.default_routes + + # Change this for your home page to be available at / + # r.match('/').to(:controller => 'whatever', :action =>'index') +end \ No newline at end of file -- 2.11.4.GIT