admin_view 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75c33648b3776e0a936f358a9927a43dff397524
4
+ data.tar.gz: e12dee840643c2bfbcf07e3fa7faedcb9d1b263c
5
+ SHA512:
6
+ metadata.gz: 2f5ad171e3c5d6e60d543d6f02cfd4fefde17abecaba6a8ac6e677c496ae51f456a9ce272232f2df8b679fe5a2679d419b2d723a4b6f64796d3c843604487d39
7
+ data.tar.gz: b02916d24b92c1dfcb5b16a38b81ca127313bbb1a318512508236f82a777b42a8770a450458546f2509e8984cc6027af10f9940beed9e3637321bd3bab8972ef
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # admin_view
2
2
 
3
- Rails 3 generator of CRUD admin controllers, views and specs for existing ActiveRecord models.
3
+ Code generator of CRUD admin controllers, views and specs for existing ActiveRecord models. It helps you get the data on screen immediately, so you can customize the specifics to your liking.
4
4
 
5
- It uses [meta_search](https://github.com/ernie/meta_search) for search and [kaminari](https://github.com/amatsuda/kaminari) for pagination. It also assumes that you have [dynamic_form](https://github.com/joelmoss/dynamic_form) plugin installed.
5
+ It works with Rails 4 and uses [ransack](https://github.com/activerecord-hackery/ransack) for search and [kaminari](https://github.com/amatsuda/kaminari) for pagination.
6
+
7
+ The produced markup in views is compatible with [Bootstrap 3](http://getbootstrap.com).
6
8
 
7
9
  Screenshot:
8
10
 
9
- ![admin_view example screenshot](http://renderedtext.com/images/blog/admin_view.png)
11
+ ![admin_view example screenshot](http://cl.ly/image/1o3n1P153V0O/Screen%20Shot%202014-05-16%20at%2014.57.29%20.png)
10
12
 
11
13
  ## Usage
12
14
 
@@ -18,7 +20,7 @@ Run the generator:
18
20
 
19
21
  $ bundle exec rails g admin_view User --search_by name_or_email
20
22
 
21
- The `--search_by` option is not required - if you don't pass it, the form template will come out commented out. However, it's useful most of the time, and you can use any meta_search-compatible expression to search in string or text fields.
23
+ The `--search_by` option is not required. However, it's useful most of the time, and you can use any ransack-compatible expression to search in string or text fields.
22
24
 
23
25
  Other options available are:
24
26
 
@@ -33,4 +35,4 @@ If you're having a problem or found a bug, please open an issue in the GitHub [i
33
35
 
34
36
  ## License
35
37
 
36
- Copyright © 2011 [Rendered Text](http://renderedtext.com). admin_view is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
38
+ Copyright © 2011-2014 [Rendered Text](http://renderedtext.com). admin_view is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
data/admin_view.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Marko Anastasov", "Darko Fabijan"]
10
10
  s.email = ["devs@renderedtext.com"]
11
11
  s.homepage = "http://github.com/renderedtext/admin_view"
12
- s.summary = %q{Rails 3 generator of admin views and controllers for existing models.}
13
- s.description = %q{Rails 3 generator of admin views and controllers for existing models.}
12
+ s.summary = %q{Admin view code generator for Rails.}
13
+ s.description = %q{Code generator of admin views and controllers for ActiveRecord models.}
14
14
 
15
15
  s.rubyforge_project = "admin_view"
16
16
 
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency("rails", ">= 3.0")
23
- s.add_dependency("meta_search", ">= 1.0")
24
- s.add_dependency("kaminari", ">= 0.12")
25
- s.add_development_dependency("rspec-rails", ">= 2.4.0")
22
+ s.add_dependency("rails", "~> 4.0")
23
+ s.add_dependency("ransack", "~> 1.2")
24
+ s.add_dependency("kaminari", "~> 0.15")
25
+ s.add_development_dependency("rspec-rails", "~> 2.4")
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module AdminView
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,15 +1,15 @@
1
1
  class Admin::<%= controller_class_name %>Controller < Admin::BaseController
2
2
 
3
- helper_method :sort_column, :sort_direction, :search_params
3
+ helper_method :sort_column, :sort_direction
4
4
 
5
5
  before_filter :find_<%= singular_table_name %>, :only => [<% unless options[:read_only] %>:edit, :update,<% end %> :show, :destroy]
6
6
 
7
7
  def index
8
- @search = <%= class_name %>.search(params[:search])
8
+ @q = <%= class_name %>.search(params[:q])
9
9
  @<%= plural_table_name %> = find_<%= plural_table_name %>
10
10
  end
11
11
 
12
- <% unless options[:no_create] or options[:read_only] %>
12
+ <% unless options[:no_create] || options[:read_only] %>
13
13
  def new
14
14
  @<%= singular_table_name %> = <%= class_name %>.new
15
15
  end
@@ -22,12 +22,12 @@ class Admin::<%= controller_class_name %>Controller < Admin::BaseController
22
22
  render :new
23
23
  end
24
24
  end
25
- <% end -%>
25
+ <% end -%>
26
26
 
27
27
  def show
28
28
  end
29
29
 
30
- <% unless options[:read_only] %>
30
+ <% unless options[:read_only] -%>
31
31
  def edit
32
32
  end
33
33
 
@@ -38,11 +38,11 @@ class Admin::<%= controller_class_name %>Controller < Admin::BaseController
38
38
  render :edit
39
39
  end
40
40
  end
41
- <% end -%>
41
+ <% end -%>
42
42
 
43
43
  def destroy
44
44
  @<%= singular_table_name %>.destroy
45
- redirect_to admin_<%= plural_table_name %>_path, :notice => "<%= human_name %> has been deleted."
45
+ redirect_to admin_<%= plural_table_name %>_path, :notice => "<%= human_name %> deleted."
46
46
  end
47
47
 
48
48
  protected
@@ -52,8 +52,8 @@ class Admin::<%= controller_class_name %>Controller < Admin::BaseController
52
52
  end
53
53
 
54
54
  def find_<%= plural_table_name %>
55
- search_relation = @search.relation
56
- search_relation.order(sort_column + " " + sort_direction).page params[:page]
55
+ search_relation = @q.result
56
+ @<%= plural_table_name %> = search_relation.order(sort_column + " " + sort_direction).references(:<%= singular_table_name %>).page params[:page]
57
57
  end
58
58
 
59
59
  def sort_column
@@ -64,8 +64,4 @@ class Admin::<%= controller_class_name %>Controller < Admin::BaseController
64
64
  %w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
65
65
  end
66
66
 
67
- def search_params
68
- {:search => params[:search]}
69
- end
70
-
71
67
  end
@@ -1,12 +1,24 @@
1
- <%%= f.error_messages %>
1
+ <%% if @<%= singular_table_name %>.errors.any? -%>
2
+ <ul class="errors">
3
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
4
+ <li><%%= msg %></li>
5
+ <%% end %>
6
+ </ul>
7
+ <%% end %>
2
8
 
3
9
  <% @attributes.each do |attribute| -%>
4
10
  <% next if ["id", "created_at", "updated_at"].include?(attribute.name) -%>
5
- <p>
6
- <%%= f.label :<%= attribute.name %> %><br />
7
- <%%= f.text_field :<%= attribute.name %> %>
8
- </p>
11
+ <div class="form-group">
12
+ <%%= f.label :<%= attribute.name %>, :class => "col-sm-2 control-label" %>
13
+ <div class="col-sm-4">
14
+ <%%= f.text_field :<%= attribute.name %>, :class => "form-control", :placeholder => "<%= attribute.name.capitalize %>" %>
15
+ </div>
16
+ </div>
9
17
  <% end -%>
10
18
 
11
19
  <%% label = @<%= singular_table_name %>.new_record? ? "Create" : "Update" -%>
12
- <%%= f.submit label %>
20
+ <div class="form-group">
21
+ <div class="col-sm-offset-2 col-sm-4">
22
+ <button type="submit" class="btn btn-default"><%%= label %></button>
23
+ </div>
24
+ </div>
@@ -1,5 +1,7 @@
1
- <h1>Editing <%= human_name.downcase %></h1>
1
+ <div class="page-header">
2
+ <h1>Editing <%%= link_to "<%= human_name.downcase %> #{@<%= singular_table_name %>.id}", admin_<%= singular_table_name %>_path(@<%= singular_table_name %>) %></h1>
3
+ </div>
2
4
 
3
- <%%= form_for [:admin, @<%= singular_table_name %>] do |f| -%>
5
+ <%%= form_for [:admin, @<%= singular_table_name %>], :html => { :class => "form-horizontal", :role => "form" } do |f| -%>
4
6
  <%%= render "form", { :f => f } %>
5
7
  <%% end -%>
@@ -1,29 +1,28 @@
1
- <h2><%= human_name.pluralize %></h2>
1
+ <div class="page-header">
2
+ <h1><%= human_name.pluralize %></h1>
3
+ </div>
2
4
 
3
- <%%= form_for @search, :url => admin_<%= plural_table_name %>_path, :html => {:method => :get} do |f| %>
4
- <% if options[:search_by].blank? -%>
5
- <!--
6
- <% end %>
7
- <!-- feel free to add further search options, eg foo_or_bar_contains -->
8
- <%%= f.label :<%= options[:search_by] %>_contains, "Search by <%= options[:search_by] %>" %>
9
- <%%= f.text_field :<%= options[:search_by] %>_contains %>
10
- <%%= f.submit %>
11
- <% if options[:search_by].blank? -%>
12
- --><p>Set up your search form or delete.</p>
13
- <% end %>
5
+ <% if options[:search_by].present? -%>
6
+ <%%= search_form_for @q, :url => admin_<%= plural_table_name %>_path, :html => { :method => :get, :class => "well form-inline" } do |f| %>
7
+ <div class="form-group">
8
+ <%%= f.text_field :<%= options[:search_by] %>_cont, :type => "search", :class => "form-control", :placeholder => "Search by <%= options[:search_by] %>" %>
9
+ </div>
10
+
11
+ <%%= f.submit "Search", :class => "btn btn-default" %>
14
12
  <%% end %>
13
+ <% end -%>
15
14
 
16
- <% unless options[:no_create] or options[:read_only] %>
15
+ <% unless options[:no_create] || options[:read_only] %>
17
16
  <p><%%= link_to("Create a new <%= human_name %>", new_admin_<%= singular_table_name %>_path) %></p>
18
17
  <% end -%>
19
18
 
20
- <table class="sortable">
19
+ <table class="sortable table table-striped table-bordered table-condensed">
21
20
  <thead>
22
21
  <tr>
23
22
  <% @attributes.each do |attribute| -%>
24
23
  <th><%%= sortable "<%= attribute.name %>" %></th>
25
24
  <% end -%>
26
- <% unless options[:read_only] %>
25
+ <% unless options[:read_only] -%>
27
26
  <th>Edit</th>
28
27
  <% end -%>
29
28
  <th>Delete</th>
@@ -31,13 +30,13 @@
31
30
  </thead>
32
31
  <tbody>
33
32
  <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
34
- <tr>
33
+ <tr class="<%= singular_table_name %>">
35
34
  <td><%%= link_to(<%= singular_table_name %>.id, admin_<%= singular_table_name %>_path(<%= singular_table_name %>)) %></td>
36
35
  <% @attributes.each do |attribute| -%>
37
36
  <% next if attribute.name == "id" -%>
38
37
  <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
39
38
  <% end -%>
40
- <% unless options[:read_only] %>
39
+ <% unless options[:read_only] -%>
41
40
  <td><%%= link_to('Edit', edit_admin_<%= singular_table_name %>_path(<%= singular_table_name %>)) %></td>
42
41
  <% end -%>
43
42
  <td><%%= link_to('Delete', admin_<%= singular_table_name %>_path(<%= singular_table_name %>), :confirm => "Are you sure?", :method => :delete) %></td>
@@ -1,5 +1,7 @@
1
- <h1>Create new <%= human_name.downcase %></h1>
1
+ <div class="page-header">
2
+ <h1>Create new <%= human_name.downcase %></h1>
3
+ </div>
2
4
 
3
- <%%= form_for [:admin, @<%= singular_table_name %>] do |f| -%>
5
+ <%%= form_for [:admin, @<%= singular_table_name %>], :html => { :class => "form-horizontal", :role => "form" } do |f| -%>
4
6
  <%%= render "form", { :f => f } %>
5
7
  <%% end -%>
@@ -1,11 +1,24 @@
1
- <h1><%= human_name.capitalize %> <%%= @<%= singular_table_name %>.id %></h1>
1
+ <div class="page-header">
2
+ <h1>
3
+ <%= human_name.capitalize %> <%%= @<%= singular_table_name %>.id %>
4
+ </h1>
5
+ </div>
2
6
 
7
+ <table class="table table-bordered">
3
8
  <% @attributes.each do |attribute| -%>
4
- <p>
5
- <strong><%= attribute.human_name %>:</strong>
6
- <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
- </p>
9
+ <tr>
10
+ <td><%= attribute.human_name %>:</td>
11
+ <td><%%= @<%= singular_table_name %>.<%= attribute.name %> %></td>
12
+ </tr>
8
13
  <% end -%>
14
+ <tr>
15
+ <td>Actions</td>
16
+ <td>
17
+ <% unless options[:read_only] -%>
18
+ <%%= link_to "Edit", edit_admin_<%= singular_table_name %>_path(@<%= singular_table_name %>), :class => "btn btn-default" %>
19
+ <% end -%>
20
+ <%%= link_to("Delete", admin_user_path(@user), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => "btn btn-danger btn-xs") %>
21
+ </td>
22
+ </tr>
23
+ </table>
9
24
 
10
- <%%= link_to "Edit", edit_admin_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
11
- <%%= link_to "Back", admin_<%= plural_table_name %>_path %>
data/test/test_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
- require 'test/unit'
4
+ require 'minitest/autorun'
5
5
  require 'active_support/test_case'
6
6
  require 'rails/all'
7
7
  require 'rails/generators'
metadata CHANGED
@@ -1,87 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: admin_view
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Marko Anastasov
13
8
  - Darko Fabijan
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-14 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2014-05-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 3
30
- - 0
31
- version: "3.0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '4.0'
32
21
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: meta_search
36
22
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 1
43
- - 0
44
- version: "1.0"
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '4.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: ransack
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.2'
45
35
  type: :runtime
46
- version_requirements: *id002
47
- - !ruby/object:Gem::Dependency
48
- name: kaminari
49
36
  prerelease: false
50
- requirement: &id003 !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- - 12
57
- version: "0.12"
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.2'
42
+ - !ruby/object:Gem::Dependency
43
+ name: kaminari
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.15'
58
49
  type: :runtime
59
- version_requirements: *id003
60
- - !ruby/object:Gem::Dependency
61
- name: rspec-rails
62
50
  prerelease: false
63
- requirement: &id004 !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 2
69
- - 4
70
- - 0
71
- version: 2.4.0
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.15'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.4'
72
63
  type: :development
73
- version_requirements: *id004
74
- description: Rails 3 generator of admin views and controllers for existing models.
75
- email:
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.4'
70
+ description: Code generator of admin views and controllers for ActiveRecord models.
71
+ email:
76
72
  - devs@renderedtext.com
77
73
  executables: []
78
-
79
74
  extensions: []
80
-
81
75
  extra_rdoc_files: []
82
-
83
- files:
84
- - .gitignore
76
+ files:
77
+ - ".gitignore"
85
78
  - Gemfile
86
79
  - MIT-LICENSE
87
80
  - README.md
@@ -102,36 +95,27 @@ files:
102
95
  - lib/generators/templates/views/show.html.erb
103
96
  - test/admin_view_generator_test.rb
104
97
  - test/test_helper.rb
105
- has_rdoc: true
106
98
  homepage: http://github.com/renderedtext/admin_view
107
99
  licenses: []
108
-
100
+ metadata: {}
109
101
  post_install_message:
110
102
  rdoc_options: []
111
-
112
- require_paths:
103
+ require_paths:
113
104
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
115
- requirements:
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
116
107
  - - ">="
117
- - !ruby/object:Gem::Version
118
- segments:
119
- - 0
120
- version: "0"
121
- required_rubygems_version: !ruby/object:Gem::Requirement
122
- requirements:
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
123
112
  - - ">="
124
- - !ruby/object:Gem::Version
125
- segments:
126
- - 0
127
- version: "0"
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
128
115
  requirements: []
129
-
130
116
  rubyforge_project: admin_view
131
- rubygems_version: 1.3.6
117
+ rubygems_version: 2.2.2
132
118
  signing_key:
133
- specification_version: 3
134
- summary: Rails 3 generator of admin views and controllers for existing models.
135
- test_files:
136
- - test/admin_view_generator_test.rb
137
- - test/test_helper.rb
119
+ specification_version: 4
120
+ summary: Admin view code generator for Rails.
121
+ test_files: []