rails-admin-scaffold 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34346574780e02f06f369704b36d6ac05abbfbac
4
- data.tar.gz: 71e1b12973cc002bd4f9a6a7d393c42b7789025f
3
+ metadata.gz: 82be34423e27de5d719dc40db221985eaf4349bc
4
+ data.tar.gz: 7c38e23be12869baf5082102a08ea34f24ed45a5
5
5
  SHA512:
6
- metadata.gz: 55282911a92016ea03153537a8839c292b0f13527e4add55b7e75e8d0785afc3bc211c8d49a2a7b1339e3f2897e4a344213549def3e27eee0e58a92fdb98e117
7
- data.tar.gz: ea55bc9b0a25f52d1723038eedf75831bc074ded07a169dc3c72dae0288c58bc5bffd3dcff5b8077f2068d750a1b6cfa72a169380eda21155574fe1533872976
6
+ metadata.gz: 7d4a1f192ccac354cd923ea7738f0ef822702719b779bb655b808adc3d5a211604648a29287544d2caf716211792ce5870b9ab6254cec7d7b05e9f58b84ce42e
7
+ data.tar.gz: c1758077b2b5ed20ec24a0c41b7b770aaa06b1774ed91c9066676e84ea5a326abe508bda07dcca9a6b8b9aa39a4fdfc85d1148d11c08bff130d227b5fea71b32
data/README.md CHANGED
@@ -36,11 +36,18 @@ controller like `AdminController` you can specify the
36
36
 
37
37
  This will generate `class Admin::PostsController < AdminController`
38
38
 
39
+ #### How to generate bootstrap-friendly views
40
+
41
+ If you want to generate bootstrap friendly views, use the `--bootstrap` option (`-b` for short)
42
+
43
+ ```bin/rails g admin:scaffold_controller Post title:string content:text published:boolean --bootstrap```
44
+
39
45
  Supports
40
46
  --------
41
47
  * Rails 4+
42
48
  * Rails default generators (erb, test::unit)
43
49
  * Haml (if haml is used for views generation)
50
+ * Twitter bootstrap support
44
51
  * Jbuilder (if jbuilder is installed for the project)
45
52
 
46
53
  Plans
@@ -29,6 +29,9 @@ module Admin
29
29
  class_option :parent_controller, banner: "admin", type: :string, default: "application",
30
30
  desc: "Define the parent controller"
31
31
 
32
+ class_option :bootstrap, required: false, default: nil, aliases: '-b',
33
+ desc: "Use bootstrap for templates"
34
+
32
35
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
33
36
 
34
37
  def initialize(args, *options) #:nodoc:
@@ -64,7 +67,12 @@ module Admin
64
67
  def copy_view_files
65
68
  available_views.each do |view|
66
69
  filename = filename_with_extensions(view)
67
- template "views/#{handler}/#{filename}.erb", File.join("app/views", prefix, controller_file_path, filename)
70
+ if bootstrap
71
+ template_path = "views/#{handler}_bootstrap/#{filename}.erb"
72
+ else
73
+ template_path = "views/#{handler}/#{filename}.erb"
74
+ end
75
+ template template_path, File.join("app/views", prefix, controller_file_path, filename)
68
76
  end
69
77
 
70
78
  # I think there should be a better way to detect if jbuilder is in use
@@ -81,6 +89,10 @@ module Admin
81
89
 
82
90
  protected
83
91
 
92
+ def bootstrap
93
+ options[:bootstrap]
94
+ end
95
+
84
96
  def prefix
85
97
  options[:prefix_name]
86
98
  end
