lightek_vpm 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/lightek_vpm/controller_generator.rb +39 -40
- data/lib/generators/lightek_vpm/generator_helpers.rb +1 -1
- data/lib/lightek_vpm/version.rb +1 -1
- metadata +1 -11
- data/lib/generators/controller_generator.rb +0 -45
- data/lib/generators/generator_helpers.rb +0 -50
- data/lib/generators/init_generator.rb +0 -54
- data/lib/generators/templates/controller.rb +0 -47
- data/lib/generators/templates/views/_form.html.erb +0 -26
- data/lib/generators/templates/views/edit.html.erb +0 -2
- data/lib/generators/templates/views/index.html.erb +0 -19
- data/lib/generators/templates/views/new.html.erb +0 -2
- data/lib/generators/templates/views/show.html.erb +0 -12
- data/lib/generators/test_generator.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3d1bed86ba80696b8278e8d43b324501cbab7face5be0df875dde95773adeba
|
4
|
+
data.tar.gz: e737bf277544478c2c61d5a1bd6596072b4d6ebd4a739ebb744a72731773849f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8feaf2c50f82cfa960704d865bc203fe35870fd025f6881091929e658baf1d079d5d149ced1ff4b25abf02469d9919e1a92d0742f01166bf351a1ef8280b6da2
|
7
|
+
data.tar.gz: e581536a16f1740d6a8a30bcf1d6be2282a81f7d0d489dc7fb0b492765aa0e1ecf5c81cf6c4777aeb46cb21d2ecb8f753d6b34c569d3d05abf6ca5e7fe19ceda
|
@@ -1,45 +1,44 @@
|
|
1
|
-
source_root File.expand_path('../templates', __FILE__)
|
2
1
|
require 'rails/generators'
|
3
2
|
require 'generators/lightek_vpm/generator_helpers'
|
4
|
-
module LightekVpm
|
5
|
-
module Generators
|
6
|
-
# Custom scaffolding generator
|
7
|
-
class ControllerGenerator < Rails::Generators::NamedBase
|
8
|
-
include Rails::Generators::ResourceHelper
|
9
|
-
class_option :skip_show, type: :boolean, default: false, desc: "Skip "show" action"
|
10
|
-
|
11
|
-
desc 'Generates controller, controller_spec and views for the model with the given NAME.'
|
12
|
-
|
13
|
-
def copy_controller_and_spec_files
|
14
|
-
template "controller.rb", File.join("app/controllers", "#{controller_file_name}_controller.rb")
|
15
|
-
end
|
16
3
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
4
|
+
module LightekVpm
|
5
|
+
module Generators
|
6
|
+
# Custom scaffolding generator
|
7
|
+
class ControllerGenerator < Rails::Generators::NamedBase
|
8
|
+
include Rails::Generators::ResourceHelper
|
9
|
+
class_option :skip_show, type: :boolean, default: false, desc: 'Skip "show" action'
|
10
|
+
|
11
|
+
desc 'Generates controller, controller_spec and views for the model with the given NAME.'
|
12
|
+
|
13
|
+
def copy_controller_and_spec_files
|
14
|
+
template 'controller.rb', File.join('app/controllers', "#{controller_file_name}_controller.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_view_files
|
18
|
+
directory_path = File.join('app/views', controller_file_path)
|
19
|
+
empty_directory directory_path
|
20
|
+
|
21
|
+
view_files.each do |file_name|
|
22
|
+
template "views/#{file_name}.html.erb", File.join(directory_path, "#{file_name}.html.erb")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_routes
|
27
|
+
routes_string = "resources :#{singular_name}"
|
28
|
+
routes_string += ', except: :show' unless show_action?
|
29
|
+
route routes_string
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_abilities
|
33
|
+
ability_string = "n can :manage, #{class_name}, user_id: user.id"
|
34
|
+
inject_into_file "#{Rails.root}/app/models/ability.rb", ability_string, after: /def initialize[a-z()]+/i
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def show_action?
|
40
|
+
!options['skip_show']
|
41
|
+
end
|
23
42
|
end
|
24
43
|
end
|
25
|
-
|
26
|
-
def add_routes
|
27
|
-
routes_string = "resources :#{singular_name}"
|
28
|
-
routes_string += ', except: :show' unless show_action?
|
29
|
-
route routes_string
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_abilities
|
33
|
-
ability_string = "n can :manage, #{class_name}, user_id: user.id"
|
34
|
-
inject_into_file "#{Rails.root}/app/models/ability.rb", ability_string, after: /def initialize[a-z()]+/i
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def show_action?
|
40
|
-
!options['skip_show']
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
44
|
+
end
|
data/lib/lightek_vpm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightek_vpm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marlon Henry
|
@@ -17,9 +17,6 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- lib/generators/controller_generator.rb
|
21
|
-
- lib/generators/generator_helpers.rb
|
22
|
-
- lib/generators/init_generator.rb
|
23
20
|
- lib/generators/lightek_vpm/controller_generator.rb
|
24
21
|
- lib/generators/lightek_vpm/generator_helpers.rb
|
25
22
|
- lib/generators/lightek_vpm/init_generator.rb
|
@@ -30,13 +27,6 @@ files:
|
|
30
27
|
- lib/generators/lightek_vpm/templates/views/new.html.erb
|
31
28
|
- lib/generators/lightek_vpm/templates/views/show.html.erb
|
32
29
|
- lib/generators/lightek_vpm/test_generator.rb
|
33
|
-
- lib/generators/templates/controller.rb
|
34
|
-
- lib/generators/templates/views/_form.html.erb
|
35
|
-
- lib/generators/templates/views/edit.html.erb
|
36
|
-
- lib/generators/templates/views/index.html.erb
|
37
|
-
- lib/generators/templates/views/new.html.erb
|
38
|
-
- lib/generators/templates/views/show.html.erb
|
39
|
-
- lib/generators/test_generator.rb
|
40
30
|
- lib/lightek_vpm.rb
|
41
31
|
- lib/lightek_vpm/version.rb
|
42
32
|
homepage: http://lighteksystems.tech
|
@@ -1,45 +0,0 @@
|
|
1
|
-
source_root File.expand_path('../templates', __FILE__)
|
2
|
-
require 'rails/generators'
|
3
|
-
require 'generators/lightek_vpm/generator_helpers'
|
4
|
-
module LightekVpm
|
5
|
-
module Generators
|
6
|
-
# Custom scaffolding generator
|
7
|
-
class ControllerGenerator < Rails::Generators::NamedBase
|
8
|
-
include Rails::Generators::ResourceHelper
|
9
|
-
class_option :skip_show, type: :boolean, default: false, desc: "Skip "show" action"
|
10
|
-
|
11
|
-
desc 'Generates controller, controller_spec and views for the model with the given NAME.'
|
12
|
-
|
13
|
-
def copy_controller_and_spec_files
|
14
|
-
template "controller.rb", File.join("app/controllers", "#{controller_file_name}_controller.rb")
|
15
|
-
end
|
16
|
-
|
17
|
-
def copy_view_files
|
18
|
-
directory_path = File.join("app/views", controller_file_path)
|
19
|
-
empty_directory directory_path
|
20
|
-
|
21
|
-
view_files.each do |file_name|
|
22
|
-
template "views/#{file_name}.html.erb", File.join(directory_path, "#{file_name}.html.erb")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def add_routes
|
27
|
-
routes_string = "resources :#{singular_name}"
|
28
|
-
routes_string += ', except: :show' unless show_action?
|
29
|
-
route routes_string
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_abilities
|
33
|
-
ability_string = "n can :manage, #{class_name}, user_id: user.id"
|
34
|
-
inject_into_file "#{Rails.root}/app/models/ability.rb", ability_string, after: /def initialize[a-z()]+/i
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def show_action?
|
40
|
-
!options['skip_show']
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module LightekVpm
|
2
|
-
module Generators
|
3
|
-
# Some helpers for generating scaffolding
|
4
|
-
module GeneratorHelpers
|
5
|
-
|
6
|
-
attr_accessor :options, :attributes
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
|
-
def model_columns_for_attributes
|
11
|
-
class_name.constantize.columns.reject do |column|
|
12
|
-
column.name.to_s =~ /^(id|user_id|created_at|updated_at)$/
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def editable_attributes
|
17
|
-
attributes ||= model_columns_for_attributes.map do |column|
|
18
|
-
Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def view_files
|
23
|
-
actions = %w(index new edit _form)
|
24
|
-
actions << 'show' if show_action?
|
25
|
-
actions
|
26
|
-
end
|
27
|
-
|
28
|
-
def all_actions
|
29
|
-
actions = %w(index new create edit update destroy)
|
30
|
-
actions << 'show' if show_action?
|
31
|
-
actions
|
32
|
-
end
|
33
|
-
|
34
|
-
def controller_methods(dir_name)
|
35
|
-
all_actions.map do |action|
|
36
|
-
read_template("#{dir_name}/#{action}.rb")
|
37
|
-
end.join("n").strip
|
38
|
-
end
|
39
|
-
|
40
|
-
def read_template(relative_path)
|
41
|
-
ERB.new(File.read(source_path(relative_path)), nil, '-').result(binding)
|
42
|
-
end
|
43
|
-
|
44
|
-
def source_path(relative_path)
|
45
|
-
File.expand_path(File.join("../templates/", relative_path), __FILE__)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
End
|
@@ -1,54 +0,0 @@
|
|
1
|
-
source_root File.expand_path('../templates', __FILE__)
|
2
|
-
require 'rails/generators'
|
3
|
-
module LightekVpm
|
4
|
-
module Generators
|
5
|
-
class InitGenerator < Rails::Generators::Base
|
6
|
-
|
7
|
-
def add_gems_needed
|
8
|
-
desc "Adding the gems and models needed for base work"
|
9
|
-
# Add Bootstrap gem
|
10
|
-
puts "Adding Bootstrap gem..."
|
11
|
-
gem 'bootstrap', '~> 5.3.3'
|
12
|
-
|
13
|
-
# Run bundle install
|
14
|
-
puts "Running bundle install..."
|
15
|
-
Bundler.with_clean_env { run 'bundle install' }
|
16
|
-
|
17
|
-
# Add Devise gem
|
18
|
-
puts "Adding Devise gem..."
|
19
|
-
gem 'devise'
|
20
|
-
Bundler.with_clean_env { run 'bundle install' }
|
21
|
-
|
22
|
-
# Run Devise installation
|
23
|
-
puts "Now installing Devise..."
|
24
|
-
generate 'devise:install'
|
25
|
-
|
26
|
-
# Create Devise User model
|
27
|
-
puts "Creating User model with Devise..."
|
28
|
-
generate 'devise User role:integer first_name:string last_name:string bio:text website:string twitter:string facebook:string instagram:string dob:date street:string city:string state:string'
|
29
|
-
puts "Running db migration for user"
|
30
|
-
rake 'db:migrate'
|
31
|
-
|
32
|
-
|
33
|
-
# Add CanCanCan gem
|
34
|
-
puts "Adding CanCanCan gem..."
|
35
|
-
gem 'cancancan'
|
36
|
-
Bundler.with_clean_env { run 'bundle install' }
|
37
|
-
|
38
|
-
# Run CanCanCan installation (if needed)
|
39
|
-
# Replace the following lines with CanCanCan installation commands if necessary
|
40
|
-
|
41
|
-
# Add ActionText gem
|
42
|
-
puts "Adding ActionText gem..."
|
43
|
-
gem 'actiontext'
|
44
|
-
Bundler.with_clean_env { run 'bundle install' }
|
45
|
-
|
46
|
-
# Install Action Text
|
47
|
-
puts "Installing Action Text..."
|
48
|
-
generate 'action_text:install'
|
49
|
-
rake 'db:migrate'
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
-
before_action :authenticate_user!
|
3
|
-
load_and_authorize_resource
|
4
|
-
|
5
|
-
def index
|
6
|
-
end
|
7
|
-
|
8
|
-
<% if show_action? -%>
|
9
|
-
|
10
|
-
def show
|
11
|
-
end
|
12
|
-
<% end -%>
|
13
|
-
|
14
|
-
def new
|
15
|
-
end
|
16
|
-
|
17
|
-
def create
|
18
|
-
if @<%= singular_name %>.save
|
19
|
-
redirect_to @<%= singular_name %>, notice: '<%= human_name %> was successfully created.'
|
20
|
-
else
|
21
|
-
render :new
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def edit
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
if @<%= singular_name %>.update(<%= singular_name %>_params)
|
30
|
-
redirect_to @<%= singular_name %>, notice: '<%= human_name %> was successfully updated.'
|
31
|
-
else
|
32
|
-
render :edit
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def destroy
|
37
|
-
@<%= singular_name %>.destroy
|
38
|
-
redirect_to <%= plural_name %>_url, notice: '<%= human_name %> was successfully destroyed.'
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def <%= singular_name %>_params
|
44
|
-
params.require(:<%= singular_name %>).permit(<%= editable_attributes.map { |a| a.name.prepend(':') }.join(', ') %>)
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
<%= "<%= form_for @#{singular_name} do |f| %%>" %>
|
2
|
-
|
3
|
-
<div class="row">
|
4
|
-
<div class="col-md-4">
|
5
|
-
<%= "<% if @#{singular_name}.errors.any? %%>" %>
|
6
|
-
<div id="error_explanation">
|
7
|
-
<%= "<h2><%= pluralize(@#{singular_name}.errors.count, 'error') %%>" %> prohibited this <%= class_name %> from being saved:</h2>
|
8
|
-
<ul class="list-unstyled">
|
9
|
-
<%= "<% @#{singular_name}.errors.full_messages.each do |message| %%>" %>
|
10
|
-
<%= "<li><%= message %%></li>" %>
|
11
|
-
<%= "<% end %%>" %>
|
12
|
-
</ul>
|
13
|
-
</div>
|
14
|
-
<%= "<% end %%>" %>
|
15
|
-
<% editable_attributes.each do |attribute| %>
|
16
|
-
<div class="form-group">
|
17
|
-
<%= "<%= f.label :#{attribute.name} %%>" %>
|
18
|
-
<%= "<%= f.#{attribute.field_type} :#{attribute.name}, class: \"form-control\" %%>" %>
|
19
|
-
</div>
|
20
|
-
<% end -%>
|
21
|
-
|
22
|
-
<%= "<%= f.submit 'Submit', class: \"btn btn-success\" %%>" %>
|
23
|
-
</div>
|
24
|
-
</div>
|
25
|
-
|
26
|
-
<%= "<% end %%>" %>
|
@@ -1,19 +0,0 @@
|
|
1
|
-
<%= "<%= link_to 'Create new', new_#{singular_name}_path, class: 'btn btn-primary btn-sm mb-2' %%>" %>
|
2
|
-
|
3
|
-
<table class="table table-sm">
|
4
|
-
<tbody>
|
5
|
-
<%= "<% @#{plural_name}.each do |#{singular_name}| %%>" %>
|
6
|
-
<tr>
|
7
|
-
<td> <%= "<%= #{singular_name}.id %%>" %> </td>
|
8
|
-
<td> [ADD INFO] </td>
|
9
|
-
<td>
|
10
|
-
<% if show_action? -%>
|
11
|
-
<%= "<%= link_to 'Show', #{singular_name}_path(#{singular_name}), class: 'btn btn-sm btn-outline-info' %%>" %>
|
12
|
-
<% end -%>
|
13
|
-
<%= "<%= link_to 'Edit', edit_#{singular_name}_path(#{singular_name}), class: 'btn btn-sm btn-outline-info' %%>" %>
|
14
|
-
<%= "<%= link_to 'Destroy', #{singular_name}_path(#{singular_name}), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-outline-danger' %%>" %>
|
15
|
-
</td>
|
16
|
-
</tr>
|
17
|
-
<%= "<% end %%>" %>
|
18
|
-
</tbody>
|
19
|
-
</table>
|
@@ -1,12 +0,0 @@
|
|
1
|
-
<div>
|
2
|
-
<% editable_attributes.each do |attribute| -%>
|
3
|
-
<dl class="row">
|
4
|
-
<dt class="col-sm-3"><%= attribute.human_name.titleize %>:</dt>
|
5
|
-
<dd class="col-sm-9"><%= "<%= @#{singular_name}.#{attribute.name} %%>" %></dd>
|
6
|
-
</dl>
|
7
|
-
<% end -%>
|
8
|
-
</div>
|
9
|
-
<p>
|
10
|
-
<%= "<%= link_to 'Edit', edit_#{singular_name}_path(@#{singular_name}), class: 'btn btn-sm btn-outline-info' %%>" %>
|
11
|
-
<%= "<%= link_to 'Destroy', #{singular_name}_path(@#{singular_name}), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-outline-danger' %%>" %>
|
12
|
-
</p>
|