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
@@ -0,0 +1,5 @@
1
+ <% if current_page.first? %>
2
+ <span class="csb" style="background-position:-28px 0;width:42px"></span>
3
+ <% else %>
4
+ <%= link_to raw("<span class='csb ch' style='background-position:-6px 0;float:right;width:60px'></span><span style='display:block;margin-right:35px;clear:right;text-decoration:underline'>#{t('views.pagination.previous')}</span>"), url, :class => 'pn knavi', :id => 'pnprev', :style => 'text-decoration:none', :remote => remote %>
5
+ <% end %>
@@ -0,0 +1,38 @@
1
+ <div id="header">
2
+ <div id="app-title">
3
+ <h1><%%= link_to CONFIG[:application][:name], root_url %> <span class="subtitle"><%%= ENV["RAILS_ENV"] %> <%%= CONFIG[:application][:version] %></span></h1>
4
+ </div>
5
+ <div class="clear"></div>
6
+ <% if options.authentication? -%>
7
+ <%%= render 'session' %>
8
+ <% end -%>
9
+ <div class="navigation primary">
10
+ <ul>
11
+ <li class="<%%= controller.controller_path == 'home' ? 'active' : '' %>"><a href="<%%= root_path %>"><%%= t('home') %></a></li>
12
+ <!-- Insert below other elements -->
13
+ </ul>
14
+ <div class="clear"></div>
15
+ </div>
16
+ </div>
17
+
18
+ <div id="wrapper">
19
+ <div class="navigation secondary">
20
+ <%%= yield(:secondary_navigation) %>
21
+ </div>
22
+ <div id="container">
23
+ <%%= render 'message' %>
24
+
25
+ <%% if show_title? -%>
26
+ <h1><%%= yield(:title) %></h1>
27
+ <%% end -%>
28
+
29
+ <div id="dynamic">
30
+ <%%= yield %>
31
+ </div>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="footer">
36
+ <p><%%= style_image_tag("logo.png", {:style=>"border: gray 1px solid"}) %></p>
37
+ <p><%%= CONFIG[:application][:name] %> 2011, all rights reserved.</p>
38
+ </div>
@@ -0,0 +1,3 @@
1
+ <%- flash.each do |name, msg| -%>
2
+ <%= content_tag :div, msg, :class => "message #{name}" %>
3
+ <%- end -%>
@@ -0,0 +1,10 @@
1
+ <div id="session">
2
+ <%- if user_signed_in? -%>
3
+ <%= t("authentication.signed_in_as") %> <strong><%= current_user.email || "Guest" %></strong>. <%= t("authentication.not_you") %>
4
+ <%= link_to t("authentication.sign_out"), destroy_user_session_path, :method => :delete %>
5
+ <%- else -%>
6
+ <%= link_to t("authentication.sign_up"), new_user_registration_path %> -
7
+ <%= link_to t("authentication.sign_in"), new_user_session_path %>
8
+ <%- end -%>
9
+ </div>
10
+ <div class="clear"></div>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= "#{CONFIG[:application][:name]} #{controller.controller_name.capitalize}: #{controller.action_name}" %></title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ <%= yield(:head) %>
9
+ </head>
10
+ <body>
11
+ <%= render "layouts/#{CONFIG[:default_style]}" %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,23 @@
1
+ Description:
2
+ en: Copy all templates in the project directory lib \ generators to allow customization.
3
+ it: Copia tutti i template nella directory del progetto lib\generators per consentire la personalizzazione.
4
+
5
+ Example:
6
+ rails generate leosca:install
7
+
8
+ This will create:
9
+ lib/generators/erb/leosca/USAGE
10
+ lib/generators/erb/leosca/leosca_generator.rb
11
+ lib/generators/erb/leosca/templates/_form.html.erb
12
+ lib/generators/erb/leosca/templates/_list.erb
13
+ lib/generators/erb/leosca/templates/edit.html.erb
14
+ lib/generators/erb/leosca/templates/index.html.erb
15
+ lib/generators/erb/leosca/templates/index.js.erb
16
+ lib/generators/erb/leosca/templates/new.html.erb
17
+ lib/generators/erb/leosca/templates/show.html.erb
18
+ lib/generators/rails/leosca/USAGE
19
+ lib/generators/rails/leosca/leosca_generator.rb
20
+ lib/generators/rails/leosca/templates/leosca.css
21
+ lib/generators/rails/leosca_controller/USAGE
22
+ lib/generators/rails/leosca_controller/leosca_controller_generator.rb
23
+ lib/generators/rails/leosca_controller/templates/controller.rb
@@ -0,0 +1,15 @@
1
+ module Leosca
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../', __FILE__)
5
+ class_option :erb, :type => :boolean, :default => true, :description => "Copy erb files"
6
+
7
+ def copy_templates_to_local
8
+ directory "erb/leosca", "lib/generators/erb/leosca" if options.erb?
9
+ directory "rails/leosca", "lib/generators/rails/leosca"
10
+ directory "rails/leosca_controller", "lib/generators/rails/leosca_controller"
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,41 @@
1
+ Description:
2
+ en: Customized version of rails's scaffold, to be used after leolay.
3
+ it: Versione personalizzata dello scaffold di rails, da usare dopo leolay.
4
+
5
+ Scaffolds an entire resource, from model and migration to controller and
6
+ views, along with a full test suite. The resource is ready to use as a
7
+ starting point for your RESTful, resource-oriented application.
8
+
9
+ Pass the name of the model (in singular form), either CamelCased or
10
+ under_scored, as the first argument, and an optional list of attribute
11
+ pairs.
12
+
13
+ Attribute pairs are field:type arguments specifying the
14
+ model's attributes. Timestamps are added by default, so you don't have to
15
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
16
+
17
+ You don't have to think up every attribute up front, but it helps to
18
+ sketch out a few so you can start working with the resource immediately.
19
+
20
+ For example, 'scaffold post title:string body:text published:boolean'
21
+ gives you a model with those three attributes, a controller that handles
22
+ the create/show/update/destroy, forms to create and edit your posts, and
23
+ an index that lists them all, as well as a resources :posts
24
+ declaration in config/routes.rb.
25
+
26
+ If you want to remove all the generated files, run
27
+ 'rails destroy scaffold ModelName'.
28
+
29
+ Use after leolay:
30
+ 1. rails generate leolay
31
+ 2. rails generate leosca
32
+
33
+ Usage example:
34
+ rails generate leosca product name:string description:text active:boolean items:integer price:decimal
35
+
36
+ Available options:
37
+ rails generate leosca product name:string --skip-remote => if you do not want ajax
38
+ rails generate leosca product name:string --skip-seeds
39
+ rails generate leosca product name:string --seeds=60 => if you need more records
40
+
41
+ Of course, these options are in addition to those provided by the original scaffold
@@ -0,0 +1,26 @@
1
+ require 'rails/generators/rails/resource/resource_generator'
2
+
3
+ module Rails
4
+ module Generators
5
+ class LeoscaGenerator < ResourceGenerator #metagenerator
6
+ #puts 'rails:leosca'
7
+
8
+ remove_hook_for :resource_controller
9
+ remove_class_option :actions
10
+
11
+ class_option :stylesheets, :type => :boolean, :default => false, :desc => "Generate Stylesheets"
12
+ class_option :stylesheet_engine, :desc => "Engine for Stylesheets"
13
+
14
+ hook_for :leosca_controller, :required => true
15
+
16
+ hook_for :assets do |assets|
17
+ invoke assets, [controller_name]
18
+ end
19
+
20
+ hook_for :stylesheet_engine do |stylesheet_engine|
21
+ invoke stylesheet_engine, [controller_name] if options[:stylesheets] && behavior == :invoke
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,23 @@
1
+ Description:
2
+ en: Customized version of rails's scaffold_controller, to be used after leolay.
3
+ it: Versione personalizzata dello scaffold_controller di rails, da usare dopo leolay.
4
+
5
+ Stubs out a scaffolded controller and its views. Pass the model name,
6
+ either CamelCased or under_scored, and a list of views as arguments.
7
+ The controller name is retrieved as a pluralized version of the model
8
+ name.
9
+
10
+ To create a controller within a module, specify the model name as a
11
+ path like 'parent_module/controller_name'.
12
+
13
+ This generates a controller class in app/controllers and invokes helper,
14
+ template engine and test framework generators.
15
+
16
+ Example:
17
+ `rails generate leosca_controller CreditCard`
18
+
19
+ Credit card controller with URLs like /credit_card/debit.
20
+ Controller: app/controllers/credit_cards_controller.rb
21
+ Functional Test: test/functional/credit_cards_controller_test.rb
22
+ Views: app/views/credit_cards/index.html.erb [...]
23
+ Helper: app/helpers/credit_cards_helper.rb
@@ -0,0 +1,159 @@
1
+ require 'rails/generators/resource_helpers'
2
+
3
+ WINDOWS = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
4
+ CRLF = WINDOWS ? "\r\n" : "\n"
5
+
6
+ module Rails
7
+ module Generators
8
+ class LeoscaControllerGenerator < NamedBase
9
+ include ResourceHelpers
10
+ #puts 'rails:leosca_controller'
11
+
12
+ source_root File.expand_path('../templates', __FILE__)
13
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
14
+ class_option :seeds, :type => :boolean, :default => true, :description => "Create seeds to run with rake db:seed"
15
+ class_option :seeds_elements, :type => :string, :default => "30", :description => "Choose seeds elements", :banner => "NUMBER OF ARRAY ELEMENTS"
16
+ class_option :remote, :type => :boolean, :default => true, :description => "Enable ajax. You can also do later set remote to true into index view."
17
+ #class_option :authentication, :type => :boolean, :default => true, :description => "Add code to manage authentication with devise"
18
+ #class_option :authorization, :type => :boolean, :default => true, :description => "Add code to manage authorization with cancan"
19
+
20
+ check_class_collision :suffix => "Controller"
21
+
22
+ class_option :orm, :banner => "NAME", :type => :string, :required => true,
23
+ :desc => "ORM to generate the controller for"
24
+
25
+ def create_controller_files
26
+ template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
27
+ end
28
+
29
+ hook_for :template_engine, :as => :leosca
30
+ hook_for :test_framework, :as => :scaffold
31
+
32
+ # Invoke the helper using the controller name (pluralized)
33
+ hook_for :helper, :as => :scaffold do |invoked|
34
+ invoke invoked, [ controller_name ]
35
+ end
36
+
37
+ def update_yaml_locales
38
+ #Inject model and attributes name into yaml files for i18n
39
+ path = "config/locales"
40
+ files = []
41
+ files = Dir["#{path}/??.yml"]
42
+ files.each do |file|
43
+
44
+ next unless File.exists?(file)
45
+
46
+ #Fields name
47
+ inject_into_file file, :after => "#Attributes zone - do not remove#{CRLF}" do
48
+ content = " #{file_name}:#{CRLF}"
49
+ attributes.each do |attribute|
50
+ content << " #{attribute.name}: \"#{attribute.name.capitalize}\"#{CRLF}"
51
+ end
52
+ content << " op_new: \"New #{singular_table_name}\"#{CRLF}"
53
+ content << " op_edit: \"Editing #{singular_table_name}\"#{CRLF}"
54
+ content << " op_index: \"Listing #{plural_table_name}\"#{CRLF}"
55
+ content
56
+ end
57
+
58
+ #Model name
59
+ inject_into_file file, :after => "models: &models#{CRLF}" do
60
+ <<-FILE.gsub(/^ /, '')
61
+ #{file_name}: "#{file_name.capitalize}"
62
+ #{controller_name}: "#{controller_name.capitalize}"
63
+ FILE
64
+ end
65
+
66
+ #Formtastic
67
+ inject_into_file file, :after => " hints:#{CRLF}" do
68
+ content = " #{file_name}:#{CRLF}"
69
+ attributes.each do |attribute|
70
+ case attribute.type
71
+ when :integer, :decimal, :float
72
+ content << " #{attribute.name}: \"Insert #{attribute.name} as #{attribute.type.to_s} number\"#{CRLF}"
73
+ when :boolean
74
+ content << " #{attribute.name}: \"Select if #{attribute.name} or not\"#{CRLF}"
75
+ else
76
+ content << " #{attribute.name}: \"Choose a good #{attribute.name} for this #{file_name}\"#{CRLF}"
77
+ end
78
+ end
79
+ content
80
+ end
81
+
82
+ end
83
+ end
84
+
85
+ def update_layout_html
86
+ file = "app/views/layouts/_#{CONFIG[:default_style]}.html.erb"
87
+ inject_into_file file, :after => "<!-- Insert below other elements -->#{CRLF}" do
88
+ <<-FILE.gsub(/^ /, '')
89
+ #{"<% if can? :read, #{class_name} -%>" if authorization?}
90
+ <li class="<%= controller.controller_path == '#{controller_name}' ? 'active' : '' %>"><a href="<%= #{controller_name}_path %>"><%= t('models.#{controller_name}') %></a></li>
91
+ #{"<% end -%>" if authorization?}
92
+ FILE
93
+ end if File.exists?(file)
94
+ end
95
+
96
+ def update_ability_model
97
+ file = "app/models/ability.rb"
98
+ return unless File.exists?(file)
99
+ inject_into_file file, :before => " end\nend" do
100
+ <<-FILE.gsub(/^ /, '')
101
+ #can :read, #{class_name} if user.new_record? #Guest
102
+ can :read, #{class_name} if user.role? :guest #Registered guest
103
+ if user.role? :user
104
+ can :read, #{class_name}
105
+ can :update, #{class_name}
106
+ can :create, #{class_name}
107
+ end
108
+ if user.role? :manager
109
+ can :read, #{class_name}
110
+ can :update, #{class_name}
111
+ can :create, #{class_name}
112
+ can :destroy, #{class_name}
113
+ end
114
+
115
+ FILE
116
+ end
117
+ end
118
+
119
+ def add_seeds_db
120
+ return unless options.seeds? and options[:seeds_elements].to_i > 0
121
+ file = "db/seeds.rb"
122
+ append_file file do
123
+ items = []
124
+ attributes.each do |attribute|
125
+ value = case attribute.type
126
+ when :boolean then :true
127
+ when :integer then "#"
128
+ when :float, :decimal then "#.46"
129
+ else "'#{attribute.name.capitalize}\#'"
130
+ end
131
+ items << " :#{attribute.name} => #{value}"
132
+ end
133
+ row = "{ #{items.join(', ')} }"
134
+
135
+ #TODO: to have different values for every row
136
+ content = "#{CRLF}### Created by leosca controller generator ### #{CRLF}#{class_name}.create([#{CRLF}"
137
+ options[:seeds_elements].to_i.times do |n|
138
+ content << "#{row.gsub(/\#/, (n+1).to_s)},#{CRLF}"
139
+ end
140
+ content << "])#{CRLF}"
141
+ content
142
+ end if File.exists?(file)
143
+ end
144
+
145
+ protected
146
+ def authorization?
147
+ File.exists? "app/models/ability.rb"
148
+ end
149
+ def authentication?
150
+ file = "app/models/user.rb"
151
+ File.exists?(file)
152
+ #get file do |content|
153
+ # content.include? "devise"
154
+ #end
155
+ end
156
+
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,132 @@
1
+ <% module_namespacing do -%>
2
+ class <%= controller_class_name %>Controller < ApplicationController
3
+ <%= "before_filter :authenticate_user!" if authentication? %>
4
+ <%= "load_and_authorize_resource" if authorization? %>
5
+
6
+ # GET <%= route_url %>
7
+ # GET <%= route_url %>.json
8
+ def index
9
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
10
+ conditions = nil
11
+
12
+ if params[:<%= singular_table_name %>]
13
+ request.format = :csv if params[:commit] == 'Csv'
14
+ conditions_fields = []
15
+ conditions_values = []
16
+
17
+ <%- attributes.each do |attribute| -%>
18
+ if params[:<%= singular_table_name %>][:<%= attribute.name %>] && params[:<%= singular_table_name %>][:<%= attribute.name %>].length>0
19
+ <%- conditions_operator_sign = case attribute.type
20
+ when :string, :text then "LIKE"
21
+ else "="
22
+ end -%>
23
+ <%- conditions_operator_value = case attribute.type
24
+ when :string, :text then "%"
25
+ else ""
26
+ end -%>
27
+ conditions_fields << "#{<%= class_name %>.table_name}.<%= attribute.name %> <%= conditions_operator_sign %> ?"
28
+ conditions_values << "<%= conditions_operator_value %>#{params[:<%= singular_table_name %>][:<%= attribute.name %>]}<%= conditions_operator_value %>"
29
+ @<%= singular_table_name %>.<%= attribute.name %> = params[:<%= singular_table_name %>][:<%= attribute.name %>]
30
+ end
31
+ <%- end -%>
32
+
33
+ conditions = conditions_fields.join(' and ').to_a + conditions_values
34
+ end
35
+
36
+ request.format = :csv if params[:commit] == 'Csv'
37
+
38
+ @<%= plural_table_name %> = case request.format
39
+ when 'text/html', 'text/javascript'
40
+ <%= class_name %>.where(conditions).order(:id).page(params[:page])
41
+ else
42
+ <%= class_name %>.where(conditions)
43
+ end
44
+
45
+ respond_to do |format|
46
+ format.html # index.html.erb
47
+ format.json { render <%= key_value :json, "@#{plural_table_name}" %> }
48
+ format.csv do
49
+ send_data(Utility::export(:collection => @<%= plural_table_name %>,
50
+ #:column => [:column_name ],
51
+ :i18n => true
52
+ ),
53
+ :type => 'text/csv; charset=utf-8; header=present',
54
+ :filename => "<%%=CONFIG[:application][:name]%>_#{t('models.<%= plural_table_name %>')}_#{Time.now.strftime("%Y%m%d")}.csv")
55
+ end
56
+ format.js
57
+ end
58
+ end
59
+
60
+ # GET <%= route_url %>/1
61
+ # GET <%= route_url %>/1.json
62
+ def show
63
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
64
+
65
+ respond_to do |format|
66
+ format.html # show.html.erb
67
+ format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
68
+ end
69
+ end
70
+
71
+ # GET <%= route_url %>/new
72
+ # GET <%= route_url %>/new.json
73
+ def new
74
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
75
+
76
+ respond_to do |format|
77
+ format.html # new.html.erb
78
+ format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
79
+ end
80
+ end
81
+
82
+ # GET <%= route_url %>/1/edit
83
+ def edit
84
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
85
+ end
86
+
87
+ # POST <%= route_url %>
88
+ # POST <%= route_url %>.json
89
+ def create
90
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
91
+
92
+ respond_to do |format|
93
+ if @<%= orm_instance.save %>
94
+ format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "I18n.t(:created, :model => I18n.t('models.#{singular_table_name}'))" %> }
95
+ format.json { render <%= key_value :json, "@#{singular_table_name}" %>, <%= key_value :status, ':created' %>, <%= key_value :location, "@#{singular_table_name}" %> }
96
+ else
97
+ format.html { render <%= key_value :action, '"new"' %> }
98
+ format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
99
+ end
100
+ end
101
+ end
102
+
103
+ # PUT <%= route_url %>/1
104
+ # PUT <%= route_url %>/1.json
105
+ def update
106
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
107
+
108
+ respond_to do |format|
109
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
110
+ format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "I18n.t(:updated, :model => I18n.t('models.#{singular_table_name}'))" %> }
111
+ format.json { head :ok }
112
+ else
113
+ format.html { render <%= key_value :action, '"edit"' %> }
114
+ format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
115
+ end
116
+ end
117
+ end
118
+
119
+ # DELETE <%= route_url %>/1
120
+ # DELETE <%= route_url %>/1.json
121
+ def destroy
122
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
123
+ @<%= orm_instance.destroy %>
124
+
125
+ respond_to do |format|
126
+ format.html { redirect_to <%= index_helper %>_url }
127
+ format.json { head :ok }
128
+ format.js
129
+ end
130
+ end
131
+ end
132
+ <% end -%>
data/template.rb ADDED
@@ -0,0 +1,104 @@
1
+ #This is a Rails 3.1.x template
2
+ #Written by Marco Mastrodonato 27/07/2011
3
+ #
4
+ # USAGE: rails new yourapp -m template.rb
5
+
6
+ puts '*' * 40
7
+ puts "* Processing template..."
8
+ puts '*' * 40
9
+
10
+ use_git = yes?("Do you think to use git ?")
11
+ if use_git
12
+ git :init
13
+ file ".gitignore", <<-EOS.gsub(/^ /, '')
14
+ .DS_Store
15
+ log/*.log
16
+ tmp/**/*
17
+ config/database.yml
18
+ db/*.sqlite3
19
+ nbproject/*
20
+ .idea
21
+ EOS
22
+ end
23
+
24
+ gem 'kaminari' if yes?("Pagination ?")
25
+
26
+ gem 'paperclip' if yes?("Attachment ?")
27
+
28
+ gem 'fastercsv' if yes?("FasterCSV ?")
29
+
30
+ formtastic = yes?("Formtastic ?")
31
+ if formtastic
32
+ #gem 'justinfrench-formtastic', :lib => 'formtastic', :source => 'http://gems.github.com'
33
+ #rake "gems:install" if install_gem
34
+
35
+ #A Rails FormBuilder DSL (with some other goodies) to make it far easier to create beautiful, semantically rich, syntactically awesome, readily stylable and wonderfully accessible HTML forms in your Rails applications.
36
+ gem 'formtastic'
37
+ gem 'validation_reflection'
38
+ end
39
+
40
+ if yes?("Add testing framework ?")
41
+ gem 'rspec-rails', :group => :test
42
+ gem 'capybara', :group => :test
43
+ gem 'launchy', :group => :test
44
+ end
45
+
46
+ model_name = nil
47
+ devise = yes?("Would you like to install Devise?")
48
+ if devise
49
+ gem("devise")
50
+ model_name = ask(" What would you like the user model to be called? [user]")
51
+ model_name = "user" if model_name.blank?
52
+ end
53
+
54
+ cancan = yes?("Authorization ?")
55
+ gem "cancan" if cancan
56
+
57
+ home = yes?("Generate controller home ? (raccomanded)")
58
+
59
+ leolay = yes?("Layout ?")
60
+ leolay_main_color = leolay_second_color = nil
61
+ if leolay
62
+ gem 'leonardo'
63
+ puts " Enter colors, for example:"
64
+ puts " #c8c8c8 or rgb(200,200,200) or gray"
65
+ leolay_main_color = ask(" Choose main color [blank=default color]:")
66
+ leolay_second_color = ask(" Choose secondary color [blank=default color]:")
67
+ end
68
+
69
+ run "bundle install"
70
+
71
+ generate "formtastic:install" if formtastic
72
+
73
+ if devise
74
+ generate("devise:install")
75
+ generate("devise", model_name)
76
+ #generate("devise:views") #not use since leolay copies custom views
77
+ end
78
+
79
+ generate "cancan:ability" if cancan
80
+
81
+ if leolay
82
+ generate "leolay",
83
+ (leolay_main_color && leolay_main_color.any? ? leolay_main_color : ""),
84
+ (leolay_second_color && leolay_second_color.any? ? leolay_second_color : ""),
85
+ (cancan ? "" : "--skip-authorization"),
86
+ (devise ? "" : "--skip-authentication"),
87
+ (formtastic ? "" : "--skip-formtastic")
88
+ end
89
+
90
+ if home
91
+ generate "controller", "home", "index"
92
+ route "root :to => 'home#index'"
93
+ end
94
+
95
+ File.unlink "public/index.html"
96
+
97
+ rake "db:create:all"
98
+ rake "db:migrate"
99
+
100
+ #rake "gems:unpack" if yes?("Unpack to vendor/gems ?")
101
+
102
+ git :add => ".", :commit => "-m 'initial commit'" if use_git
103
+
104
+ puts "ENJOY!"