active_leonardo 0.0.2

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 (38) hide show
  1. data/CHANGELOG +2 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +157 -0
  4. data/active_template.rb +88 -0
  5. data/lib/generators/active_leonardo.rb +334 -0
  6. data/lib/generators/erb/leosca/leosca_generator.rb +122 -0
  7. data/lib/generators/leolay/USAGE +21 -0
  8. data/lib/generators/leolay/install_generator.rb +16 -0
  9. data/lib/generators/leolay/leolay_generator.rb +368 -0
  10. data/lib/generators/leolay/templates/app/admin/users.rb +63 -0
  11. data/lib/generators/leolay/templates/app/assets/javascripts/custom.js +10 -0
  12. data/lib/generators/leolay/templates/app/helpers/layout_helper.rb +27 -0
  13. data/lib/generators/leolay/templates/app/views/admin/users/_form.html.erb +21 -0
  14. data/lib/generators/leolay/templates/config.rb +11 -0
  15. data/lib/generators/leolay/templates/config/locales/en.yml +271 -0
  16. data/lib/generators/leolay/templates/config/locales/it.yml +298 -0
  17. data/lib/generators/leolay/templates/lib/development_mail_interceptor.rb +6 -0
  18. data/lib/generators/leolay/templates/lib/upd_activeadmin.rb +65 -0
  19. data/lib/generators/leolay/templates/lib/upd_array.rb +25 -0
  20. data/lib/generators/leolay/templates/styles/active/images/logo.png +0 -0
  21. data/lib/generators/leolay/templates/styles/active/images/style/Thumbs.db +0 -0
  22. data/lib/generators/leolay/templates/styles/active/images/style/ico_v.png +0 -0
  23. data/lib/generators/leolay/templates/styles/active/images/style/ico_x.png +0 -0
  24. data/lib/generators/leolay/templates/styles/active/stylesheets/app/_enviroment.css.scss +25 -0
  25. data/lib/generators/leolay/templates/styles/active/stylesheets/app/custom_active_admin.css.scss +23 -0
  26. data/lib/generators/leolay/templates/styles/active/stylesheets/app/stylesheet.css.scss +51 -0
  27. data/lib/generators/leolay/templates/styles/active/views/layout/_message.html.erb +3 -0
  28. data/lib/generators/leolay/templates/styles/active/views/layout/_session.html.erb +10 -0
  29. data/lib/generators/leolay/templates/styles/active/views/layout/application.html.erb +45 -0
  30. data/lib/generators/leosca/USAGE +23 -0
  31. data/lib/generators/leosca/install_generator.rb +16 -0
  32. data/lib/generators/rails/leosca/USAGE +40 -0
  33. data/lib/generators/rails/leosca/leosca_generator.rb +56 -0
  34. data/lib/generators/rails/leosca/templates/leosca.css +56 -0
  35. data/lib/generators/rails/leosca_controller/USAGE +23 -0
  36. data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +197 -0
  37. data/lib/generators/rails/leosca_controller/templates/controller.rb +3 -0
  38. metadata +117 -0
