lazy-head-gen 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Gemfile +0 -2
  2. data/README.md +10 -2
  3. data/VERSION +1 -1
  4. data/lazy-head-gen.gemspec +43 -10
  5. data/lib/lazy-head-gen.rb +1 -1
  6. data/lib/lazy-head-gen/admin_controller_test.rb +2 -1
  7. data/lib/lazy-head-gen/bootstrapped_admin_app.rb +121 -0
  8. data/lib/lazy-head-gen/bootstrapped_admin_page.rb +58 -0
  9. data/lib/lazy-head-gen/scaffold.rb +8 -7
  10. data/lib/lazy-head-gen/templates/admin_app/account/activerecord.rb.tt +38 -0
  11. data/lib/lazy-head-gen/templates/admin_app/account/seeds.rb.tt +28 -0
  12. data/lib/lazy-head-gen/templates/admin_app/app.rb.tt +36 -0
  13. data/lib/lazy-head-gen/templates/admin_app/app/controllers/base.rb +6 -0
  14. data/lib/lazy-head-gen/templates/admin_app/app/controllers/sessions.rb.tt +26 -0
  15. data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.css +815 -0
  16. data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.min.css +9 -0
  17. data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.css +4983 -0
  18. data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.min.css +9 -0
  19. data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-114-precomposed.png +0 -0
  20. data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-144-precomposed.png +0 -0
  21. data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-57-precomposed.png +0 -0
  22. data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-72-precomposed.png +0 -0
  23. data/lib/lazy-head-gen/templates/admin_app/assets/ico/favicon.ico +0 -0
  24. data/lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings-white.png +0 -0
  25. data/lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings.png +0 -0
  26. data/lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.js +1825 -0
  27. data/lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.min.js +6 -0
  28. data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery-min.js +4 -0
  29. data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery-ujs.js +92 -0
  30. data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery.js +9404 -0
  31. data/lib/lazy-head-gen/templates/admin_app/erb/app/base/index.erb.tt +14 -0
  32. data/lib/lazy-head-gen/templates/admin_app/erb/app/layouts/application.erb.tt +79 -0
  33. data/lib/lazy-head-gen/templates/admin_app/erb/app/sessions/new.erb.tt +98 -0
  34. data/lib/lazy-head-gen/templates/admin_app/erb/page/_form.erb.tt +16 -0
  35. data/lib/lazy-head-gen/templates/admin_app/erb/page/edit.erb.tt +26 -0
  36. data/lib/lazy-head-gen/templates/admin_app/erb/page/index.erb.tt +41 -0
  37. data/lib/lazy-head-gen/templates/admin_app/erb/page/new.erb.tt +23 -0
  38. data/lib/lazy-head-gen/templates/admin_app/page/controller.rb.tt +47 -0
  39. data/lib/lazy-head-gen/templates/{admin_controller_test.rb.tt → admin_controller_test/admin_controller_test.rb.tt} +0 -0
  40. data/lib/lazy-head-gen/templates/{blueprints.rb.tt → scaffold/blueprints.rb.tt} +0 -0
  41. data/lib/lazy-head-gen/templates/{controller.rb.tt → scaffold/controller.rb.tt} +0 -0
  42. data/lib/lazy-head-gen/templates/{controller_test.rb.tt → scaffold/controller_test.rb.tt} +0 -0
  43. data/lib/lazy-head-gen/templates/{helper.rb.tt → scaffold/helper.rb.tt} +0 -0
  44. data/lib/lazy-head-gen/templates/{model.rb.tt → scaffold/model.rb.tt} +0 -0
  45. data/lib/lazy-head-gen/templates/{model_test.rb.tt → scaffold/model_test.rb.tt} +0 -0
  46. data/lib/lazy-head-gen/templates/{view.erb.tt → scaffold/view.erb.tt} +0 -0
  47. data/test/helper.rb +1 -5
  48. data/test/lazy-head-gen/test_bootstrapped_admin_app_generator.rb +211 -0
  49. data/test/lazy-head-gen/test_bootstrapped_admin_page_generator.rb +94 -0
  50. metadata +45 -12