@@ -0,0 +1,59 @@
1
+ <%%= form_for(<%= "[:#{prefix}, @#{singular_table_name}]" %>, html: { class: 'form-horizontal <%= singular_table_name %>' }) do |f| %>
2
+ <%% if @<%= singular_table_name %>.errors.any? %>
3
+ <div id="error_explanation" class="panel panel-danger">
4
+ <div class="panel-heading">
5
+ <h2 class="panel-title"><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
6
+ </div>
7
+ <div class="panel-body">
8
+ <ul>
9
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
10
+ <li><%%= msg %></li>
11
+ <%% end %>
12
+ </ul>
13
+ </div>
14
+ </div>
15
+ <%% end %>
16
+
17
+ <% attributes.each do |attribute| -%>
18
+ <div class="form-group">
19
+ <%- if attribute.field_type != :check_box -%>
20
+ <%- if attribute.password_digest? -%>
21
+ <%%= f.label :password, class: 'control-label col-md-2' %>
22
+ <div class="col-md-10">
23
+ <%%= f.password_field :password, class: 'form-control' %>
24
+ </div>
25
+ </div>
26
+ <div class="form-group">
27
+ <%%= f.label :password_confirmation, class: 'control-label col-md-2' %>
28
+ <div class="col-md-10">
29
+ <%%= f.password_field :password_confirmation, class: 'form-control' %>
30
+ </div>
31
+ <%- else -%>
32
+ <%- if attribute.reference? -%>
33
+ <%%= f.label :<%= attribute.column_name %>, class: 'control-label col-md-2' %>
34
+ <div class="col-md-10">
35
+ <%%= f.<%= attribute.field_type %> :<%= attribute.column_name %>, class: 'form-control' %>
36
+ </div>
37
+ <%- else -%>
38
+ <%%= f.label :<%= attribute.name %>, class: 'control-label col-md-2' %>
39
+ <div class="col-md-10">
40
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %>, class: 'form-control' %>
41
+ </div>
42
+ <%- end -%>
43
+ <%- end -%>
44
+ <%- else -%>
45
+ <div class="col-md-offset-2 col-md-10">
46
+ <%%= f.label :<%= attribute.name %>, for: nil do %>
47
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
48
+ <%%= <%= class_name %>.human_attribute_name(:<%= attribute.name %>) %>
49
+ <%% end %>
50
+ </div>
51
+ <%- end -%>
52
+ </div>
53
+ <% end -%>
54
+ <div class="form-group">
55
+ <div class="col-md-offset-2 col-md-10">
56
+ <%%= f.submit nil, class: 'btn btn-primary' %>
57
+ </div>
58
+ </div>
59
+ <%% end %>
@@ -0,0 +1,8 @@
1
+ <div class="page-header">
2
+ <h1>Editing <%= singular_table_name %></h1>
3
+ </div>
4
+
5
+ <%%= render 'form' %>
6
+
7
+ <%%= link_to 'Show', <%= "[:#{prefix}, @#{singular_table_name}]" %>, class: 'btn btn-default' %>
8
+ <%%= link_to 'Back', <%= prefixed_index_helper %>_path, class: 'btn btn-default' %>
@@ -0,0 +1,33 @@
1
+ <div class="page-header">
2
+ <h1>Listing <%= plural_table_name %></h1>
3
+ </div>
4
+
5
+ <table class="table table-striped">
6
+ <thead>
7
+ <tr>
8
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
9
+ <th><%= attribute.human_name %></th>
10
+ <% end -%>
11
+ <th></th>
12
+ <th></th>
13
+ <th></th>
14
+ </tr>
15
+ </thead>
16
+
17
+ <tbody>
18
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
19
+ <tr>
20
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
21
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
22
+ <% end -%>
23
+ <td><%%= link_to 'Show', <%= "[:#{prefix}, #{singular_table_name}]" %>, class: 'btn btn-default btn-xs' %></td>
24
+ <td><%%= link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(<%= singular_table_name %>), class: 'btn btn-default btn-xs' %></td>
25
+ <td><%%= link_to 'Destroy', <%= "[:#{prefix}, #{singular_table_name}]" %>, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-xs btn-danger' %></td>
26
+ </tr>
27
+ <%% end %>
28
+ </tbody>
29
+ </table>
30
+
31
+ <br>
32
+
33
+ <%%= link_to 'New <%= human_name %>', new_<%= prefixed_plain_model_url %>_path, class: 'btn btn-primary' %>
@@ -0,0 +1,7 @@
1
+ <div class="page-header">
2
+ <h1>New <%= singular_table_name %></h1>
3
+ </div>
4
+
5
+ <%%= render 'form' %>
6
+
7
+ <%%= link_to 'Back', <%= prefixed_index_helper %>_path, class: 'btn btn-default' %>
@@ -0,0 +1,11 @@
1
+ <p id="notice"><%%= notice %></p>
2
+
3
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
4
+ <dl class="dl-horizontal">
5
+ <dt><strong><%= attribute.human_name %>:</strong></dt>
6
+ <dd><%%= @<%= singular_table_name %>.<%= attribute.name %> %></dd>
7
+ </dl>
8
+
9
+ <% end -%>
10
+ <%%= link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(@<%= singular_table_name %>), class: 'btn btn-default' %>
11
+ <%%= link_to 'Back', <%= prefixed_index_helper %>_path, class: 'btn btn-default' %>
@@ -0,0 +1,25 @@
1
+ = form_for(<%= "[:#{prefix}, @#{singular_table_name}], html: { class: 'form-horizontal #{singular_table_name}'} " %>) do |f|
2
+ - if @<%= singular_table_name %>.errors.any?
3
+ #error_explanation.panel.panel-danger
4
+ .panel-heading
5
+ %h2.panel-title= "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
6
+ .panel-body
7
+ %ul
8
+ - @<%= singular_table_name %>.errors.full_messages.each do |msg|
9
+ %li= msg
10
+
11
+ <% for attribute in attributes -%>
12
+ <%- if attribute.field_type != :check_box -%>
13
+ .form-group
14
+ = f.label :<%= attribute.name %>, class: 'control-label col-md-2'
15
+ .col-md-10= f.<%= attribute.field_type %> :<%= attribute.name %>, class: 'form-control'
16
+ <%- else -%>
17
+ .col-md-offset-2.col-md-10
18
+ = f.label :<%= attribute.name %>, for: nil do
19
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
20
+ = <%= class_name %>.human_attribute_name(:<%= attribute.name %>)
21
+ <%- end -%>
22
+ <% end -%>
23
+ .form-group
24
+ .col-md-offset-2.col-md-10
25
+ = f.submit nil, class: 'btn btn-primary'
@@ -0,0 +1,7 @@
1
+ .page-header
2
+ %h1 Editing <%= singular_table_name %>
3
+
4
+ = render 'form'
5
+
6
+ = link_to 'Show', <%= "[:#{prefix}, @#{singular_table_name}]" %>, class: 'btn btn-default'
7
+ = link_to 'Back', <%= prefixed_index_helper %>_path, class: 'btn btn-default'
@@ -0,0 +1,24 @@
1
+ .page-header
2
+ %h1 Listing <%= plural_table_name %>
3
+
4
+ %table.table.table-stripped
5
+ %tr
6
+ <% for attribute in attributes -%>
7
+ %th <%= attribute.human_name %>
8
+ <% end -%>
9
+ %th
10
+ %th
11
+ %th
12
+
13
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
14
+ %tr
15
+ <% for attribute in attributes -%>
16
+ %td= <%= singular_table_name %>.<%= attribute.name %>
17
+ <% end -%>
18
+ %td= link_to 'Show', <%= "[:#{prefix}, #{singular_table_name}]" %>, class: 'btn btn-default btn-xs'
19
+ %td= link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(<%= singular_table_name %>), class: 'btn btn-default btn-xs'
20
+ %td= link_to 'Destroy', <%= "[:#{prefix}, #{singular_table_name}]" %>, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger btn-xs'
21
+
22
+ %br
23
+
24
+ = link_to 'New <%= human_name %>', new_<%= prefixed_plain_model_url %>_path, class: 'btn btn-primary'
@@ -0,0 +1,6 @@
1
+ .page-header
2
+ %h1 New <%= singular_table_name %>
3
+
4
+ = render 'form'
5
+
6
+ = link_to 'Back', <%= prefixed_index_helper %>_path, class: 'btn btn-default'
@@ -0,0 +1,11 @@
1
+ %p#notice= notice
2
+
3
+ <% for attribute in attributes -%>
4
+ %dl.dl-horizontal
5
+ %dt
6
+ %strong <%= attribute.human_name %>:
7
+ %dd= @<%= singular_table_name %>.<%= attribute.name %>
8
+ <% end -%>
9
+
10
+ = link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(@<%= singular_table_name %>), class: 'btn btn-default'
11
+ = link_to 'Back', <%= prefixed_index_helper %>_path, class: 'btn btn-default'
@@ -1,3 +1,3 @@
1
1
  module RailsAdminScaffold
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -71,6 +71,20 @@ class Admin::Generators::ScaffoldControllerGeneratorTest < Rails::Generators::Te
71
71
  %w(index edit new show).each do |view|