@@ -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,197 @@
1
+ require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
2
+ require File.join(File.dirname(__FILE__), '../../active_leonardo')
3
+
4
+ WINDOWS = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
5
+ CRLF = WINDOWS ? "\r\n" : "\n"
6
+
7
+ module Rails
8
+ module Generators
9
+ class LeoscaControllerGenerator < ::Rails::Generators::ScaffoldControllerGenerator
10
+ include ::ActiveLeonardo::Base
11
+ include ::ActiveLeonardo::Leosca
12
+ #include ::Leonardo::Nested
13
+ #include ::Leonardo::Nested::Test
14
+ #puts 'rails:leosca_controller'
15
+
16
+ source_root File.expand_path('../templates', __FILE__)
17
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
18
+ class_option :seeds, :type => :boolean, :default => true, :desc => "Create seeds to run with rake db:seed"
19
+ class_option :seeds_elements, :type => :string, :default => "30", :desc => "Choose seeds elements", :banner => "NUMBER"
20
+ #class_option :remote, :type => :boolean, :default => true, :desc => "Enable ajax. You can also do later set remote to true into index view."
21
+ #class_option :under, :type => :string, :default => "", :banner => "brand/category", :desc => "To nest a resource under another(s)"
22
+ #class_option :leospace, :type => :string, :default => "", :banner => ":admin", :desc => "To nest a resource under namespace(s)"
23
+ class_option :auth_class, :type => :boolean, :default => 'User', :desc => "Set the authentication class name"
24
+ class_option :activeadmin, :type => :boolean, :default => true, :desc => "Add code to manage activeadmin gem"
25
+
26
+ #Override
27
+ def create_controller_files
28
+ template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
29
+ end
30
+
31
+ #Override
32
+ #hook_for :template_engine, :test_framework, :as => :leosca
33
+
34
+ def update_yaml_locales
35
+ #Inject model and attributes name into yaml files for i18n
36
+ path = "config/locales"
37
+ files = []
38
+ files = Dir["#{path}/??.yml"]
39
+ files.each do |file|
40
+
41
+ next unless File.exists?(file)
42
+
43
+ #Fields name
44
+ inject_into_file file, :after => "#Attributes zone - do not remove#{CRLF}" do
45
+ content = " #{file_name}:#{CRLF}"
46
+ attributes.each do |attribute|
47
+ content << " #{attribute.name}: \"#{attribute.name.humanize}\"#{CRLF}"
48
+ end
49
+ content << " op_new: \"New #{singular_table_name}\"#{CRLF}"
50
+ content << " op_edit: \"Editing #{singular_table_name}\"#{CRLF}"
51
+ content << " op_edit_multiple: \"Editing #{plural_table_name}\"#{CRLF}"
52
+ content << " op_copy: \"Creating new #{plural_table_name}\"#{CRLF}"
53
+ #if nested?
54
+ # content << " op_index: \"Listing #{plural_table_name} belongings to %{parent} %{name}\"#{CRLF}"
55
+ #else
56
+ content << " op_index: \"Listing #{plural_table_name}\"#{CRLF}"
57
+ #end
58
+ content
59
+ end
60
+
61
+ #Model name
62
+ inject_into_file file, :after => "models: &models#{CRLF}" do
63
+ <<-FILE.gsub(/^ /, '')
64
+ #{file_name}: "#{file_name.capitalize}"
65
+ #{controller_name}: "#{controller_name.capitalize}"
66
+ FILE
67
+ end
68
+
69
+ #Formtastic
70
+ inject_into_file file, :after => " hints:#{CRLF}" do
71
+ content = " #{file_name}:#{CRLF}"
72
+ attributes.each do |attribute|
73
+ attr_name = attribute.name.humanize
74
+ case attribute.type
75
+ when :integer, :decimal, :float
76
+ content << " #{attribute.name}: \"Fill the #{attr_name} with a#{"n" if attribute.type == :integer} #{attribute.type.to_s} number\"#{CRLF}"
77
+ when :boolean
78
+ content << " #{attribute.name}: \"Select if this #{file_name} should be #{attr_name} or not\"#{CRLF}"
79
+ when :string, :text
80
+ content << " #{attribute.name}: \"Choose a good #{attr_name} for this #{file_name}\"#{CRLF}"
81
+ when :date, :datetime, :time, :timestamp
82
+ content << " #{attribute.name}: \"Choose a #{attribute.type.to_s} for #{attr_name}\"#{CRLF}"
83
+ else
84
+ content << " #{attribute.name}: \"Choose a #{attr_name}\"#{CRLF}"
85
+ end
86
+ end
87
+ content
88
+ end
89
+
90
+ end
91
+ end
92
+
93
+ def update_ability_model
94
+ file = "app/models/ability.rb"
95
+ return unless File.exists?(file)
96
+ inject_into_file file, :before => " end\nend" do
97
+ <<-FILE.gsub(/^ /, '')
98
+ #can :read, #{class_name} if #{options[:auth_class].downcase}.new_record? #Guest
99
+ can :read, #{class_name} if #{options[:auth_class].downcase}.role? :guest #Registered guest
100
+ if #{options[:auth_class].downcase}.role? :user
101
+ can [:read, :create], #{class_name}
102
+ can [:update, :destroy], #{class_name} do |#{singular_table_name}|
103
+ if defined?(#{singular_table_name}.#{options[:auth_class].downcase}_id)
104
+ #{singular_table_name}.#{options[:auth_class].downcase}_id == #{options[:auth_class].downcase}.id
105
+ else
106
+ true
107
+ end
108
+ end
109
+ end
110
+ if #{options[:auth_class].downcase}.role? :manager
111
+ can [:read, :create, :update, :destroy], #{class_name}
112
+ end
113
+
114
+ FILE
115
+ end
116
+ end
117
+
118
+ def add_seeds_db
119
+ return unless options.seeds? and options[:seeds_elements].to_i > 0
120
+ file = "db/seeds.rb"
121
+ append_file file do
122
+ items = []
123
+ attributes.each do |attribute|
124
+ items << attribute_to_hash(attribute)
125
+ end
126
+ row = "{ #{items.join(', ')} }"
127
+
128
+ #TODO: to have different values for every row
129
+ content = "#{CRLF}### Created by leosca controller generator ### #{CRLF}#{class_name}.create([#{CRLF}"
130
+ options[:seeds_elements].to_i.times do |n|
131
+ content << "#{row.gsub(/\#/, (n+1).to_s)},#{CRLF}"
132
+ end
133
+ content << "])#{CRLF}"
134
+ content
135
+ end if File.exists?(file)
136
+ end
137
+
138
+ def invoke_active_admin
139
+ return unless activeadmin? and options[:activeadmin]
140
+ #Rails::Generators.invoke("active_admin:resource", [singular_table_name])
141
+ invoke "active_admin:resource", [singular_table_name]
142
+ file = "app/admin/#{plural_table_name}.rb"
143
+
144
+ inject_into_file file, :after => "ActiveAdmin.register #{class_name} do" do
145
+ <<-FILE.gsub(/^ /, '')
146
+
147
+ menu :if => proc{ can?(:read, #{class_name}) }
148
+ controller.authorize_resource
149
+
150
+ controller do
151
+ # don't show prohibited actions on the index page
152
+ def action_methods
153
+ actions_abilities = {'show' => :read, 'new' => :create, 'edit' => :update, 'destroy' => :destroy}
154
+ prohibited_methods = actions_abilities.keys.select{|m| !can? actions_abilities[m], #{class_name}}
155
+ super - prohibited_methods
156
+ end
157
+ end
158
+ FILE
159
+ end if authorization? && File.exists?(file)
160
+ end
161
+
162
+ #def update_specs
163
+ # file = "spec/spec_helper.rb"
164
+ # return unless File.exists? file
165
+ #
166
+ # file = "spec/factories.rb"
167
+ # inject_into_file file, :before => " ### Insert below here other your factories ###" do
168
+ # items = []
169
+ # attributes.each do |attribute|
170
+ # items << attribute_to_factories(attribute)
171
+ # end
172
+ # <<-FILE.gsub(/^ /, '')
173
+ #
174
+ # factory :#{singular_table_name} do |#{singular_table_name[0..0]}|
175
+ # #{items.join(CRLF)}
176
+ # end
177
+ # FILE
178
+ # end if File.exists?(file)
179
+ #end
180
+
181
+ #def update_parent_controller
182
+ # return unless nested?
183
+ # file = "app/controllers/#{plural_last_parent}_controller.rb"
184
+ # inject_into_file file, :before => " private" do
185
+ # <<-FILE.gsub(/^ /, '')
186
+ # def with_#{plural_table_name}
187
+ # @#{last_parent} = #{last_parent.classify}.find params[:#{last_parent}_id]
188
+ # @#{plural_table_name} = #{class_name}.where(:#{last_parent}_id => params[:#{last_parent}_id])
189
+ # end
190
+ #
191
+ # FILE
192
+ # end if File.exists?(file)
193
+ #end
194
+
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,3 @@
1
+ class <%= controller_class_name %>Controller < InheritedResources::Base
2
+ respond_to :html, :xml, :json
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_leonardo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Marco Mastrodonato
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-23 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activeadmin
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 0
31
+ - 4
32
+ - 0
33
+ version: 0.4.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: This generator help you to create new Rails applications to combine with active admin gem. It generates application structure to easily get the internationalization and authorization.
37
+ email:
38
+ - m.mastrodonato@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - lib/generators/active_leonardo.rb
47
+ - lib/generators/erb/leosca/leosca_generator.rb
48
+ - lib/generators/leolay/install_generator.rb
49
+ - lib/generators/leolay/leolay_generator.rb
50
+ - lib/generators/leolay/templates/app/admin/users.rb
51
+ - lib/generators/leolay/templates/app/assets/javascripts/custom.js
52
+ - lib/generators/leolay/templates/app/helpers/layout_helper.rb
53
+ - lib/generators/leolay/templates/app/views/admin/users/_form.html.erb
54
+ - lib/generators/leolay/templates/config/locales/en.yml
55
+ - lib/generators/leolay/templates/config/locales/it.yml
56
+ - lib/generators/leolay/templates/config.rb
57
+ - lib/generators/leolay/templates/lib/development_mail_interceptor.rb
58
+ - lib/generators/leolay/templates/lib/upd_activeadmin.rb
59
+ - lib/generators/leolay/templates/lib/upd_array.rb
60
+ - lib/generators/leolay/templates/styles/active/images/logo.png
61
+ - lib/generators/leolay/templates/styles/active/images/style/ico_v.png
62
+ - lib/generators/leolay/templates/styles/active/images/style/ico_x.png
63
+ - lib/generators/leolay/templates/styles/active/images/style/Thumbs.db
64
+ - lib/generators/leolay/templates/styles/active/stylesheets/app/custom_active_admin.css.scss
65
+ - lib/generators/leolay/templates/styles/active/stylesheets/app/stylesheet.css.scss
66
+ - lib/generators/leolay/templates/styles/active/stylesheets/app/_enviroment.css.scss
67
+ - lib/generators/leolay/templates/styles/active/views/layout/application.html.erb
68
+ - lib/generators/leolay/templates/styles/active/views/layout/_message.html.erb
69
+ - lib/generators/leolay/templates/styles/active/views/layout/_session.html.erb
70
+ - lib/generators/leolay/USAGE
71
+ - lib/generators/leosca/install_generator.rb
72
+ - lib/generators/leosca/USAGE
73
+ - lib/generators/rails/leosca/leosca_generator.rb
74
+ - lib/generators/rails/leosca/templates/leosca.css
75
+ - lib/generators/rails/leosca/USAGE
76
+ - lib/generators/rails/leosca_controller/leosca_controller_generator.rb
77
+ - lib/generators/rails/leosca_controller/templates/controller.rb
78
+ - lib/generators/rails/leosca_controller/USAGE
79
+ - LICENSE
80
+ - README.rdoc
81
+ - CHANGELOG
82
+ - active_template.rb
83
+ homepage: https://github.com/marcomd/Active_Leonardo
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements:
110
+ - Start a new app with the template.rb inside root folder
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.24
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: This gem provides a new customized scaffold generator to combine with active admin
116
+ test_files: []
117
+