lightek_vpm 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/controller_generator.rb +45 -0
- data/lib/generators/generator_helpers.rb +50 -0
- data/lib/generators/init_generator.rb +54 -0
- data/lib/generators/templates/controller.rb +47 -0
- data/lib/generators/templates/views/_form.html.erb +26 -0
- data/lib/generators/templates/views/edit.html.erb +2 -0
- data/lib/generators/templates/views/index.html.erb +19 -0
- data/lib/generators/templates/views/new.html.erb +2 -0
- data/lib/generators/templates/views/show.html.erb +12 -0
- data/lib/lightek_vpm/version.rb +1 -1
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4980bdeffe1b52d125d49b41e31337f7454eae3aca53185c0a36e2dbda58a10
|
4
|
+
data.tar.gz: 6230460a556b07e88f52cd4c0f941f7c6b438a31907cd6c6929d00a8a38800eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aaf5ce8f2873da6f818eb6ce8f22d590f5175d2f4c4a2e946dfa734c7e9cf3a49ea3994cdf1e6f0c931005ebf293b10c6478f7e88abd97b471938b25baa8ddd
|
7
|
+
data.tar.gz: 64d7a97e7091965ce95bc7dd656779e9171e97ec003e9429e2326fb1993ffa05d7387d4be663e3b6e777c01d9650bd77d5c663f7375378da71c362d2ece37176
|
@@ -0,0 +1,45 @@
|
|
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
|
@@ -0,0 +1,50 @@
|
|
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
|
@@ -0,0 +1,54 @@
|
|
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
|
@@ -0,0 +1,47 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
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 %%>" %>
|
@@ -0,0 +1,19 @@
|
|
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>
|
@@ -0,0 +1,12 @@
|
|
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>
|
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.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marlon Henry
|
@@ -17,6 +17,9 @@ 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
|
20
23
|
- lib/generators/lightek_vpm/controller_generator.rb
|
21
24
|
- lib/generators/lightek_vpm/generator_helpers.rb
|
22
25
|
- lib/generators/lightek_vpm/init_generator.rb
|
@@ -27,6 +30,12 @@ files:
|
|
27
30
|
- lib/generators/lightek_vpm/templates/views/new.html.erb
|
28
31
|
- lib/generators/lightek_vpm/templates/views/show.html.erb
|
29
32
|
- 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
|
30
39
|
- lib/generators/test_generator.rb
|
31
40
|
- lib/lightek_vpm.rb
|
32
41
|
- lib/lightek_vpm/version.rb
|