sharp_admin 0.0.1 → 1.0.1

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: d833990187e75b9fedc524e9bd1fab0b8dcab152
4
- data.tar.gz: f0a52fe45bc1dd7ca08380d38aa8a3973a6e3bd5
3
+ metadata.gz: 0e5c5ac1533bb18d44fbdd64810313d26f6241e5
4
+ data.tar.gz: 74b63c9887268ac4b688a345ec3089efe837d8d6
5
5
  SHA512:
6
- metadata.gz: 2188637259156f62c06a2ace1c46b502d4cd14de4ea690bf16152f6515c5032f501d9817c09b4f279e486f9048f1a2742190ae5c5cdeb6a4fd05ee144b3245dc
7
- data.tar.gz: 53863881c2c65db47d478160c6ed31a78053347ad281785d9707cf2c64dbf222135d6ff4bd68a2b0bc00ced12ca6887a66497d9d323dc990e1d15111cfe261b5
6
+ metadata.gz: ab4b9883e33f42566424414c8a75e53aff8623da045ea7f335382f6f03a98b90e9946a4bb8001d70c070e524a446b12c73d8ed85506bbc11a8f823e0f69ebf86
7
+ data.tar.gz: 65ce854f4dbc9b0b0e45b1a0962611dba00c2943609e76ccb1cb30ce53f87c3f0a1c386ffa439061ef7a288021a4f7831c688f3b92afbe4af4de34b11a70bc33
data/lib/sharp_admin.rb CHANGED
@@ -1,2 +1,5 @@
1
+
2
+ require 'sharp_admin/sharp_admin_generator'
3
+
1
4
  module SharpAdmin
2
5
  end
@@ -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/admin"
18
- path = File.join("app/controllers/admin", "base_controller.rb")
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/admin"
24
- path = File.join("spec/controllers/admin", "base_controller_spec.rb")
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/admin", "#{controller_file_name}_controller.rb")
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/admin", "#{controller_file_name}_controller_spec.rb")
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/admin"
39
- template "base_helper.rb", File.join("app/helpers/admin", "base_helper.rb")
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/admin/#{controller_file_name}"
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/admin", controller_file_name, "#{view}.html.haml")
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 :admin do "
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,4 +1,4 @@
1
- module Admin::BaseHelper
1
+ module <%= options[:read_only].classify %>::BaseHelper
2
2
 
3
3
  def sortable(column, title = nil)
4
4
  title ||= column.titleize
@@ -1,4 +1,4 @@
1
- class Admin::<%= controller_class_name %>Controller < Admin::BaseController
1
+ class <%= options[:read_only].classify %>::<%= controller_class_name %>Controller < <%= options[:read_only].classify %>::BaseController
2
2
 
3
3
  helper_method :sort_column, :sort_direction
4
4
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Admin::<%= controller_class_name %>Controller do
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
- .page-header
2
- %h3
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 => admin_<%= plural_table_name %>_path, :html => { :method => :get, :class => "well form-inline" } do |f|
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
- <p>
15
- = link_to("Create a new <%= human_name %>", new_admin_<%= singular_table_name %>_path)
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
- <th>
21
+ %th
23
22
  = sortable "<%= attribute.name %>"
24
23
  <% end -%>
25
24
  <% unless options[:read_only] -%>
26
- <th> Edit
27
- <th> Delete
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, admin_<%= singular_table_name %>_path(<%= singular_table_name %>)) %>
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', edit_admin_<%= singular_table_name %>_path(<%= singular_table_name %>))
41
- %td= link_to('Delete', admin_<%= singular_table_name %>_path(<%= singular_table_name %>), :confirm => "Are you sure?", :method => :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 %>
@@ -1,3 +1,3 @@
1
1
  module EasyAdmin
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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: 0.0.1
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-19 00:00:00.000000000 Z
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.2.2
101
+ rubygems_version: 2.4.8
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: generator for your admin.