scaf-generator 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Instala los componentes necesarios para que funcione mini_form.
3
+
4
+ Example:
5
+ rails generate mini_form
6
+
7
+ This will create:
8
+ lib/mini_form.rb
@@ -0,0 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class MiniFormGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def initialize(*arguments, &block)
6
+ super
7
+ end
8
+ def body
9
+ copy_file 'mini_form.rb', 'lib/mini_form.rb'
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module MiniForm
2
+ def mini_form_for(object, *args, &block)
3
+ args ||= []
4
+ options = args.extract_options!.merge!({:wrapper => :mini, :html => {:id => :mini, :class => 'collapse form-inline'}})
5
+ simple_form_for(object, *(args << options.merge(:builder => MiniFormBuilder)), &block)
6
+ end
7
+
8
+ class MiniFormBuilder < SimpleForm::FormBuilder
9
+ def input(attribute_name, options = {}, &block)
10
+ options[:input_html] = { :class => 'input-medium'}
11
+ super
12
+ end
13
+ end
14
+
15
+ # Wrapper para Mini Formularios
16
+ # TODO: encontrar la manera de cambiar la clase de todos los input por 'input-medium'
17
+ SimpleForm.setup do |config|
18
+ config.wrappers :mini, :tag => 'span' , :class => 'controls', :error_class => 'error' do |b|
19
+ b.use :html5
20
+ b.use :placeholder
21
+ b.use :input
22
+ b.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
23
+ end
24
+ end
25
+ end
@@ -46,7 +46,8 @@ class Atributo
46
46
  case @clase
47
47
  when :string then "'Lorem Ipsum'"
48
48
  when :integer then rand(50)
49
- else ":ejemplo"
49
+ when :boolean then 'true'
50
+ else false
50
51
  end
51
52
  end
52
53
 
@@ -36,7 +36,7 @@ class PruebaGenerator < Rails::Generators::Base
36
36
  args.each do |arg|
37
37
  @atributos << Atributo.new(arg)
38
38
  end
39
-
39
+ @identificador = @atributos.first.nombre
40
40
  info #TODO: sacar de aca!.
41
41
 
42
42
  end
@@ -52,7 +52,8 @@ class PruebaGenerator < Rails::Generators::Base
52
52
  end
53
53
  template "views/nombre.erb", "app/views/admin/#{@plural}/_#{@singular}.html.erb"
54
54
 
55
- # add_admin_route "\n resources :#{@plural} do\n post :reordenar, :on => :collection\n end"
55
+ resources_route = @con_orden ? "\n resources :#{@plural} do\n post :reordenar, :on => :collection\n end" : "\n resources :#{@plural}"
56
+ add_admin_route resources_route
56
57
 
57
58
  template 'cargar.erb', "lib/tasks/cargar_#{@plural}.rake"
58
59
  end
@@ -97,5 +98,9 @@ class PruebaGenerator < Rails::Generators::Base
97
98
  say "new_path #{@new_path}"
98
99
  say "edit_path #{@edit_path}"
99
100
  end
101
+
102
+ def atributos_con_referencia
103
+ @atributos.select {|a| a.clase == :references}
104
+ end
100
105
 
101
106
  end
@@ -1,4 +1,4 @@
1
- <%- atributos = @atributos.collect {|a| ":#{a.nombre} => #{a.ejemplo}" } -%>
1
+ <%- atributos = @atributos.select {|x| x.ejemplo }.collect {|a| ":#{a.nombre} => #{a.ejemplo}" } -%>
2
2
  namespace :cargar do
3
3
  task :<%= @plural %> => :environment do
4
4
  <%- 10.times do-%>
@@ -1,24 +1,27 @@
1
1
  class Admin::<%= @classes %>Controller < Admin::AdminController
2
- <%= if @con_orden? "include Sortable" %>
2
+ <%= "include Sortable" if @con_orden %>
3
3
  load_and_authorize_resource
4
4
 
5
5
  def index
6
6
  @<%= @singular %> = <%= @class %>.new
7
7
  end
8
8
 
9
- def new; end
10
- def edit; end
11
-
9
+ def new
10
+ end
11
+
12
12
  def create
13
13
  @<%= @singular %> = <%= @class %>.new params[:<%= @singular %>]
14
14
  @<%= @singular %>.save!
15
-
15
+ notice = mensaje
16
16
  respond_to do |format|
17
17
  format.html { redirect_to <%= @plural_path %>, notice: mensaje }
18
18
  format.js { @elemento = @<%= @singular %> }
19
19
  end
20
20
  end
21
21
 
22
+ def edit
23
+ end
24
+
22
25
  def update
23
26
  @<%= @singular %>.update_attributes! params[:<%= @singular %>]
24
27
  redirect_to <%= @edit_path %>(@<%= @singular %>), notice: mensaje
@@ -27,7 +30,7 @@ class Admin::<%= @classes %>Controller < Admin::AdminController
27
30
  def destroy
28
31
  @id = @<%= @singular %>.id
29
32
  @<%= @singular %>.eliminar!
30
-
33
+ notice = mensaje
31
34
  respond_to do |format|
32
35
  format.html { redirect_to <%= @plural_path %>, notice: mensaje }
33
36
  format.js