@@ -0,0 +1,14 @@
1
+ <div class="row">
2
+ <div class="span12">
3
+ <h2>Dashboard</h2>
4
+ <p>
5
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
6
+ </p>
7
+ <p>
8
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
9
+ </p>
10
+ <p>
11
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
12
+ </p>
13
+ </div>
14
+ </div>
@@ -0,0 +1,79 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Padrino Admin</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="description" content="">
8
+ <meta name="author" content="">
9
+
10
+ <!-- Le styles -->
11
+ <link href="/admin/css/bootstrap.css" rel="stylesheet">
12
+ <style>
13
+ body {
14
+ padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
15
+ }
16
+ </style>
17
+ <link href="/admin/css/bootstrap-responsive.css" rel="stylesheet">
18
+
19
+ <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
20
+ <!--[if lt IE 9]>
21
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
22
+ <![endif]-->
23
+
24
+ <!-- Le fav and touch icons -->
25
+ <link rel="shortcut icon" href="/admin/ico/favicon.ico">
26
+ <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/admin/ico/apple-touch-icon-144-precomposed.png">
27
+ <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/admin/ico/apple-touch-icon-114-precomposed.png">
28
+ <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/admin/ico/apple-touch-icon-72-precomposed.png">
29
+ <link rel="apple-touch-icon-precomposed" href="/admin/ico/apple-touch-icon-57-precomposed.png">
30
+ </head>
31
+
32
+ <body>
33
+
34
+ <div class="navbar navbar-fixed-top">
35
+ <div class="navbar-inner">
36
+ <div class="container">
37
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
38
+ <span class="icon-bar"></span>
39
+ <span class="icon-bar"></span>
40
+ <span class="icon-bar"></span>
41
+ </a>
42
+ <a class="brand" href="<%%= url_for(:base, :index) %>">Project name</a>
43
+ <div class="nav-collapse">
44
+ <ul class="nav">
45
+ <%% project_modules.each do |project_module| %>
46
+ <li class="<%%= "active" if request.path_info =~ /^#{project_module.path}/ %>">
47
+ <%%= link_to project_module.human_name, project_module.path("/admin") %>
48
+ </li>
49
+ <%% end %>
50
+ </ul>
51
+ <ul class="nav pull-right">
52
+ <li>
53
+ <%%= link_to pat(:profile), url(:<%= options[:admin_model].underscore.pluralize %>, :edit, :id => current_account.id) %>
54
+ </li>
55
+ <li>
56
+ <%%= link_to('Sign Out', url(:sessions, :destroy), :method => :delete) %>
57
+ </li>
58
+ </ul>
59
+ </div><!--/.nav-collapse -->
60
+ </div>
61
+ </div>
62
+ </div>
63
+
64
+ <div class="container">
65
+ <%%= [:error, :warning, :notice].map { |type| flash_tag(type, :class => "message #{type}") }.join %>
66
+
67
+ <%%= yield %>
68
+
69
+ </div> <!-- /container -->
70
+
71
+ <!-- Le javascript
72
+ ================================================== -->
73
+ <!-- Placed at the end of the document so the pages load faster -->
74
+ <script src="/admin/js/jquery.js"></script>
75
+ <script src="/admin/js/jquery-ujs.js"></script>
76
+ <script src="/admin/js/bootstrap.js"></script>
77
+
78
+ </body>
79
+ </html>
@@ -0,0 +1,98 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Padrino Admin</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="description" content="">
8
+ <meta name="author" content="">
9
+
10
+ <!-- Le styles -->
11
+ <link href="/admin/css/bootstrap.min.css" rel="stylesheet">
12
+ <style>
13
+ body {
14
+ padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
15
+ }
16
+ </style>
17
+ <link href="/admin/css/bootstrap-responsive.min.css" rel="stylesheet">
18
+
19
+ <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
20
+ <!--[if lt IE 9]>
21
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
22
+ <![endif]-->
23
+
24
+ <!-- Le fav and touch icons -->
25
+ <link rel="shortcut icon" href="/admin/ico/favicon.ico">
26
+ <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/admin/ico/apple-touch-icon-144-precomposed.png">
27
+ <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/admin/ico/apple-touch-icon-114-precomposed.png">
28
+ <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/admin/ico/apple-touch-icon-72-precomposed.png">
29
+ <link rel="apple-touch-icon-precomposed" href="/admin/ico/apple-touch-icon-57-precomposed.png">
30
+ </head>
31
+
32
+ <body>
33
+
34
+ <div class="navbar navbar-fixed-top">
35
+ <div class="navbar-inner">
36
+ <div class="container">
37
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
38
+ <span class="icon-bar"></span>
39
+ <span class="icon-bar"></span>
40
+ <span class="icon-bar"></span>
41
+ </a>
42
+ <a class="brand" href="<%%= url_for(:base, :index) %>">Project name</a>
43
+ <div class="nav-collapse">
44
+ </div><!--/.nav-collapse -->
45
+ </div>
46
+ </div>
47
+ </div>
48
+
49
+ <div class="container">
50
+ <%%= [:error, :warning, :notice].map { |type| flash_tag(type, :class => "alert alert-#{type}") }.join %>
51
+
52
+ <div class="row">
53
+ <div class="span6 offset3">
54
+ <%% form_tag(url(:sessions, :create), :class => "form-horizontal") do %>
55
+ <fieldset>
56
+ <legend>Please enter your login details</legend>
57
+ <div class="control-group">
58
+ <label class="control-label">Login</label>
59
+ <div class="controls">
60
+ <%%= text_field_tag :email, :value => params[:email] %>
61
+ </div>
62
+ </div>
63
+
64
+ <div class="control-group">
65
+ <label class="control-label">Password</label>
66
+ <div class="controls">
67
+ <%%= password_field_tag :password, :value => params[:password] %>
68
+ </div>
69
+ </div>
70
+
71
+ <%% if Padrino.env == :development %>
72
+ <div class="control-group">
73
+ <label class="control-label">Bypass login?</label>
74
+ <div class="controls">
75
+ <%%= check_box_tag :bypass %>
76
+ </div>
77
+ </div>
78
+ <%% end %>
79
+
80
+ <div class="form-actions">
81
+ <%%= submit_tag "Sign in", :class => "btn btn-primary" %>
82
+ </div>
83
+ </fieldset>
84
+ <%% end %>
85
+ </div>
86
+ </div>
87
+
88
+ </div> <!-- /container -->
89
+
90
+ <!-- Le javascript
91
+ ================================================== -->
92
+ <!-- Placed at the end of the document so the pages load faster -->
93
+ <script src="/admin/js/jquery.js"></script>
94
+ <script src="/admin/js/jquery-ujs.js"></script>
95
+ <script src="/admin/js/bootstrap.min.js"></script>
96
+
97
+ </body>
98
+ </html>
@@ -0,0 +1,16 @@
1
+ <fieldset>
2
+ <% @orm.column_fields.each do |column| %>
3
+ <div class="control-group">
4
+ <%%= f.label :<%= column[:name] %>, :class => "control-label" %>
5
+ <div class="controls">
6
+ <%%= f.<%= column[:field_type] %> :<%= column[:name] %>, :class => :<%= column[:field_type] %> %>
7
+ <span class="help-block">Ex: a simple text</span>
8
+ </div>
9
+ </div>
10
+ <% end %>
11
+
12
+ <div class="form-actions">
13
+ <%%= f.submit pat(:save), :class => "btn btn-primary" %>
14
+ <%%= f.submit pat(:cancel), :onclick => "window.location='#{url(:<%= @orm.name_plural %>, :index)}';return false", :class => "btn" %>
15
+ </div>
16
+ </fieldset>
@@ -0,0 +1,26 @@
1
+ <div class="subnav">
2
+ <ul class="nav nav-tabs">
3
+ <li>
4
+ <%%= link_to pat(:list), url(:<%= @orm.name_plural %>, :index) %>
5
+ </li>
6
+ <li>
7
+ <%%= link_to pat(:new), url(:<%= @orm.name_plural %>, :new) %>
8
+ </li>
9
+ <li class="active">
10
+ <%%= link_to pat(:edit), url(:<%= @orm.name_plural %>, :edit, :id => @<%= @orm.name_singular %>.id) %>
11
+ </li>
12
+ </ul>
13
+ </div>
14
+
15
+ <div class="row">
16
+ <div class="span12">
17
+ <div class="page-header">
18
+ <h2><%%= pat(:edit) %> <%%= mt(:<%= @orm.name_singular %>) %></h2>
19
+ </div>
20
+
21
+ <%% form_for :<%= @orm.name_singular %>, url(:<%= @orm.name_plural %>, :update, :id => @<%= @orm.name_singular %>.id), :method => :put, :class => "form-horizontal" do |f| %>
22
+ <%%= partial "<%= @orm.name_plural %>/form", :locals => { :f => f } %>
23
+ <%% end %>
24
+
25
+ </div>
26
+ </div>
@@ -0,0 +1,41 @@
1
+ <div class="subnav">
2
+ <ul class="nav nav-tabs">
3
+ <li class="active">
4
+ <%%= link_to pat(:list), url(:<%= @orm.name_plural %>, :index) %>
5
+ </li>
6
+ <li>
7
+ <%%= link_to pat(:new), url(:<%= @orm.name_plural %>, :new) %>
8
+ </li>
9
+ </ul>
10
+ </div>
11
+
12
+ <div class="row">
13
+ <div class="span12">
14
+ <div class="page-header">
15
+ <h2><%%= pat(:all) %> <%%= mt(:<%= @orm.name_plural %>) %></h2>
16
+ </div>
17
+
18
+ <table class="table table-striped">
19
+ <tr>
20
+ <%- @orm.columns.each_with_index do |column, i| -%>
21
+ <th<%= " class=\"first\"" if i==0 %>><%%= mat(:<%= @orm.name_singular %>, :<%= column.name %>) %></th>
22
+ <%- end -%>
23
+ <th>&nbsp;</th>
24
+ </tr>
25
+ <%% @<%= @orm.name_plural %>.each do |<%= @orm.name_singular %>| %>
26
+ <tr>
27
+ <%- @orm.columns.each_with_index do |column, i| -%>
28
+ <td<%= " class=\"first\"" if i==0 %>><%%= <%= @orm.name_singular %>.<%= column.name %> %></td>
29
+ <%- end -%>
30
+ <td>
31
+ <span class="pull-right">
32
+ <%%= link_to pat(:edit), url(:<%= @orm.name_plural %>, :edit, :id => <%= @orm.name_singular %>.id), :class => "btn btn-primary" %>
33
+ <%%= link_to pat(:delete), url(:<%= @orm.name_plural %>, :destroy, :id => <%= @orm.name_singular %>.id), :method => :delete, :confirm => "Are you sure?", :class => "btn btn-danger" %>
34
+ </span>
35
+ </td>
36
+ </tr>
37
+ <%% end %>
38
+ </table>
39
+
40
+ </div>
41
+ </div>
@@ -0,0 +1,23 @@
1
+ <div class="subnav">
2
+ <ul class="nav nav-tabs">
3
+ <li>
4
+ <%%= link_to pat(:list), url(:<%= @orm.name_plural %>, :index) %>
5
+ </li>
6
+ <li class="active">
7
+ <%%= link_to pat(:new), url(:<%= @orm.name_plural %>, :new) %>
8
+ </li>
9
+ </ul>
10
+ </div>
11
+
12
+ <div class="row">
13
+ <div class="span12">
14
+ <div class="page-header">
15
+ <h2><%%= pat(:new) %> <%%= mt(:<%= @orm.name_singular %>) %></h2>
16
+ </div>
17
+
18
+ <%% form_for :<%= @orm.name_singular %>, url(:<%= @orm.name_plural %>, :create), :class => "form-horizontal" do |f| %>
19
+ <%%= partial "<%= @orm.name_plural %>/form", :locals => { :f => f } %>
20
+ <%% end %>
21
+
22
+ </div>
23
+ </div>
@@ -0,0 +1,47 @@
1
+ Admin.controllers :<%= @orm.name_plural %> do
2
+
3
+ get :index do
4
+ @<%= @orm.name_plural %> = <%= @orm.all %>
5
+ render '<%= @orm.name_plural %>/index'
6
+ end
7
+
8
+ get :new do
9
+ @<%= @orm.name_singular %> = <%= @orm.build %>
10
+ render '<%= @orm.name_plural %>/new'
11
+ end
12
+
13
+ post :create do
14
+ @<%= @orm.name_singular %> = <%= @orm.build("params[:#{@orm.name_singular}]") %>
15
+ if <%= @orm.save %>
16
+ flash[:notice] = '<%= @orm.klass_name %> was successfully created.'
17
+ redirect url(:<%= @orm.name_plural %>, :edit, :id => @<%= @orm.name_singular%>.id)
18
+ else
19
+ render '<%= @orm.name_plural %>/new'
20
+ end
21
+ end
22
+
23
+ get :edit, :with => :id do
24
+ @<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
25
+ render '<%= @orm.name_plural %>/edit'
26
+ end
27
+
28
+ put :update, :with => :id do
29
+ @<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
30
+ if <%= @orm.update_attributes("params[:#{@orm.name_singular}]") %>
31
+ flash[:notice] = '<%= @orm.klass_name %> was successfully updated.'
32
+ redirect url(:<%= @orm.name_plural %>, :edit, :id => @<%= @orm.name_singular %>.id)
33
+ else
34
+ render '<%= @orm.name_plural %>/edit'
35
+ end
36
+ end
37
+
38
+ delete :destroy, :with => :id do
39
+ <%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
40
+ if <%= @orm.destroy %>
41
+ flash[:notice] = '<%= @orm.klass_name %> was successfully destroyed.'
42
+ else
43
+ flash[:error] = 'Unable to destroy <%= @orm.klass_name %>!'
44
+ end
45
+ redirect url(:<%= @orm.name_plural %>, :index)
46
+ end
47
+ end
data/test/helper.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  ENV['PADRINO_ENV'] = 'test'
2
2
  PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