72
72
  assert_file "app/views/admin/users/#{view}.html.erb"
73
73
  end
74
+
75
+ # Ensure we're not using the bootstrap templates (which will have a class inside the table tag)
76
+ assert_file "app/views/admin/users/index.html.erb", /<table>/
77
+ end
78
+
79
+ def test_erb_bootstrap_views_are_generated
80
+ run_generator ['user', '-b']
81
+
82
+ %w(index edit new show).each do |view|
83
+ assert_file "app/views/admin/users/#{view}.html.erb"
84
+ end
85
+
86
+ # Ensure we're not using the regular erb templates
87
+ assert_file "app/views/admin/users/index.html.erb", /<table class="table/
74
88
  end
75
89
 
76
90
  def test_haml_views_are_generated
@@ -81,6 +95,15 @@ class Admin::Generators::ScaffoldControllerGeneratorTest < Rails::Generators::Te
81
95
  end
82
96
  end
83
97
 
98
+ def test_haml_bootstrap_views_are_generated
99
+ run_generator ['user', '-b', '-e', 'haml']
100
+
101
+ %w(index edit new show).each do |view|
102
+ assert_file "app/views/admin/users/#{view}.html.haml"
103
+ end
104
+ end
105
+
106
+
84
107
  def test_functional_tests
