gemboree 0.1.2
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 +59 -0
- data/Rakefile +38 -0
- data/app/assets/images/glyphicons-halflings-white.png +0 -0
- data/app/assets/images/glyphicons-halflings.png +0 -0
- data/app/assets/javascripts/bootstrap.js +2027 -0
- data/app/assets/javascripts/gemboree.js +2 -0
- data/app/assets/javascripts/scaffolds.js +20 -0
- data/app/assets/stylesheets/bootstrap-responsive.css +1092 -0
- data/app/assets/stylesheets/bootstrap.css +6039 -0
- data/app/assets/stylesheets/gemboree-nores.css +4 -0
- data/app/assets/stylesheets/gemboree.css +6 -0
- data/app/assets/stylesheets/navspace.css +4 -0
- data/app/assets/stylesheets/scaffolds.css +2 -0
- data/app/helpers/nav_helper.rb +7 -0
- data/app/helpers/sortable_helper.rb +10 -0
- data/app/models/role.rb +14 -0
- data/app/models/user_role.rb +11 -0
- data/app/views/layouts/_error_messages.html.erb +20 -0
- data/app/views/layouts/_errors.html.erb +11 -0
- data/config/routes.rb +3 -0
- data/lib/gemboree.rb +22 -0
- data/lib/gemboree/acts_as_actor.rb +47 -0
- data/lib/gemboree/version.rb +3 -0
- data/lib/generators/gemboree/devise_generator.rb +13 -0
- data/lib/generators/gemboree/install_generator.rb +46 -0
- data/lib/generators/gemboree/migration_generator.rb +25 -0
- data/lib/templates/devise/passwords/new.html.erb +27 -0
- data/lib/templates/devise/registrations/edit.html.erb +65 -0
- data/lib/templates/devise/registrations/new.html.erb +45 -0
- data/lib/templates/devise/sessions/new.html.erb +41 -0
- data/lib/templates/erb/scaffold/_form.html.erb +19 -0
- data/lib/templates/erb/scaffold/edit.html.erb +22 -0
- data/lib/templates/erb/scaffold/index.html.erb +31 -0
- data/lib/templates/erb/scaffold/new.html.erb +11 -0
- data/lib/templates/erb/scaffold/show.html.erb +22 -0
- data/lib/templates/gemboree/install/ability.rb +7 -0
- data/lib/templates/gemboree/install/application.html.erb +19 -0
- data/lib/templates/gemboree/install/home_controller.rb +6 -0
- data/lib/templates/gemboree/install/index.html.erb +5 -0
- data/lib/templates/gemboree/install/nav.html.erb +38 -0
- data/lib/templates/gemboree/install/users_controller.rb +7 -0
- data/lib/templates/migration/migration.rb +19 -0
- data/lib/templates/rails/scaffold_controller/controller.rb +81 -0
- data/test/gemboree_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +195 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
module SortableHelper
|
2
|
+
|
3
|
+
def sortable(column, title = nil)
|
4
|
+
title ||= column.titleize
|
5
|
+
css_class = column == sort_column ? "current #{sort_direction}" : nil
|
6
|
+
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
|
7
|
+
link_to title, {:sort => column, :direction => direction}, {:class => css_class}
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
data/app/models/role.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class Role < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessible :name, :access_level
|
4
|
+
|
5
|
+
has_many :user_roles, :dependent => :destroy
|
6
|
+
has_many :users, :through => :user_roles
|
7
|
+
|
8
|
+
validates :name,
|
9
|
+
:presence => true,
|
10
|
+
:uniqueness => true
|
11
|
+
|
12
|
+
validates :access_level, :presence => true
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<% if notice %>
|
2
|
+
<div class="alert alert-success">
|
3
|
+
<button type="button" class="close" data-dismiss="alert">x</button>
|
4
|
+
<strong><%= notice %></strong>
|
5
|
+
</div>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<% if alert %>
|
9
|
+
<div class="alert alert-alert">
|
10
|
+
<button type="button" class="close" data-dismiss="alert">x</button>
|
11
|
+
<strong><%= alert %></strong>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<% if flash[:error] %>
|
16
|
+
<div class="alert alert-error">
|
17
|
+
<button type="button" class="close" data-dismiss="alert">x</button>
|
18
|
+
<strong><%= flash[:error] %></strong>
|
19
|
+
</div>
|
20
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% if target.errors.any? %>
|
2
|
+
<div id="errorExplanation">
|
3
|
+
<h2><%= pluralize(target.errors.count, "Error") %> prohibited this form from submission:</h2>
|
4
|
+
<ul class="errors_explained">
|
5
|
+
<% target.errors.full_messages.each do |message| %>
|
6
|
+
<li><%= message %></li>
|
7
|
+
<% end %>
|
8
|
+
</ul>
|
9
|
+
</div>
|
10
|
+
<br class="clear"/>
|
11
|
+
<% end %>
|
data/config/routes.rb
ADDED
data/lib/gemboree.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'devise'
|
2
|
+
require 'cancan'
|
3
|
+
require 'will_paginate'
|
4
|
+
require 'gemboree/version'
|
5
|
+
require 'gemboree/acts_as_actor'
|
6
|
+
require 'paperclip'
|
7
|
+
|
8
|
+
module Gemboree
|
9
|
+
|
10
|
+
class Engine < Rails::Engine
|
11
|
+
|
12
|
+
initializer 'acts_as_actor.ar_extensions' do |app|
|
13
|
+
ActiveRecord::Base.extend Gemboree::ActsAsActor
|
14
|
+
end
|
15
|
+
|
16
|
+
config.app_generators do |g|
|
17
|
+
g.templates.unshift File::expand_path('../templates', __FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Gemboree
|
2
|
+
module ActsAsActor
|
3
|
+
|
4
|
+
def acts_as_actor(options = {})
|
5
|
+
has_many :user_roles, :foreign_key => "user_id", :dependent => :destroy
|
6
|
+
has_many :roles, :through => :user_roles
|
7
|
+
include InstanceMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
|
12
|
+
def role_name
|
13
|
+
roles.order('access_level desc').first.try(:name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def access_level
|
17
|
+
roles.first.nil? ? 0 : roles.order('access_level desc').first.access_level
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_access?(level)
|
21
|
+
access_level >= level
|
22
|
+
end
|
23
|
+
|
24
|
+
def has_role?(name)
|
25
|
+
roles.find_by_name(name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_role(name)
|
29
|
+
return false if has_role?(name)
|
30
|
+
role = Role.find_by_name(name)
|
31
|
+
role ? roles << role : false
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove_role(name)
|
35
|
+
role = has_role?(name)
|
36
|
+
role ? UserRole.where(user_id: id, role_id: role.id).first.delete : false
|
37
|
+
end
|
38
|
+
|
39
|
+
def change_role(name)
|
40
|
+
roles.clear
|
41
|
+
add_role(name)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Gemboree
|
2
|
+
module Generators
|
3
|
+
class DeviseGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path("../../../templates/devise/", __FILE__)
|
6
|
+
|
7
|
+
def copy_views
|
8
|
+
copy_file "registrations/new.html.erb", "app/views/devise/registrations/new.html.erb"
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Gemboree
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
def setup_home_page
|
6
|
+
remove_file "public/index.html"
|
7
|
+
remove_file "app/assets/images/rails.png"
|
8
|
+
remove_file "app/views/layouts/application.html.erb"
|
9
|
+
copy_file "home_controller.rb", "app/controllers/home_controller.rb"
|
10
|
+
copy_file "index.html.erb", "app/views/home/index.html.erb"
|
11
|
+
copy_file "nav.html.erb", "app/views/layouts/_nav.html.erb"
|
12
|
+
copy_file "application.html.erb", "app/views/layouts/application.html.erb"
|
13
|
+
route "root :to => 'home#index'"
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup_asssets
|
17
|
+
insert_into_file "app/assets/javascripts/application.js", :after => "jquery_ujs\n" do
|
18
|
+
"//= require gemboree\n"
|
19
|
+
end
|
20
|
+
insert_into_file "app/assets/stylesheets/application.css", :after => "require_self\n" do
|
21
|
+
" *= require gemboree\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_devise
|
26
|
+
generate "devise:install"
|
27
|
+
generate "devise", "User"
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup_cancan
|
31
|
+
copy_file "ability.rb", "app/models/ability.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_roles
|
35
|
+
generate "gemboree:migration"
|
36
|
+
insert_into_file "app/models/user.rb", :after => "ActiveRecord::Base\n" do
|
37
|
+
%{ acts_as_actor
|
38
|
+
has_many :user_roles, :dependent => :destroy
|
39
|
+
has_many :roles, :through => :user_roles
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Gemboree
|
2
|
+
module Generators
|
3
|
+
class MigrationGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
source_root File.expand_path("../../../templates/migration/", __FILE__)
|
8
|
+
|
9
|
+
def self.next_migration_number(dirname)
|
10
|
+
if ActiveRecord::Base.timestamped_migrations
|
11
|
+
migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
12
|
+
migration_number += 1
|
13
|
+
migration_number.to_s
|
14
|
+
else
|
15
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_migration
|
20
|
+
migration_template "migration.rb", "db/migrate/acts_as_actor"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<h2>Forgot your password?</h2>
|
2
|
+
|
3
|
+
<div class="row-fluid">
|
4
|
+
<div class="span6">
|
5
|
+
|
6
|
+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name),
|
7
|
+
:html => { :method => :post, class: 'form-horizontal well' }) do |f| %>
|
8
|
+
|
9
|
+
<%= devise_error_messages! %>
|
10
|
+
|
11
|
+
<div class="control-group">
|
12
|
+
<%= f.label :email, class: 'control-label' %>
|
13
|
+
<div class="controls">
|
14
|
+
<%= f.email_field :email %>
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="form-actions">
|
19
|
+
<%= f.submit "Send me reset password instructions", class: 'btn btn-warning' %>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<%= render "devise/shared/links" %>
|
26
|
+
|
27
|
+
</div><!--/.row-fluid -->
|
@@ -0,0 +1,65 @@
|
|
1
|
+
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
2
|
+
|
3
|
+
<div class="row-fluid">
|
4
|
+
<div class="span6">
|
5
|
+
|
6
|
+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name),
|
7
|
+
:html => { :method => :put, class: 'form-horizontal well' }) do |f| %>
|
8
|
+
|
9
|
+
<%= devise_error_messages! %>
|
10
|
+
|
11
|
+
<div class="control-group">
|
12
|
+
<%= f.label :first_name, class: 'control-label' %>
|
13
|
+
<div class="controls">
|
14
|
+
<%= f.text_field :first_name %>
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="control-group">
|
19
|
+
<%= f.label :last_name, class: 'control-label' %>
|
20
|
+
<div class="controls">
|
21
|
+
<%= f.text_field :last_name %>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div class="control-group">
|
26
|
+
<%= f.label :email, class: 'control-label' %>
|
27
|
+
<div class="controls">
|
28
|
+
<%= f.email_field :email %>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<div class="control-group">
|
33
|
+
<%= f.label :password, class: 'control-label' %>
|
34
|
+
<div class="controls">
|
35
|
+
<%= f.password_field :password, :autocomplete => "off" %><br />
|
36
|
+
<i>(leave blank if you don't want to change it)</i>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<div class="control-group">
|
41
|
+
<%= f.label :password_confirmation, class: 'control-label' %>
|
42
|
+
<div class="controls">
|
43
|
+
<%= f.password_field :password_confirmation %>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<div class="control-group">
|
48
|
+
<%= f.label :current_password, class: 'control-label' %>
|
49
|
+
<div class="controls">
|
50
|
+
<%= f.password_field :current_password %><br />
|
51
|
+
<i>(we need your current password to confirm your changes)</i>
|
52
|
+
</div>
|
53
|
+
</div>
|
54
|
+
|
55
|
+
<div class="form-actions btn-group">
|
56
|
+
<%= link_to "Back", :back, class: 'btn' %>
|
57
|
+
<%= f.submit "Update", class: 'btn btn-success' %>
|
58
|
+
<%= link_to "Cancel my account", registration_path(resource_name),
|
59
|
+
:data => { :confirm => "Are you sure?" }, :method => :delete, class: 'btn btn-danger' %>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<% end %>
|
63
|
+
</div>
|
64
|
+
|
65
|
+
</div><!--/.row-fluid -->
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<div class="row-fluid">
|
2
|
+
<legend>Sign Up</legend>
|
3
|
+
<div class="span6">
|
4
|
+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name),
|
5
|
+
:html => { class: 'form-horizontal well' }) do |f| %>
|
6
|
+
|
7
|
+
<%= devise_error_messages! %>
|
8
|
+
|
9
|
+
<div class="control-group">
|
10
|
+
<%= f.label :email, class: 'control-label' %>
|
11
|
+
<div class="controls">
|
12
|
+
<%= f.email_field :email %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="control-group">
|
17
|
+
<%= f.label :password, class: 'control-label' %>
|
18
|
+
<div class="controls">
|
19
|
+
<%= f.password_field :password %>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div class="control-group">
|
24
|
+
<%= f.label :password_confirmation, class: 'control-label' %>
|
25
|
+
<div class="controls">
|
26
|
+
<%= f.password_field :password_confirmation %>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class="form-actions">
|
31
|
+
<%= f.submit "Sign up", class: 'btn' %>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<% end %>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div class="span4">
|
38
|
+
<div class="well sidebar-nav">
|
39
|
+
<ul class="nav nav-list">
|
40
|
+
<%= render "devise/shared/links" %>
|
41
|
+
</ul>
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
</div><!--./row-fluid>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<h2>Sign in</h2>
|
2
|
+
|
3
|
+
<div class="row-fluid">
|
4
|
+
<div class="span6">
|
5
|
+
|
6
|
+
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name),
|
7
|
+
:html => { class: 'form-horizontal well' }) do |f| %>
|
8
|
+
|
9
|
+
<div class="control-group">
|
10
|
+
<%= f.label :email, class: 'control-label' %>
|
11
|
+
<div class="controls">
|
12
|
+
<%= f.email_field :email %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="control-group">
|
17
|
+
<%= f.label :password, class: 'control-label' %>
|
18
|
+
<div class="controls">
|
19
|
+
<%= f.password_field :password %>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<% if devise_mapping.rememberable? -%>
|
24
|
+
<div class="control-group">
|
25
|
+
<%= f.label :remember_me, class: 'control-label' %>
|
26
|
+
<div class="controls">
|
27
|
+
<%= f.check_box :remember_me %>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
<% end -%>
|
31
|
+
|
32
|
+
<div class="form-actions">
|
33
|
+
<%= f.submit "Sign in", class: 'btn btn-primary' %>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<% end %>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<%= render "devise/shared/links" %>
|
40
|
+
|
41
|
+
</div><!--/.row-fluid -->
|