cat_router 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +109 -0
- data/Rakefile +23 -0
- data/lib/cat_router/routes.rb +13 -0
- data/lib/cat_router/version.rb +9 -0
- data/lib/cat_router.rb +14 -0
- data/lib/generators/cat_router_generator.rb +25 -0
- data/lib/generators/templates/migration.rb +20 -0
- data/test/cat_router_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +79 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
= CatRouter - The most simplistic CMS in the world
|
2
|
+
|
3
|
+
CatRouter is a simple router/CMS for displaying dynamic content on your site.
|
4
|
+
Buttons with content are defined in the database (using CatRoute model). A click of a button displays it's content (yield).
|
5
|
+
|
6
|
+
Copyright (c) 2011 [Kristijan Sedlak], released under the MIT license
|
7
|
+
|
8
|
+
|
9
|
+
== Installation (Rails 3 ready)
|
10
|
+
|
11
|
+
Add this line to your Gemfile (and run bundle install):
|
12
|
+
|
13
|
+
gem 'cat_router'
|
14
|
+
|
15
|
+
Open config/routes.rb and add this to the end
|
16
|
+
|
17
|
+
# define custom routes CatRouter::Routes.draw action.
|
18
|
+
# scope "(/:locale)" do
|
19
|
+
# match 'my_slug', :to => "controller#action"
|
20
|
+
# end
|
21
|
+
|
22
|
+
# CatRouter implementation
|
23
|
+
CatRouter::Routes.draw
|
24
|
+
|
25
|
+
Generate migration
|
26
|
+
|
27
|
+
rails g cat_router
|
28
|
+
rake db:migrate
|
29
|
+
|
30
|
+
Open app/controllers/application_controller.rb and add locale setter like this
|
31
|
+
|
32
|
+
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
|
39
|
+
end
|
40
|
+
|
41
|
+
The plugin comes with a CatRoute model and CatRouterController. You can append the default model or controller by creating a new
|
42
|
+
app/models/cat_route.rb file with content
|
43
|
+
|
44
|
+
class CatRoute
|
45
|
+
end
|
46
|
+
|
47
|
+
or app/controllers/cat_router_controller.rb file with content
|
48
|
+
|
49
|
+
class CatRouterController
|
50
|
+
end
|
51
|
+
|
52
|
+
== Examples
|
53
|
+
|
54
|
+
-------
|
55
|
+
|
56
|
+
You create a route by creating a CatRoute model record:
|
57
|
+
|
58
|
+
myRoute = CatRoute.create(:title => 'Welcome', :html => '<b>welcome</b>')
|
59
|
+
|
60
|
+
Note that :locale column is set to I18n.locale value by default but you can set it manually:
|
61
|
+
|
62
|
+
myRoute = CatRoute.create(:title => 'Welcome', :html => '<b>welcome</b>', :locale => 'en')
|
63
|
+
|
64
|
+
The plugin will auto generate the :slug value but you can set it manually:
|
65
|
+
|
66
|
+
myRoute = CatRoute.create(:title => 'Welcome', :html => '<b>welcome</b>', :slug => 'home/first_page')
|
67
|
+
|
68
|
+
If you would like to create a subroute (a sub button of myRoute) you would do it like this
|
69
|
+
|
70
|
+
mySubRoute = myRoute.cat_routes.create(:title => 'About', :html => 'about us html')
|
71
|
+
|
72
|
+
Records that has slug == '' are root buttons
|
73
|
+
|
74
|
+
rootRoute = CatRoute.create(:title => 'Home', :html => 'home html', :slug => '')
|
75
|
+
|
76
|
+
-------
|
77
|
+
|
78
|
+
You can get a list of subbuttons like this
|
79
|
+
|
80
|
+
mySubRoutes = CatRoute.find(13).cat_routes
|
81
|
+
|
82
|
+
To get the list of main buttons for your main menu, you will use
|
83
|
+
|
84
|
+
mainButtons = CatRoute.base_routes.with_locale(I18n.locale)
|
85
|
+
|
86
|
+
You get a root button like this
|
87
|
+
|
88
|
+
rootButton = CatRoute.root_routes.with_locale(I18n.locale).first
|
89
|
+
|
90
|
+
You get a button by slug like this
|
91
|
+
|
92
|
+
button = CatRoute.with_slug('about/our_business').first
|
93
|
+
|
94
|
+
-------
|
95
|
+
|
96
|
+
The @cat_route variable is also available (defined inside CatRoutesController) which holds the current route record.
|
97
|
+
|
98
|
+
Using HAML you will define a main-menu like this
|
99
|
+
|
100
|
+
.mainmenu
|
101
|
+
- CatRoute.base_routes.with_locale(I18n.locale).each do |b|
|
102
|
+
= link_to b.title, b.url, :class => b.slug == @cat_route.slug || b.id == @cat_route.parent_id ? 'selected' : ''
|
103
|
+
|
104
|
+
and a sub-menu like this
|
105
|
+
|
106
|
+
.submenu
|
107
|
+
- @cat_route.cat_routes_or_neighbours.each do |b|
|
108
|
+
= link_to b.title, b.url, :class => b.slug == @cat_route.slug || b.id == @cat_route.parent_id ? 'selected' : ''
|
109
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the cat_router plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the cat_router plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'CatRouter'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CatRouter
|
2
|
+
module Routes
|
3
|
+
|
4
|
+
def self.draw
|
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"
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
data/lib/cat_router.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module CatRouter
|
2
|
+
end
|
3
|
+
|
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'),
|
8
|
+
File.join(Rails.root, 'app', 'models', 'cat_route.rb'),
|
9
|
+
File.join(Rails.root, 'app', 'controllers', 'cat_router_controller.rb')
|
10
|
+
].each do |path|
|
11
|
+
if File.exists?(path)
|
12
|
+
require path
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class CatRouterGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
# Implement the required interface for Rails::Generators::Migration.
|
12
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
13
|
+
def self.next_migration_number(dirname)
|
14
|
+
if ActiveRecord::Base.timestamped_migrations
|
15
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
16
|
+
else
|
17
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_migration_file
|
22
|
+
migration_template 'migration.rb', 'db/migrate/cat_router_migration.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CatRouterMigration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :cat_routes do |t|
|
4
|
+
t.string :locale
|
5
|
+
t.string :title
|
6
|
+
t.string :slug
|
7
|
+
t.text :html
|
8
|
+
t.integer :parent_id
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :cat_routes, :locale
|
13
|
+
add_index :cat_routes, :slug
|
14
|
+
add_index :cat_routes, [:locale, :slug]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
drop_table :cat_routes
|
19
|
+
end
|
20
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cat_router
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kristijan Sedlak
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-06 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A simple router/CMS for displaying dynamic content on your site.
|
23
|
+
email: xpepermint@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
- MIT-LICENSE
|
31
|
+
files:
|
32
|
+
- Rakefile
|
33
|
+
- lib/cat_router/routes.rb
|
34
|
+
- lib/cat_router/version.rb
|
35
|
+
- lib/cat_router.rb
|
36
|
+
- lib/generators/cat_router_generator.rb
|
37
|
+
- lib/generators/templates/migration.rb
|
38
|
+
- test/cat_router_test.rb
|
39
|
+
- test/test_helper.rb
|
40
|
+
- README.rdoc
|
41
|
+
- MIT-LICENSE
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/xpepermint/cat_router
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --main
|
49
|
+
- README.rdoc
|
50
|
+
- --charset=UTF-8
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.6.1
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: CatRouter - The most simplistic CMS in the world.
|
78
|
+
test_files: []
|
79
|
+
|