foldscaf 2.0.0.rc1 → 2.0.0.rc2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f7d3d0b22f0d5aa42ce91cc8a8a3dda338fa28e
4
- data.tar.gz: f236e61baca2a8a3ebf4d7258099dfa80d34ebb4
3
+ metadata.gz: ab40cfaef66dbc87c3b6b0da1383ef4064c7ff04
4
+ data.tar.gz: 799cb3ba0267dbb0d52c706e364e5f38aafc3588
5
5
  SHA512:
6
- metadata.gz: 98657825eb56dfbbc320b1106005008eee6a2e59c630898f72f54931af5e9c2c4eb09a72ac0767eba0eff54e5310dbbfbd72db24e43788885e9fee0083eaa752
7
- data.tar.gz: 4b2ce1bafa6e7d73e37f044d3bbb03907237ddbfa376100f9090d1761f3c36c95f5dbabc8fef0b34bc469e17d127433aee52e814618c903a2a16cf1881f5cbde
6
+ metadata.gz: ec552e383f7e163ade814fdf10ddca7286228913d0e34da90295154027d31a98c00d809ff86d9ee702913e2ad4480ef2f96d3888173a085c0b58b256abdefe8a
7
+ data.tar.gz: 8573cb1a3038988645cdbd53e8b7d755229a83c670538470a149d26cac5a755d095e2ec6cff28aa51d16e1f1674e1505b92a7b291fa10980aa54341ad867c1d6
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
- ## v2.0.0.beta1
1
+ ## v2.0.0.rc2
2
+ * Minor fixes.
3
+ * Tipo :imagen. Agrega todo lo necesario para hacer que ese atributo sea una imagen.
4
+ * Opción -R: Crea un archivo cargar_modelo.rake en lib/tasks con el formato predeterminado de los rakes.
5
+
6
+ ## v2.0.0.rc1
2
7
  * Minor fixes.
3
8
  * Helpers.
4
9
 
@@ -2,7 +2,7 @@ Descripción:
2
2
  Generador Scaffold-Like adaptado a las necesidades de Xaver.
3
3
 
4
4
  Ejemplo:
5
- rails generate fold recurso nombre descripcion contenido:text es_destacado:boolean:true
5
+ rails generate fold recurso nombre descripcion contenido:text es_destacado:boolean:true banner:imagen
6
6
 
7
7
  Esto generará:
8
8
  app/models/recurso
@@ -18,6 +18,8 @@ Ejemplo:
18
18
  app/views/admin/new.html.erb
19
19
  app/views/admin/index.html.erb
20
20
 
21
+ lib/tasks/cargar_recursos.html
22
+
21
23
  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
24
+
25
+ rails generate fold recurso nombre:index categoria:string{100}:uniq contenido:text precio:decimal{15.2} banner:imagen -O -A -S -R
@@ -16,6 +16,7 @@ class FoldGenerator < ActiveRecord::Generators::Base
16
16
  class_option :ordenable, :desc => 'el modelo se puede reordenar', :type => :boolean, :aliases => "-O", :default => false
17
17
  class_option :archivable, :desc => 'el modelo tiene archivos', :type => :boolean, :aliases => "-A", :default => false
18
18
  class_option :sluggable, :desc => 'el modelo tiene una url amigable', :type => :boolean, :aliases => "-S", :default => false
19
+ class_option :rake, :desc => "crear archivo rake", :type => :boolean, :aliases => "-R", :default => false
19
20
  class_option :padre, :desc => "el padre del modelo", :type => :string, :aliases => "-P"
20
21
 
21
22
  class_option :orm, :type => :string, :required => true
@@ -34,6 +35,10 @@ class FoldGenerator < ActiveRecord::Generators::Base
34
35
  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>'
35
36
  end
36
37
 
38
+ def rake_cargar_todo
39
+ insert_into_file "lib/tasks/cargar_todo.rake", "\n cargar :#{table_name}", :before => "\n puts 'Listo!'" if options.rake?
40
+ end
41
+
37
42
  private
38
43
 
39
44
  def attributes_with_index
@@ -44,6 +49,26 @@ class FoldGenerator < ActiveRecord::Generators::Base
44
49
  attributes.select &:reference?
45
50
  end
46
51
 
