cat_router 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +11 -15
- data/lib/cat_router/class_methods.rb +2 -0
- data/lib/cat_router/hook.rb +9 -0
- data/lib/cat_router/instance_methods.rb +14 -0
- data/lib/cat_router/railtie.rb +12 -0
- data/lib/cat_router/routes.rb +3 -4
- data/lib/cat_router/version.rb +1 -1
- data/lib/cat_router.rb +9 -5
- metadata +7 -4
- data/app/controllers/cat_router_controller.rb +0 -14
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
|
-
|
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
|
31
|
+
Open app/controllers/application_controller.rb and load it
|
31
32
|
|
32
33
|
class ApplicationController < ActionController::Base
|
33
|
-
|
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
|
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,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
|
data/lib/cat_router/routes.rb
CHANGED
@@ -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 =>
|
7
|
-
root :to =>
|
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
|
data/lib/cat_router/version.rb
CHANGED
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__), '
|
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
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
|