padrino-admin 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +30 -57
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/lib/padrino-admin.rb +2 -2
- data/lib/padrino-admin/access_control.rb +4 -4
- data/lib/padrino-admin/generators/actions.rb +1 -1
- data/lib/padrino-admin/generators/admin_app.rb +9 -7
- data/lib/padrino-admin/generators/admin_page.rb +6 -5
- data/lib/padrino-admin/generators/orm.rb +4 -2
- data/lib/padrino-admin/generators/templates/account/activerecord.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/account/datamapper.rb.tt +9 -2
- data/lib/padrino-admin/generators/templates/account/mongoid.rb.tt +59 -0
- data/lib/padrino-admin/generators/templates/account/mongomapper.rb.tt +52 -0
- data/lib/padrino-admin/generators/templates/erb/app/base/_sidebar.erb.tt +2 -2
- data/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt +3 -3
- data/lib/padrino-admin/generators/templates/erb/app/sessions/new.erb.tt +1 -1
- data/lib/padrino-admin/generators/templates/erb/page/_form.erb.tt +1 -1
- data/lib/padrino-admin/generators/templates/haml/app/base/_sidebar.haml.tt +11 -0
- data/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt +25 -0
- data/lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt +31 -0
- data/lib/padrino-admin/generators/templates/haml/app/sessions/new.haml.tt +25 -0
- data/lib/padrino-admin/generators/templates/haml/page/_form.haml.tt +12 -0
- data/lib/padrino-admin/generators/templates/haml/page/edit.haml.tt +15 -0
- data/lib/padrino-admin/generators/templates/haml/page/index.haml.tt +29 -0
- data/lib/padrino-admin/generators/templates/haml/page/new.haml.tt +14 -0
- data/lib/padrino-admin/helpers/authentication_helpers.rb +1 -1
- data/padrino-admin.gemspec +22 -16
- data/test/fixtures/data_mapper.rb +7 -0
- data/test/generators/test_admin_app_generator.rb +31 -1
- data/test/generators/test_admin_page_generator.rb +19 -1
- data/test/helper.rb +1 -1
- data/test/test_admin_application.rb +0 -24
- metadata +50 -92
- data/lib/padrino-admin/middleware/flash_middleware.rb +0 -30
data/README.rdoc
CHANGED
@@ -2,50 +2,53 @@
|
|
2
2
|
|
3
3
|
=== Overview
|
4
4
|
|
5
|
-
Padrino has a beautiful Admin
|
5
|
+
Padrino has a beautiful Admin management dashboard with these features:
|
6
6
|
|
7
|
-
Orm Agnostic:: Adapters for
|
7
|
+
Orm Agnostic:: Data Adapters for Datamapper, Activerecord, Mongomapper, Mongoid
|
8
|
+
Template Agnostic:: Erb and Haml Renderer
|
8
9
|
Authentication:: Support for Account authentication, Account Permission managment
|
9
|
-
Scaffold:: You can simply create a new "admin interface"
|
10
|
+
Scaffold:: You can simply create a new "admin interface" by providing a Model
|
11
|
+
Access Control:: Supports authentication and role permissions for your application
|
10
12
|
|
11
|
-
=== Admin Usage
|
13
|
+
=== Admin Dashboard Usage
|
12
14
|
|
13
|
-
|
15
|
+
For a complete look at usage of the Admin dashboard functionality, be sure to check out the
|
16
|
+
{Padrino Admin}[http://wiki.github.com/padrino/padrino-framework/padrino-admin] guide.
|
14
17
|
|
15
|
-
|
16
|
-
$ cd fun-test
|
18
|
+
Create a new project:
|
17
19
|
|
18
|
-
|
20
|
+
$ padrino-gen project demo
|
21
|
+
$ cd demo
|
19
22
|
|
20
|
-
|
23
|
+
Create the admin subapplication:
|
21
24
|
|
22
|
-
|
25
|
+
demo$ padrino-gen admin
|
23
26
|
|
24
|
-
|
25
|
-
* run padrino rake dm:migrate # or ar:migrate if you use activerecord
|
26
|
-
* run padrino rake seed
|
27
|
+
Next, follow the admin setup steps:
|
27
28
|
|
28
|
-
|
29
|
+
* configure your <tt>config/database.rb</tt> to connect to the correct data.
|
30
|
+
* run <tt>padrino rake dm:migrate</tt> # or ar:migrate if you use activerecord
|
31
|
+
* run <tt>padrino rake seed</tt>
|
29
32
|
|
30
|
-
|
33
|
+
Your admin panel now is ready and you can start your server with <tt>padrino start</tt> and point your browser to <tt>/admin</tt>!
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
To create a new "scaffold" you need to provide only a Model name to the command:
|
36
|
+
|
37
|
+
demo$ padrino-gen model post --skip-migration # edit your post.rb model and add some fields
|
38
|
+
demo$ padrino-gen rake dm:auto:migrate
|
39
|
+
demo$ padrino-gen admin_page post
|
40
|
+
demo$ padrino start # and go to http://localhost:3000/admin
|
36
41
|
|
37
42
|
That's all!!
|
38
43
|
|
39
|
-
=== Admin
|
44
|
+
=== Admin Access Control
|
40
45
|
|
41
46
|
Padrino Admin use a model Account for manage role, membership and permissions.
|
42
47
|
|
48
|
+
For an ecommerce website, usually certain actions require permissions and authentication. This is supported
|
49
|
+
by the admin access control features:
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
For an ecommerce we usually deny some controllers/actions like
|
47
|
-
|
48
|
-
class MyEcommerce < Padrino::Application
|
51
|
+
class EcommerceSite < Padrino::Application
|
49
52
|
enable :authentication
|
50
53
|
enable :store_location
|
51
54
|
set :login_page, "/login"
|
@@ -59,38 +62,8 @@ For an ecommerce we usually deny some controllers/actions like
|
|
59
62
|
In this example +if+ we visit urls that start with /+customer+/+orders+ or /+cart/checkout+ we will be redirected
|
60
63
|
to our :+login_page+ "/login". Once we are correctly logged in we can visit these pages.
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
Suppose that you need to some actions for +admin+ accounts and others for +editors+
|
65
|
-
|
66
|
-
When you generate padrino-admin will be created for you an +Account+ model that have a +role+ attribute. So:
|
67
|
-
|
68
|
-
class Admin < Padrino::Application
|
69
|
-
enable :authentication
|
70
|
-
disable :store_location
|
71
|
-
set :login_page, "/admin/sessions/new"
|
72
|
-
|
73
|
-
access_control.roles_for :any do |role|
|
74
|
-
role.protect "/"
|
75
|
-
role.allow "/sessions"
|
76
|
-
end
|
77
|
-
|
78
|
-
access_control.roles_for :admin do |role|
|
79
|
-
role.project_module :settings, "/settings"
|
80
|
-
end
|
81
|
-
|
82
|
-
access_control.roles_for :editor do |role|
|
83
|
-
role.project_module :posts, "/posts"
|
84
|
-
role.project_module :categories, "/categories"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
In this case we +protect+ the entire admin (all paths that start with "/") except paths that start with /+sessions+ so
|
89
|
-
an +unauthenticated+ user can login.
|
90
|
-
|
91
|
-
If we login as +admin+ (account.role == 'admin') we have access *only* to paths that start with /+settings+.
|
92
|
-
|
93
|
-
If we login as +editor+ (account.role == 'editor') we have access *only* to paths that start with /+posts+ and /+categories+
|
65
|
+
For a more complete look at using the Admin panel functionality and access features, be sure to check out the
|
66
|
+
{Padrino Admin}[http://wiki.github.com/padrino/padrino-framework/padrino-admin] guide.
|
94
67
|
|
95
68
|
== Copyright
|
96
69
|
|
data/Rakefile
CHANGED
@@ -14,7 +14,6 @@ begin
|
|
14
14
|
gem.homepage = "http://github.com/padrino/padrino-framework/tree/master/padrino-admin"
|
15
15
|
gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
16
16
|
gem.rubyforge_project = 'padrino-admin'
|
17
|
-
gem.add_runtime_dependency "json_pure", ">= 1.2.0"
|
18
17
|
gem.add_runtime_dependency "padrino-core", "= #{GEM_VERSION}"
|
19
18
|
gem.add_runtime_dependency "padrino-gen", "= #{GEM_VERSION}"
|
20
19
|
gem.add_runtime_dependency "padrino-helpers", "= #{GEM_VERSION}"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
data/lib/padrino-admin.rb
CHANGED
@@ -2,8 +2,8 @@ require 'padrino-core'
|
|
2
2
|
require 'padrino-gen'
|
3
3
|
require 'padrino-helpers'
|
4
4
|
|
5
|
-
Dir[File.dirname(__FILE__) + '/padrino-admin/*.rb'].each {|file| require file }
|
6
|
-
Dir[File.dirname(__FILE__) + '/padrino-admin/{helpers,
|
5
|
+
Dir[File.dirname(__FILE__) + '/padrino-admin/*.rb'].each { |file| require file }
|
6
|
+
Dir[File.dirname(__FILE__) + '/padrino-admin/{helpers,utils}/*.rb'].each { |file| require file }
|
7
7
|
|
8
8
|
module Padrino
|
9
9
|
##
|
@@ -13,7 +13,6 @@ module Padrino
|
|
13
13
|
app.set :session_id, "_padrino_#{File.basename(Padrino.root)}_#{app.app_name}".to_sym
|
14
14
|
app.helpers Padrino::Admin::Helpers::AuthenticationHelpers
|
15
15
|
app.helpers Padrino::Admin::Helpers::ViewHelpers
|
16
|
-
app.use Padrino::Admin::Middleware::FlashMiddleware, app.session_id # make sure that is the same of session_name in helpers
|
17
16
|
app.before { login_required }
|
18
17
|
end
|
19
18
|
|
@@ -52,7 +51,7 @@ module Padrino
|
|
52
51
|
# Return an array of project_modules
|
53
52
|
#
|
54
53
|
def project_modules(account)
|
55
|
-
role = account
|
54
|
+
role = account.role.to_sym rescue :any
|
56
55
|
authorizations = @authorizations.find_all { |auth| auth.roles.include?(role) }
|
57
56
|
authorizations.collect(&:project_modules).flatten.uniq
|
58
57
|
end
|
@@ -62,14 +61,15 @@ module Padrino
|
|
62
61
|
#
|
63
62
|
def allowed?(account=nil, path=nil)
|
64
63
|
path = "/" if path.blank?
|
64
|
+
role = account.role.to_sym rescue nil
|
65
65
|
authorizations = @authorizations.find_all { |auth| auth.roles.include?(:any) }
|
66
66
|
allowed_paths = authorizations.collect(&:allowed).flatten.uniq
|
67
67
|
denied_paths = authorizations.collect(&:denied).flatten.uniq
|
68
68
|
if account
|
69
69
|
denied_paths.clear
|
70
|
-
authorizations = @authorizations.find_all { |auth| auth.roles.include?(
|
70
|
+
authorizations = @authorizations.find_all { |auth| auth.roles.include?(role) }
|
71
71
|
allowed_paths += authorizations.collect(&:allowed).flatten.uniq
|
72
|
-
authorizations = @authorizations.find_all { |auth| !auth.roles.include?(
|
72
|
+
authorizations = @authorizations.find_all { |auth| !auth.roles.include?(role) && !auth.roles.include?(:any) }
|
73
73
|
denied_paths += authorizations.collect(&:allowed).flatten.uniq
|
74
74
|
denied_paths += authorizations.collect(&:denied).flatten.uniq
|
75
75
|
end
|
@@ -41,6 +41,8 @@ module Padrino
|
|
41
41
|
|
42
42
|
self.behavior = :revoke if options[:destroy]
|
43
43
|
|
44
|
+
ext = fetch_component_choice(:renderer)
|
45
|
+
|
44
46
|
directory "templates/app", destination_root("admin")
|
45
47
|
directory "templates/assets", destination_root("public", "admin")
|
46
48
|
|
@@ -64,16 +66,16 @@ module Padrino
|
|
64
66
|
admin_app.orm = Padrino::Admin::Generators::Orm.new(:account, orm, columns, column_fields)
|
65
67
|
admin_app.invoke
|
66
68
|
|
67
|
-
template "templates/account/#{orm}.rb.tt",
|
68
|
-
template "templates/account/seeds.rb.tt",
|
69
|
-
template "templates/
|
70
|
-
template "templates/
|
71
|
-
template "templates/
|
72
|
-
template "templates/
|
69
|
+
template "templates/account/#{orm}.rb.tt", destination_root("app", "models", "account.rb"), :force => true
|
70
|
+
template "templates/account/seeds.rb.tt", destination_root("db/seeds.rb")
|
71
|
+
template "templates/#{ext}/app/base/_sidebar.#{ext}.tt", destination_root("admin/views/base/_sidebar.#{ext}")
|
72
|
+
template "templates/#{ext}/app/base/index.#{ext}.tt", destination_root("admin/views/base/index.#{ext}")
|
73
|
+
template "templates/#{ext}/app/layouts/application.#{ext}.tt", destination_root("admin/views/layouts/application.#{ext}")
|
74
|
+
template "templates/#{ext}/app/sessions/new.#{ext}.tt", destination_root("admin/views/sessions/new.#{ext}")
|
73
75
|
|
74
76
|
add_project_module :accounts
|
75
77
|
append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/admin\")"
|
76
|
-
gsub_file destination_root("admin/views/accounts/_form
|
78
|
+
gsub_file destination_root("admin/views/accounts/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
|
77
79
|
|
78
80
|
return if self.behavior == :revoke
|
79
81
|
say (<<-TEXT).gsub(/ {10}/,'')
|
@@ -31,12 +31,13 @@ module Padrino
|
|
31
31
|
if in_app_root?
|
32
32
|
@orm ||= Padrino::Admin::Generators::Orm.new(model, adapter)
|
33
33
|
self.behavior = :revoke if options[:destroy]
|
34
|
+
ext = fetch_component_choice(:renderer)
|
34
35
|
|
35
|
-
template "templates/page/controller.rb.tt",
|
36
|
-
template "templates/
|
37
|
-
template "templates/
|
38
|
-
template "templates/
|
39
|
-
template "templates/
|
36
|
+
template "templates/page/controller.rb.tt", destination_root("/admin/controllers/#{@orm.name_plural}.rb")
|
37
|
+
template "templates/#{ext}/page/_form.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/_form.#{ext}")
|
38
|
+
template "templates/#{ext}/page/edit.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/edit.#{ext}")
|
39
|
+
template "templates/#{ext}/page/index.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/index.#{ext}")
|
40
|
+
template "templates/#{ext}/page/new.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/new.#{ext}")
|
40
41
|
|
41
42
|
add_project_module(@orm.name_plural)
|
42
43
|
else
|
@@ -31,6 +31,8 @@ module Padrino
|
|
31
31
|
@columns ||= case orm
|
32
32
|
when :activerecord then @klass.columns
|
33
33
|
when :datamapper then @klass.properties
|
34
|
+
when :mongoid then @klass.fields.values
|
35
|
+
when :mongomapper then @klass.keys.values.reject { |key| key.name == "_id" } # On MongoMapper keys are an hash
|
34
36
|
else raise OrmError, "Adapter #{orm} not yet supported!"
|
35
37
|
end
|
36
38
|
end
|
@@ -50,7 +52,7 @@ module Padrino
|
|
50
52
|
|
51
53
|
def find(params=nil)
|
52
54
|
case orm
|
53
|
-
when :activerecord then "#{klass_name}.find(#{params})"
|
55
|
+
when :activerecord, :mongomapper, :mongoid then "#{klass_name}.find(#{params})"
|
54
56
|
when :datamapper then "#{klass_name}.get(#{params})"
|
55
57
|
else raise OrmError, "Adapter #{orm} not yet supported!"
|
56
58
|
end
|
@@ -70,7 +72,7 @@ module Padrino
|
|
70
72
|
|
71
73
|
def update_attributes(params=nil)
|
72
74
|
case orm
|
73
|
-
when :activerecord then "#{name_singular}.update_attributes(#{params})"
|
75
|
+
when :activerecord, :mongomapper, :mongoid then "#{name_singular}.update_attributes(#{params})"
|
74
76
|
when :datamapper then "#{name_singular}.update(#{params})"
|
75
77
|
else raise OrmError, "Adapter #{orm} not yet supported!"
|
76
78
|
end
|
@@ -16,7 +16,7 @@ class Account < ActiveRecord::Base
|
|
16
16
|
before_save :generate_password
|
17
17
|
|
18
18
|
##
|
19
|
-
# This method
|
19
|
+
# This method is for authentication purpose
|
20
20
|
#
|
21
21
|
def self.authenticate(email, password)
|
22
22
|
account = first(:conditions => { :email => email }) if email.present?
|
@@ -24,7 +24,7 @@ class Account < ActiveRecord::Base
|
|
24
24
|
end
|
25
25
|
|
26
26
|
##
|
27
|
-
# This method
|
27
|
+
# This method is used for retrive the original password.
|
28
28
|
#
|
29
29
|
def password_clean
|
30
30
|
crypted_password.decrypt(salt)
|
@@ -27,7 +27,7 @@ class Account
|
|
27
27
|
before :save, :generate_password
|
28
28
|
|
29
29
|
##
|
30
|
-
# This method
|
30
|
+
# This method is for authentication purpose
|
31
31
|
#
|
32
32
|
def self.authenticate(email, password)
|
33
33
|
account = first(:conditions => { :email => email }) if email.present?
|
@@ -35,7 +35,14 @@ class Account
|
|
35
35
|
end
|
36
36
|
|
37
37
|
##
|
38
|
-
# This method
|
38
|
+
# This method is used from AuthenticationHelper
|
39
|
+
#
|
40
|
+
def self.find_by_id(id)
|
41
|
+
get(id) rescue nil
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# This method is used for retrive the original password.
|
39
46
|
#
|
40
47
|
def password_clean
|
41
48
|
crypted_password.decrypt(salt)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Account
|
2
|
+
include Mongoid::Document
|
3
|
+
attr_accessor :password
|
4
|
+
|
5
|
+
# Fields
|
6
|
+
field :name, :type => String
|
7
|
+
field :surname, :type => String
|
8
|
+
field :email, :type => String
|
9
|
+
field :crypted_password, :type => String
|
10
|
+
field :salt, :type => String
|
11
|
+
field :role, :type => String
|
12
|
+
|
13
|
+
# Validations
|
14
|
+
validates_presence_of :email, :role
|
15
|
+
validates_presence_of :password, :if => :password_required
|
16
|
+
validates_presence_of :password_confirmation, :if => :password_required
|
17
|
+
validates_length_of :password, :within => 4..40, :if => :password_required
|
18
|
+
validates_confirmation_of :password, :if => :password_required
|
19
|
+
validates_length_of :email, :within => 3..100
|
20
|
+
validates_uniqueness_of :email
|
21
|
+
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
22
|
+
validates_format_of :role, :with => /[A-Za-z]/
|
23
|
+
|
24
|
+
# Callbacks
|
25
|
+
before_save :generate_password
|
26
|
+
|
27
|
+
##
|
28
|
+
# This method is for authentication purpose
|
29
|
+
#
|
30
|
+
def self.authenticate(email, password)
|
31
|
+
account = first(:conditions => { :email => email }) if email.present?
|
32
|
+
account && account.password_clean == password ? account : nil
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# This method is used from AuthenticationHelper
|
37
|
+
#
|
38
|
+
def self.find_by_id(id)
|
39
|
+
find(id) rescue nil
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# This method is used for retrive the original password.
|
44
|
+
#
|
45
|
+
def password_clean
|
46
|
+
crypted_password.decrypt(salt)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def generate_password
|
51
|
+
return if password.blank?
|
52
|
+
self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new_record?
|
53
|
+
self.crypted_password = password.encrypt(self.salt)
|
54
|
+
end
|
55
|
+
|
56
|
+
def password_required
|
57
|
+
crypted_password.blank? || !password.blank?
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class Account
|
2
|
+
include MongoMapper::Document
|
3
|
+
attr_accessor :password
|
4
|
+
|
5
|
+
# Keys
|
6
|
+
key :name, String
|
7
|
+
key :surname, String
|
8
|
+
key :email, String
|
9
|
+
key :crypted_password, String
|
10
|
+
key :salt, String
|
11
|
+
key :role, String
|
12
|
+
|
13
|
+
# Validations
|
14
|
+
validates_presence_of :email, :role
|
15
|
+
validates_presence_of :password, :if => :password_required
|
16
|
+
validates_presence_of :password_confirmation, :if => :password_required
|
17
|
+
validates_length_of :password, :within => 4..40, :if => :password_required
|
18
|
+
validates_confirmation_of :password, :if => :password_required
|
19
|
+
validates_length_of :email, :within => 3..100
|
20
|
+
validates_uniqueness_of :email, :case_sensitive => false
|
21
|
+
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
22
|
+
validates_format_of :role, :with => /[A-Za-z]/
|
23
|
+
|
24
|
+
# Callbacks
|
25
|
+
before_save :generate_password
|
26
|
+
|
27
|
+
##
|
28
|
+
# This method is for authentication purpose
|
29
|
+
#
|
30
|
+
def self.authenticate(email, password)
|
31
|
+
account = first(:email => email) if email.present?
|
32
|
+
account && account.password_clean == password ? account : nil
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# This method is used for retrive the original password.
|
37
|
+
#
|
38
|
+
def password_clean
|
39
|
+
crypted_password.decrypt(salt)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def generate_password
|
44
|
+
return if password.blank?
|
45
|
+
self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new_record?
|
46
|
+
self.crypted_password = password.encrypt(self.salt)
|
47
|
+
end
|
48
|
+
|
49
|
+
def password_required
|
50
|
+
crypted_password.blank? || !password.blank?
|
51
|
+
end
|
52
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
2
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
3
3
|
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<title><%= options[:name] %></title>
|
6
|
+
<%%= stylesheet_link_tag :base, :override, "themes/<%= options[:theme] %>/style" %>
|
7
7
|
</head>
|
8
8
|
<body>
|
9
9
|
<div id="container">
|
@@ -7,5 +7,5 @@
|
|
7
7
|
<% end %>
|
8
8
|
<div class="group navform wat-cf">
|
9
9
|
<%%= f.submit pat(:save), :class => :button %>
|
10
|
-
<%%= f.submit pat(:cancel), :onclick => "window.location='#{url(
|
10
|
+
<%%= f.submit pat(:cancel), :onclick => "window.location='#{url(:<%= @orm.name_plural %>, :index)}';return false", :class => :button %>
|
11
11
|
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
.block
|
2
|
+
%h3 Simple Block
|
3
|
+
.content
|
4
|
+
%p
|
5
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
6
|
+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
7
|
+
.block
|
8
|
+
%h3 Links
|
9
|
+
%ul.navigation
|
10
|
+
%li=link_to "Link 1"
|
11
|
+
%li=link_to "Link 2"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#block-text.block
|
2
|
+
.content
|
3
|
+
%h2.title Dashboard
|
4
|
+
.inner
|
5
|
+
%p.first
|
6
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
7
|
+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
8
|
+
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
9
|
+
%span.hightlight
|
10
|
+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
11
|
+
%p
|
12
|
+
%span.small
|
13
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
|
14
|
+
%p
|
15
|
+
%span.gray
|
16
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
|
17
|
+
%hr
|
18
|
+
%p
|
19
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
20
|
+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
21
|
+
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
22
|
+
%span.hightlight
|
23
|
+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
24
|
+
|
25
|
+
-content_for :sidebar, partial("base/sidebar")
|
@@ -0,0 +1,31 @@
|
|
1
|
+
!!! Strict
|
2
|
+
%html{:lang => "en", :xmlns => "http://www.w3.org/1999/xhtml"}
|
3
|
+
%head
|
4
|
+
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
|
5
|
+
%title <%= options[:name] %>
|
6
|
+
=stylesheet_link_tag :base, :override, "themes/<%= options[:theme] %>/style"
|
7
|
+
%body
|
8
|
+
#container
|
9
|
+
#header
|
10
|
+
%h1=link_to "<%= options[:name] %>", url(:base_index)
|
11
|
+
#user-navigation
|
12
|
+
%ul.wat-cf
|
13
|
+
%li=link_to pat(:profile), url(:accounts, :edit, :id => current_account.id)
|
14
|
+
%li=link_to pat(:logout), url(:sessions, :destroy), :method => :delete
|
15
|
+
#main-navigation
|
16
|
+
%ul.wat-cf
|
17
|
+
-project_modules.each do |project_module|
|
18
|
+
%li{:class => ("active" if request.path_info =~ /^#{project_module.path}/)}
|
19
|
+
=link_to project_module.human_name, project_module.path("/admin")
|
20
|
+
#wrapper.wat-cf
|
21
|
+
.flash=[:error, :warning, :notice].map { |type| flash_tag(type, :class => "message #{type}") }.join
|
22
|
+
#main
|
23
|
+
=yield
|
24
|
+
#footer
|
25
|
+
.block
|
26
|
+
%p
|
27
|
+
Copyright ©
|
28
|
+
=Time.now.year
|
29
|
+
Your Site - Powered by
|
30
|
+
=link_to "Padrino v.#{Padrino.version}", "http://padrino.github.com", :target => :_blank
|
31
|
+
#sidebar=yield_content :sidebar
|
@@ -0,0 +1,25 @@
|
|
1
|
+
!!! Strict
|
2
|
+
%html{:lang => "en", :xmlns => "http://www.w3.org/1999/xhtml"}
|
3
|
+
%head
|
4
|
+
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
|
5
|
+
%title <%= options[:name] %>
|
6
|
+
=stylesheet_link_tag :base, :override, "themes/<%= options[:theme] %>/style"
|
7
|
+
%body
|
8
|
+
#container
|
9
|
+
#box
|
10
|
+
%h1 <%= options[:name] %>
|
11
|
+
#block-login.block
|
12
|
+
%h2 Login Box
|
13
|
+
.content.login
|
14
|
+
.flash=[:error, :warning, :notice].map { |type| flash_tag(type, :class => "message #{type}") }.join
|
15
|
+
-form_tag(url(:sessions, :create), :class => 'form login') do
|
16
|
+
.group.wat-cf
|
17
|
+
.left
|
18
|
+
%label.label.right Login
|
19
|
+
.right=text_field_tag :email, :value => params[:email], :class => :text_field
|
20
|
+
.group.wat-cf
|
21
|
+
.left
|
22
|
+
%label.label.right Password
|
23
|
+
.right=password_field_tag :password, :value => params[:password], :class => :text_field
|
24
|
+
.group.navform.wat-cf
|
25
|
+
.right=submit_tag('Sign In', :class => :button)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%- @orm.column_fields.each do |column| -%>
|
2
|
+
.group
|
3
|
+
=f.label :<%= column[:name] %>
|
4
|
+
=f.error_message_on :<%= column[:name] %>
|
5
|
+
=f.<%= column[:field_type] %> :<%= column[:name] %>, :class => :<%= column[:field_type] %>
|
6
|
+
%span.description Ex: a simple text
|
7
|
+
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
.group.navform.wat-cf
|
11
|
+
=f.submit pat(:save), :class => :button
|
12
|
+
=f.submit pat(:cancel), :onclick => "window.location='#{url(:<%= @orm.name_plural %>, :index)}';return false", :class => :button
|
@@ -0,0 +1,15 @@
|
|
1
|
+
.block
|
2
|
+
.secondary-navigation
|
3
|
+
%ul.wat-cf
|
4
|
+
%li.first=link_to pat(:list), url(:<%= @orm.name_plural %>, :index)
|
5
|
+
%li=link_to pat(:new), url(:<%= @orm.name_plural %>, :new)
|
6
|
+
%li.active=link_to pat(:edit), url(:<%= @orm.name_plural %>, :edit, :id => @<%= @orm.name_singular %>.id)
|
7
|
+
.content
|
8
|
+
%h2.title
|
9
|
+
=pat(:edit)
|
10
|
+
=mt(:<%= @orm.name_singular %>)
|
11
|
+
.inner
|
12
|
+
-form_for :<%= @orm.name_singular %>, url(:<%= @orm.name_plural %>, :update, :id => @<%= @orm.name_singular %>.id), :method => :put, :class => :form do |f|
|
13
|
+
=partial "<%= @orm.name_plural %>/form", :locals => { :f => f }
|
14
|
+
|
15
|
+
-content_for :sidebar, partial("base/sidebar")
|
@@ -0,0 +1,29 @@
|
|
1
|
+
.block
|
2
|
+
.secondary-navigation
|
3
|
+
%ul.wat-cf
|
4
|
+
%li.first.active=link_to pat(:list), url(:<%= @orm.name_plural %>, :index)
|
5
|
+
%li=link_to pat(:new), url(:<%= @orm.name_plural %>, :new)
|
6
|
+
.content
|
7
|
+
%h2.title
|
8
|
+
=pat(:all)
|
9
|
+
=mt(:<%= @orm.name_singular %>)
|
10
|
+
.inner
|
11
|
+
%table.table
|
12
|
+
%tr
|
13
|
+
<%- @orm.columns.each_with_index do |column, i| -%>
|
14
|
+
%th<%= ".first" if i==0 %>=mat(:<%= @orm.name_singular %>, :<%= column.name %>)
|
15
|
+
<%- end -%>
|
16
|
+
%th.last=" "
|
17
|
+
-@<%= @orm.name_plural %>.each do |<%= @orm.name_singular %>|
|
18
|
+
%tr
|
19
|
+
<%- @orm.columns.each_with_index do |column, i| -%>
|
20
|
+
%td<%= ".first" if i==0 %>=link_to <%= @orm.name_singular %>.<%= column.name %>, url(:<%= @orm.name_plural %>, :edit, :id => <%= @orm.name_singular %>.id)
|
21
|
+
<%- end -%>
|
22
|
+
%td.last
|
23
|
+
=button_to pat(:edit), url(:<%= @orm.name_plural %>, :edit, :id => <%= @orm.name_singular %>.id), :method => :get, :class => :button_to
|
24
|
+
="|"
|
25
|
+
=button_to pat(:delete), url(:<%= @orm.name_plural %>, :destroy, :id => <%= @orm.name_singular %>.id), :method => :delete, :class => :button_to
|
26
|
+
.actions-bar.wat-cf
|
27
|
+
.actions=" "
|
28
|
+
|
29
|
+
-content_for :sidebar, partial("base/sidebar")
|
@@ -0,0 +1,14 @@
|
|
1
|
+
.block
|
2
|
+
.secondary-navigation
|
3
|
+
%ul.wat-cf
|
4
|
+
%li.first=link_to pat(:list), url(:<%= @orm.name_plural %>, :index)
|
5
|
+
%li.active=link_to pat(:new), url(:<%= @orm.name_plural %>, :new)
|
6
|
+
.content
|
7
|
+
%h2.title
|
8
|
+
=pat(:new)
|
9
|
+
=mt(:<%= @orm.name_singular %>)
|
10
|
+
.inner
|
11
|
+
-form_for :<%= @orm.name_singular %>, url(:<%= @orm.name_plural %>, :create), :class => :form do |f|
|
12
|
+
=partial "<%= @orm.name_plural %>/form", :locals => { :f => f }
|
13
|
+
|
14
|
+
-content_for :sidebar, partial("base/sidebar")
|
@@ -94,7 +94,7 @@ module Padrino
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def login_from_session
|
97
|
-
Account.
|
97
|
+
Account.find_by_id(session[options.session_id]) if defined?(Account)
|
98
98
|
end
|
99
99
|
end # AuthenticationHelpers
|
100
100
|
end # Helpers
|
data/padrino-admin.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-admin}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-01}
|
13
13
|
s.description = %q{Admin View for Padrino applications}
|
14
14
|
s.email = %q{padrinorb@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/padrino-admin/generators/orm.rb",
|
31
31
|
"lib/padrino-admin/generators/templates/account/activerecord.rb.tt",
|
32
32
|
"lib/padrino-admin/generators/templates/account/datamapper.rb.tt",
|
33
|
+
"lib/padrino-admin/generators/templates/account/mongoid.rb.tt",
|
34
|
+
"lib/padrino-admin/generators/templates/account/mongomapper.rb.tt",
|
33
35
|
"lib/padrino-admin/generators/templates/account/seeds.rb.tt",
|
34
36
|
"lib/padrino-admin/generators/templates/app/app.rb",
|
35
37
|
"lib/padrino-admin/generators/templates/app/controllers/base.rb",
|
@@ -55,6 +57,14 @@ Gem::Specification.new do |s|
|
|
55
57
|
"lib/padrino-admin/generators/templates/erb/page/edit.erb.tt",
|
56
58
|
"lib/padrino-admin/generators/templates/erb/page/index.erb.tt",
|
57
59
|
"lib/padrino-admin/generators/templates/erb/page/new.erb.tt",
|
60
|
+
"lib/padrino-admin/generators/templates/haml/app/base/_sidebar.haml.tt",
|
61
|
+
"lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt",
|
62
|
+
"lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt",
|
63
|
+
"lib/padrino-admin/generators/templates/haml/app/sessions/new.haml.tt",
|
64
|
+
"lib/padrino-admin/generators/templates/haml/page/_form.haml.tt",
|
65
|
+
"lib/padrino-admin/generators/templates/haml/page/edit.haml.tt",
|
66
|
+
"lib/padrino-admin/generators/templates/haml/page/index.haml.tt",
|
67
|
+
"lib/padrino-admin/generators/templates/haml/page/new.haml.tt",
|
58
68
|
"lib/padrino-admin/generators/templates/page/controller.rb.tt",
|
59
69
|
"lib/padrino-admin/helpers/authentication_helpers.rb",
|
60
70
|
"lib/padrino-admin/helpers/view_helpers.rb",
|
@@ -64,7 +74,6 @@ Gem::Specification.new do |s|
|
|
64
74
|
"lib/padrino-admin/locale/orm/de.yml",
|
65
75
|
"lib/padrino-admin/locale/orm/en.yml",
|
66
76
|
"lib/padrino-admin/locale/orm/it.yml",
|
67
|
-
"lib/padrino-admin/middleware/flash_middleware.rb",
|
68
77
|
"lib/padrino-admin/utils/crypt.rb",
|
69
78
|
"padrino-admin.gemspec",
|
70
79
|
"test/fixtures/data_mapper.rb",
|
@@ -77,7 +86,7 @@ Gem::Specification.new do |s|
|
|
77
86
|
s.rdoc_options = ["--charset=UTF-8"]
|
78
87
|
s.require_paths = ["lib"]
|
79
88
|
s.rubyforge_project = %q{padrino-admin}
|
80
|
-
s.rubygems_version = %q{1.3.
|
89
|
+
s.rubygems_version = %q{1.3.5}
|
81
90
|
s.summary = %q{Admin Dashboard for Padrino}
|
82
91
|
|
83
92
|
if s.respond_to? :specification_version then
|
@@ -85,20 +94,18 @@ Gem::Specification.new do |s|
|
|
85
94
|
s.specification_version = 3
|
86
95
|
|
87
96
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
88
|
-
s.add_runtime_dependency(%q<
|
89
|
-
s.add_runtime_dependency(%q<padrino-
|
90
|
-
s.add_runtime_dependency(%q<padrino-
|
91
|
-
s.add_runtime_dependency(%q<padrino-helpers>, ["= 0.9.1"])
|
97
|
+
s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.2"])
|
98
|
+
s.add_runtime_dependency(%q<padrino-gen>, ["= 0.9.2"])
|
99
|
+
s.add_runtime_dependency(%q<padrino-helpers>, ["= 0.9.2"])
|
92
100
|
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
93
101
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
94
102
|
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
95
103
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
96
104
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
97
105
|
else
|
98
|
-
s.add_dependency(%q<
|
99
|
-
s.add_dependency(%q<padrino-
|
100
|
-
s.add_dependency(%q<padrino-
|
101
|
-
s.add_dependency(%q<padrino-helpers>, ["= 0.9.1"])
|
106
|
+
s.add_dependency(%q<padrino-core>, ["= 0.9.2"])
|
107
|
+
s.add_dependency(%q<padrino-gen>, ["= 0.9.2"])
|
108
|
+
s.add_dependency(%q<padrino-helpers>, ["= 0.9.2"])
|
102
109
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
103
110
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
104
111
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
@@ -106,10 +113,9 @@ Gem::Specification.new do |s|
|
|
106
113
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
107
114
|
end
|
108
115
|
else
|
109
|
-
s.add_dependency(%q<
|
110
|
-
s.add_dependency(%q<padrino-
|
111
|
-
s.add_dependency(%q<padrino-
|
112
|
-
s.add_dependency(%q<padrino-helpers>, ["= 0.9.1"])
|
116
|
+
s.add_dependency(%q<padrino-core>, ["= 0.9.2"])
|
117
|
+
s.add_dependency(%q<padrino-gen>, ["= 0.9.2"])
|
118
|
+
s.add_dependency(%q<padrino-helpers>, ["= 0.9.2"])
|
113
119
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
114
120
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
115
121
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
@@ -53,6 +53,13 @@ class Account
|
|
53
53
|
account && account.password_clean == password ? account : nil
|
54
54
|
end
|
55
55
|
|
56
|
+
##
|
57
|
+
# This method is used from AuthenticationHelper
|
58
|
+
#
|
59
|
+
def self.find_by_id(id)
|
60
|
+
get(id)
|
61
|
+
end
|
62
|
+
|
56
63
|
##
|
57
64
|
# This method it's used for retrive the original password.
|
58
65
|
#
|
@@ -35,7 +35,7 @@ class TestAdminAppGenerator < Test::Unit::TestCase
|
|
35
35
|
assert_raise(SystemExit) { silence_logger { @admin.start(['-r=/tmp/sample_project', '--theme=foo']) } }
|
36
36
|
end
|
37
37
|
|
38
|
-
should 'correctyl generate a new padrino admin application' do
|
38
|
+
should 'correctyl generate a new padrino admin application with default renderer' do
|
39
39
|
assert_nothing_raised { silence_logger { @project.start(['sample_project', '--root=/tmp', '-d=activerecord']) } }
|
40
40
|
assert_nothing_raised { silence_logger { @admin.start(['--root=/tmp/sample_project']) } }
|
41
41
|
assert_file_exists('/tmp/sample_project')
|
@@ -46,6 +46,36 @@ class TestAdminAppGenerator < Test::Unit::TestCase
|
|
46
46
|
assert_file_exists('/tmp/sample_project/admin/controllers/base.rb')
|
47
47
|
assert_file_exists('/tmp/sample_project/admin/controllers/sessions.rb')
|
48
48
|
assert_file_exists('/tmp/sample_project/admin/views')
|
49
|
+
assert_file_exists('/tmp/sample_project/admin/views/accounts/_form.haml')
|
50
|
+
assert_file_exists('/tmp/sample_project/admin/views/accounts/edit.haml')
|
51
|
+
assert_file_exists('/tmp/sample_project/admin/views/accounts/index.haml')
|
52
|
+
assert_file_exists('/tmp/sample_project/admin/views/accounts/new.haml')
|
53
|
+
assert_file_exists('/tmp/sample_project/admin/views/base/index.haml')
|
54
|
+
assert_file_exists('/tmp/sample_project/admin/views/sessions/new.haml')
|
55
|
+
assert_file_exists('/tmp/sample_project/admin/views/base/_sidebar.haml')
|
56
|
+
assert_file_exists('/tmp/sample_project/admin/views/base/index.haml')
|
57
|
+
assert_file_exists('/tmp/sample_project/admin/views/layouts/application.haml')
|
58
|
+
assert_file_exists('/tmp/sample_project/admin/views/sessions/new.haml')
|
59
|
+
assert_file_exists('/tmp/sample_project/public/admin')
|
60
|
+
assert_file_exists('/tmp/sample_project/public/admin/stylesheets')
|
61
|
+
assert_file_exists('/tmp/sample_project/app/models/account.rb')
|
62
|
+
assert_file_exists('/tmp/sample_project/db/seeds.rb')
|
63
|
+
assert_match_in_file 'Padrino.mount("Admin").to("/admin")', '/tmp/sample_project/config/apps.rb'
|
64
|
+
assert_match_in_file 'class Admin < Padrino::Application', '/tmp/sample_project/admin/app.rb'
|
65
|
+
assert_match_in_file 'role.project_module :accounts, "/accounts"', '/tmp/sample_project/admin/app.rb'
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'correctyl generate a new padrino admin application with erb renderer' do
|
69
|
+
assert_nothing_raised { silence_logger { @project.start(['sample_project', '--root=/tmp', '-d=activerecord', '-e=erb']) } }
|
70
|
+
assert_nothing_raised { silence_logger { @admin.start(['--root=/tmp/sample_project']) } }
|
71
|
+
assert_file_exists('/tmp/sample_project')
|
72
|
+
assert_file_exists('/tmp/sample_project/admin')
|
73
|
+
assert_file_exists('/tmp/sample_project/admin/app.rb')
|
74
|
+
assert_file_exists('/tmp/sample_project/admin/controllers')
|
75
|
+
assert_file_exists('/tmp/sample_project/admin/controllers/accounts.rb')
|
76
|
+
assert_file_exists('/tmp/sample_project/admin/controllers/base.rb')
|
77
|
+
assert_file_exists('/tmp/sample_project/admin/controllers/sessions.rb')
|
78
|
+
assert_file_exists('/tmp/sample_project/admin/views')
|
49
79
|
assert_file_exists('/tmp/sample_project/admin/views/accounts/_form.erb')
|
50
80
|
assert_file_exists('/tmp/sample_project/admin/views/accounts/edit.erb')
|
51
81
|
assert_file_exists('/tmp/sample_project/admin/views/accounts/index.erb')
|
@@ -34,13 +34,31 @@ class TestAdminPageGenerator < Test::Unit::TestCase
|
|
34
34
|
assert_raise(Padrino::Admin::Generators::OrmError) { @page.start(['foo', '-r=/tmp/sample_project']) }
|
35
35
|
end
|
36
36
|
|
37
|
-
should 'correctyl generate a new padrino admin application' do
|
37
|
+
should 'correctyl generate a new padrino admin application default renderer' do
|
38
38
|
'Person'.classify.constantize
|
39
39
|
silence_logger { @project.start(['sample_project', '--root=/tmp', '-d=datamapper']) }
|
40
40
|
silence_logger { @admin.start(['--root=/tmp/sample_project']) }
|
41
41
|
silence_logger { @model.start(['person', "name:string", "age:integer", "email:string", '-root=/tmp/sample_project']) }
|
42
42
|
silence_logger { @page.start(['person', '--root=/tmp/sample_project']) }
|
43
43
|
assert_file_exists '/tmp/sample_project/admin/controllers/people.rb'
|
44
|
+
assert_file_exists '/tmp/sample_project/admin/views/people/_form.haml'
|
45
|
+
assert_file_exists '/tmp/sample_project/admin/views/people/edit.haml'
|
46
|
+
assert_file_exists '/tmp/sample_project/admin/views/people/index.haml'
|
47
|
+
assert_file_exists '/tmp/sample_project/admin/views/people/new.haml'
|
48
|
+
%w(name age email).each do |field|
|
49
|
+
assert_match_in_file "label :#{field}", '/tmp/sample_project/admin/views/people/_form.haml'
|
50
|
+
assert_match_in_file "text_field :#{field}", '/tmp/sample_project/admin/views/people/_form.haml'
|
51
|
+
end
|
52
|
+
assert_match_in_file 'role.project_module :people, "/people"', '/tmp/sample_project/admin/app.rb'
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'correctyl generate a new padrino admin application with erb renderer' do
|
56
|
+
'Person'.classify.constantize
|
57
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '-d=datamapper', '-e=erb']) }
|
58
|
+
silence_logger { @admin.start(['--root=/tmp/sample_project']) }
|
59
|
+
silence_logger { @model.start(['person', "name:string", "age:integer", "email:string", '-root=/tmp/sample_project']) }
|
60
|
+
silence_logger { @page.start(['person', '--root=/tmp/sample_project']) }
|
61
|
+
assert_file_exists '/tmp/sample_project/admin/controllers/people.rb'
|
44
62
|
assert_file_exists '/tmp/sample_project/admin/views/people/_form.erb'
|
45
63
|
assert_file_exists '/tmp/sample_project/admin/views/people/edit.erb'
|
46
64
|
assert_file_exists '/tmp/sample_project/admin/views/people/index.erb'
|
data/test/helper.rb
CHANGED
@@ -246,28 +246,4 @@ class TestAdminApplication < Test::Unit::TestCase
|
|
246
246
|
get "/modules"
|
247
247
|
assert_equal "admin => /admin", body
|
248
248
|
end
|
249
|
-
|
250
|
-
should 'use correclty flash middleware' do
|
251
|
-
mock_app do
|
252
|
-
use Padrino::Admin::Middleware::FlashMiddleware, :session_id
|
253
|
-
|
254
|
-
get "/set_session_id" do
|
255
|
-
params[:session_id]
|
256
|
-
end
|
257
|
-
|
258
|
-
get "/get_session_id" do
|
259
|
-
session[:session_id]
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
get "/set_session_id", { :session_id => 24 }, 'HTTP_USER_AGENT' => 'Adobe Flash'
|
264
|
-
assert_equal "24", body
|
265
|
-
|
266
|
-
# TODO: inspect why this fail on Ruby 1.9.1
|
267
|
-
unless RUBY_VERSION >= '1.9'
|
268
|
-
get "/get_session_id"
|
269
|
-
assert_equal "24", body
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
249
|
end
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 9
|
8
|
-
- 1
|
9
|
-
version: 0.9.1
|
4
|
+
version: 0.9.2
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Padrino Team
|
@@ -17,133 +12,89 @@ autorequire:
|
|
17
12
|
bindir: bin
|
18
13
|
cert_chain: []
|
19
14
|
|
20
|
-
date: 2010-
|
15
|
+
date: 2010-03-01 00:00:00 +01:00
|
21
16
|
default_executable:
|
22
17
|
dependencies:
|
23
|
-
- !ruby/object:Gem::Dependency
|
24
|
-
name: json_pure
|
25
|
-
prerelease: false
|
26
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
-
requirements:
|
28
|
-
- - ">="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 2
|
33
|
-
- 0
|
34
|
-
version: 1.2.0
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
18
|
- !ruby/object:Gem::Dependency
|
38
19
|
name: padrino-core
|
39
|
-
|
40
|
-
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
23
|
requirements:
|
42
24
|
- - "="
|
43
25
|
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
|
46
|
-
- 9
|
47
|
-
- 1
|
48
|
-
version: 0.9.1
|
49
|
-
type: :runtime
|
50
|
-
version_requirements: *id002
|
26
|
+
version: 0.9.2
|
27
|
+
version:
|
51
28
|
- !ruby/object:Gem::Dependency
|
52
29
|
name: padrino-gen
|
53
|
-
|
54
|
-
|
30
|
+
type: :runtime
|
31
|
+
version_requirement:
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
33
|
requirements:
|
56
34
|
- - "="
|
57
35
|
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
- 9
|
61
|
-
- 1
|
62
|
-
version: 0.9.1
|
63
|
-
type: :runtime
|
64
|
-
version_requirements: *id003
|
36
|
+
version: 0.9.2
|
37
|
+
version:
|
65
38
|
- !ruby/object:Gem::Dependency
|
66
39
|
name: padrino-helpers
|
67
|
-
|
68
|
-
|
40
|
+
type: :runtime
|
41
|
+
version_requirement:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
43
|
requirements:
|
70
44
|
- - "="
|
71
45
|
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
|
74
|
-
- 9
|
75
|
-
- 1
|
76
|
-
version: 0.9.1
|
77
|
-
type: :runtime
|
78
|
-
version_requirements: *id004
|
46
|
+
version: 0.9.2
|
47
|
+
version:
|
79
48
|
- !ruby/object:Gem::Dependency
|
80
49
|
name: haml
|
81
|
-
|
82
|
-
|
50
|
+
type: :development
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
53
|
requirements:
|
84
54
|
- - ">="
|
85
55
|
- !ruby/object:Gem::Version
|
86
|
-
segments:
|
87
|
-
- 2
|
88
|
-
- 2
|
89
|
-
- 1
|
90
56
|
version: 2.2.1
|
91
|
-
|
92
|
-
version_requirements: *id005
|
57
|
+
version:
|
93
58
|
- !ruby/object:Gem::Dependency
|
94
59
|
name: shoulda
|
95
|
-
|
96
|
-
|
60
|
+
type: :development
|
61
|
+
version_requirement:
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
63
|
requirements:
|
98
64
|
- - ">="
|
99
65
|
- !ruby/object:Gem::Version
|
100
|
-
segments:
|
101
|
-
- 0
|
102
66
|
version: "0"
|
103
|
-
|
104
|
-
version_requirements: *id006
|
67
|
+
version:
|
105
68
|
- !ruby/object:Gem::Dependency
|
106
69
|
name: mocha
|
107
|
-
|
108
|
-
|
70
|
+
type: :development
|
71
|
+
version_requirement:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
73
|
requirements:
|
110
74
|
- - ">="
|
111
75
|
- !ruby/object:Gem::Version
|
112
|
-
segments:
|
113
|
-
- 0
|
114
|
-
- 9
|
115
|
-
- 7
|
116
76
|
version: 0.9.7
|
117
|
-
|
118
|
-
version_requirements: *id007
|
77
|
+
version:
|
119
78
|
- !ruby/object:Gem::Dependency
|
120
79
|
name: rack-test
|
121
|
-
|
122
|
-
|
80
|
+
type: :development
|
81
|
+
version_requirement:
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
83
|
requirements:
|
124
84
|
- - ">="
|
125
85
|
- !ruby/object:Gem::Version
|
126
|
-
segments:
|
127
|
-
- 0
|
128
|
-
- 5
|
129
|
-
- 0
|
130
86
|
version: 0.5.0
|
131
|
-
|
132
|
-
version_requirements: *id008
|
87
|
+
version:
|
133
88
|
- !ruby/object:Gem::Dependency
|
134
89
|
name: webrat
|
135
|
-
|
136
|
-
|
90
|
+
type: :development
|
91
|
+
version_requirement:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
93
|
requirements:
|
138
94
|
- - ">="
|
139
95
|
- !ruby/object:Gem::Version
|
140
|
-
segments:
|
141
|
-
- 0
|
142
|
-
- 5
|
143
|
-
- 1
|
144
96
|
version: 0.5.1
|
145
|
-
|
146
|
-
version_requirements: *id009
|
97
|
+
version:
|
147
98
|
description: Admin View for Padrino applications
|
148
99
|
email: padrinorb@gmail.com
|
149
100
|
executables: []
|
@@ -167,6 +118,8 @@ files:
|
|
167
118
|
- lib/padrino-admin/generators/orm.rb
|
168
119
|
- lib/padrino-admin/generators/templates/account/activerecord.rb.tt
|
169
120
|
- lib/padrino-admin/generators/templates/account/datamapper.rb.tt
|
121
|
+
- lib/padrino-admin/generators/templates/account/mongoid.rb.tt
|
122
|
+
- lib/padrino-admin/generators/templates/account/mongomapper.rb.tt
|
170
123
|
- lib/padrino-admin/generators/templates/account/seeds.rb.tt
|
171
124
|
- lib/padrino-admin/generators/templates/app/app.rb
|
172
125
|
- lib/padrino-admin/generators/templates/app/controllers/base.rb
|
@@ -192,6 +145,14 @@ files:
|
|
192
145
|
- lib/padrino-admin/generators/templates/erb/page/edit.erb.tt
|
193
146
|
- lib/padrino-admin/generators/templates/erb/page/index.erb.tt
|
194
147
|
- lib/padrino-admin/generators/templates/erb/page/new.erb.tt
|
148
|
+
- lib/padrino-admin/generators/templates/haml/app/base/_sidebar.haml.tt
|
149
|
+
- lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt
|
150
|
+
- lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt
|
151
|
+
- lib/padrino-admin/generators/templates/haml/app/sessions/new.haml.tt
|
152
|
+
- lib/padrino-admin/generators/templates/haml/page/_form.haml.tt
|
153
|
+
- lib/padrino-admin/generators/templates/haml/page/edit.haml.tt
|
154
|
+
- lib/padrino-admin/generators/templates/haml/page/index.haml.tt
|
155
|
+
- lib/padrino-admin/generators/templates/haml/page/new.haml.tt
|
195
156
|
- lib/padrino-admin/generators/templates/page/controller.rb.tt
|
196
157
|
- lib/padrino-admin/helpers/authentication_helpers.rb
|
197
158
|
- lib/padrino-admin/helpers/view_helpers.rb
|
@@ -201,7 +162,6 @@ files:
|
|
201
162
|
- lib/padrino-admin/locale/orm/de.yml
|
202
163
|
- lib/padrino-admin/locale/orm/en.yml
|
203
164
|
- lib/padrino-admin/locale/orm/it.yml
|
204
|
-
- lib/padrino-admin/middleware/flash_middleware.rb
|
205
165
|
- lib/padrino-admin/utils/crypt.rb
|
206
166
|
- padrino-admin.gemspec
|
207
167
|
- test/fixtures/data_mapper.rb
|
@@ -222,20 +182,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
222
182
|
requirements:
|
223
183
|
- - ">="
|
224
184
|
- !ruby/object:Gem::Version
|
225
|
-
segments:
|
226
|
-
- 0
|
227
185
|
version: "0"
|
186
|
+
version:
|
228
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
188
|
requirements:
|
230
189
|
- - ">="
|
231
190
|
- !ruby/object:Gem::Version
|
232
|
-
segments:
|
233
|
-
- 0
|
234
191
|
version: "0"
|
192
|
+
version:
|
235
193
|
requirements: []
|
236
194
|
|
237
195
|
rubyforge_project: padrino-admin
|
238
|
-
rubygems_version: 1.3.
|
196
|
+
rubygems_version: 1.3.5
|
239
197
|
signing_key:
|
240
198
|
specification_version: 3
|
241
199
|
summary: Admin Dashboard for Padrino
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'rack/utils'
|
2
|
-
|
3
|
-
module Padrino
|
4
|
-
module Admin
|
5
|
-
module Middleware
|
6
|
-
##
|
7
|
-
# FlashMiddleware help you passing your session in the URI, when it should be in the cookie.
|
8
|
-
#
|
9
|
-
# This code it's only performed when:
|
10
|
-
#
|
11
|
-
# env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
|
12
|
-
#
|
13
|
-
class FlashMiddleware
|
14
|
-
def initialize(app, session_key = 'session_id')
|
15
|
-
@app = app
|
16
|
-
@session_key = session_key.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
def call(env)
|
20
|
-
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
|
21
|
-
params = ::Rack::Request.new(env).params
|
22
|
-
env['rack.session'] ||= {}
|
23
|
-
env['rack.session'][@session_key.to_sym] = params[@session_key] if params[@session_key].present?
|
24
|
-
end
|
25
|
-
@app.call(env)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|