52
+ def imagen_attributes
53
+ attributes.select { |a| a.type == :imagen }
54
+ end
55
+
56
+ def estandar_attributes
57
+ attributes - reference_attributes - imagen_attributes
58
+ end
59
+
60
+ def listable_attributes
61
+ estandar_attributes + reference_attributes
62
+ end
63
+
64
+ def accessible_attributes
65
+ array = estandar_attributes.map { |a| ":#{a.name}" }
66
+ array.push imagen_attributes.map { |a| [":#{a.name}", ":remove_#{a.name}"] }
67
+ array.push reference_attributes.map { |a| ":#{a.name}_id" }
68
+ array.push [":adjuntos_attributes", ":fotos_attributes", ":videos_attributes"] if options.archivable?
69
+ array.flatten.join(', ')
70
+ end
71
+
47
72
  def parent_class_name
48
73
  options[:padre] || "ActiveRecord::Base"
49
74
  end
@@ -25,6 +25,10 @@ module Fold
25
25
  File.join 'app/views', namespace.to_s, class_path, table_name, "#{action}.erb"
26
26
  end
27
27
 
28
+ def rake_path(filename)
29
+ File.join 'lib/tasks', "#{filename}.rake"
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def fecha
@@ -6,6 +6,7 @@ module Fold
6
6
  !options.padre? ? migrations : puts("Recuerde que debe agregar la columna :type a la tabla :#{options[:padre].tableize}")
7
7
  controllers
8
8
  views
9
+ rake if options.rake?
9
10
  end
10
11
 
11
12
  private
@@ -31,5 +32,9 @@ module Fold
31
32
  template "views/_partial.html.erb", view_path("_#{file_name}.html", :admin)
32
33
  end
33
34
 
35
+ def rake
36
+ template 'rake.rake', rake_path("cargar_#{table_name}")
37
+ end
38
+
34
39
  end
35
40
  end
@@ -1,9 +1,15 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :<%= table_name %> do |t|
4
- <% attributes.each do |attribute| -%>
4
+ <% estandar_attributes.each do |attribute| -%>
5
5
  t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
6
6
  <% end -%>
7
+ <% imagen_attributes.each do |attribute| -%>
8
+ t.string :<%= attribute.name %>_uid, :<%= attribute.name %>_name
9
+ <% end -%>
10
+ <% reference_attributes.each do |attribute| -%>
11
+ t.references :<%= attribute.name %><%= attribute.inject_options %>
12
+ <% end -%>
7
13
 
8
14
  <% if options.ordenable? %>
9
15
  t.integer :orden
@@ -8,9 +8,12 @@ class <%= class_name %> < <%= parent_class_name.classify %>
8
8
  extend FriendlyId
9
9
  friendly_id <%= ":#{attributes.first.name}" if attributes.first.name != "nombre" %>
10
10
  <%- end -%>
11
- <% if attributes.any? %>
12
- attr_accessible <%= attributes.map { |a| ":#{a.name}#{"_id" if a.reference?}" }.join(', ') %>
11
+ <% if accessible_attributes.present? %>
12
+ attr_accessible <%= accessible_attributes %>
13
13
  <%- end -%>
14
+ <% if imagen_attributes.any? %>
15
+ after_create :guardar_archivos!
16
+ <% end -%>
14
17
  <% reference_attributes.each do |attribute| %>
15
18
  belongs_to :<%= attribute.name %>
16
19
  <%- end -%>
@@ -20,6 +23,11 @@ class <%= class_name %> < <%= parent_class_name.classify %>
20
23
  has_many :adjuntos, :as => :propietario
21
24
  has_many :videos, :as => :propietario
22
25
  accepts_nested_attributes_for :fotos, :adjuntos, :videos
26
+ <% end %>
27
+ <%- imagen_attributes.each do |attribute| -%>
28
+ image_accessor :<%= attribute.name %> do
29
+ storage_path { |f| File.join carpeta, "<%= attribute.name %>-#{rand(10000)}.#{f.format}" }
30
+ end
23
31
  <% end %>
24
32
  ##############################################################################
25
33
  #### SCOPES Y VALIDACIONES
@@ -32,7 +40,7 @@ class <%= class_name %> < <%= parent_class_name.classify %>
32
40
  ##############################################################################
33
41
  #### MÉTODOS PÚBLICOS
34
42
  ##############################################################################
