cat_router 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -12,6 +12,11 @@ Add this line to your Gemfile (and run bundle install):
12
12
 
13
13
  gem 'cat_router'
14
14
 
15
+ Generate migration
16
+
17
+ rails g cat_router
18
+ rake db:migrate
19
+
15
20
  Open config/routes.rb and add this to the end
16
21
 
17
22
  # define custom routes CatRouter::Routes.draw action.
@@ -19,26 +24,17 @@ Open config/routes.rb and add this to the end
19
24
  # match 'my_slug', :to => "controller#action"
20
25
  # end
21
26
 
22
- # CatRouter implementation
23
- CatRouter::Routes.draw
24
-
25
- Generate migration
26
-
27
- rails g cat_router
28
- rake db:migrate
27
+ # CatRouter implementation (application controller will handle all requests
28
+ # over a handle_cat_routes action)
29
+ CatRouter::Routes.draw('application#handle_cat_routes')
29
30
 
30
- Open app/controllers/application_controller.rb and add locale setter like this
31
+ Open app/controllers/application_controller.rb and load it
31
32
 
32
33
  class ApplicationController < ActionController::Base
33
- before_filter :set_locale
34
- private
35
- def set_locale
36
- I18n.locale = :en
37
- I18n.locale = params[:locale] if params[:locale]
38
- end
34
+ acts_as_cat_router
39
35
  end
40
36
 
41
- The plugin comes with a CatRoute model and CatRouterController. You can append the default model or controller by creating a new
37
+ The plugin comes with a CatRoute model. You can append the default model or controller by creating a new
42
38
  app/models/cat_route.rb file with content
43
39
 
44
40
  class CatRoute
@@ -0,0 +1,2 @@
1
+ module CatRouter::ClassMethods
2
+ end
@@ -0,0 +1,9 @@
1
+ module CatRouter::Hook
2
+ def acts_as_cat_router(*args)
3
+ options = args.extract_options!
4
+
5
+ # now do the things that make the controller
6
+ include CatRouter::InstanceMethods
7
+ before_filter :set_locale
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module CatRouter::InstanceMethods
2
+
3
+ def set_locale
4
+ puts 'set_locale!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
5
+ I18n.locale = :sl
6
+ I18n.locale = params[:locale] if params[:locale]
7
+ end
8
+
9
+ def handle_cat_routes
10
+ @cat_route = CatRoute.with_slug(params[:slug] ? params[:slug] : '').first
11
+ render :layout => true, :inline => @cat_route.html ? @cat_route.html : ''
12
+ end
13
+
14
+ end
@@ -0,0 +1,12 @@
1
+ require "action_controller"
2
+ require "rails"
3
+ require "action_view/railtie"
4
+ require 'cat_router'
5
+
6
+ module CatRouter
7
+ class Railtie < Rails::Railtie
8
+ config.to_prepare do
9
+ ActionController::Base.send(:extend, CatRouter::Hook)
10
+ end
11
+ end
12
+ end
@@ -1,12 +1,11 @@
1
1
  module CatRouter
2
2
  module Routes
3
3
 
4
- def self.draw
4
+ def self.draw(to)
5
5
  Rails.application.routes.draw do
6
- match "/:locale(/*slug(.:extension))", :as => :cat_router, :to => 'cat_router#router', :constraints => { :locale => /[a-z]{2,2}/ }
7
- root :to => "cat_router#router"
6
+ match "/:locale(/*slug(.:extension))", :as => :cat_router, :to => to, :constraints => { :locale => /[a-z]{2,2}/ }
7
+ root :to => to
8
8
  end
9
-
10
9
  end
11
10
 
12
11
  end
@@ -2,7 +2,7 @@ module CatRouter
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/cat_router.rb CHANGED
@@ -1,12 +1,16 @@
1
+ require 'active_support/core_ext'
2
+ require File.join(File.dirname(__FILE__), "cat_router/railtie")
3
+
1
4
  module CatRouter
5
+ autoload :Version, File.join(File.dirname(__FILE__), "cat_router/version")
6
+ autoload :Routes, File.join(File.dirname(__FILE__), "cat_router/routes")
7
+ autoload :Hook, File.join(File.dirname(__FILE__), "cat_router/hook")
8
+ autoload :InstanceMethods, File.join(File.dirname(__FILE__), "cat_router/instance_methods")
9
+ autoload :ClassMethods, File.join(File.dirname(__FILE__), "cat_router/class_methods")
2
10
  end
3
11
 
4
- [ File.join(File.dirname(__FILE__), 'cat_router', 'routes.rb'),
5
- File.join(File.dirname(__FILE__), 'cat_router', 'version.rb'),
6
- File.join(File.dirname(__FILE__), '..', 'app', 'models', 'cat_route.rb'),
7
- File.join(File.dirname(__FILE__), '..', 'app', 'controllers', 'cat_router_controller.rb'),
12
+ [ File.join(File.dirname(__FILE__), '..', 'app', 'models', 'cat_route.rb'),
8
13
  File.join(Rails.root||RAILS_ROOT, 'app', 'models', 'cat_route.rb'),
9
- File.join(Rails.root||RAILS_ROOT, 'app', 'controllers', 'cat_router_controller.rb')
10
14
  ].each do |path|
11
15
  if File.exists?(path)
12
16
  require path
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cat_router
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kristijan Sedlak
@@ -30,8 +30,11 @@ extra_rdoc_files:
30
30
  - MIT-LICENSE
31
31
  files:
32
32
  - Rakefile
33
- - app/controllers/cat_router_controller.rb
34
33
  - app/models/cat_route.rb
34
+ - lib/cat_router/class_methods.rb
35
+ - lib/cat_router/hook.rb
36
+ - lib/cat_router/instance_methods.rb
37
+ - lib/cat_router/railtie.rb
35
38
  - lib/cat_router/routes.rb
36
39
  - lib/cat_router/version.rb
37
40
  - lib/cat_router.rb
@@ -1,14 +0,0 @@
1
- class CatRouterController < ApplicationController
2
-
3
- def router
4
- handle
5
- end
6
-
7
- protected
8
-
9
- def handle
10
- @cat_route = CatRoute.with_slug(params[:slug] ? params[:slug] : '').first
11
- render :layout => true, :inline => @cat_route.html ? @cat_route.html : ''
12
- end
13
-
14
- end