flexi_generators 0.2.2 → 0.2.3
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/README.textile +63 -63
- data/Rakefile +16 -16
- data/VERSION +1 -1
- data/flexi_generators.gemspec +1 -1
- data/lib/flexi_generators.rb +2 -2
- data/lib/generators/flexi_auth/USAGE +5 -5
- data/lib/generators/flexi_auth/flexi_auth_generator.rb +116 -116
- data/lib/generators/flexi_auth/templates/users_controller.rb +1 -1
- data/lib/generators/flexi_auth/templates/views/erb/edit.html.erb +24 -24
- data/lib/generators/flexi_auth/templates/views/erb/index.html.erb +27 -27
- data/lib/generators/flexi_auth/templates/views/erb/new.html.erb +23 -23
- data/lib/generators/flexi_auth/templates/views/erb/show.html.erb +16 -16
- data/lib/generators/flexi_prepare/USAGE +6 -6
- data/lib/generators/flexi_prepare/flexi_prepare_generator.rb +56 -56
- data/lib/generators/flexi_prepare/templates/menu.png +0 -0
- data/lib/generators/flexi_prepare/templates/pt-BR.yml +203 -203
- data/lib/generators/flexi_prepare/templates/users.png +0 -0
- data/lib/generators/flexi_scaffold/USAGE +8 -8
- data/lib/generators/flexi_scaffold/flexi_scaffold_generator.rb +98 -98
- data/lib/generators/flexi_scaffold/templates/views/erb/edit.html.erb +3 -3
- data/lib/generators/flexi_scaffold/templates/views/erb/index.html.erb +29 -29
- data/lib/generators/flexi_scaffold/templates/views/erb/new.html.erb +2 -2
- data/lib/generators/flexi_scaffold/templates/views/erb/show.html.erb +15 -15
- data/template.rb +1 -1
- metadata +3 -3
Binary file
|
@@ -1,8 +1,8 @@
|
|
1
|
-
Description:
|
2
|
-
Explain the generator
|
3
|
-
|
4
|
-
Example:
|
5
|
-
rails generate flexi_scaffold Thing
|
6
|
-
|
7
|
-
This will create:
|
8
|
-
what/will/it/create
|
1
|
+
Description:
|
2
|
+
Explain the generator
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate flexi_scaffold Thing
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
what/will/it/create
|
@@ -1,98 +1,98 @@
|
|
1
|
-
require 'rails/generators/migration'
|
2
|
-
require 'rails/generators/generated_attribute'
|
3
|
-
|
4
|
-
class FlexiScaffoldGenerator < Rails::Generators::Base
|
5
|
-
include Rails::Generators::Migration
|
6
|
-
source_root File.expand_path('../templates', __FILE__)
|
7
|
-
|
8
|
-
no_tasks { attr_accessor :model_name, :model_attributes }
|
9
|
-
argument :model_name, :type => :string, :required => true, :banner => 'ModelName'
|
10
|
-
argument :args_for_m, :type => :array, :default => [], :banner => 'model:attributes'
|
11
|
-
|
12
|
-
def initialize(*args, &block)
|
13
|
-
super
|
14
|
-
@model_attributes = []
|
15
|
-
|
16
|
-
args_for_m.each do |arg|
|
17
|
-
if arg.include?(':')
|
18
|
-
@model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
@model_attributes.uniq!
|
23
|
-
|
24
|
-
if @model_attributes.empty?
|
25
|
-
if model_exists?
|
26
|
-
model_columns_for_attributes.each do |column|
|
27
|
-
@model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
28
|
-
end
|
29
|
-
else
|
30
|
-
@model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def create_model
|
36
|
-
template 'model.rb', "app/models/#{singular_name}.rb"
|
37
|
-
template "tests/model.rb", "test/unit/#{singular_name}_test.rb"
|
38
|
-
template 'fixtures.yml', "test/fixtures/#{plural_name}.yml"
|
39
|
-
end
|
40
|
-
|
41
|
-
def create_controller
|
42
|
-
template "controller.rb", "app/controllers/admin/#{plural_name}_controller.rb"
|
43
|
-
inject_into_file "config/routes.rb", "\n\tresources #{plural_name.to_sym.inspect}", :after => 'match "home" => "home#index"'
|
44
|
-
template "tests/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
|
45
|
-
template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
|
46
|
-
template "tests/helper.rb", "test/unit/helpers/#{plural_name}_controller_test.rb"
|
47
|
-
end
|
48
|
-
|
49
|
-
def create_view_files
|
50
|
-
template "views/erb/index.html.erb", "app/views/admin/#{plural_name}/index.html.erb"
|
51
|
-
template "views/erb/_form.html.erb", "app/views/admin/#{plural_name}/_form.html.erb"
|
52
|
-
template "views/erb/show.html.erb", "app/views/admin/#{plural_name}/show.html.erb"
|
53
|
-
template "views/erb/new.html.erb", "app/views/admin/#{plural_name}/new.html.erb"
|
54
|
-
template "views/erb/edit.html.erb", "app/views/admin/#{plural_name}/edit.html.erb"
|
55
|
-
template "views/erb/_error_messages.html.erb", "app/views/shared/_error_messages.html.erb"
|
56
|
-
end
|
57
|
-
|
58
|
-
def create_migration
|
59
|
-
migration_template 'migration.rb', "db/migrate/create_#{plural_name}.rb"
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def singular_name
|
65
|
-
model_name.underscore
|
66
|
-
end
|
67
|
-
|
68
|
-
def plural_name
|
69
|
-
model_name.underscore.pluralize
|
70
|
-
end
|
71
|
-
|
72
|
-
def class_name
|
73
|
-
model_name.camelize
|
74
|
-
end
|
75
|
-
|
76
|
-
def plural_class_name
|
77
|
-
plural_name.camelize
|
78
|
-
end
|
79
|
-
|
80
|
-
def model_exists?
|
81
|
-
File.exist? destination_path("app/models/#{singular_name}.rb")
|
82
|
-
end
|
83
|
-
|
84
|
-
def model_columns_for_attributes
|
85
|
-
class_name.constantize.columns.reject do |column|
|
86
|
-
column.name.to_s =~ /^(id|created_at|updated_at)$/
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.next_migration_number(dirname) #:nodoc:
|
91
|
-
if ActiveRecord::Base.timestamped_migrations
|
92
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
93
|
-
else
|
94
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
require 'rails/generators/generated_attribute'
|
3
|
+
|
4
|
+
class FlexiScaffoldGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
no_tasks { attr_accessor :model_name, :model_attributes }
|
9
|
+
argument :model_name, :type => :string, :required => true, :banner => 'ModelName'
|
10
|
+
argument :args_for_m, :type => :array, :default => [], :banner => 'model:attributes'
|
11
|
+
|
12
|
+
def initialize(*args, &block)
|
13
|
+
super
|
14
|
+
@model_attributes = []
|
15
|
+
|
16
|
+
args_for_m.each do |arg|
|
17
|
+
if arg.include?(':')
|
18
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
@model_attributes.uniq!
|
23
|
+
|
24
|
+
if @model_attributes.empty?
|
25
|
+
if model_exists?
|
26
|
+
model_columns_for_attributes.each do |column|
|
27
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_model
|
36
|
+
template 'model.rb', "app/models/#{singular_name}.rb"
|
37
|
+
template "tests/model.rb", "test/unit/#{singular_name}_test.rb"
|
38
|
+
template 'fixtures.yml', "test/fixtures/#{plural_name}.yml"
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_controller
|
42
|
+
template "controller.rb", "app/controllers/admin/#{plural_name}_controller.rb"
|
43
|
+
inject_into_file "config/routes.rb", "\n\tresources #{plural_name.to_sym.inspect}", :after => 'match "home" => "home#index"'
|
44
|
+
template "tests/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
|
45
|
+
template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
|
46
|
+
template "tests/helper.rb", "test/unit/helpers/#{plural_name}_controller_test.rb"
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_view_files
|
50
|
+
template "views/erb/index.html.erb", "app/views/admin/#{plural_name}/index.html.erb"
|
51
|
+
template "views/erb/_form.html.erb", "app/views/admin/#{plural_name}/_form.html.erb"
|
52
|
+
template "views/erb/show.html.erb", "app/views/admin/#{plural_name}/show.html.erb"
|
53
|
+
template "views/erb/new.html.erb", "app/views/admin/#{plural_name}/new.html.erb"
|
54
|
+
template "views/erb/edit.html.erb", "app/views/admin/#{plural_name}/edit.html.erb"
|
55
|
+
template "views/erb/_error_messages.html.erb", "app/views/shared/_error_messages.html.erb"
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_migration
|
59
|
+
migration_template 'migration.rb', "db/migrate/create_#{plural_name}.rb"
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def singular_name
|
65
|
+
model_name.underscore
|
66
|
+
end
|
67
|
+
|
68
|
+
def plural_name
|
69
|
+
model_name.underscore.pluralize
|
70
|
+
end
|
71
|
+
|
72
|
+
def class_name
|
73
|
+
model_name.camelize
|
74
|
+
end
|
75
|
+
|
76
|
+
def plural_class_name
|
77
|
+
plural_name.camelize
|
78
|
+
end
|
79
|
+
|
80
|
+
def model_exists?
|
81
|
+
File.exist? destination_path("app/models/#{singular_name}.rb")
|
82
|
+
end
|
83
|
+
|
84
|
+
def model_columns_for_attributes
|
85
|
+
class_name.constantize.columns.reject do |column|
|
86
|
+
column.name.to_s =~ /^(id|created_at|updated_at)$/
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.next_migration_number(dirname) #:nodoc:
|
91
|
+
if ActiveRecord::Base.timestamped_migrations
|
92
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
93
|
+
else
|
94
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
<%% title "Editando <%= singular_name.titleize %>" %>
|
2
|
-
|
3
|
-
<%%= render "form" %>
|
1
|
+
<%% title "Editando <%= singular_name.titleize %>" %>
|
2
|
+
|
3
|
+
<%%= render "form" %>
|
@@ -1,29 +1,29 @@
|
|
1
|
-
<%% title("<%= plural_name.titleize %>") %>
|
2
|
-
|
3
|
-
<div id="new_box">
|
4
|
-
<%%= link_to 'Adicionar', new_admin_<%= singular_name %>_path, :class => 'button medium green' %>
|
5
|
-
</div>
|
6
|
-
|
7
|
-
<table cellspacing="0" cellpadding="2">
|
8
|
-
<tr>
|
9
|
-
<%- for attribute in model_attributes -%>
|
10
|
-
<th><%= attribute.human_name.titleize %></th>
|
11
|
-
<%- end -%>
|
12
|
-
<th></th>
|
13
|
-
</tr>
|
14
|
-
<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
|
15
|
-
<tr>
|
16
|
-
<%- for attribute in model_attributes -%>
|
17
|
-
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
18
|
-
<%- end -%>
|
19
|
-
<td width="11%">
|
20
|
-
<ul class="actions">
|
21
|
-
<li><%%= link_to( image_tag("show.png"), [:admin, <%= singular_name %>], :title => "Mostrar" ) %></li>
|
22
|
-
<li><%%= link_to( image_tag("edit.png"), edit_admin_<%= singular_name %>_path(<%= singular_name %>), :title => "Editar" ) %></li>
|
23
|
-
<li><%%= link_to( image_tag("delete.png"), [:admin, <%= singular_name %>], :confirm => 'Tem certeza que deseja excluir?', :method => :delete, :title => "Excluir" ) %></li>
|
24
|
-
</ul>
|
25
|
-
</td>
|
26
|
-
</tr>
|
27
|
-
<%% end %>
|
28
|
-
</table>
|
29
|
-
<%%= will_paginate @<%= plural_name %>, :previous_label=>'« Anterior', :next_label=>'Próximo »' %>
|
1
|
+
<%% title("<%= plural_name.titleize %>") %>
|
2
|
+
|
3
|
+
<div id="new_box">
|
4
|
+
<%%= link_to 'Adicionar', new_admin_<%= singular_name %>_path, :class => 'button medium green' %>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<table cellspacing="0" cellpadding="2">
|
8
|
+
<tr>
|
9
|
+
<%- for attribute in model_attributes -%>
|
10
|
+
<th><%= attribute.human_name.titleize %></th>
|
11
|
+
<%- end -%>
|
12
|
+
<th></th>
|
13
|
+
</tr>
|
14
|
+
<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
|
15
|
+
<tr>
|
16
|
+
<%- for attribute in model_attributes -%>
|
17
|
+
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
18
|
+
<%- end -%>
|
19
|
+
<td width="11%">
|
20
|
+
<ul class="actions">
|
21
|
+
<li><%%= link_to( image_tag("show.png"), [:admin, <%= singular_name %>], :title => "Mostrar" ) %></li>
|
22
|
+
<li><%%= link_to( image_tag("edit.png"), edit_admin_<%= singular_name %>_path(<%= singular_name %>), :title => "Editar" ) %></li>
|
23
|
+
<li><%%= link_to( image_tag("delete.png"), [:admin, <%= singular_name %>], :confirm => 'Tem certeza que deseja excluir?', :method => :delete, :title => "Excluir" ) %></li>
|
24
|
+
</ul>
|
25
|
+
</td>
|
26
|
+
</tr>
|
27
|
+
<%% end %>
|
28
|
+
</table>
|
29
|
+
<%%= will_paginate @<%= plural_name %>, :previous_label=>'« Anterior', :next_label=>'Próximo »' %>
|
@@ -1,3 +1,3 @@
|
|
1
|
-
<%% title "Novo <%= singular_name.titleize %>" %>
|
2
|
-
|
1
|
+
<%% title "Novo <%= singular_name.titleize %>" %>
|
2
|
+
|
3
3
|
<%%= render "form" %>
|
@@ -1,15 +1,15 @@
|
|
1
|
-
<%% title "<%= singular_name.titleize %>" %>
|
2
|
-
|
3
|
-
<%- for attribute in model_attributes -%>
|
4
|
-
<p>
|
5
|
-
<b><%= attribute.human_name.titleize %>:</b>
|
6
|
-
<%%= @<%= singular_name %>.<%= attribute.name %> %>
|
7
|
-
</p>
|
8
|
-
<%- end -%>
|
9
|
-
|
10
|
-
<div id="control_box">
|
11
|
-
<%%= link_to( image_tag("back.png"), admin_<%= plural_name %>_path, :title => "Voltar" ) %> |
|
12
|
-
<%%= link_to( image_tag("edit.png"), edit_admin_<%= singular_name %>_path(@<%= singular_name %>), :title => "Editar" ) %> |
|
13
|
-
<%%= link_to( image_tag("delete.png"), [:admin, @<%= singular_name %>], :confirm => 'Tem certeza que deseja excluir?', :method => :delete, :title => "Exlcuir" ) %>
|
14
|
-
</div>
|
15
|
-
|
1
|
+
<%% title "<%= singular_name.titleize %>" %>
|
2
|
+
|
3
|
+
<%- for attribute in model_attributes -%>
|
4
|
+
<p>
|
5
|
+
<b><%= attribute.human_name.titleize %>:</b>
|
6
|
+
<%%= @<%= singular_name %>.<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
<div id="control_box">
|
11
|
+
<%%= link_to( image_tag("back.png"), admin_<%= plural_name %>_path, :title => "Voltar" ) %> |
|
12
|
+
<%%= link_to( image_tag("edit.png"), edit_admin_<%= singular_name %>_path(@<%= singular_name %>), :title => "Editar" ) %> |
|
13
|
+
<%%= link_to( image_tag("delete.png"), [:admin, @<%= singular_name %>], :confirm => 'Tem certeza que deseja excluir?', :method => :delete, :title => "Exlcuir" ) %>
|
14
|
+
</div>
|
15
|
+
|
data/template.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexi_generators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Leandro de Oliveira
|