85
108
  run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}"]
86
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-admin-scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Kalachev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-04 00:00:00.000000000 Z
11
+ date: 2014-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,11 +72,21 @@ files:
72
72
  - lib/generators/admin/scaffold_controller/templates/views/erb/index.html.erb.erb
73
73
  - lib/generators/admin/scaffold_controller/templates/views/erb/new.html.erb.erb
74
74
  - lib/generators/admin/scaffold_controller/templates/views/erb/show.html.erb.erb
75
+ - lib/generators/admin/scaffold_controller/templates/views/erb_bootstrap/_form.html.erb.erb
76
+ - lib/generators/admin/scaffold_controller/templates/views/erb_bootstrap/edit.html.erb.erb
77
+ - lib/generators/admin/scaffold_controller/templates/views/erb_bootstrap/index.html.erb.erb
78
+ - lib/generators/admin/scaffold_controller/templates/views/erb_bootstrap/new.html.erb.erb
79
+ - lib/generators/admin/scaffold_controller/templates/views/erb_bootstrap/show.html.erb.erb
75
80
  - lib/generators/admin/scaffold_controller/templates/views/haml/_form.html.haml.erb
76
81
  - lib/generators/admin/scaffold_controller/templates/views/haml/edit.html.haml.erb
77
82
  - lib/generators/admin/scaffold_controller/templates/views/haml/index.html.haml.erb
78
83
  - lib/generators/admin/scaffold_controller/templates/views/haml/new.html.haml.erb
79
84
  - lib/generators/admin/scaffold_controller/templates/views/haml/show.html.haml.erb
85
+ - lib/generators/admin/scaffold_controller/templates/views/haml_bootstrap/_form.html.haml.erb
86
+ - lib/generators/admin/scaffold_controller/templates/views/haml_bootstrap/edit.html.haml.erb
87
+ - lib/generators/admin/scaffold_controller/templates/views/haml_bootstrap/index.html.haml.erb
88
+ - lib/generators/admin/scaffold_controller/templates/views/haml_bootstrap/new.html.haml.erb
89
+ - lib/generators/admin/scaffold_controller/templates/views/haml_bootstrap/show.html.haml.erb
80
90
  - lib/generators/admin/scaffold_controller/templates/views/jbuilder/index.json.jbuilder.erb
81
91
  - lib/generators/admin/scaffold_controller/templates/views/jbuilder/show.json.jbuilder.erb
82
92
  - lib/rails-admin-scaffold/version.rb
@@ -105,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
115
  version: 1.3.6
106
116
  requirements: []
107
117
  rubyforge_project: rails-admin-scaffold
108
- rubygems_version: 2.2.2
118
+ rubygems_version: 2.4.3
109
119
  signing_key:
110
120
  specification_version: 4
111
121
  summary: Rails admin controllers scaffolding generator