3
3
 
4
- # require 'simplecov'
5
- # SimpleCov.start
6
-
7
4
  require File.expand_path('../load_paths', __FILE__)
8
5
  require 'minitest/autorun'
9
6
  require 'rack/test'
@@ -13,9 +10,8 @@ require 'thor/group'
13
10
  require 'padrino-core/support_lite' unless defined?(SupportLite)
14
11
  require 'padrino-admin'
15
12
  require File.dirname(__FILE__) + '/../lib/lazy-head-gen.rb'
16
-
13
+ require 'debugger'
17
14
  begin; require 'turn/autorun'; rescue LoadError; end
18
- # require 'ruby-debug'
19
15
 
20
16
  Padrino::Generators.load_components!
21
17
 
@@ -0,0 +1,211 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../helper')
2
+
3
+ describe "BootstrappedAdminAppGenerator" do
4
+
5
+ def setup
6
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
7
+ `mkdir -p #{@apptmp}`
8
+ end
9
+
10
+ def teardown
11
+ `rm -rf #{@apptmp}`
12
+ end
13
+
14
+ describe 'the bootstrapped admin app generator' do
15
+
16
+ it 'should fail outside app root' do
17
+ out, err = capture_io { generate(:admin_app, "-r=#{@apptmp}") }
18
+ assert_match(/not at the root/, out)
19
+ assert_no_file_exists('/tmp/admin')
20
+ end
21
+
22
+ it "should fail if we don't specify an orm" do
23
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-e=erb') }
24
+ assert_raises(SystemExit) { @out, @err = capture_io { generate(:admin_app, "-r=#{@apptmp}/sample_project") } }
25
+ end
26
+
27
+ it "should fail if we don't specify a valid theme" do
28
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=haml') }
29
+ assert_raises(SystemExit) { @out, @err = capture_io { generate(:admin_app, "-r=#{@apptmp}/sample_project", '--theme=foo') } }
30
+ end
31
+
32
+ it 'should correctly generate a new bootstrapped padrino admin application with erb renderer' do
33
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=erb') }
34
+ capture_io { generate(:bootstrapped_admin_app, "--root=#{@apptmp}/sample_project") }
35
+ assert_file_exists("#{@apptmp}/sample_project")
36
+ assert_file_exists("#{@apptmp}/sample_project/admin")
37
+ assert_file_exists("#{@apptmp}/sample_project/admin/app.rb")
38
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers")
39
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/accounts.rb")
40
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/base.rb")
41
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/sessions.rb")
42
+ assert_file_exists("#{@apptmp}/sample_project/admin/views")
43
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/_form.erb")
44
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/edit.erb")
45
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/index.erb")
46
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/new.erb")
47
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/index.erb")
48
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.erb")
49
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/index.erb")
50
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/layouts/application.erb")
51
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.erb")
52
+ assert_file_exists("#{@apptmp}/sample_project/public/admin")
53
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css")
54
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap.css")
55
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap.min.css")
56
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap-responsive.css")
57
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap-responsive.min.css")
58
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico")
59
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-114-precomposed.png")
60
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-144-precomposed.png")
61
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-57-precomposed.png")
62
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-72-precomposed.png")
63
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/favicon.ico")
64
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img")
65
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img/glyphicons-halflings-white.png")
66
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img/glyphicons-halflings.png")
67
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js")
68
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/bootstrap.js")
69
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/bootstrap.min.js")
70
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery-min.js")
71
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery-ujs.js")
72
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery.js")
73
+ assert_file_exists("#{@apptmp}/sample_project/models/account.rb")
74
+ assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
75
+ assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_accounts.rb")
76
+ assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
77
+ assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
78
+ assert_match_in_file 'role.project_module :accounts, \'/accounts\'', "#{@apptmp}/sample_project/admin/app.rb"
79
+ assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.erb"
80
+ end
81
+
82
+ it 'should correctly generate a new padrino admin application with a custom account model' do
83
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=erb') }
84
+ capture_io { generate(:bootstrapped_admin_app, "--root=#{@apptmp}/sample_project", '-m=User') }
85
+ assert_file_exists("#{@apptmp}/sample_project")
86
+ assert_file_exists("#{@apptmp}/sample_project/admin")
87
+ assert_file_exists("#{@apptmp}/sample_project/admin/app.rb")
88
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers")
89
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/users.rb")
90
+ assert_no_match_in_file(/[^_]account/i, "#{@apptmp}/sample_project/admin/controllers/users.rb")
91
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/base.rb")
92
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/sessions.rb")
93
+ assert_file_exists("#{@apptmp}/sample_project/admin/views")
94
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/users/_form.erb")
95
+ assert_no_match_in_file(/[^_]account/i, "#{@apptmp}/sample_project/admin/views/users/_form.erb")
96
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/users/edit.erb")
97
+ assert_no_match_in_file(/[^_]account/i, "#{@apptmp}/sample_project/admin/views/users/edit.erb")
98
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/users/index.erb")
99
+ assert_no_match_in_file(/[^_]account/i, "#{@apptmp}/sample_project/admin/views/users/index.erb")
100
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/users/new.erb")
101
+ assert_no_match_in_file(/[^_]account/i, "#{@apptmp}/sample_project/admin/views/users/new.erb")
102
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/index.erb")
103
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.erb")
104
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/index.erb")
105
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/layouts/application.erb")
106
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.erb")
107
+ assert_file_exists("#{@apptmp}/sample_project/public/admin")
108
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css")
109
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap.css")
110
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap.min.css")
111
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap-responsive.css")
112
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap-responsive.min.css")
113
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico")
114
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-114-precomposed.png")
115
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-144-precomposed.png")
116
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-57-precomposed.png")
117
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-72-precomposed.png")
118
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/favicon.ico")
119
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img")
120
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img/glyphicons-halflings-white.png")
121
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img/glyphicons-halflings.png")
122
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js")
123
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/bootstrap.js")
124
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/bootstrap.min.js")
125
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery-min.js")
126
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery-ujs.js")
127
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery.js")
128
+ assert_file_exists("#{@apptmp}/sample_project/models/user.rb")
129
+ assert_no_match_in_file(/Account/, "#{@apptmp}/sample_project/models/user.rb")
130
+ assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
131
+ assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_users.rb")
132
+ assert_no_match_in_file(/[^_]account/i, "#{@apptmp}/sample_project/db/migrate/001_create_users.rb")
133
+ assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
134
+ assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
135
+ assert_match_in_file 'role.project_module :users, \'/users\'', "#{@apptmp}/sample_project/admin/app.rb"
136
+ assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.erb"
137
+ end
138
+
139
+ it 'should correctly generate a new padrino admin application with model in non-default application path' do
140
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=erb') }
141
+ capture_io { generate(:bootstrapped_admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
142
+ assert_file_exists("#{@apptmp}/sample_project")
143
+ assert_file_exists("#{@apptmp}/sample_project/admin")
144
+ assert_file_exists("#{@apptmp}/sample_project/admin/app.rb")
145
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers")
146
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/accounts.rb")
147
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/base.rb")
148
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/sessions.rb")
149
+ assert_file_exists("#{@apptmp}/sample_project/admin/views")
150
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/_form.erb")
151
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/edit.erb")
152
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/index.erb")
153
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/new.erb")
154
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/index.erb")
155
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.erb")
156
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/index.erb")
157
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/layouts/application.erb")
158
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.erb")
159
+ assert_file_exists("#{@apptmp}/sample_project/public/admin")
160
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css")
161
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap.css")
162
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap.min.css")
163
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap-responsive.css")
164
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/css/bootstrap-responsive.min.css")
165
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico")
166
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-114-precomposed.png")
167
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-144-precomposed.png")
168
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-57-precomposed.png")
169
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/apple-touch-icon-72-precomposed.png")
170
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/ico/favicon.ico")
171
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img")
172
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img/glyphicons-halflings-white.png")
173
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/img/glyphicons-halflings.png")
174
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js")
175
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/bootstrap.js")
176
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/bootstrap.min.js")
177
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery-min.js")
178
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery-ujs.js")
179
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/js/jquery.js")
180
+ assert_file_exists("#{@apptmp}/sample_project/admin/models/account.rb")
181
+ assert_no_file_exists("#{@apptmp}/sample_project/models/account.rb")
182
+ assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
183
+ assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_accounts.rb")
184
+ assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
185
+ assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
186
+ assert_match_in_file 'role.project_module :accounts, \'/accounts\'', "#{@apptmp}/sample_project/admin/app.rb"
187
+ assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.erb"
188
+ end
189
+
190
+ it 'should add activerecord middleware for #activerecord' do
191
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=haml') }
192
+ capture_io { generate(:bootstrapped_admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
193
+ assert_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/admin/app.rb")
194
+ end
195
+
196
+ it 'should not conflict with existing seeds file' do
197
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=erb') }
198
+
199
+ # Add seeds file
200
+ FileUtils.mkdir_p @apptmp + '/sample_project/db' unless File.exist?(@apptmp + '/sample_project/db')
201
+ File.open(@apptmp + '/sample_project/db/seeds.rb', 'w+') do |seeds_rb|
202
+ seeds_rb.puts "# Old Seeds Content"
203
+ end
204
+
205
+ capture_io { generate(:bootstrapped_admin_app, "--root=#{@apptmp}/sample_project") }
206
+
207
+ assert_file_exists "#{@apptmp}/sample_project/db/seeds.old"
208
+ assert_match_in_file 'Account.create(', "#{@apptmp}/sample_project/db/seeds.rb"
209
+ end
210
+ end
211
+ end