foldscaf 1.0.6 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -0
- data/README.md +5 -5
- data/Rakefile +1 -1
- data/foldscaf.gemspec +8 -4
- data/lib/foldscaf.rb +0 -1
- data/lib/generators/fold/USAGE +18 -13
- data/lib/generators/fold/fold_generator.rb +44 -62
- data/lib/generators/fold/helpers/fold.rb +9 -0
- data/lib/generators/fold/helpers/paths.rb +43 -0
- data/lib/generators/fold/helpers/routes.rb +30 -0
- data/lib/generators/fold/helpers/templates.rb +35 -0
- data/lib/generators/fold/templates/admin_controller.rb +51 -0
- data/lib/generators/fold/templates/controller.rb +8 -0
- data/lib/generators/fold/templates/migration.rb +23 -0
- data/lib/generators/fold/templates/model.rb +62 -0
- data/lib/generators/fold/templates/views/_form.html.erb +9 -0
- data/lib/generators/fold/templates/views/_partial.html.erb +6 -0
- data/lib/generators/fold/templates/views/edit.html.erb +11 -0
- data/lib/generators/fold/templates/views/index.html.erb +15 -0
- data/lib/generators/fold/templates/views/new.html.erb +8 -0
- data/lib/version.rb +1 -1
- metadata +94 -22
- data/lib/generators/fold/atributo.rb +0 -54
- data/lib/generators/fold/templates/admin_controller.erb +0 -53
- data/lib/generators/fold/templates/cargar.erb +0 -9
- data/lib/generators/fold/templates/controller.erb +0 -4
- data/lib/generators/fold/templates/migration.erb +0 -23
- data/lib/generators/fold/templates/model.erb +0 -25
- data/lib/generators/fold/templates/views/_form.erb +0 -9
- data/lib/generators/fold/templates/views/edit.erb +0 -8
- data/lib/generators/fold/templates/views/index.erb +0 -22
- data/lib/generators/fold/templates/views/new.erb +0 -13
- data/lib/generators/fold/templates/views/nombre.erb +0 -10
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjFjOWZhMmRlNjZmNGQ1YjJiMjA1NGNjODkxZGViYTQzM2E5NTM4OA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODMyODFjYWVmZjM1MjNlMGIzNDI1NzMzMGNlNDIyZDJiOWFiYjVmZg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YmU0ZGMxMTk3MzY3OWUxNWJlMjZiOWU5NGM1NjBjYzc3MWU0NzExMWNjMzVk
|
10
|
+
YmIzMWZjNzkwZDliOTZlM2VmMTZjMjY2NTllNjcxZDVhZjkwYzE3Yjg4YTQw
|
11
|
+
OWUyNGU0NjY1NDUyZTYxZTdjOWM1YzMwMjk3ODRhODFkNjc0OTE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODBhZDIzYzZjYzBhNTY2NDc0NDI5MThhNDZhN2FmMWQ0YzQ5MjFmMDY4ODdm
|
14
|
+
NjRhZTU3OWVmNjI3Mjc5Mjk3NWRlZmZjZjM0MGY2ZTZiODhkMmViNGFhMTM4
|
15
|
+
MDdmNTdlNzM3MDUxZGE5MDVjODc5ZWI1MDUyZmE2YWZkZWJhYzE=
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Incluye varios generadores adaptados a las necesidades de Xaver.
|
4
4
|
Debe usarse en conjunto con el template de Xaver.
|
5
|
-
Versión 1.0.0 Presenta incompatibilidades con versiones pasadas y con XaverTemplates <= 1.0.0
|
6
|
-
Con recaudos, puede usarse en versiones anteriores de XaverTemplate,
|
7
5
|
|
8
6
|
## Instalación
|
9
7
|
|
10
|
-
Agrega al Gemfile y ejecuta el comando `bundle` para instalarlo.
|
8
|
+
Agrega al Gemfile y ejecuta el comando `bundle install` para instalarlo.
|
11
9
|
|
12
10
|
```ruby
|
13
|
-
|
11
|
+
group :development do
|
12
|
+
gem "foldscaf"
|
13
|
+
end
|
14
14
|
```
|
15
15
|
|
16
|
-
**Requiere Ruby 1.9.2 o superior.**
|
16
|
+
**Requiere Ruby 1.9.2 o superior.**
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
require "bundler/gem_tasks"
|
data/foldscaf.gemspec
CHANGED
@@ -5,9 +5,9 @@ require "version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "foldscaf"
|
7
7
|
s.version = Foldscaf::VERSION
|
8
|
-
s.authors = ["Nicanor Perera"]
|
9
|
-
s.email = ["nicanorperera@gmail.com"]
|
10
|
-
s.homepage = "http://github.com/
|
8
|
+
s.authors = ["Nicanor Perera", "Gustavo Molinari"]
|
9
|
+
s.email = ["nicanorperera@gmail.com", "gustavo.molinari@xaver.com.ar"]
|
10
|
+
s.homepage = "http://github.com/Xaver/foldscaf"
|
11
11
|
s.summary = %q{Generadores adaptados a las necesidades de Xaver}
|
12
12
|
s.description = %q{Generadores adaptados a las necesidades de Xaver}
|
13
13
|
|
@@ -20,5 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
22
|
# s.add_development_dependency "rspec"
|
23
|
-
|
23
|
+
s.add_runtime_dependency "sorcery"
|
24
|
+
s.add_runtime_dependency "simple_form"
|
25
|
+
s.add_runtime_dependency "friendly_id"
|
26
|
+
s.add_runtime_dependency "cancan"
|
27
|
+
s.add_runtime_dependency "dragonfly"
|
24
28
|
end
|
data/lib/foldscaf.rb
CHANGED
data/lib/generators/fold/USAGE
CHANGED
@@ -1,18 +1,23 @@
|
|
1
|
-
|
1
|
+
Descripción:
|
2
2
|
Generador Scaffold-Like adaptado a las necesidades de Xaver.
|
3
3
|
|
4
|
-
|
5
|
-
rails generate fold
|
4
|
+
Ejemplo:
|
5
|
+
rails generate fold recurso nombre descripcion contenido:text es_destacado:boolean:true
|
6
6
|
|
7
|
-
|
8
|
-
app/
|
9
|
-
|
10
|
-
app/helpers/thing_helper.rb
|
7
|
+
Esto generará:
|
8
|
+
app/models/recurso
|
9
|
+
db/migration/<<fecha>>_create_recursos.rb
|
11
10
|
|
12
|
-
app/
|
13
|
-
app/
|
14
|
-
app/views/admin/_thing.rb
|
15
|
-
app/views/admin/edit.rb
|
16
|
-
app/views/admin/index.rb
|
17
|
-
app/views/admin/show.rb
|
11
|
+
app/controllers/recursos_controller.rb
|
12
|
+
app/controllers/admin/recursos_controller.rb
|
18
13
|
|
14
|
+
app/views/admin/_form.html.erb
|
15
|
+
app/views/admin/_mini_form.html.erb
|
16
|
+
app/views/admin/_recurso.html.erb
|
17
|
+
app/views/admin/edit.html.erb
|
18
|
+
app/views/admin/new.html.erb
|
19
|
+
app/views/admin/index.html.erb
|
20
|
+
|
21
|
+
Se pueden utilizar muchas opciones. Por ejemplo:
|
22
|
+
|
23
|
+
rails generate fold recurso nombre:index categoria:string{100}:uniq contenido:text precio:decimal{15.2} -O -A -S
|
@@ -1,79 +1,61 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
require 'rails/generators/resource_helpers'
|
4
|
+
require 'generators/fold/helpers/fold'
|
2
5
|
|
3
|
-
|
6
|
+
class FoldGenerator < ActiveRecord::Generators::Base
|
7
|
+
include Rails::Generators::ResourceHelpers
|
8
|
+
include Fold
|
4
9
|
|
5
|
-
class FoldGenerator < Rails::Generators::Base
|
6
10
|
source_root File.expand_path('../templates', __FILE__)
|
7
11
|
|
8
|
-
|
9
|
-
|
12
|
+
check_class_collision
|
13
|
+
|
14
|
+
argument :attributes, :type => :array, :required => true, :banner => "nombre descripcion contenido:text es_destacado:boolean:index precio:decimal{15.2}"
|
15
|
+
|
16
|
+
class_option :ordenable, :desc => 'el modelo se puede reordenar', :type => :boolean, :aliases => "-O", :default => false
|
17
|
+
class_option :archivable, :desc => 'el modelo tiene archivos', :type => :boolean, :aliases => "-A", :default => false
|
18
|
+
class_option :sluggable, :desc => 'el modelo tiene una url amigable', :type => :boolean, :aliases => "-S", :default => false
|
19
|
+
class_option :padre, :desc => "el padre del modelo", :type => :string, :aliases => "-P"
|
20
|
+
|
21
|
+
class_option :orm, :type => :string, :required => true
|
10
22
|
|
11
|
-
class_option :orden , :desc => 'Soporte para Ordenable.' , :type => :boolean, :aliases => "-o", :default => false
|
12
|
-
class_option :slug , :desc => 'Soporte pare FriendlyId.' , :type => :boolean, :aliases => "-i", :default => false
|
13
|
-
|
14
23
|
def initialize(*arguments, &block)
|
15
24
|
super
|
16
|
-
|
17
|
-
|
18
|
-
@con_slug = options.slug?
|
19
|
-
|
20
|
-
@singular = @name.downcase
|
21
|
-
@plural = @singular.pluralize
|
22
|
-
@class = @name.camelize
|
23
|
-
@classes = @plural.camelize
|
24
|
-
|
25
|
-
@singular_path = "admin_#{@singular}_path"
|
26
|
-
@plural_path = "admin_#{@plural}_path"
|
27
|
-
@new_path = "new_admin_#{@singular}_path"
|
28
|
-
@edit_path = "edit_admin_#{@singular}_path"
|
29
|
-
@reordenar_path = "reordenar_admin_#{@plural}_path"
|
30
|
-
|
31
|
-
@atributos = []
|
32
|
-
arguments.first.drop(1).each do |arg|
|
33
|
-
@atributos << Atributo.new(arg)
|
34
|
-
end
|
35
|
-
@identificador = @atributos.first.nombre
|
25
|
+
@paths = paths
|
26
|
+
end
|
36
27
|
|
28
|
+
def ejecutar
|
29
|
+
aplicar_templates
|
30
|
+
aplicar_rutas
|
37
31
|
end
|
38
|
-
|
39
|
-
def
|
40
|
-
|
41
|
-
template 'migration.erb' , "db/migrate/#{fecha}_create_#{@plural}.rb"
|
42
|
-
template 'controller.erb', "app/controllers/#{@plural}_controller.rb"
|
43
|
-
template 'admin_controller.erb', "app/controllers/admin/#{@plural}_controller.rb"
|
44
|
-
|
45
|
-
%w[_form edit index new].each do |action|
|
46
|
-
template "views/#{action}.erb", "app/views/admin/#{@plural}/#{action}.html.erb"
|
47
|
-
end
|
48
|
-
template "views/nombre.erb", "app/views/admin/#{@plural}/_#{@singular}.html.erb"
|
49
|
-
|
50
|
-
resources_route = @con_orden ? "\n resources :#{@plural} do\n post :reordenar, :on => :collection\n end" : "\n resources :#{@plural}"
|
51
|
-
add_admin_route resources_route
|
52
|
-
|
53
|
-
template 'cargar.erb', "lib/tasks/cargar_#{@plural}.rake"
|
32
|
+
|
33
|
+
def navegacion
|
34
|
+
insert_into_file "app/views/admin/admin/_nav_lateral.html.erb", "\n <li><%= link_to '#{plural_name.humanize}', #{@paths[:index]} if can? :index, #{class_name} %></li>", :after => '<li class="nav-header">General</li>'
|
54
35
|
end
|
55
|
-
|
36
|
+
|
56
37
|
private
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
inject_into_file 'config/routes.rb', ruta , :after => /namespace :admin do/
|
38
|
+
|
39
|
+
def attributes_with_index
|
40
|
+
attributes.select { |a| a.has_index? || a.reference? }
|
61
41
|
end
|
62
|
-
|
63
|
-
def
|
64
|
-
|
65
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
66
|
-
else
|
67
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
68
|
-
end
|
42
|
+
|
43
|
+
def reference_attributes
|
44
|
+
attributes.select &:reference?
|
69
45
|
end
|
70
|
-
|
71
|
-
def
|
72
|
-
|
46
|
+
|
47
|
+
def parent_class_name
|
48
|
+
options[:padre] || "ActiveRecord::Base"
|
73
49
|
end
|
74
|
-
|
75
|
-
def
|
76
|
-
|
50
|
+
|
51
|
+
def parent_controller_name(namespace = nil)
|
52
|
+
if options.padre?
|
53
|
+
[namespace.to_s.camelize, options[:padre].pluralize.camelize + "Controller"].compact.join("::")
|
54
|
+
elsif namespace.present?
|
55
|
+
[namespace.to_s.camelize, namespace.to_s.camelize + "Controller"].join("::")
|
56
|
+
else
|
57
|
+
"ApplicationController"
|
58
|
+
end
|
77
59
|
end
|
78
|
-
|
60
|
+
|
79
61
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Fold
|
2
|
+
module Paths
|
3
|
+
|
4
|
+
def paths
|
5
|
+
{
|
6
|
+
:index => [:admin, table_name.to_sym],
|
7
|
+
:new => [:new, :admin, file_name.to_sym],
|
8
|
+
:reordenar => [:reordenar, :admin, table_name.to_sym]
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def model_path
|
13
|
+
File.join 'app/models', class_path, "#{file_name}.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def controller_path(namespace = nil)
|
17
|
+
File.join 'app/controllers', namespace.to_s, class_path, "#{controller_file_name}_controller.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
def migration_path
|
21
|
+
File.join 'db/migrate', "create_#{table_name}.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
def view_path(action, namespace = nil)
|
25
|
+
File.join 'app/views', namespace.to_s, class_path, table_name, "#{action}.erb"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def fecha
|
31
|
+
Time.zone.now.strftime("%Y%m%d%H%M%S")
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.next_migration_number(dirname) #:nodoc:
|
35
|
+
if ActiveRecord::Base.timestamped_migrations
|
36
|
+
Time.zone.now.strftime("%Y%m%d%H%M%S")
|
37
|
+
else
|
38
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fold
|
2
|
+
module Routes
|
3
|
+
|
4
|
+
def aplicar_rutas
|
5
|
+
ruta_admin
|
6
|
+
ruta_publica
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def ruta_admin
|
12
|
+
ruta = "\n resources :#{table_name}"
|
13
|
+
ruta += concerns.to_s
|
14
|
+
inject_into_file 'config/routes.rb', ruta, :after => /namespace :admin do/
|
15
|
+
end
|
16
|
+
|
17
|
+
def ruta_publica
|
18
|
+
ruta = "resources :#{table_name}\n\n "
|
19
|
+
inject_into_file 'config/routes.rb', ruta, :before => /namespace :admin do/
|
20
|
+
end
|
21
|
+
|
22
|
+
def concerns
|
23
|
+
modulos = []
|
24
|
+
modulos.push ":ordenable" if options.ordenable?
|
25
|
+
modulos.push ":archivable" if options.archivable?
|
26
|
+
return ", :concerns => [#{modulos.compact.join(", ")}]" if modulos.present?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fold
|
2
|
+
module Templates
|
3
|
+
|
4
|
+
def aplicar_templates
|
5
|
+
models
|
6
|
+
!options.padre? ? migrations : puts("Recuerde que debe agregar la columna :type a la tabla :#{options[:padre].tableize}")
|
7
|
+
controllers
|
8
|
+
views
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def models
|
14
|
+
template 'model.rb', model_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def migrations
|
18
|
+
migration_template 'migration.rb', migration_path
|
19
|
+
end
|
20
|
+
|
21
|
+
def controllers
|
22
|
+
template 'controller.rb', controller_path
|
23
|
+
template 'admin_controller.rb', controller_path(:admin)
|
24
|
+
end
|
25
|
+
|
26
|
+
def views
|
27
|
+
%w[_form edit index new].each do |action|
|
28
|
+
action += ".html"
|
29
|
+
template File.join('views', "#{action}.erb"), view_path(action, :admin)
|
30
|
+
end
|
31
|
+
template "views/_partial.html.erb", view_path("_#{file_name}.html", :admin)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
<% if namespaced? -%>
|
3
|
+
require_dependency "<%= namespaced_file_path %>/application_controller"
|
4
|
+
|
5
|
+
<% end -%>
|
6
|
+
<% module_namespacing do -%>
|
7
|
+
class Admin::<%= controller_class_name %>Controller < <%= parent_controller_name(:admin) %>
|
8
|
+
<% if !options.padre? -%>
|
9
|
+
load_and_authorize_resource
|
10
|
+
<% end -%>
|
11
|
+
<%- if options.ordenable? -%>
|
12
|
+
include Ordenable
|
13
|
+
<%- end -%>
|
14
|
+
|
15
|
+
def index
|
16
|
+
# @q = <%= singular_table_name.camelize %>.search params[:q]
|
17
|
+
# @<%= plural_table_name %> = @q.relation.page(params[:page]).per(50)
|
18
|
+
@<%= plural_table_name%> = <%= singular_table_name.camelize %>.page(params[:page]).per(50)
|
19
|
+
end
|
20
|
+
|
21
|
+
def new
|
22
|
+
end
|
23
|
+
|
24
|
+
def create
|
25
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
|
26
|
+
@<%= orm_instance.save %>!
|
27
|
+
redirect_to [:admin, :<%= plural_table_name %>], notice: mensaje
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
@<%= singular_table_name %>.update_attributes! params[:<%= singular_table_name %>]
|
35
|
+
redirect_to [:edit, :admin, @<%= singular_table_name %>], notice: mensaje
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
@<%= orm_instance.destroy %>
|
40
|
+
mensaje
|
41
|
+
end
|
42
|
+
|
43
|
+
<%- if options.ordenable? -%>
|
44
|
+
private
|
45
|
+
|
46
|
+
def sort_coleccion
|
47
|
+
<%= orm_class.all(class_name) %>
|
48
|
+
end
|
49
|
+
|
50
|
+
<%- end -%>
|
51
|
+
end<%- end -%>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :<%= table_name %> do |t|
|
4
|
+
<% attributes.each do |attribute| -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
<% if options.ordenable? %>
|
9
|
+
t.integer :orden
|
10
|
+
<% end -%>
|
11
|
+
<%- if options.sluggable? -%>
|
12
|
+
t.string :slug
|
13
|
+
<% end -%>
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
<% attributes_with_index.each do |attribute| -%>
|
17
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
18
|
+
<% end -%>
|
19
|
+
<%- if options.sluggable? -%>
|
20
|
+
add_index :<%= table_name %>, :slug, :unique => true
|
21
|
+
<% end -%>
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= class_name %> < <%= parent_class_name.classify %>
|
3
|
+
|
4
|
+
##############################################################################
|
5
|
+
#### CONFIGURACIONES Y RELACIONES
|
6
|
+
##############################################################################
|
7
|
+
<% if options.sluggable? %>
|
8
|
+
extend FriendlyId
|
9
|
+
friendly_id <%= ":#{attributes.first.name}" if attributes.first.name != "nombre" %>
|
10
|
+
<%- end -%>
|
11
|
+
<% if attributes.any? %>
|
12
|
+
attr_accessible <%= attributes.map { |a| ":#{a.name}#{"_id" if a.reference?}" }.join(', ') %>
|
13
|
+
<%- end -%>
|
14
|
+
<% reference_attributes.each do |attribute| %>
|
15
|
+
belongs_to :<%= attribute.name %>
|
16
|
+
<%- end -%>
|
17
|
+
<% if options.archivable? %>
|
18
|
+
has_many :archivos, :as => :propietario, :dependent => :destroy
|
19
|
+
has_many :fotos, :as => :propietario
|
20
|
+
has_many :adjuntos, :as => :propietario
|
21
|
+
has_many :videos, :as => :propietario
|
22
|
+
accepts_nested_attributes_for :fotos, :adjuntos, :videos
|
23
|
+
<% end %>
|
24
|
+
##############################################################################
|
25
|
+
#### SCOPES Y VALIDACIONES
|
26
|
+
##############################################################################
|
27
|
+
<% if options.ordenable? %>
|
28
|
+
default_scope -> { order{orden} }
|
29
|
+
<% else %>
|
30
|
+
default_scope -> { order{<%= attributes.first.name %>} }
|
31
|
+
<% end %>
|
32
|
+
##############################################################################
|
33
|
+
#### MÉTODOS PÚBLICOS
|
34
|
+
##############################################################################
|
35
|
+
<% if options.archivable? %>
|
36
|
+
def carpeta
|
37
|
+
File.join Rails.env, self.class.name.tableize, id.to_s
|
38
|
+
end
|
39
|
+
<% end %>
|
40
|
+
def se_puede_eliminar?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
super if se_puede_eliminar?
|
46
|
+
end
|
47
|
+
|
48
|
+
##############################################################################
|
49
|
+
#### ALIAS E IMPRESIONES
|
50
|
+
##############################################################################
|
51
|
+
|
52
|
+
alias_attribute :to_label, :<%= attributes.first.name %>
|
53
|
+
alias_attribute :to_s, :<%= attributes.first.name %>
|
54
|
+
|
55
|
+
##############################################################################
|
56
|
+
#### MÉTODOS PRIVADOS
|
57
|
+
##############################################################################
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
end
|
62
|
+
<% end -%>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%%= simple_form_for <%= singular_table_name %>, :url => [:admin, <%= singular_table_name %>], :html => { :class => 'form-horizontal' }, :defaults => { :input_html => { :class => 'input-xlarge' } } do |f| %>
|
2
|
+
<%- attributes.each_with_index do |atributo, i| -%>
|
3
|
+
<%%= f.<%= atributo.reference? ? :association : :input %> :<%= atributo.name %><%= ", :autofocus => true" if i.zero? %> %>
|
4
|
+
<%- end -%>
|
5
|
+
|
6
|
+
<div class="form-actions">
|
7
|
+
<%%= f.button :submit, :name => nil, :data => { :disable_with => t('espere') }, :class => 'btn btn-primary' %>
|
8
|
+
</div>
|
9
|
+
<%% end %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%%= tr_for <%= singular_table_name %> do %>
|
2
|
+
<%- for atributo in attributes.first(3) -%>
|
3
|
+
<td><%%= <%= "number_to_currency " if atributo.name =~ /precio/ %><%= singular_table_name %>.<%= atributo.name %> %></td>
|
4
|
+
<%- end -%>
|
5
|
+
<td><%%= acciones <%= ":mover => boton_mover(#{class_name}), " if options.ordenable? %><%= ":archivos => boton_archivos(#{singular_table_name}), " if options.archivable? %>:editar => boton_editar(<%= singular_table_name %>), :eliminar => boton_eliminar(<%= singular_table_name %>) %></td>
|
6
|
+
<%% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="page-header">
|
2
|
+
<nav class="pull-right">
|
3
|
+
<%%= boton_volver <%= class_name %> %>
|
4
|
+
</nav>
|
5
|
+
<h1>
|
6
|
+
<%= plural_name.humanize %>
|
7
|
+
<small><%%= @<%= singular_table_name %>.to_label %></small>
|
8
|
+
</h1>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<%%= render "form", :<%= singular_table_name %> => @<%= singular_table_name %> %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div class="page-header">
|
2
|
+
<nav class="pull-right">
|
3
|
+
<%%= boton_new <%= class_name %> %>
|
4
|
+
</nav>
|
5
|
+
<h1><%= plural_name.humanize %></h1>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<%%= content_tag :table, :id => nombre_tabla(<%= class_name %>), :class => [:table, :"table-striped"<%= ", :ordenable" if options.ordenable? %>] do %>
|
9
|
+
<%%= thead <%= attributes.first(3).map{ |a| ":#{a.name}" }.join(", ") %> %>
|
10
|
+
<%%= content_tag :tbody, render(@<%= plural_table_name %>) %>
|
11
|
+
<%- if options.ordenable? -%>
|
12
|
+
<%%= hidden_field_tag :url, url_for(<%= @paths[:reordenar] %>), :class => :url %>
|
13
|
+
<%- end -%>
|
14
|
+
<%% end %>
|
15
|
+
<%%= paginate @<%= plural_table_name %>, :theme => :bootstrap %>
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,19 +1,90 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foldscaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0.beta
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nicanor Perera
|
8
|
+
- Gustavo Molinari
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sorcery
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: simple_form
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: friendly_id
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: cancan
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: dragonfly
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
14
84
|
description: Generadores adaptados a las necesidades de Xaver
|
15
85
|
email:
|
16
86
|
- nicanorperera@gmail.com
|
87
|
+
- gustavo.molinari@xaver.com.ar
|
17
88
|
executables: []
|
18
89
|
extensions: []
|
19
90
|
extra_rdoc_files: []
|
@@ -26,41 +97,42 @@ files:
|
|
26
97
|
- foldscaf.gemspec
|
27
98
|
- lib/foldscaf.rb
|
28
99
|
- lib/generators/fold/USAGE
|
29
|
-
- lib/generators/fold/atributo.rb
|
30
100
|
- lib/generators/fold/fold_generator.rb
|
31
|
-
- lib/generators/fold/
|
32
|
-
- lib/generators/fold/
|
33
|
-
- lib/generators/fold/
|
34
|
-
- lib/generators/fold/templates
|
35
|
-
- lib/generators/fold/templates/
|
36
|
-
- lib/generators/fold/templates/
|
37
|
-
- lib/generators/fold/templates/
|
38
|
-
- lib/generators/fold/templates/
|
39
|
-
- lib/generators/fold/templates/views/
|
40
|
-
- lib/generators/fold/templates/views/
|
101
|
+
- lib/generators/fold/helpers/fold.rb
|
102
|
+
- lib/generators/fold/helpers/paths.rb
|
103
|
+
- lib/generators/fold/helpers/routes.rb
|
104
|
+
- lib/generators/fold/helpers/templates.rb
|
105
|
+
- lib/generators/fold/templates/admin_controller.rb
|
106
|
+
- lib/generators/fold/templates/controller.rb
|
107
|
+
- lib/generators/fold/templates/migration.rb
|
108
|
+
- lib/generators/fold/templates/model.rb
|
109
|
+
- lib/generators/fold/templates/views/_form.html.erb
|
110
|
+
- lib/generators/fold/templates/views/_partial.html.erb
|
111
|
+
- lib/generators/fold/templates/views/edit.html.erb
|
112
|
+
- lib/generators/fold/templates/views/index.html.erb
|
113
|
+
- lib/generators/fold/templates/views/new.html.erb
|
41
114
|
- lib/version.rb
|
42
|
-
homepage: http://github.com/
|
115
|
+
homepage: http://github.com/Xaver/foldscaf
|
43
116
|
licenses: []
|
117
|
+
metadata: {}
|
44
118
|
post_install_message:
|
45
119
|
rdoc_options: []
|
46
120
|
require_paths:
|
47
121
|
- lib
|
48
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
123
|
requirements:
|
51
124
|
- - ! '>='
|
52
125
|
- !ruby/object:Gem::Version
|
53
126
|
version: '0'
|
54
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
128
|
requirements:
|
57
|
-
- - ! '
|
129
|
+
- - ! '>'
|
58
130
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
131
|
+
version: 1.3.1
|
60
132
|
requirements: []
|
61
133
|
rubyforge_project: foldscaf
|
62
|
-
rubygems_version:
|
134
|
+
rubygems_version: 2.0.0
|
63
135
|
signing_key:
|
64
|
-
specification_version:
|
136
|
+
specification_version: 4
|
65
137
|
summary: Generadores adaptados a las necesidades de Xaver
|
66
138
|
test_files: []
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
class Atributo
|
3
|
-
CLASES = [:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean, :references]
|
4
|
-
VALORES = [:true, :false, :nil]
|
5
|
-
OPCIONES = [:unique, :index, :polymorphic]
|
6
|
-
ANCHO = 15
|
7
|
-
attr_accessor :nombre, :clase, :default, :opciones
|
8
|
-
|
9
|
-
def initialize(s)
|
10
|
-
parametros = s.split(':')
|
11
|
-
|
12
|
-
@nombre = parametros.shift
|
13
|
-
@clase = :string if parametros.empty?
|
14
|
-
@opciones = []
|
15
|
-
|
16
|
-
parametros.each do |parametro|
|
17
|
-
incluir parametro.to_sym
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def incluir(parametro)
|
23
|
-
if CLASES.include? parametro
|
24
|
-
@clase = parametro
|
25
|
-
end
|
26
|
-
|
27
|
-
if VALORES.include? parametro
|
28
|
-
@clase ||= :boolean
|
29
|
-
@default = parametro
|
30
|
-
end
|
31
|
-
|
32
|
-
if OPCIONES.include? parametro
|
33
|
-
@opciones << parametro
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def es?(opcion)
|
38
|
-
@opciones.include? opcion
|
39
|
-
end
|
40
|
-
|
41
|
-
def tiene_opciones?
|
42
|
-
! @opciones.empty?
|
43
|
-
end
|
44
|
-
|
45
|
-
def ejemplo
|
46
|
-
case @clase
|
47
|
-
when :string then "'Lorem Ipsum'"
|
48
|
-
when :integer then rand(50)
|
49
|
-
when :boolean then 'true'
|
50
|
-
else false
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
class Admin::<%= @classes %>Controller < Admin::AdminController
|
3
|
-
load_and_authorize_resource
|
4
|
-
<%- if @con_orden -%>
|
5
|
-
include Ordenable
|
6
|
-
<%- end -%>
|
7
|
-
|
8
|
-
def index
|
9
|
-
@q = <%= @class %>.search params[:q]
|
10
|
-
@<%= @plural %> = @q.relation.page(params[:page]).per(50)
|
11
|
-
end
|
12
|
-
|
13
|
-
def new
|
14
|
-
@<%= @plural %> = <%= @class %>.last(5)
|
15
|
-
end
|
16
|
-
|
17
|
-
def create
|
18
|
-
@<%= @singular %> = <%= @class %>.new params[:<%= @singular %>]
|
19
|
-
@<%= @singular %>.save!
|
20
|
-
notice = mensaje
|
21
|
-
|
22
|
-
respond_to do |format|
|
23
|
-
format.html { redirect_to <%= @plural_path %>, notice: notice }
|
24
|
-
format.js { @elemento = @<%= @singular %> }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def edit
|
29
|
-
end
|
30
|
-
|
31
|
-
def update
|
32
|
-
@<%= @singular %>.update_attributes! params[:<%= @singular %>]
|
33
|
-
redirect_to <%= @edit_path %>(@<%= @singular %>), notice: mensaje
|
34
|
-
end
|
35
|
-
|
36
|
-
def destroy
|
37
|
-
@id = @<%= @singular %>.id
|
38
|
-
@<%= @singular %>.destroy
|
39
|
-
notice = mensaje
|
40
|
-
|
41
|
-
respond_to do |format|
|
42
|
-
format.html { redirect_to <%= @plural_path %>, notice: notice }
|
43
|
-
format.js
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
<%- if @con_orden -%>
|
48
|
-
private
|
49
|
-
def sort_coleccion
|
50
|
-
<%= @class %>.all
|
51
|
-
end
|
52
|
-
<%- end -%>
|
53
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
<%- atributos = @atributos.select {|x| x.ejemplo }.collect {|a| ":#{a.nombre} => #{a.ejemplo}" } -%>
|
3
|
-
namespace :cargar do
|
4
|
-
task :<%= @plural %> => :environment do
|
5
|
-
<%- 10.times do-%>
|
6
|
-
<%= @class %>.create! <%= atributos.join(', ') %>
|
7
|
-
<%- end -%>
|
8
|
-
end
|
9
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
class Create<%= @classes %> < ActiveRecord::Migration
|
3
|
-
def change
|
4
|
-
create_table :<%= @plural %> do |t|
|
5
|
-
<%- @atributos.each do |a| -%>
|
6
|
-
t.<%= a.clase %> :<%= a.nombre %><%= ", :default => #{a.default}" if (a.default && a.ejemplo) %>
|
7
|
-
<%- end -%>
|
8
|
-
|
9
|
-
<%- if @con_slug -%>
|
10
|
-
t.string :slug
|
11
|
-
<%- end -%>
|
12
|
-
<%- if @con_orden -%>
|
13
|
-
t.integer :orden
|
14
|
-
<%- end -%>
|
15
|
-
|
16
|
-
t.boolean :es_activo, :default => true
|
17
|
-
t.timestamps
|
18
|
-
end
|
19
|
-
<%- if @con_slug -%>
|
20
|
-
add_index :<%= @plural %>, :slug, :unique => true
|
21
|
-
<%- end -%>
|
22
|
-
end
|
23
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
class <%= @class %> < ActiveRecord::Base
|
3
|
-
<%- if @con_slug -%>
|
4
|
-
extend FriendlyId
|
5
|
-
friendly_id :<%= @identificador %>
|
6
|
-
<%- end -%>
|
7
|
-
<%- atributos_con_referencia.each do |a| -%>
|
8
|
-
belongs_to :<%= a.nombre %>
|
9
|
-
<%- end -%>
|
10
|
-
default_scope -> { where{es_activo.eq true}<%= ".order('#{@plural}.orden')" if @con_orden %> }
|
11
|
-
|
12
|
-
def se_puede_eliminar?
|
13
|
-
true
|
14
|
-
end
|
15
|
-
|
16
|
-
def destroy
|
17
|
-
if se_puede_eliminar?
|
18
|
-
run_callbacks :destroy do
|
19
|
-
update_attribute :es_activo, false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
alias_attribute :to_s, :<%= @identificador %>
|
25
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<%%= simple_form_for <%= @singular %>, :url => url, :remote => remote, :html => { :class => 'form-horizontal' } do |f| %>
|
2
|
-
<%- @atributos.each do |a| -%>
|
3
|
-
<%%= f.<%= a.clase == :references ? :association : :input %> :<%= a.nombre %> %>
|
4
|
-
<%- end -%>
|
5
|
-
|
6
|
-
<div class="controls">
|
7
|
-
<%%= f.button :submit, :name => nil, :data => { :disable_with => t('espere') }, :class => 'btn btn-primary' %>
|
8
|
-
</div>
|
9
|
-
<%% end %>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<div class="page-header">
|
2
|
-
<nav class="pull-right">
|
3
|
-
<%%= link_to icono('arrow-left', :blanco) + ' Volver', <%= @plural_path %>, :class => 'btn btn-primary btn-large' %>
|
4
|
-
</nav>
|
5
|
-
<h1>Editar <%= @class %></h1>
|
6
|
-
</div>
|
7
|
-
|
8
|
-
<%%= render "form", :<%= @singular %> => @<%= @singular %>, :url => <%= @singular_path %>(@<%= @singular %>), :remote => false %>
|
@@ -1,22 +0,0 @@
|
|
1
|
-
<div class="page-header">
|
2
|
-
<nav class="pull-right">
|
3
|
-
<%%= link_to icono('plus', :blanco) + " Agregar <%= @singular %>", <%= @new_path %>, :class => 'btn btn-primary btn-large' %>
|
4
|
-
</nav>
|
5
|
-
<h1><%= @classes %></h1>
|
6
|
-
</div>
|
7
|
-
|
8
|
-
<%%= simple_form_for @q, :as => :q, :url => <%= @plural_path %>, :method => :get do |f| %>
|
9
|
-
<%%= f.input :<%= @identificador %>_contains, :placeholder => '<%= @identificador.humanize %>', :required => false, :autofocus => true %>
|
10
|
-
<%%= f.button :submit, "Buscar", :name => nil, :disable_with => t("espere"), :class => 'btn btn-primary' %>
|
11
|
-
<%% end %>
|
12
|
-
|
13
|
-
<%%= paginate @<%= @plural %>, :theme => :bootstrap %>
|
14
|
-
|
15
|
-
<%%= content_tag :table, :id => nombre_tabla(<%= @class %>), :class => [:table, :"table-striped", :ordenable] do %>
|
16
|
-
<%%= thead :<%= @identificador %> %>
|
17
|
-
<%%= content_tag :tbody, render(@<%= @plural %>) %>
|
18
|
-
<%% end %>
|
19
|
-
|
20
|
-
<%- if @con_orden -%>
|
21
|
-
<%%= hidden_field_tag :url, <%= @reordenar_path %>, :class => :url %>
|
22
|
-
<%- end -%>
|
@@ -1,13 +0,0 @@
|
|
1
|
-
<div class="page-header">
|
2
|
-
<nav class="pull-right">
|
3
|
-
<%%= link_to icono('arrow-left', :blanco) + ' Volver', <%= @plural_path %>, :class => 'btn btn-primary btn-large' %>
|
4
|
-
</nav>
|
5
|
-
<h1>Agregar <%= @class %>
|
6
|
-
</div>
|
7
|
-
|
8
|
-
<%%= content_tag :table, :id => nombre_tabla(<%= @class %>), :class => [:table, :"table-striped", :ordenable] do %>
|
9
|
-
<%%= thead :<%= @identificador %> %>
|
10
|
-
<%%= content_tag :tbody, render(@<%= @plural %>) %>
|
11
|
-
<%% end %>
|
12
|
-
|
13
|
-
<%%= render "form", :<%= @singular %> => @<%= @singular %>, :url => <%= @plural_path %>, :remote => true %>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<%%= content_tag :tr, :id => "elementos_#{<%= @singular %>.id}" do %>
|
2
|
-
<td><%%= <%= @singular %>.<%= @identificador %> %></td>
|
3
|
-
<td style="text-align:right;">
|
4
|
-
<%- if @con_orden -%>
|
5
|
-
<%%= link_to icono('move', :black) + " Mover", "#", :class => 'btn btn-mini handle', :title => 'Mantenga click y arrastre para reordenar' %>
|
6
|
-
<%- end -%>
|
7
|
-
<%%= link_to 'Editar', <%= @edit_path %>(<%= @singular %>), :class => 'btn btn-mini' if can? :update, <%= @singular %> %>
|
8
|
-
<%%= link_to 'Eliminar', <%= @singular_path %>(<%= @singular %>), :method => :delete, :data => { :confirm => t('confirmacion') }, :remote => true, :class => 'btn btn-mini btn-danger' if <%= @singular %>.se_puede_eliminar? && can?(:destroy, <%= @singular %>) %>
|
9
|
-
</td>
|
10
|
-
<%% end %>
|