scaf-generator 0.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.
- data/CHANGELOG +3 -0
- data/Gemfile +4 -0
- data/README.md +15 -0
- data/Rakefile +1 -0
- data/lib/generators/scaf/USAGE +8 -0
- data/lib/generators/scaf/scaf_generator.rb +74 -0
- data/lib/generators/scaf/templates/admin_controller.rb +46 -0
- data/lib/generators/scaf/templates/views/_formulario.html.erb +18 -0
- data/lib/generators/scaf/templates/views/edit.html.erb +5 -0
- data/lib/generators/scaf/templates/views/index.html.erb +12 -0
- data/lib/generators/scaf/templates/views/new.html.erb +5 -0
- data/lib/generators/scaf/templates/views/nombre.html.erb +12 -0
- data/lib/scaf-generator/version.rb +5 -0
- data/lib/scaf-generator.rb +7 -0
- data/scaf-generator.gemspec +24 -0
- metadata +60 -0
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Scaf-Generator
|
2
|
+
|
3
|
+
Un generador Scaffold-like adaptado a las necesidades de Xaver.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add to your Gemfile and run the `bundle` command to install it.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "scaf-generator"
|
12
|
+
```
|
13
|
+
|
14
|
+
**Requires Ruby 1.9.2 or later.**
|
15
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rails/generators/generated_attribute'
|
2
|
+
|
3
|
+
class ScafGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
no_tasks { attr_accessor :scaffold_name, :attributes}
|
7
|
+
argument :scaffold_name, :type => :string, :required => true
|
8
|
+
argument :arguments, :type => :array, :default => [], :banner => 'attributes'
|
9
|
+
|
10
|
+
def initialize(*args, &block)
|
11
|
+
super
|
12
|
+
|
13
|
+
# Inicializa la variable de instancia @attributos a partir de los argumentos
|
14
|
+
obtener_atributos
|
15
|
+
|
16
|
+
# Genera un Controller
|
17
|
+
generate "controller", "#{scaffold_name}"
|
18
|
+
|
19
|
+
# Genera un Scaffold sin Controller ni Vistas
|
20
|
+
generate("scaffold", "#{scaffold_name} #{arguments.join(' ')} --no-scaffold-controller")
|
21
|
+
|
22
|
+
# Agrega controller de administracion en controllers/admin/
|
23
|
+
template 'admin_controller.rb', "app/controllers/admin/#{plural_name}_controller.rb"
|
24
|
+
|
25
|
+
# Agrega Vistas en views/admin/
|
26
|
+
%w[index new edit _formulario].each do |action|
|
27
|
+
template "views/#{action}.html.erb", "app/views/admin/#{plural_name}/#{action}.html.erb"
|
28
|
+
end
|
29
|
+
template "views/nombre.html.erb", "app/views/admin/#{plural_name}/_#{singular_name}.html.erb"
|
30
|
+
|
31
|
+
# Agrega Ruta en namespace :admin
|
32
|
+
inject_into_file 'config/routes.rb', "\n resources :#{plural_name}" , :after => /namespace :admin do/
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def obtener_atributos
|
38
|
+
@attributes = []
|
39
|
+
|
40
|
+
arguments.each do |arg|
|
41
|
+
@attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
42
|
+
end
|
43
|
+
|
44
|
+
@attributes.uniq!
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def singular_name; scaffold_name.underscore; end
|
49
|
+
def plural_name; scaffold_name.underscore.pluralize; end
|
50
|
+
|
51
|
+
def table_name; end
|
52
|
+
|
53
|
+
def class_name; scaffold_name.split('::').last.camelize; end
|
54
|
+
def model_path; class_name.underscore; end
|
55
|
+
def plural_class_name; plural_name.camelize; end
|
56
|
+
|
57
|
+
def item; singular_name.split('/').last; end
|
58
|
+
def items; item.pluralize; end
|
59
|
+
|
60
|
+
def item_resource; scaffold_name.underscore.gsub('/','_'); end
|
61
|
+
|
62
|
+
def admin_items_path; "admin_#{items_path}"; end
|
63
|
+
|
64
|
+
def items_path; "#{items}_path"; end
|
65
|
+
|
66
|
+
def admin_item_path; "admin_#{item}_path"; end
|
67
|
+
def admin_items_path; "admin_#{items}_path"; end
|
68
|
+
|
69
|
+
def admin_show_path; admin_item_path; end
|
70
|
+
def admin_index_path; admin_items_path; end
|
71
|
+
def admin_new_path; "new_admin_#{item}_path"; end
|
72
|
+
def admin_edit_path; "edit_admin_#{item}_path"; end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Admin::<%= plural_class_name %>Controller < Admin::AdminController
|
2
|
+
# include Sortable
|
3
|
+
load_and_authorize_resource
|
4
|
+
|
5
|
+
def index
|
6
|
+
@<%= item %> = <%= class_name %>.new
|
7
|
+
@<%= items %> = <%= class_name %>.page params[:page]
|
8
|
+
end
|
9
|
+
|
10
|
+
def new; end
|
11
|
+
def edit; end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@<%= item %> = <%= class_name %>.new params[:<%= item %>]
|
15
|
+
@<%= item %>.save!
|
16
|
+
respond_to do |format|
|
17
|
+
format.html { redirect_to <%= admin_index_path %>, notice: (flash.now.notice = translate_notice) }
|
18
|
+
format.js { @elemento = @<%= item %> }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def update
|
23
|
+
@<%= item %>.update_attributes! params[:<%= item %>]
|
24
|
+
redirect_to <%= admin_edit_path %>(@<%= item %>), notice: translate_notice
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy
|
28
|
+
@id = @<%= item %>.id
|
29
|
+
@<%= item %>.eliminar!
|
30
|
+
|
31
|
+
respond_to do |format|
|
32
|
+
format.html { redirect_to <%= admin_items_path %>, notice: (flash.now.notice = translate_notice) }
|
33
|
+
format.js
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# def sort_coleccion
|
40
|
+
# <%= class_name %>.scoped
|
41
|
+
# end
|
42
|
+
|
43
|
+
def translate_notice
|
44
|
+
t("notice.#{action_name}", :elemento => @<%= item %>)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%%- mini = false if mini.nil? %>
|
2
|
+
<%%- opciones = { :class => (mini.present? ? :mini : :normal) } -%>
|
3
|
+
<%%- remote = false if remote.nil? -%>
|
4
|
+
|
5
|
+
<%%= simple_form_for <%= item %> , :url => url, :remote => remote, :html => opciones do |f| %>
|
6
|
+
<%%- if mini -%>
|
7
|
+
<%%- else -%>
|
8
|
+
<%- attributes.each do |attribute| -%>
|
9
|
+
<%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
|
10
|
+
<%- end -%>
|
11
|
+
<%%- end -%>
|
12
|
+
<%%= f.button :submit, :name => nil, :disable_with => t("espere") %>
|
13
|
+
<%%- end -%>
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h1><%= plural_name.titleize %><h1>
|
2
|
+
<nav>
|
3
|
+
<%%= link_to "Mostrar formulario", "#mostrar-formulario", :class => :"mostrar-formulario" %>
|
4
|
+
<%%= link_to "Agregar <%= item %> ", new_admin_<%= item %>_path %>
|
5
|
+
</nav>
|
6
|
+
|
7
|
+
<%%= render "formulario", :<%= item %> => @<%= item %>, :url => <%= admin_items_path %>, :mini => true, :remote => true %>
|
8
|
+
<%%= content_tag :section, :id => :listado, :class => [:listado, :ordenable] do %>
|
9
|
+
<%%= render "header" %>
|
10
|
+
<%%= render @<%= items %> %>
|
11
|
+
<%%= hidden_field_tag :url, reordenar_admin_<%= items %>_path, :class => :url %>
|
12
|
+
<%%- end -%>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%%- clase = nil if clase.nil? -%>
|
2
|
+
|
3
|
+
<%%= content_tag :article, :id => "elementos_#{<%= item %>.id}", :class => clase.presence || cycle(:impar, :par, :name => :listado) do %>
|
4
|
+
<%%= link_to <%= admin_item_path %>(<%= item %>) do %>
|
5
|
+
# <%%= <%= item %>.nombre %>
|
6
|
+
<%%- end -%>
|
7
|
+
<aside>
|
8
|
+
<%%= link_to "Ordenar", "javascript:(return false)", :title => "Mantenga click y arrastre para reordenar", :class => "arrastrable principal" %>
|
9
|
+
<%%= link_to "Editar", edit_admin_<%= item %>_path(<%= item %>) if can? :editar, <%= item %> %>
|
10
|
+
<%%= link_to "Eliminar", admin_<%= item %>_path(<%= item %>), :method => :delete, :confirm => t("confirmacion"), :remote => true %>
|
11
|
+
</aside>
|
12
|
+
<%%- end -%>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "scaf-generator/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "scaf-generator"
|
7
|
+
s.version = Scaf::Generator::VERSION
|
8
|
+
s.authors = ["Nicanor Perera"]
|
9
|
+
s.email = ["nicanorperera@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/nicanorperera/scaf-generator"
|
11
|
+
s.summary = %q{Un Scaffold Generator con Controller en namespace::Admin}
|
12
|
+
s.description = %q{Scaffold adaptado a las necesidades de Xaver}
|
13
|
+
|
14
|
+
s.rubyforge_project = "scaf-generator"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scaf-generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicanor Perera
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Scaffold adaptado a las necesidades de Xaver
|
15
|
+
email:
|
16
|
+
- nicanorperera@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- CHANGELOG
|
22
|
+
- Gemfile
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/generators/scaf/USAGE
|
26
|
+
- lib/generators/scaf/scaf_generator.rb
|
27
|
+
- lib/generators/scaf/templates/admin_controller.rb
|
28
|
+
- lib/generators/scaf/templates/views/_formulario.html.erb
|
29
|
+
- lib/generators/scaf/templates/views/edit.html.erb
|
30
|
+
- lib/generators/scaf/templates/views/index.html.erb
|
31
|
+
- lib/generators/scaf/templates/views/new.html.erb
|
32
|
+
- lib/generators/scaf/templates/views/nombre.html.erb
|
33
|
+
- lib/scaf-generator.rb
|
34
|
+
- lib/scaf-generator/version.rb
|
35
|
+
- scaf-generator.gemspec
|
36
|
+
homepage: http://github.com/nicanorperera/scaf-generator
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project: scaf-generator
|
56
|
+
rubygems_version: 1.8.15
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Un Scaffold Generator con Controller en namespace::Admin
|
60
|
+
test_files: []
|