35
- <% if options.archivable? %>
43
+ <% if options.archivable? || imagen_attributes.any? %>
36
44
  def carpeta
37
45
  File.join Rails.env, self.class.name.tableize, id.to_s
38
46
  end
@@ -57,6 +65,10 @@ class <%= class_name %> < <%= parent_class_name.classify %>
57
65
  ##############################################################################
58
66
 
59
67
  private
60
-
68
+ <% if imagen_attributes.any? %>
69
+ def guardar_archivos!
70
+ update_attributes! <%= imagen_attributes.map { |a| ":#{a.name} => #{a.name}" }.join(", ") %>
71
+ end
72
+ <% end -%>
61
73
  end
62
74
  <% end -%>
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ namespace :cargar do
3
+ task :<%= table_name %> => :environment do
4
+ end
5
+ end
@@ -1,9 +1,15 @@
1
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| -%>
2
+ <%- estandar_attributes.each_with_index do |atributo, i| -%>
3
3
  <%%= f.<%= atributo.reference? ? :association : :input %> :<%= atributo.name %><%= ", :as => :date_html" if atributo.type.to_s.in? ["date", "datetime"] %><%= ", :autofocus => true" if i.zero? %> %>
4
4
  <%- end -%>
5
+ <%- imagen_attributes.each_with_index do |atributo, i| -%>
6
+ <%%= render 'imagen', f: f, atributo: :<%= atributo.name %> %>
7
+ <%- end -%>
8
+ <%- reference_attributes.each_with_index do |atributo, i| -%>
9
+ <%%= f.association :<%= atributo.name %> %>
10
+ <%- end -%>
5
11
 
6
- <div class="form-actions">
7
- <%%= f.button :submit, :name => nil, :data => { :disable_with => t('espere') }, :class => 'btn btn-primary' %>
8
- </div>
12
+ <div class="form-actions">
13
+ <%%= f.button :submit, :name => nil, :data => { :disable_with => t('espere') }, :class => 'btn btn-primary' %>
14
+ </div>
9
15
  <%% end %>
@@ -1,5 +1,5 @@
1
1
  <%%= tr_for <%= singular_table_name %> do %>
2
- <%- for atributo in attributes.first(3) -%>
2
+ <%- for atributo in listable_attributes.first(3) -%>
3
3
  <td><%%= <%= "number_to_currency " if atributo.name =~ /precio/ %><%= singular_table_name %>.<%= atributo.name %> %></td>
4
4
  <%- end -%>
5
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>
@@ -5,8 +5,8 @@
5
5
  <h1><%= plural_name.humanize %></h1>
6
6
  </div>
7
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(", ") %> %>
8
+ <%%= content_tag :table, :id => nombre_tabla(<%= class_name %>), :class => ["table", "table-condensed", "table-hover"<%= ", :ordenable" if options.ordenable? %>] do %>
9
+ <%%= thead <%= listable_attributes.first(3).map{ |a| ":#{a.name}" }.join(", ") %> %>
10
10
  <%%= content_tag :tbody, render(@<%= plural_table_name %>) %>
11
11
  <%- if options.ordenable? -%>
12
12
  <%%= hidden_field_tag :url, url_for(<%= @paths[:reordenar] %>), :class => :url %>
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Foldscaf
2
- VERSION = "2.0.0.rc1"
2
+ VERSION = "2.0.0.rc2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foldscaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc1
4
+ version: 2.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicanor Perera
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-23 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sorcery
@@ -106,6 +106,7 @@ files:
106
106
  - lib/generators/fold/templates/controller.rb
107
107
  - lib/generators/fold/templates/migration.rb
108
108
  - lib/generators/fold/templates/model.rb
109
+ - lib/generators/fold/templates/rake.rake
109
110
  - lib/generators/fold/templates/views/_form.html.erb
110
111
  - lib/generators/fold/templates/views/_partial.html.erb
111
112
  - lib/generators/fold/templates/views/edit.html.erb
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  version: 1.3.1
132
133
  requirements: []
133
134
  rubyforge_project: foldscaf
134
- rubygems_version: 2.0.2
135
+ rubygems_version: 2.0.0.rc.2
135
136
  signing_key:
136
137
  specification_version: 4
137
138
  summary: Generadores adaptados a las necesidades de Xaver