sharp_admin 0.0.1 → 1.0.1
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.
- checksums.yaml +4 -4
- data/lib/sharp_admin.rb +3 -0
- data/lib/sharp_admin/sharp_admin_generator.rb +13 -11
- data/lib/sharp_admin/templates/base_helper.rb +1 -1
- data/lib/sharp_admin/templates/controller.rb +1 -1
- data/lib/sharp_admin/templates/controller_spec.rb +1 -1
- data/lib/sharp_admin/templates/views/index.html.erb +12 -13
- data/lib/sharp_admin/version.rb +1 -1
- data/test/easy_admin_test.rb +14 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e5c5ac1533bb18d44fbdd64810313d26f6241e5
|
4
|
+
data.tar.gz: 74b63c9887268ac4b688a345ec3089efe837d8d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab4b9883e33f42566424414c8a75e53aff8623da045ea7f335382f6f03a98b90e9946a4bb8001d70c070e524a446b12c73d8ed85506bbc11a8f823e0f69ebf86
|
7
|
+
data.tar.gz: 65ce854f4dbc9b0b0e45b1a0962611dba00c2943609e76ccb1cb30ce53f87c3f0a1c386ffa439061ef7a288021a4f7831c688f3b92afbe4af4de34b11a70bc33
|
data/lib/sharp_admin.rb
CHANGED
@@ -13,43 +13,45 @@ class SharpAdminGenerator < Rails::Generators::NamedBase
|
|
13
13
|
|
14
14
|
class_option :read_only, :type => :boolean, :default => false, :desc => "Omit create, edit and update functionality."
|
15
15
|
|
16
|
+
class_option :ns, :type => :string, :default => 'admin', :desc => "the namespace of admin"
|
17
|
+
|
16
18
|
def create_base_controller
|
17
|
-
empty_directory "app/controllers
|
18
|
-
path = File.join("app/controllers
|
19
|
+
empty_directory "app/controllers/#{options[:ns]}"
|
20
|
+
path = File.join("app/controllers/#{options[:ns]}", "base_controller.rb")
|
19
21
|
template("base_controller.rb", path) unless File.exists?(path)
|
20
22
|
end
|
21
23
|
|
22
24
|
def create_base_controller_spec
|
23
|
-
empty_directory "spec/controllers
|
24
|
-
path = File.join("spec/controllers
|
25
|
+
empty_directory "spec/controllers/#{options[:ns]}"
|
26
|
+
path = File.join("spec/controllers/#{options[:ns]}", "base_controller_spec.rb")
|
25
27
|
template("base_controller_spec.rb", path) unless File.exists?(path)
|
26
28
|
end
|
27
29
|
|
28
30
|
def create_controller
|
29
31
|
@attributes_symbols = get_model_columns.dup.delete_if {|attribute| ['id', 'created_at', 'updated_at'].include? attribute.name }.collect {|attribute| ":#{attribute.name}" }
|
30
|
-
template "controller.rb", File.join("app/controllers
|
32
|
+
template "controller.rb", File.join("app/controllers/#{options[:ns]}", "#{controller_file_name}_controller.rb")
|
31
33
|
end
|
32
34
|
|
33
35
|
def create_controller_rspec
|
34
|
-
template "controller_spec.rb", File.join("spec/controllers
|
36
|
+
template "controller_spec.rb", File.join("spec/controllers/#{options[:ns]}", "#{controller_file_name}_controller_spec.rb")
|
35
37
|
end
|
36
38
|
|
37
39
|
def create_helper
|
38
|
-
empty_directory "app/helpers
|
39
|
-
template "base_helper.rb", File.join("app/helpers
|
40
|
+
empty_directory "app/helpers/#{options[:ns]}"
|
41
|
+
template "base_helper.rb", File.join("app/helpers/#{options[:ns]}", "base_helper.rb")
|
40
42
|
end
|
41
43
|
|
42
44
|
def create_views
|
43
|
-
empty_directory "app/views
|
45
|
+
empty_directory "app/views/#{options[:ns]}/#{controller_file_name}"
|
44
46
|
@attributes = get_model_columns
|
45
47
|
available_views.each do |view|
|
46
|
-
template "views/#{view}.html.erb", File.join("app/views
|
48
|
+
template "views/#{view}.html.erb", File.join("app/views/#{options[:ns]}", controller_file_name, "#{view}.html.haml")
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
52
|
def add_resource_route
|
51
53
|
return if not File.exists?("config/routes.rb")
|
52
|
-
route_config = "namespace :
|
54
|
+
route_config = "namespace #{options[:ns]}.to_sym do "
|
53
55
|
route_config << "resources :#{file_name.pluralize}"
|
54
56
|
route_config << " end"
|
55
57
|
route route_config
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe <%= options[:read_only].classify %>::<%= controller_class_name %>Controller do
|
4
4
|
|
5
5
|
def mock_<%= singular_table_name %>(stubs={})
|
6
6
|
(@mock_<%= singular_table_name %> ||= mock_model(<%= class_name %>).as_null_object).tap do |<%= singular_table_name %>|
|
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<%= human_name.pluralize %>
|
1
|
+
%h3
|
2
|
+
<%= human_name.pluralize %>
|
4
3
|
|
5
4
|
<% if options[:search_by].present? -%>
|
6
|
-
= search_form_for @q, :url =>
|
5
|
+
= search_form_for @q, :url => <%= options[:ns] %>_<%= plural_table_name %>_path, :html => { :method => :get, :class => "well form-inline" } do |f|
|
7
6
|
.class="form-group
|
8
7
|
= f.text_field :<%= options[:search_by] %>_cont, :type => "search", :class => "form-control", :placeholder => "Search by <%= options[:search_by] %>"
|
9
8
|
|
@@ -11,34 +10,34 @@
|
|
11
10
|
<% end %>
|
12
11
|
|
13
12
|
<% unless options[:no_create] || options[:read_only] %>
|
14
|
-
|
15
|
-
= link_to("Create a new <%= human_name %>",
|
13
|
+
%p
|
14
|
+
= link_to("Create a new <%= human_name %>", new_<%= options[:ns] %>_<%= singular_table_name %>_path)
|
16
15
|
<% end -%>
|
17
16
|
|
18
17
|
%table.sortable.table.table-striped.table-bordered.table-condensed
|
19
18
|
%thead
|
20
19
|
%tr
|
21
20
|
<% @attributes.each do |attribute| -%>
|
22
|
-
|
21
|
+
%th
|
23
22
|
= sortable "<%= attribute.name %>"
|
24
23
|
<% end -%>
|
25
24
|
<% unless options[:read_only] -%>
|
26
|
-
|
27
|
-
|
25
|
+
%th Edit
|
26
|
+
%th Delete
|
28
27
|
<% end -%>
|
29
28
|
%tbody
|
30
29
|
- @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
|
31
30
|
%tr.<%= singular_table_name %>
|
32
31
|
%td
|
33
|
-
= link_to(<%= singular_table_name %>.id,
|
32
|
+
= link_to(<%= singular_table_name %>.id, <%= options[:ns] %>_<%= singular_table_name %>_path(<%= singular_table_name %>)) %>
|
34
33
|
<% @attributes.each do |attribute| -%>
|
35
34
|
<% next if attribute.name == "id" -%>
|
36
35
|
%td
|
37
|
-
= <%= singular_table_name %>.<%= attribute.name %>
|
36
|
+
= <%= singular_table_name %>.<%= attribute.name %>
|
38
37
|
<% end -%>
|
39
38
|
<% unless options[:read_only] -%>
|
40
|
-
%td= link_to('Edit',
|
41
|
-
%td= link_to('Delete',
|
39
|
+
%td= link_to('Edit', edit_<%= options[:ns] %>_<%= singular_table_name %>_path(<%= singular_table_name %>))
|
40
|
+
%td= link_to('Delete', <%= options[:ns] %>_<%= singular_table_name %>_path(<%= singular_table_name %>), :confirm => "Are you sure?", :method => :delete)
|
42
41
|
<% end -%>
|
43
42
|
|
44
43
|
= paginate @<%= plural_table_name %>
|
data/lib/sharp_admin/version.rb
CHANGED
data/test/easy_admin_test.rb
CHANGED
@@ -24,6 +24,20 @@ class SharpAdminGeneratorTest < Rails::Generators::TestCase
|
|
24
24
|
assert_file "app/helpers/admin/base_helper.rb", /def sortable/
|
25
25
|
end
|
26
26
|
|
27
|
+
test "-ns option with namespace" do
|
28
|
+
run_generator %w(User --ns namespace)
|
29
|
+
assert_file "app/controllers/namespace/base_controller.rb", /class Admin::BaseController < ApplicationController/
|
30
|
+
assert_file "app/controllers/namespace/users_controller.rb", /class Admin::UsersController < Admin::BaseController/
|
31
|
+
assert_file "spec/controllers/namespace/base_controller_spec.rb", /describe Admin::BaseController do/
|
32
|
+
assert_file "spec/controllers/namespace/users_controller_spec.rb", /describe Admin::UsersController do/
|
33
|
+
assert_file "app/views/namespace/users/index.html.haml"
|
34
|
+
assert_file "app/views/namespace/users/show.html.haml"
|
35
|
+
assert_file "app/views/namespace/users/new.html.haml"
|
36
|
+
assert_file "app/views/namespace/users/edit.html.haml"
|
37
|
+
assert_file "app/views/namespace/users/_form.html.haml"
|
38
|
+
assert_file "app/helpers/namespace/base_helper.rb", /def sortable/
|
39
|
+
end
|
40
|
+
|
27
41
|
test "--no-create option skips assets to create new record" do
|
28
42
|
run_generator %w(User --no_create)
|
29
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sharp_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sharp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.4.8
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: generator for your admin.
|