@@ -40,7 +43,7 @@ class Admin::<%= @classes %>Controller < Admin::AdminController
40
43
  flash.now.notice = t("notice.#{action_name}")
41
44
  end
42
45
 
43
- <%- if @con_orden? -%>
46
+ <%- if @con_orden -%>
44
47
  def sort_coleccion
45
48
  <%= @class %>.all
46
49
  end
@@ -2,12 +2,15 @@ class Create<%= @classes %> < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :<%= @plural %> do |t|
4
4
  <%- @atributos.each do |a| -%>
5
- t.<%= a.clase %> :<%= a.nombre %> <%= ", :default => #{a.default}" if a.default %>
5
+ t.<%= a.clase %> :<%= a.nombre %> <%= ", :default => #{a.default}" if (a.default && a.ejemplo) %>
6
6
  <%- end -%>
7
7
 
8
8
  <%- if @con_slug -%>
9
9
  t.string :slug
10
10
  <%- end -%>
11
+ <%- if @con_orden -%>
12
+ t.integer :orden
13
+ <%- end -%>
11
14
  t.boolean :es_activo, :default => true
12
15
 
13
16
  t.timestamps
@@ -1,14 +1,26 @@
1
1
  class <%= @class %> < ActiveRecord::Base
2
-
3
- <%- if @con_slug? -%>
2
+ <%= 'before_create :set_orden' if @con_orden %>
3
+ <%- if @con_slug -%>
4
4
  extend FriendlyId
5
- friendly_id :codigo, use: :slugged
5
+ friendly_id :<%= @identificador %>, use: :slugged
6
+ <%- end -%>
7
+
8
+ <%- atributos_con_referencia.each do |a| -%>
9
+ belongs_to :<%= a.nombre %>
6
10
  <%- end -%>
7
11
 
8
- default_scope where(:es_activo => true)<%= if @con_orden? ".order('#{@plural}.orden')" %>
12
+ default_scope where(:es_activo => true)<%= ".order('#{@plural}.orden')" if @con_orden %>
9
13
 
10
14
  def eliminar!
11
15
  update_attributes :es_activo => false
12
16
  end
17
+
18
+ alias_attribute :to_s, :<%= @identificador %>
13
19
 
20
+ private
21
+ <%- if @con_orden -%>
22
+ def set_orden
23
+ self.orden = self.id
24
+ end
25
+ <%- end -%>
14
26
  end
@@ -1,4 +1,4 @@
1
1
  <%%= mini_form_for <%= @singular %>, :url => url, :remote => true do |f| %>
2
- <%%= f.input :<%= @atributos.first.nombre %> %>
2
+ <%%= f.input :<%= @identificador %> %>
3
3
  <%%= f.button :submit, :name => nil, :disable_with => t("espere") %>
4
4
  <%%- end -%>
@@ -10,7 +10,7 @@
10
10
  <%%= render "mini_form", :<%= @singular %> => @<%= @singular %>, :url => <%= @plural_path %> %>
11
11
 
12
12
  <table id="ordenable" class="table table-striped ordenable">
13
- <%%= thead(:<%= @atributos.first.nombre %>) %>
13
+ <%%= thead(:<%= @identificador %>) %>
14
14
  <tbody>
15
15
  <%%= render @<%= @plural %> %>
16
16
  </tbody>
@@ -1,6 +1,6 @@
1
1
  <%%- clase ||= 'elemento' -%>
2
2
  <%%= content_tag :tr, :class => clase, :id => "elementos_#{<%= @singular %>.id}" do %>
3
- <td><%%= <%= @singular %>.<%= @atributos.first.nombre %> %></td>
3
+ <td><%%= <%= @singular %>.<%= @identificador %> %></td>
4
4
  <td><%%= content_tag :i, '',:class => "handle icon-move", :title => "Mantenga click y arrastre para reordenar" %></td>
5
5
  <td><%%= link_to 'Editar' , <%= @edit_path %>(<%= @singular %>), :class => 'btn btn-mini' if can? :editar, <%= @singular %> %></td>
6
6
  <td><%%= link_to "Eliminar", <%= @singular_path %>(<%= @singular %>), :method => :delete, :confirm => t("confirmacion"), :remote => true, :class => 'btn btn-mini btn-danger' %></td>
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Scaf
2
2
  module Generator
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
5
5
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaf-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -22,6 +22,9 @@ files:
22
22
  - Gemfile
23
23
  - README.md
24
24
  - Rakefile
25
+ - lib/generators/mini_form/USAGE
26
+ - lib/generators/mini_form/mini_form_generator.rb
27
+ - lib/generators/mini_form/templates/mini_form.rb
25
28
  - lib/generators/prueba/USAGE
26
29
  - lib/generators/prueba/atributo.rb
27
30
  - lib/generators/prueba/prueba_generator.rb
@@ -57,6 +60,7 @@ files:
57
60
  - pkg/scaf-generator-0.1.7.gem
58
61
  - pkg/scaf-generator-0.2.1.gem
59
62
  - pkg/scaf-generator-0.2.2.gem
63
+ - pkg/scaf-generator-0.2.4.gem
60
64
  - scaf-generator.gemspec
61
65
  homepage: http://github.com/nicanorperera/scaf-generator
62
66
  licenses: []