lazy-head-gen 0.3.4 → 0.4.0
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.md +0 -52
- data/VERSION +1 -1
- data/lazy-head-gen.gemspec +1 -35
- data/lib/lazy-head-gen.rb +1 -1
- data/lib/lazy-head-gen/templates/admin_controller_test/admin_controller_test.rb.tt +0 -1
- metadata +3 -37
- data/lib/lazy-head-gen/bootstrapped_admin_app.rb +0 -119
- data/lib/lazy-head-gen/bootstrapped_admin_page.rb +0 -58
- data/lib/lazy-head-gen/templates/admin_app/account/activerecord.rb.tt +0 -38
- data/lib/lazy-head-gen/templates/admin_app/account/seeds.rb.tt +0 -28
- data/lib/lazy-head-gen/templates/admin_app/app.rb.tt +0 -36
- data/lib/lazy-head-gen/templates/admin_app/app/controllers/base.rb +0 -6
- data/lib/lazy-head-gen/templates/admin_app/app/controllers/sessions.rb.tt +0 -26
- data/lib/lazy-head-gen/templates/admin_app/app/helpers/application_helper.rb +0 -23
- data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.css +0 -815
- data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.min.css +0 -9
- data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.css +0 -4983
- data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.min.css +0 -9
- data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-114-precomposed.png +0 -0
- data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-144-precomposed.png +0 -0
- data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-57-precomposed.png +0 -0
- data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-72-precomposed.png +0 -0
- data/lib/lazy-head-gen/templates/admin_app/assets/ico/favicon.ico +0 -0
- data/lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings-white.png +0 -0
- data/lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings.png +0 -0
- data/lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.js +0 -1825
- data/lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.min.js +0 -6
- data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery-min.js +0 -4
- data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery-ujs.js +0 -92
- data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery.js +0 -9404
- data/lib/lazy-head-gen/templates/admin_app/erb/app/base/index.erb.tt +0 -16
- data/lib/lazy-head-gen/templates/admin_app/erb/app/layouts/application.erb.tt +0 -79
- data/lib/lazy-head-gen/templates/admin_app/erb/app/sessions/new.erb.tt +0 -98
- data/lib/lazy-head-gen/templates/admin_app/erb/page/_form.erb.tt +0 -16
- data/lib/lazy-head-gen/templates/admin_app/erb/page/edit.erb.tt +0 -26
- data/lib/lazy-head-gen/templates/admin_app/erb/page/index.erb.tt +0 -41
- data/lib/lazy-head-gen/templates/admin_app/erb/page/new.erb.tt +0 -23
- data/lib/lazy-head-gen/templates/admin_app/page/controller.rb.tt +0 -47
- data/test/lazy-head-gen/test_bootstrapped_admin_app_generator.rb +0 -211
- data/test/lazy-head-gen/test_bootstrapped_admin_page_generator.rb +0 -94
data/README.md
CHANGED
@@ -23,58 +23,6 @@ Also you will need to add this gem for both :development and :test groups. There
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
### Bootstrapped Admin Generator
|
27
|
-
|
28
|
-
Generates a new Padrino Admin application with Twitter Bootstrapped integrated.
|
29
|
-
|
30
|
-
**Usage:**
|
31
|
-
|
32
|
-
```
|
33
|
-
padrino g bootstrapped_admin
|
34
|
-
```
|
35
|
-
|
36
|
-
**Options:**
|
37
|
-
|
38
|
-
-r, [--root=ROOT] The root destination. Default: .
|
39
|
-
|
40
|
-
-s, [--skip-migration]
|
41
|
-
|
42
|
-
-d, [--destroy]
|
43
|
-
|
44
|
-
-m, [--admin-model=ADMIN_MODEL] The name of model for access controlling. Default: Account
|
45
|
-
|
46
|
-
-a, [--app=APP] The model destination path. Default: .
|
47
|
-
|
48
|
-
**Example:**
|
49
|
-
|
50
|
-
```
|
51
|
-
padrino g bootstrapped_admin
|
52
|
-
```
|
53
|
-
|
54
|
-
### Bootstrapped Admin Page Generator
|
55
|
-
|
56
|
-
Generates a new Padrino Admin page with Twitter Bootstrapped integrated.
|
57
|
-
|
58
|
-
**Usage:**
|
59
|
-
|
60
|
-
```
|
61
|
-
padrino g bootstrapped_admin_page [model]
|
62
|
-
```
|
63
|
-
|
64
|
-
**Options:**
|
65
|
-
|
66
|
-
-r, [--root=ROOT] The root destination.
|
67
|
-
|
68
|
-
-s, [--skip-migration]
|
69
|
-
|
70
|
-
-d, [--destroy]
|
71
|
-
|
72
|
-
**Example:**
|
73
|
-
|
74
|
-
```
|
75
|
-
padrino g bootstrapped_admin_page product
|
76
|
-
```
|
77
|
-
|
78
26
|
### Admin Controller Tests Generator
|
79
27
|
|
80
28
|
Generates a fully tested admin controller test for the 6 CRUD actions of a standard Padrino admin controller.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lazy-head-gen.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "lazy-head-gen"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Stuart Chinery"]
|
@@ -27,39 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lazy-head-gen.gemspec",
|
28
28
|
"lib/lazy-head-gen.rb",
|
29
29
|
"lib/lazy-head-gen/admin_controller_test.rb",
|
30
|
-
"lib/lazy-head-gen/bootstrapped_admin_app.rb",
|
31
|
-
"lib/lazy-head-gen/bootstrapped_admin_page.rb",
|
32
30
|
"lib/lazy-head-gen/scaffold.rb",
|
33
|
-
"lib/lazy-head-gen/templates/admin_app/account/activerecord.rb.tt",
|
34
|
-
"lib/lazy-head-gen/templates/admin_app/account/seeds.rb.tt",
|
35
|
-
"lib/lazy-head-gen/templates/admin_app/app.rb.tt",
|
36
|
-
"lib/lazy-head-gen/templates/admin_app/app/controllers/base.rb",
|
37
|
-
"lib/lazy-head-gen/templates/admin_app/app/controllers/sessions.rb.tt",
|
38
|
-
"lib/lazy-head-gen/templates/admin_app/app/helpers/application_helper.rb",
|
39
|
-
"lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.css",
|
40
|
-
"lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.min.css",
|
41
|
-
"lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.css",
|
42
|
-
"lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.min.css",
|
43
|
-
"lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-114-precomposed.png",
|
44
|
-
"lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-144-precomposed.png",
|
45
|
-
"lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-57-precomposed.png",
|
46
|
-
"lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-72-precomposed.png",
|
47
|
-
"lib/lazy-head-gen/templates/admin_app/assets/ico/favicon.ico",
|
48
|
-
"lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings-white.png",
|
49
|
-
"lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings.png",
|
50
|
-
"lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.js",
|
51
|
-
"lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.min.js",
|
52
|
-
"lib/lazy-head-gen/templates/admin_app/assets/js/jquery-min.js",
|
53
|
-
"lib/lazy-head-gen/templates/admin_app/assets/js/jquery-ujs.js",
|
54
|
-
"lib/lazy-head-gen/templates/admin_app/assets/js/jquery.js",
|
55
|
-
"lib/lazy-head-gen/templates/admin_app/erb/app/base/index.erb.tt",
|
56
|
-
"lib/lazy-head-gen/templates/admin_app/erb/app/layouts/application.erb.tt",
|
57
|
-
"lib/lazy-head-gen/templates/admin_app/erb/app/sessions/new.erb.tt",
|
58
|
-
"lib/lazy-head-gen/templates/admin_app/erb/page/_form.erb.tt",
|
59
|
-
"lib/lazy-head-gen/templates/admin_app/erb/page/edit.erb.tt",
|
60
|
-
"lib/lazy-head-gen/templates/admin_app/erb/page/index.erb.tt",
|
61
|
-
"lib/lazy-head-gen/templates/admin_app/erb/page/new.erb.tt",
|
62
|
-
"lib/lazy-head-gen/templates/admin_app/page/controller.rb.tt",
|
63
31
|
"lib/lazy-head-gen/templates/admin_controller_test/admin_controller_test.rb.tt",
|
64
32
|
"lib/lazy-head-gen/templates/scaffold/blueprints.rb.tt",
|
65
33
|
"lib/lazy-head-gen/templates/scaffold/controller.rb.tt",
|
@@ -70,8 +38,6 @@ Gem::Specification.new do |s|
|
|
70
38
|
"lib/lazy-head-gen/templates/scaffold/view.erb.tt",
|
71
39
|
"test/helper.rb",
|
72
40
|
"test/lazy-head-gen/test_admin_controller_test.rb",
|
73
|
-
"test/lazy-head-gen/test_bootstrapped_admin_app_generator.rb",
|
74
|
-
"test/lazy-head-gen/test_bootstrapped_admin_page_generator.rb",
|
75
41
|
"test/lazy-head-gen/test_scaffold.rb",
|
76
42
|
"test/load_paths.rb",
|
77
43
|
"test/test_lazy-head-gen.rb"
|
data/lib/lazy-head-gen.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
begin
|
2
2
|
require 'padrino-gen'
|
3
|
-
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{bootstrapped_admin_app,
|
3
|
+
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{bootstrapped_admin_app,admin_controller_test,scaffold}.rb']
|
4
4
|
rescue LoadError
|
5
5
|
# Fail silently
|
6
6
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy-head-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 3
|
9
8
|
- 4
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Stuart Chinery
|
@@ -408,39 +408,7 @@ files:
|
|
408
408
|
- lazy-head-gen.gemspec
|
409
409
|
- lib/lazy-head-gen.rb
|
410
410
|
- lib/lazy-head-gen/admin_controller_test.rb
|
411
|
-
- lib/lazy-head-gen/bootstrapped_admin_app.rb
|
412
|
-
- lib/lazy-head-gen/bootstrapped_admin_page.rb
|
413
411
|
- lib/lazy-head-gen/scaffold.rb
|
414
|
-
- lib/lazy-head-gen/templates/admin_app/account/activerecord.rb.tt
|
415
|
-
- lib/lazy-head-gen/templates/admin_app/account/seeds.rb.tt
|
416
|
-
- lib/lazy-head-gen/templates/admin_app/app.rb.tt
|
417
|
-
- lib/lazy-head-gen/templates/admin_app/app/controllers/base.rb
|
418
|
-
- lib/lazy-head-gen/templates/admin_app/app/controllers/sessions.rb.tt
|
419
|
-
- lib/lazy-head-gen/templates/admin_app/app/helpers/application_helper.rb
|
420
|
-
- lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.css
|
421
|
-
- lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.min.css
|
422
|
-
- lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.css
|
423
|
-
- lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.min.css
|
424
|
-
- lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-114-precomposed.png
|
425
|
-
- lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-144-precomposed.png
|
426
|
-
- lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-57-precomposed.png
|
427
|
-
- lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-72-precomposed.png
|
428
|
-
- lib/lazy-head-gen/templates/admin_app/assets/ico/favicon.ico
|
429
|
-
- lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings-white.png
|
430
|
-
- lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings.png
|
431
|
-
- lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.js
|
432
|
-
- lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.min.js
|
433
|
-
- lib/lazy-head-gen/templates/admin_app/assets/js/jquery-min.js
|
434
|
-
- lib/lazy-head-gen/templates/admin_app/assets/js/jquery-ujs.js
|
435
|
-
- lib/lazy-head-gen/templates/admin_app/assets/js/jquery.js
|
436
|
-
- lib/lazy-head-gen/templates/admin_app/erb/app/base/index.erb.tt
|
437
|
-
- lib/lazy-head-gen/templates/admin_app/erb/app/layouts/application.erb.tt
|
438
|
-
- lib/lazy-head-gen/templates/admin_app/erb/app/sessions/new.erb.tt
|
439
|
-
- lib/lazy-head-gen/templates/admin_app/erb/page/_form.erb.tt
|
440
|
-
- lib/lazy-head-gen/templates/admin_app/erb/page/edit.erb.tt
|
441
|
-
- lib/lazy-head-gen/templates/admin_app/erb/page/index.erb.tt
|
442
|
-
- lib/lazy-head-gen/templates/admin_app/erb/page/new.erb.tt
|
443
|
-
- lib/lazy-head-gen/templates/admin_app/page/controller.rb.tt
|
444
412
|
- lib/lazy-head-gen/templates/admin_controller_test/admin_controller_test.rb.tt
|
445
413
|
- lib/lazy-head-gen/templates/scaffold/blueprints.rb.tt
|
446
414
|
- lib/lazy-head-gen/templates/scaffold/controller.rb.tt
|
@@ -451,8 +419,6 @@ files:
|
|
451
419
|
- lib/lazy-head-gen/templates/scaffold/view.erb.tt
|
452
420
|
- test/helper.rb
|
453
421
|
- test/lazy-head-gen/test_admin_controller_test.rb
|
454
|
-
- test/lazy-head-gen/test_bootstrapped_admin_app_generator.rb
|
455
|
-
- test/lazy-head-gen/test_bootstrapped_admin_page_generator.rb
|
456
422
|
- test/lazy-head-gen/test_scaffold.rb
|
457
423
|
- test/load_paths.rb
|
458
424
|
- test/test_lazy-head-gen.rb
|
@@ -1,119 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
module Generators
|
3
|
-
##
|
4
|
-
# Defines the generator for creating a new admin app.
|
5
|
-
#
|
6
|
-
class BootstrappedAdminApp < Thor::Group
|
7
|
-
|
8
|
-
# Add this generator to our padrino-gen
|
9
|
-
Padrino::Generators.add_generator(:bootstrapped_admin, self)
|
10
|
-
|
11
|
-
# Define the source template root and themes.
|
12
|
-
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
13
|
-
# Defines the "banner" text for the CLI.
|
14
|
-
def self.banner; "padrino g bootstrapped_admin"; end
|
15
|
-
|
16
|
-
# Include related modules
|
17
|
-
include Thor::Actions
|
18
|
-
include Padrino::Generators::Actions
|
19
|
-
include Padrino::Generators::Admin::Actions
|
20
|
-
|
21
|
-
desc "Description:\n\n\tpadrino g bootstrapped_admin - Generates a new Padrino Admin application with Twitter Bootstrapped integrated"
|
22
|
-
|
23
|
-
class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
|
24
|
-
|
25
|
-
class_option :app, :aliases => "-a", :desc => "The model destination path", :default => '.', :type => :string
|
26
|
-
|
27
|
-
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
28
|
-
|
29
|
-
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
30
|
-
|
31
|
-
class_option :admin_model, :aliases => '-m', :desc => "The name of model for access controlling", :default => 'Account', :type => :string
|
32
|
-
|
33
|
-
# Copies over the Padrino base admin application
|
34
|
-
def create_admin
|
35
|
-
self.destination_root = options[:root]
|
36
|
-
if in_app_root?
|
37
|
-
store_component_choice(:admin_renderer, :erb)
|
38
|
-
|
39
|
-
self.behavior = :revoke if options[:destroy]
|
40
|
-
|
41
|
-
empty_directory destination_root("admin")
|
42
|
-
directory "templates/admin_app/app", destination_root("admin")
|
43
|
-
directory "templates/admin_app/assets", destination_root("public", "admin")
|
44
|
-
template "templates/admin_app/app.rb.tt", destination_root("admin/app.rb")
|
45
|
-
append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/admin\")"
|
46
|
-
insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement', 'admin'
|
47
|
-
|
48
|
-
account_params = [
|
49
|
-
options[:admin_model].underscore, "name:string", "surname:string", "email:string", "crypted_password:string", "role:string",
|
50
|
-
"-a=#{options[:app]}",
|
51
|
-
"-r=#{options[:root]}"
|
52
|
-
]
|
53
|
-
|
54
|
-
account_params << "-s" if options[:skip_migration]
|
55
|
-
account_params << "-d" if options[:destroy]
|
56
|
-
|
57
|
-
Padrino::Generators::Model.start(account_params)
|
58
|
-
column = Struct.new(:name, :type)
|
59
|
-
columns = [:id, :name, :surname, :email].map { |col| column.new(col) }
|
60
|
-
column_fields = [
|
61
|
-
{ :name => :name, :field_type => :text_field },
|
62
|
-
{ :name => :surname, :field_type => :text_field },
|
63
|
-
{ :name => :email, :field_type => :text_field },
|
64
|
-
{ :name => :password, :field_type => :password_field },
|
65
|
-
{ :name => :password_confirmation, :field_type => :password_field },
|
66
|
-
{ :name => :role, :field_type => :text_field }
|
67
|
-
]
|
68
|
-
|
69
|
-
admin_page = Padrino::Generators::BootstrappedAdminPage.new([options[:admin_model].underscore], :root => options[:root], :destroy => options[:destroy])
|
70
|
-
admin_page.default_orm = Padrino::Admin::Generators::Orm.new(options[:admin_model].underscore, orm, columns, column_fields)
|
71
|
-
admin_page.invoke_all
|
72
|
-
|
73
|
-
template "templates/admin_app/account/activerecord.rb.tt", destination_root(options[:app], "models", "#{options[:admin_model].underscore}.rb"), :force => true
|
74
|
-
|
75
|
-
if File.exist?(destination_root("db/seeds.rb"))
|
76
|
-
run "mv #{destination_root('db/seeds.rb')} #{destination_root('db/seeds.old')}"
|
77
|
-
end
|
78
|
-
template "templates/admin_app/account/seeds.rb.tt", destination_root("db/seeds.rb")
|
79
|
-
|
80
|
-
empty_directory destination_root("admin/controllers")
|
81
|
-
empty_directory destination_root("admin/views")
|
82
|
-
empty_directory destination_root("admin/views/base")
|
83
|
-
empty_directory destination_root("admin/views/layouts")
|
84
|
-
empty_directory destination_root("admin/views/sessions")
|
85
|
-
|
86
|
-
template "templates/admin_app/#{ext}/app/base/index.#{ext}.tt", destination_root("admin/views/base/index.#{ext}")
|
87
|
-
template "templates/admin_app/#{ext}/app/layouts/application.#{ext}.tt", destination_root("admin/views/layouts/application.#{ext}")
|
88
|
-
template "templates/admin_app/#{ext}/app/sessions/new.#{ext}.tt", destination_root("admin/views/sessions/new.#{ext}")
|
89
|
-
|
90
|
-
model_singular = options[:admin_model].underscore
|
91
|
-
model_plural = model_singular.pluralize
|
92
|
-
|
93
|
-
add_project_module model_plural
|
94
|
-
require_dependencies('bcrypt-ruby', :require => 'bcrypt')
|
95
|
-
gsub_file destination_root("admin/views/#{model_plural}/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
|
96
|
-
gsub_file destination_root("admin/controllers/#{model_plural}.rb"), "if #{model_singular}.destroy", "if #{model_singular} != current_account && #{model_singular}.destroy"
|
97
|
-
return if self.behavior == :revoke
|
98
|
-
|
99
|
-
instructions = []
|
100
|
-
instructions << "Run 'bundle install'"
|
101
|
-
instructions << "Run 'padrino rake ar:migrate'"
|
102
|
-
instructions << "Run 'padrino rake seed'"
|
103
|
-
instructions << "Visit the admin panel in the browser at '/admin'"
|
104
|
-
instructions.map! { |i| " #{instructions.index(i)+1}) #{i}" }
|
105
|
-
|
106
|
-
say
|
107
|
-
say "="*65, :green
|
108
|
-
say "The admin panel has been mounted! Next, follow these steps:", :green
|
109
|
-
say "="*65, :green
|
110
|
-
say instructions.join("\n")
|
111
|
-
say "="*65, :green
|
112
|
-
say
|
113
|
-
else
|
114
|
-
say "You are not at the root of a Padrino application! (config/boot.rb not found)"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end # AdminApp
|
118
|
-
end # Generators
|
119
|
-
end # Padrino
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
module Generators
|
3
|
-
##
|
4
|
-
# Defines the generator for creating a new admin page.
|
5
|
-
#
|
6
|
-
class BootstrappedAdminPage < Thor::Group
|
7
|
-
attr_accessor :default_orm
|
8
|
-
|
9
|
-
# Add this generator to our padrino-gen
|
10
|
-
Padrino::Generators.add_generator(:bootstrapped_admin_page, self)
|
11
|
-
|
12
|
-
# Define the source template root
|
13
|
-
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
14
|
-
# Defines the "banner" text for the CLI.
|
15
|
-
def self.banner; "padrino g bootstrapped_admin_page [model]"; end
|
16
|
-
|
17
|
-
# Include related modules
|
18
|
-
include Thor::Actions
|
19
|
-
include Padrino::Generators::Actions
|
20
|
-
include Padrino::Generators::Admin::Actions
|
21
|
-
|
22
|
-
desc "Description:\n\n\tpadrino g bootstrapped_admin_page [model(s)] - Generates a new Padrino Admin page with Twitter Bootstrapped integrated"
|
23
|
-
|
24
|
-
argument :models, :desc => "The name(s) of your model(s)", :type => :array
|
25
|
-
|
26
|
-
class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
|
27
|
-
|
28
|
-
class_option :root, :desc => "The root destination", :aliases => '-r', :type => :string
|
29
|
-
|
30
|
-
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
31
|
-
|
32
|
-
# Show help if no argv given
|
33
|
-
require_arguments!
|
34
|
-
|
35
|
-
# Create controller for admin
|
36
|
-
def create_controller
|
37
|
-
self.destination_root = options[:root]
|
38
|
-
if in_app_root?
|
39
|
-
models.each do |model|
|
40
|
-
@orm = default_orm || Padrino::Admin::Generators::Orm.new(model, adapter)
|
41
|
-
self.behavior = :revoke if options[:destroy]
|
42
|
-
empty_directory destination_root("/admin/views/#{@orm.name_plural}")
|
43
|
-
|
44
|
-
template "templates/admin_app/page/controller.rb.tt", destination_root("/admin/controllers/#{@orm.name_plural}.rb")
|
45
|
-
template "templates/admin_app/erb/page/_form.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/_form.erb")
|
46
|
-
template "templates/admin_app/erb/page/edit.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/edit.erb")
|
47
|
-
template "templates/admin_app/erb/page/index.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/index.erb")
|
48
|
-
template "templates/admin_app/erb/page/new.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/new.erb")
|
49
|
-
|
50
|
-
options[:destroy] ? remove_project_module(@orm.name_plural) : add_project_module(@orm.name_plural)
|
51
|
-
end
|
52
|
-
else
|
53
|
-
say "You are not at the root of a Padrino application! (config/boot.rb not found)"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end # AdminPage
|
57
|
-
end # Generators
|
58
|
-
end # Padrino
|
@@ -1,38 +0,0 @@
|
|
1
|
-
class <%= options[:admin_model].underscore.camelize %> < ActiveRecord::Base
|
2
|
-
attr_accessor :password, :password_confirmation
|
3
|
-
|
4
|
-
# Validations
|
5
|
-
validates_presence_of :email, :role
|
6
|
-
validates_presence_of :password, :if => :password_required
|
7
|
-
validates_presence_of :password_confirmation, :if => :password_required
|
8
|
-
validates_length_of :password, :within => 4..40, :if => :password_required
|
9
|
-
validates_confirmation_of :password, :if => :password_required
|
10
|
-
validates_length_of :email, :within => 3..100
|
11
|
-
validates_uniqueness_of :email, :case_sensitive => false
|
12
|
-
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
13
|
-
validates_format_of :role, :with => /[A-Za-z]/
|
14
|
-
|
15
|
-
# Callbacks
|
16
|
-
before_save :encrypt_password, :if => :password_required
|
17
|
-
|
18
|
-
##
|
19
|
-
# This method is for authentication purpose
|
20
|
-
#
|
21
|
-
def self.authenticate(email, password)
|
22
|
-
account = first(:conditions => { :email => email }) if email.present?
|
23
|
-
account && account.has_password?(password) ? account : nil
|
24
|
-
end
|
25
|
-
|
26
|
-
def has_password?(password)
|
27
|
-
::BCrypt::Password.new(crypted_password) == password
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
def encrypt_password
|
32
|
-
self.crypted_password = ::BCrypt::Password.create(password)
|
33
|
-
end
|
34
|
-
|
35
|
-
def password_required
|
36
|
-
crypted_password.blank? || password.present?
|
37
|
-
end
|
38
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# Seed add you the ability to populate your db.
|
2
|
-
# We provide you a basic shell for interaction with the end user.
|
3
|
-
# So try some code like below:
|
4
|
-
#
|
5
|
-
# name = shell.ask("What's your name?")
|
6
|
-
# shell.say name
|
7
|
-
#
|
8
|
-
email = shell.ask "Which email do you want use for logging into admin?"
|
9
|
-
password = shell.ask "Tell me the password to use:"
|
10
|
-
|
11
|
-
shell.say ""
|
12
|
-
|
13
|
-
account = <%= options[:admin_model].underscore.camelize %>.create(:email => email, :name => "Foo", :surname => "Bar", :password => password, :password_confirmation => password, :role => "admin")
|
14
|
-
|
15
|
-
if account.valid?
|
16
|
-
shell.say "================================================================="
|
17
|
-
shell.say "<%= options[:admin_model].underscore.camelize %> has been successfully created, now you can login with:"
|
18
|
-
shell.say "================================================================="
|
19
|
-
shell.say " email: #{email}"
|
20
|
-
shell.say " password: #{password}"
|
21
|
-
shell.say "================================================================="
|
22
|
-
else
|
23
|
-
shell.say "Sorry but some thing went wrong!"
|
24
|
-
shell.say ""
|
25
|
-
account.errors.full_messages.each { |m| shell.say " - #{m}" }
|
26
|
-
end
|
27
|
-
|
28
|
-
shell.say ""
|