leonardo 1.3.0

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.
Files changed (69) hide show
  1. data/CHANGELOG +58 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +115 -0
  4. data/lib/generators/erb/leosca/leosca_generator.rb +73 -0
  5. data/lib/generators/erb/leosca/templates/_form.html.erb +23 -0
  6. data/lib/generators/erb/leosca/templates/_list.erb +47 -0
  7. data/lib/generators/erb/leosca/templates/destroy.js.erb +1 -0
  8. data/lib/generators/erb/leosca/templates/edit.html.erb +11 -0
  9. data/lib/generators/erb/leosca/templates/formtastic/_form.html.erb +10 -0
  10. data/lib/generators/erb/leosca/templates/index.html.erb +35 -0
  11. data/lib/generators/erb/leosca/templates/index.js.erb +1 -0
  12. data/lib/generators/erb/leosca/templates/new.html.erb +7 -0
  13. data/lib/generators/erb/leosca/templates/show.html.erb +13 -0
  14. data/lib/generators/leolay/USAGE +21 -0
  15. data/lib/generators/leolay/leolay_generator.rb +195 -0
  16. data/lib/generators/leolay/templates/app/assets/stylesheets/formtastic.css +145 -0
  17. data/lib/generators/leolay/templates/app/assets/stylesheets/formtastic_changes.css +16 -0
  18. data/lib/generators/leolay/templates/app/views/devise/confirmations/new.html.erb +12 -0
  19. data/lib/generators/leolay/templates/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  20. data/lib/generators/leolay/templates/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  21. data/lib/generators/leolay/templates/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  22. data/lib/generators/leolay/templates/app/views/devise/passwords/edit.html.erb +16 -0
  23. data/lib/generators/leolay/templates/app/views/devise/passwords/new.html.erb +12 -0
  24. data/lib/generators/leolay/templates/app/views/devise/registrations/edit.html.erb +25 -0
  25. data/lib/generators/leolay/templates/app/views/devise/registrations/new.html.erb +18 -0
  26. data/lib/generators/leolay/templates/app/views/devise/sessions/new.html.erb +17 -0
  27. data/lib/generators/leolay/templates/app/views/devise/shared/_links.erb +25 -0
  28. data/lib/generators/leolay/templates/app/views/devise/unlocks/new.html.erb +12 -0
  29. data/lib/generators/leolay/templates/config/locales/devise.en.yml +53 -0
  30. data/lib/generators/leolay/templates/config/locales/devise.it.yml +51 -0
  31. data/lib/generators/leolay/templates/config/locales/en.yml +79 -0
  32. data/lib/generators/leolay/templates/config/locales/it.yml +176 -0
  33. data/lib/generators/leolay/templates/config/locales/kaminari.en.yml +10 -0
  34. data/lib/generators/leolay/templates/config/locales/kaminari.it.yml +10 -0
  35. data/lib/generators/leolay/templates/config.rb +11 -0
  36. data/lib/generators/leolay/templates/layout_helper.rb +39 -0
  37. data/lib/generators/leolay/templates/lib/utility.rb +48 -0
  38. data/lib/generators/leolay/templates/styles/cloudy/images/kaminari/nav.png +0 -0
  39. data/lib/generators/leolay/templates/styles/cloudy/images/style/bg_but_gray.png +0 -0
  40. data/lib/generators/leolay/templates/styles/cloudy/images/style/bg_top.png +0 -0
  41. data/lib/generators/leolay/templates/styles/cloudy/images/style/button_170_126.png +0 -0
  42. data/lib/generators/leolay/templates/styles/cloudy/images/style/button_229_170.png +0 -0
  43. data/lib/generators/leolay/templates/styles/cloudy/images/style/ico_back.png +0 -0
  44. data/lib/generators/leolay/templates/styles/cloudy/images/style/ico_next.png +0 -0
  45. data/lib/generators/leolay/templates/styles/cloudy/images/style/ico_v.png +0 -0
  46. data/lib/generators/leolay/templates/styles/cloudy/images/style/ico_x.png +0 -0
  47. data/lib/generators/leolay/templates/styles/cloudy/images/style/input_background_bn.png +0 -0
  48. data/lib/generators/leolay/templates/styles/cloudy/images/style/logo.png +0 -0
  49. data/lib/generators/leolay/templates/styles/cloudy/images/style/msg_error.gif +0 -0
  50. data/lib/generators/leolay/templates/styles/cloudy/images/style/msg_notice.gif +0 -0
  51. data/lib/generators/leolay/templates/styles/cloudy/stylesheet.sass +341 -0
  52. data/lib/generators/leolay/templates/styles/cloudy/views/kaminari/_next_page.html.erb +5 -0
  53. data/lib/generators/leolay/templates/styles/cloudy/views/kaminari/_page.html.erb +5 -0
  54. data/lib/generators/leolay/templates/styles/cloudy/views/kaminari/_paginator.html.erb +7 -0
  55. data/lib/generators/leolay/templates/styles/cloudy/views/kaminari/_prev_page.html.erb +5 -0
  56. data/lib/generators/leolay/templates/styles/cloudy/views/layout/_layout.html.erb +38 -0
  57. data/lib/generators/leolay/templates/styles/cloudy/views/layout/_message.html.erb +3 -0
  58. data/lib/generators/leolay/templates/styles/cloudy/views/layout/_session.html.erb +10 -0
  59. data/lib/generators/leolay/templates/styles/cloudy/views/layout/application.html.erb +13 -0
  60. data/lib/generators/leosca/USAGE +23 -0
  61. data/lib/generators/leosca/install_generator.rb +15 -0
  62. data/lib/generators/rails/leosca/USAGE +41 -0
  63. data/lib/generators/rails/leosca/leosca_generator.rb +26 -0
  64. data/lib/generators/rails/leosca/templates/leosca.css +56 -0
  65. data/lib/generators/rails/leosca_controller/USAGE +23 -0
  66. data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +159 -0
  67. data/lib/generators/rails/leosca_controller/templates/controller.rb +132 -0
  68. data/template.rb +104 -0
  69. metadata +132 -0
data/CHANGELOG ADDED
@@ -0,0 +1,58 @@
1
+ 1.3.0 (August 22th, 2011) Marco Mastrodonato
2
+ * Add formtastic support and a new custom partial
3
+
4
+
5
+
6
+ 1.2.0 (August 4th, 2011) Marco Mastrodonato
7
+ === Bug Fix
8
+ * Fixed the migration for users creation: authorizations were not set correctly
9
+ * Sign out did not work: add method :delete
10
+ * Fixed minor bugs
11
+
12
+ === Features
13
+ * Updated partial session to have i18n labels
14
+ * Add updated devise.it.yml
15
+ * Add customized devise views with i18n management (to be continue). Devise generator is not required anymore until they update it
16
+
17
+
18
+
19
+
20
+ 1.1.1 (August 4th, 2011) Marco Mastrodonato
21
+ * Fixed minor things
22
+ * Improved cancan configuration
23
+ * Added user and manager creation as well as admin
24
+ * Improved documentation
25
+
26
+ === To do
27
+ * Csv export does not work with ajax pagination
28
+ * Improve ajax management to show, add and edit in the list view
29
+
30
+
31
+
32
+ 1.1.0 (August 3th, 2011) Marco Mastrodonato
33
+
34
+ === Bug Fix
35
+ * Kaminari did not show pagination style
36
+ * Minor fix for ajax code
37
+ * Added Utility class i forgot to include
38
+
39
+ === Features
40
+ * Added authorization management to support cancan
41
+ * Improved authentication management to support warden/devise
42
+ * Added seeds creation. You can avoid using --skip-seeds or change the default elements using --seeds_elements=60
43
+ * Ajax is now the default and add option to skip --skip-remote (to enable/disable ajax set remote to true into index view)
44
+ * Added destroy js template
45
+ * Added localization management into application controller and use lang variable on url (ex: localhost:3000?lang=it)
46
+ * Added class odd/even to tables tr
47
+
48
+
49
+
50
+ 1.0.0 (August 2th, 2011) Marco Mastrodonato
51
+
52
+ * First stable release
53
+
54
+
55
+
56
+ 0.0.1 (July 27th, 2011) Marco Mastrodonato
57
+
58
+ * Starting project
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Marco Mastrodonato
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,115 @@
1
+ = Leolay Generators
2
+
3
+ A layout and customized scaffold generator for Rails 3.1
4
+ Generate a layout using the ERGO Insurance Group\'s style, you can customize it or add your own. It also provides a customized scaffold to generates cool sites ajax ready.
5
+
6
+
7
+ == Install
8
+
9
+ gem install leonardo
10
+
11
+
12
+
13
+
14
+ == Usage
15
+
16
+ Once you install the gem, the generators will be available to all Rails applications on your system.
17
+
18
+ To run the generator, go to your rails project directory and call it using rails generate or destroy command:
19
+ rails g leolay or rails destroy leolay
20
+ rails g leosca or rails destroy leosca
21
+
22
+ PS: Ergosca destroy do not remove variables parts like the attributes inserted into i18n yaml
23
+ PPS: You can run it more times and right like scaffold, is smart and won't generate tons of identical code
24
+
25
+ === Step by step
26
+
27
+ 1. Firstly, create layout and initialize your project:
28
+ rails new AppExample -m template.rb
29
+ (You could find a template into gem root folder)
30
+
31
+ there will be only a conflict on locales/en.yml which you can force
32
+
33
+ Will be:
34
+ * Created an application layout with a nice and dynamic stylesheet based on sass
35
+ * Customized views (only erb atm) and controller ajax ready and filters based on attributes, i18n messages ecc.
36
+ * Customized application.rb to exclude javascript and stylesheet for every resource you will create
37
+ * Customized application controller to manage i18n and others stuff like authentication, authorization ecc [optionals]
38
+ * Created customized partials for pagination with kaminari [optional]
39
+
40
+ 2. If you have used my template you have an application ready to work:
41
+ run rails s and try it on localhost:3000
42
+ if you choosed authentication you have to sign in, try with this different profile:
43
+ email: admin@AppExample.com, password: AppExample
44
+ [this profile can do everything]
45
+ or
46
+ email: manager@AppExample.com, password: AppExample
47
+ [can read, create and update]
48
+ or
49
+ email: user@AppExample.com, password: AppExample
50
+ [can read, create, update and destroy]
51
+
52
+ Profile exists only if you choosed authorization as well.
53
+ That are default and ready to be customized to suit your needs.
54
+
55
+ 3. Create your resource:
56
+ rails g leosca product name:string description:text active:boolean items:integer price:decimal
57
+
58
+ This will act as a normal scaffold more new stuff:
59
+ * will be invoked new leosca_controller which is a customized scaffold_controller
60
+ * customized views with new layout and ajax ready [set remote to true into index]
61
+ * attributes will be insert into i18n files for fast translation
62
+ * seeds will be created for you to populate new table
63
+
64
+ 4. Apply on db
65
+ rake db:migrate
66
+ rake db:seed
67
+
68
+ READY!
69
+
70
+
71
+ You could also customize it, copy under your project folder running:
72
+ rails g leosca:install
73
+
74
+ Then go to lib\generators\erb to change erb views like you would do with original scaffold
75
+ go to lib\generators\rails if you want to customize more.
76
+
77
+
78
+ For more information about usage:
79
+
80
+ rails g leolay --help
81
+ rails g leosca --help
82
+
83
+
84
+ === Example:
85
+
86
+ leolay:
87
+
88
+ rails generate leolay
89
+ rails generate leolay --main_color=#c8c8c8
90
+ rails generate leolay layout1 --main_color=rgb(200,150,200) --second-color=yellow
91
+ rails generate leolay layout2 --skip-pagination --skip-authentication --skip-authorization
92
+
93
+ leosca:
94
+
95
+ rails generate leosca product name:string
96
+ rails generate leosca product name:string --skip-remote => if you do not want ajax
97
+ rails generate leosca product name:string --skip-seeds
98
+ rails generate leosca product name:string --seeds=60 => if you need more records
99
+
100
+ PS: Of course, these options are in addition to those provided by the original scaffold
101
+
102
+
103
+ === Available layout
104
+
105
+ * ergo [default]
106
+
107
+
108
+ == Found a bug?
109
+
110
+ If you are having a problem please submit an issue at m.mastrodonato@gmail.com
111
+
112
+
113
+ == Rails 2 and Rails 3.0.x
114
+
115
+ This Generators does not work with versions earlier 3.1
@@ -0,0 +1,73 @@
1
+ require 'rails/generators/erb'
2
+ require 'rails/generators/resource_helpers'
3
+
4
+ module Erb
5
+ module Generators
6
+ class LeoscaGenerator < Base
7
+ include Rails::Generators::ResourceHelpers
8
+ #puts 'erb:leosca'
9
+
10
+ source_root File.expand_path('../templates', __FILE__)
11
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
12
+ class_option :authorization, :type => :boolean, :default => true, :description => "Add code to manage authorization with cancan"
13
+ class_option :remote, :type => :boolean, :default => true, :description => "Enable ajax. You can also do later set remote to true into index view."
14
+
15
+ def create_root_folder
16
+ empty_directory File.join("app/views", controller_file_path)
17
+ end
18
+
19
+ def copy_view_files
20
+ available_views.each do |view|
21
+ filenames = filenames_all_formats(view, source_paths)
22
+ filenames.each do |filename|
23
+ #Looking for custom filename into subfolder
24
+ filename_source = "#{"formtastic/" if formtastic?}#{filename}"
25
+ search_into_subfolder = nil
26
+ source_paths.each do |path|
27
+ if File.exists?(File.join(path,filename_source))
28
+ search_into_subfolder = true
29
+ break
30
+ end
31
+ end
32
+ filename_source = filename unless search_into_subfolder
33
+
34
+ template filename_source, File.join("app/views", controller_file_path, filename)
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ protected
41
+
42
+ def available_views
43
+ %w(index edit show new _form _list destroy)
44
+ end
45
+
46
+ def filenames_all_formats(name, paths=[], formats=[:html, :js, nil])
47
+ filenames = []
48
+ paths.each do |path|
49
+ formats.each do |format|
50
+ filename = filename_with_extensions(format, name)
51
+ if File.exists?(File.join(path, filename))
52
+ filenames << filename
53
+ end
54
+ end
55
+ break if filenames.any?
56
+ end
57
+ filenames
58
+ end
59
+ def filename_with_extensions(format, name, parser=:erb)
60
+ [name, format, parser].compact.join(".")
61
+ end
62
+
63
+ def authorization?
64
+ File.exists? "app/models/ability.rb"
65
+ end
66
+
67
+ def formtastic?
68
+ File.exists? "config/initializers/formtastic.rb"
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,23 @@
1
+ <%%= form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%% if @<%= singular_table_name %>.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
5
+
6
+ <ul>
7
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
8
+ <li><%%= msg %></li>
9
+ <%% end %>
10
+ </ul>
11
+ </div>
12
+ <%% end %>
13
+
14
+ <% attributes.each do |attribute| -%>
15
+ <div class="field">
16
+ <%%= f.label :<%= attribute.name %> %><br />
17
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
18
+ </div>
19
+ <% end -%>
20
+ <div class="actions">
21
+ <%%= f.submit :class => 'button large' %>
22
+ </div>
23
+ <%% end %>
@@ -0,0 +1,47 @@
1
+ <%%= paginate @<%= plural_table_name %>, :remote => remote %>
2
+ <div class="separator"></div>
3
+
4
+ <table class='user' cellspacing='0'>
5
+ <thead>
6
+ <tr>
7
+ <%- attributes.each do |attribute| -%>
8
+ <th><%%= t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %></th>
9
+ <%- end -%>
10
+ <th></th>
11
+ <th></th>
12
+ <th></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
17
+ <tr id="tr<%%= <%= singular_table_name %>.id %>" class="<%%= cycle("odd", "even")%>">
18
+ <%- attributes.each do |attribute| -%>
19
+ <%- case attribute.type
20
+ when :boolean -%>
21
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> ? style_image_tag("ico_v.png") : style_image_tag('ico_x.png') %></td>
22
+ <%- else -%>
23
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
24
+ <%- end -%>
25
+ <%- end -%>
26
+ <td><%%= link_to t(:show), <%= singular_table_name %> %></td>
27
+ <% if authorization? -%>
28
+ <%% if can? :update, <%= singular_table_name %> -%>
29
+ <% end -%>
30
+ <td><%%= link_to t(:edit), edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
31
+ <% if authorization? -%>
32
+ <%% end -%>
33
+ <% end -%>
34
+ <% if authorization? -%>
35
+ <%% if can? :destroy, <%= singular_table_name %> -%>
36
+ <% end -%>
37
+ <td><%%= link_to t(:destroy), <%= singular_table_name %>, <%= key_value :confirm, "t(:sure?)" %>, <%= key_value :method, ":delete" %>, :remote => remote %></td>
38
+ <% if authorization? -%>
39
+ <%% end -%>
40
+ <% end -%>
41
+ </tr>
42
+ <%% end %>
43
+ </tbody>
44
+ </table>
45
+
46
+ <div class="separator"></div>
47
+ <%%= paginate @<%= plural_table_name %>, :remote => remote %>
@@ -0,0 +1 @@
1
+ $("#tr<%%= @<%= singular_table_name %>.id %>").hide('fast');
@@ -0,0 +1,11 @@
1
+ <%% secondary_navigation({:value => link_to(t(:list), <%= plural_table_name %>_path)},
2
+ ({:value => link_to(t(:add), new_<%= singular_table_name %>_path)}<%= " if can?(:create, @#{singular_table_name})" if authorization? %>),
3
+ {:value => t(:edit), :active => true},
4
+ {:value => link_to(t(:show), @<%= singular_table_name %>)}
5
+ ) %>
6
+
7
+ <%% title t('attributes.<%= singular_table_name %>.op_edit') %>
8
+
9
+ <%%= render 'form' %>
10
+ <!--<%%#= link_to t(:show), @<%= singular_table_name %> %> |-->
11
+ <!--<%%#= link_to t(:back), <%= index_helper %>_path %>-->
@@ -0,0 +1,10 @@
1
+ <%%= semantic_form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%%= f.inputs do %>
3
+ <% attributes.each do |attribute| -%>
4
+ <%%= f.input :<%= attribute.name %> %>
5
+ <% end -%>
6
+ <%% end %>
7
+ <%%= f.buttons do %>
8
+ <%%= f.commit_button :button_html => { :class => "button large" } %>
9
+ <%% end %>
10
+ <%% end %>
@@ -0,0 +1,35 @@
1
+ <%% secondary_navigation({:value => t(:list), :active => true},
2
+ ({:value => link_to(t(:add), new_<%= singular_table_name %>_path)}<%= " if can?(:create, @#{singular_table_name})" if authorization? %>)
3
+ ) %>
4
+
5
+ <%% title t('attributes.<%= singular_table_name %>.op_index') %>
6
+
7
+ <%% remote = <%= options.remote? %> %>
8
+ <%%= form_for :<%= singular_table_name %>, :remote => remote, :html => { :method => :get, :id => "form_search" } do |f| %>
9
+ <div class="filter-container">
10
+ <%- attributes.each do |attribute| -%>
11
+ <div class="filter-field">
12
+ <b><%%= f.label t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %></b><br />
13
+ <%- case attribute.type -%>
14
+ <%- when :boolean -%>
15
+ <%%= radio_button("<%= singular_table_name %>", "<%= attribute.name %>", "1", {:checked => (@<%= singular_table_name %>.<%= attribute.name %>)}) %><%%= label_tag "<%= singular_table_name %>_<%= attribute.name %>_1", t(:yes) %><br />
16
+ <%%= radio_button("<%= singular_table_name %>", "<%= attribute.name %>", "0", {:checked => (!@<%= singular_table_name %>.<%= attribute.name %>)}) %><%%= label_tag "<%= singular_table_name %>_<%= attribute.name %>_0", t(:no) %><br />
17
+ <%%= radio_button("<%= singular_table_name %>", "<%= attribute.name %>", "") %><%%= label_tag "<%= singular_table_name %>_<%= attribute.name %>_", t(:all) %>
18
+ <%- when :text -%>
19
+ <%%= f.text_field :<%= attribute.name %> %>
20
+ <%- else -%>
21
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
22
+ <%- end -%>
23
+
24
+ </div>
25
+ <%- end -%>
26
+ <div style="clear:both;">
27
+ <%%= f.submit t(:search), {:class=>'button medium'} %>
28
+ <%%= f.submit 'Csv', {:class=>'button medium csv'} %>
29
+ </div>
30
+ </div>
31
+ <%% end %>
32
+
33
+ <div id="list">
34
+ <%%= render 'list', :remote => remote %>
35
+ </div>
@@ -0,0 +1 @@
1
+ $("#list").html("<%%= escape_javascript(render('list', :remote => true))%>");
@@ -0,0 +1,7 @@
1
+ <%% secondary_navigation({:value => link_to(t(:list), <%= plural_table_name %>_path)},
2
+ {:value => t(:add), :active => true})
3
+ %>
4
+
5
+ <%% title t('attributes.<%= singular_table_name %>.op_new') %>
6
+
7
+ <%%= render 'form' %>
@@ -0,0 +1,13 @@
1
+ <%% secondary_navigation({:value => link_to(t(:list),<%= plural_table_name %>_path)},
2
+ ({:value => link_to(t(:add), new_<%= singular_table_name %>_path)}<%= " if can?(:create, @#{singular_table_name})" if authorization? %>),
3
+ ({:value => link_to(t(:edit), edit_<%= singular_table_name %>_path(@<%= singular_table_name %>))}<%= " if can?(:update, @#{singular_table_name})" if authorization? %>),
4
+ {:value => link_to(t(:show), @<%= singular_table_name %>), :active => true}
5
+ )%>
6
+
7
+ <% attributes.each do |attribute| -%>
8
+ <p>
9
+ <b><%%= t('attributes.<%= singular_table_name %>.<%= attribute.name %>') %>:</b>
10
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
11
+ </p>
12
+
13
+ <% end -%>
@@ -0,0 +1,21 @@
1
+ Description:
2
+ A layout and customized scaffold generator for Rails 3.1
3
+
4
+ Rails version supported:
5
+ 3.1
6
+
7
+ Available layout:
8
+ ergo [default]
9
+
10
+ Example:
11
+ rails generate leolay
12
+ rails generate leolay --main_color=#c8c8c8
13
+ rails generate leolay layout1 --main_color=rgb(200,150,200) --second-color=yellow
14
+ rails generate leolay layout2 --skip-pagination --skip-authentication --skip-authorization
15
+
16
+ Will be:
17
+ Created an application layout with a nice and dynamic stylesheet based on sass
18
+ Customized views (only erb atm) and controller ajax ready and filters based on attributes, i18n messages ecc.
19
+ Customized application.rb to exclude javascript and stylesheet for every resource you will create
20
+ Customized application controller to manage i18n and others stuff like authentication, authorization ecc [optionals]
21
+ Created customized partials for pagination with kaminari [optional]
@@ -0,0 +1,195 @@
1
+ class LeolayGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :style, :type => :string, :default => "cloudy"
4
+ class_option :pagination, :type => :boolean, :default => true, :description => "Include pagination files"
5
+ class_option :main_color, :type => :string, :default => nil, :description => "Force a main color for the stylesheet"
6
+ class_option :second_color, :type => :string, :default => nil, :description => "Force a secondary color for the stylesheet"
7
+ class_option :authentication, :type => :boolean, :default => true, :description => "Add code to manage authentication with devise"
8
+ class_option :authorization, :type => :boolean, :default => true, :description => "Add code to manage authorization with cancan"
9
+ class_option :user_class, :type => :boolean, :default => 'user', :description => "Set the user class name"
10
+ class_option :formtastic, :type => :boolean, :default => true, :description => "Copy formtastic files into leosca custom folder (inside project)"
11
+
12
+
13
+ def generate_layout
14
+ template "config.rb", "config/initializers/config.rb"
15
+
16
+ template "styles/#{style_name}/stylesheet.sass",
17
+ "app/assets/stylesheets/#{style_name}.sass"
18
+
19
+ copy_file "layout_helper.rb", "app/helpers/layout_helper.rb"
20
+
21
+ copy_file "styles/#{style_name}/views/layout/application.html.erb", "app/views/layouts/application.html.erb", :force => true
22
+ template "styles/#{style_name}/views/layout/_layout.html.erb", "app/views/layouts/_#{style_name}.html.erb"
23
+ #{:authentication => options.authentication?,
24
+ #:authorization => options.authorization?}
25
+ copy_file "styles/#{style_name}/views/layout/_message.html.erb", "app/views/application/_message.html.erb"
26
+ copy_file "styles/#{style_name}/views/layout/_session.html.erb", "app/views/application/_session.html.erb" if options.authentication?
27
+
28
+ copy_file "config/locales/en.yml", "config/locales/en.yml"
29
+ copy_file "config/locales/it.yml", "config/locales/it.yml"
30
+
31
+ copy_file "lib/utility.rb", "lib/extras/utility.rb"
32
+
33
+ if options.pagination?
34
+ copy_file "config/locales/kaminari.en.yml", "config/locales/kaminari.en.yml"
35
+ copy_file "config/locales/kaminari.it.yml", "config/locales/kaminari.it.yml"
36
+
37
+ copy_file "styles/#{style_name}/views/kaminari/_next_page.html.erb", "app/views/kaminari/_next_page.html.erb"
38
+ copy_file "styles/#{style_name}/views/kaminari/_page.html.erb", "app/views/kaminari/_page.html.erb"
39
+ copy_file "styles/#{style_name}/views/kaminari/_paginator.html.erb", "app/views/kaminari/_paginator.html.erb"
40
+ copy_file "styles/#{style_name}/views/kaminari/_prev_page.html.erb", "app/views/kaminari/_prev_page.html.erb"
41
+
42
+ copy_file "styles/#{style_name}/images/kaminari/nav.png", "app/assets/images/styles/#{style_name}/kaminari/nav.png"
43
+ end
44
+
45
+ directory "styles/#{style_name}/images/style", "app/assets/images/styles/#{style_name}"
46
+
47
+ if options.authentication?
48
+ copy_file "config/locales/devise.en.yml", "config/locales/devise.en.yml"
49
+ copy_file "config/locales/devise.it.yml", "config/locales/devise.it.yml"
50
+ directory "app/views/devise", "app/views/devise"
51
+ end
52
+ end
53
+
54
+ def setup_application
55
+ application do
56
+ <<-FILE.gsub(/^ /, '')
57
+ config.generators do |g|
58
+ g.stylesheets false
59
+ g.javascripts false
60
+ g.leosca_controller :leosca_controller
61
+ end
62
+
63
+ config.autoload_paths += %W(\#{config.root}/lib/extras)
64
+ FILE
65
+ end
66
+
67
+ file = "app/controllers/application_controller.rb"
68
+ if File.exists?(file)
69
+ inject_into_class file, ApplicationController do
70
+ <<-FILE.gsub(/^ /, '')
71
+ rescue_from CanCan::AccessDenied do |exception|
72
+ redirect_to root_url, :alert => exception.message
73
+ end
74
+ FILE
75
+ end if options.authorization?
76
+
77
+ #{options.authentication? ? ", :authenticate_user!" : ""}
78
+ inject_into_class file, ApplicationController do
79
+ <<-FILE.gsub(/^ /, '')
80
+ before_filter :localizate
81
+
82
+ def localizate
83
+ if params[:lang]
84
+ session[:lang] = params[:lang]
85
+ else
86
+ session[:lang] ||= I18n.default_locale
87
+ end
88
+ I18n.locale = session[:lang]
89
+ end
90
+ FILE
91
+ end
92
+ end
93
+ end
94
+
95
+ def setup_authentication
96
+ file = "app/models/#{options.user_class}.rb"
97
+ #puts "File #{file} #{File.exists?(file) ? "" : "does not"} exists!"
98
+ return unless options.authentication? and File.exists?(file)
99
+
100
+ inject_into_class file, User do
101
+ <<-FILE.gsub(/^ /, '')
102
+ ROLES = %w[admin manager user guest]
103
+ scope :with_role, lambda { |role| {:conditions => "roles_mask & \#{2**ROLES.index(role.to_s)} > 0 "} }
104
+
105
+ def roles=(roles)
106
+ self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum
107
+ end
108
+ def roles
109
+ ROLES.reject { |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? }
110
+ end
111
+ def role_symbols
112
+ roles.map(&:to_sym)
113
+ end
114
+ def role?(role)
115
+ roles.include? role.to_s
116
+ end
117
+ FILE
118
+ end
119
+
120
+ end
121
+
122
+ def setup_authorization
123
+ file = "app/models/ability.rb"
124
+ return unless File.exists?(file)
125
+ inject_into_file file, :before => " end\nend" do
126
+ <<-FILE.gsub(/^ /, '')
127
+ user ||= User.new
128
+ can :manage, :all if user.role? :admin
129
+
130
+ FILE
131
+ end
132
+ end
133
+
134
+
135
+ def create_admin_migration
136
+ file = "db/migrate/*_create_admin.rb"
137
+ return unless options.authentication? and Dir[file].empty?
138
+ file = file.sub('*', Time.now.strftime("%Y%m%d%H9999"))
139
+ create_file file do
140
+ <<-FILE.gsub(/^ /, '')
141
+ class CreateAdmin < ActiveRecord::Migration
142
+ def self.up
143
+ add_column :users, :roles_mask, :integer
144
+ user=User.new :email => 'admin@#{app_name}.com', :password => '#{app_name}', :password_confirmation => '#{app_name}'
145
+ user.roles=['admin']
146
+ user.save
147
+ user=User.new :email => 'manager@#{app_name}.com', :password => '#{app_name}', :password_confirmation => '#{app_name}'
148
+ user.roles=['manager']
149
+ user.save
150
+ user=User.new :email => 'user@#{app_name}.com', :password => '#{app_name}', :password_confirmation => '#{app_name}'
151
+ user.roles=['user']
152
+ user.save
153
+ end
154
+ def self.down
155
+ User.delete User.find_all_by_email(['admin@#{app_name.downcase}.com',
156
+ 'manager@#{app_name.downcase}.com',
157
+ 'user@#{app_name.downcase}.com']).map(&:id)
158
+ remove_column :users, :roles_mask
159
+ end
160
+ end
161
+ FILE
162
+ end
163
+ end
164
+
165
+ def setup_formtastic
166
+ return unless options.formtastic?
167
+
168
+ file = "app/assets/stylesheets/formtastic.css"
169
+ copy_file file, file
170
+ file = "app/assets/stylesheets/formtastic_changes.css"
171
+ copy_file file, file
172
+
173
+ #New version include custom partial _form
174
+ #file_source = "lib/templates/erb/scaffold/_form.html.erb"
175
+ #file_destination = "lib/templates/erb/leosca/_form.html.erb"
176
+ #copy_file file_source, file_destination if File.exists?(file_source) and not File.exists?(file_destination)
177
+
178
+ file = "config/initializers/formtastic.rb"
179
+ inject_into_file file, :after => "# Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false" do
180
+ <<-FILE.gsub(/^ /, '')
181
+
182
+ Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
183
+ FILE
184
+ end if File.exists?(file)
185
+ end
186
+
187
+ private
188
+ def style_name
189
+ style.underscore
190
+ end
191
+
192
+ def app_name
193
+ File.basename(Dir.pwd)
194
+ end
195
+ end