the_silver_spoon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in the_silver_spoon.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module TheSilverSpoon
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,301 @@
1
+ require "the_silver_spoon/version"
2
+
3
+ # Require the RAILS generators to be able to extend Rails:Generators::NamedBase
4
+ require 'rails/generators'
5
+
6
+ module Everything
7
+ # If you use the NamedBase inheritance, a 'name' parameter has to follow the 'rails g integratedscaffold'. Won't work otherwise. If you don't want this, use ::Base
8
+ class Scaffold < Rails::Generators::NamedBase
9
+
10
+ # Method in the 'thor' library which gives you access to the accessor methods
11
+ no_tasks { attr_accessor :model_attributes, :controller_actions }
12
+
13
+ # This captures the arguments that the generator can take after "rails g integratedscaffold name"
14
+ argument :g_parameters, :type => :array, :default => [], :banner => "field:type field:type"
15
+
16
+ # this sets the path where the code looks for templates within the gem
17
+ def self.source_root
18
+ File.expand_path("../templates", __FILE__)
19
+ end
20
+
21
+ def initialize(*args, &block)
22
+
23
+ # This is a standard initializer
24
+
25
+ super # Call parent class
26
+ @model_attributes = [] # Initialize empty array for 'thor' attributes
27
+
28
+ # This method splits the name:type arguments in the parameters list
29
+ g_parameters.each do |arg|
30
+ @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
31
+ end
32
+
33
+ # Creates a list of all the standard actions in the controller
34
+ @controller_actions=all_actions
35
+
36
+ end
37
+
38
+
39
+ def create_model
40
+
41
+ # creates the model using the 'model.rb' template and puts it into the rails app
42
+ template 'model.rb', "app/models/#{model_path}.rb"
43
+
44
+ end
45
+
46
+ def create_controller
47
+
48
+ # creates the controller using the 'controller.rb' template and puts it into the rails app
49
+ template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
50
+ end
51
+
52
+ def create_migration
53
+
54
+ # creates the migration file using the 'migration.rb' template and puts it into the rails app with a time stamp
55
+ template 'migration.rb', "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_#{model_path.pluralize.gsub('/', '_')}.rb"
56
+
57
+ end
58
+
59
+ def create_helper
60
+
61
+ # creates the helper using the 'helper.rb' template and puts it into the rails app
62
+ template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
63
+ end
64
+
65
+ def create_routes
66
+
67
+ # adds the routes for the gem into the routes file
68
+ namespaces = plural_name.split('/')
69
+ resource = namespaces.pop
70
+ route namespaces.reverse.inject("resources :#{resource}") { |acc, namespace|
71
+ "namespace(:#{namespace}){ #{acc} }"
72
+ }
73
+ end
74
+
75
+
76
+ def create_views
77
+
78
+ # creates the standard views using the '[action].html.erb' templates and puts it into the rails app
79
+ controller_actions.each do |action|
80
+ if action!="show" and action!="create" and action!="update" and action!="destroy" and action!="parse_save_from_excel"
81
+ template "views/erb/#{action}.html.erb", "app/views/#{plural_name}/#{action}.html.erb"
82
+ end
83
+ end
84
+ if form_partial?
85
+ template "views/erb/_form.html.erb", "app/views/#{plural_name}/_form.html.erb"
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ def class_name
92
+ name.camelize
93
+ end
94
+
95
+
96
+ def model_path
97
+ name.underscore
98
+ end
99
+
100
+ def controller_methods(dir_name)
101
+ controller_actions.map do |action|
102
+ read_template("#{dir_name}/#{action}.rb")
103
+ end.join("\n").strip
104
+ end
105
+
106
+ def read_template(relative_path)
107
+ ERB.new(File.read(find_in_source_paths(relative_path)), nil, '-').result(binding)
108
+ end
109
+
110
+ def instance_name
111
+ if @namespace_model
112
+ singular_name.gsub('/', '_')
113
+ else
114
+ singular_name.split('/').last
115
+ end
116
+ end
117
+
118
+ def instances_name
119
+ instance_name.pluralize
120
+ end
121
+
122
+ def all_actions
123
+ %w[index show new create edit update destroy]
124
+ end
125
+
126
+ def item_resource
127
+ name.underscore.gsub('/', '_')
128
+ end
129
+
130
+ def items_path
131
+ if action? :index
132
+ "#{item_resource.pluralize}_path"
133
+ else
134
+ "root_path"
135
+ end
136
+ end
137
+
138
+ def item_path(options = {})
139
+ name = options[:instance_variable] ? "@#{instance_name}" : instance_name
140
+ suffix = options[:full_url] ? "url" : "path"
141
+ if options[:action].to_s == "new"
142
+ "new_#{item_resource}_#{suffix}"
143
+ elsif options[:action].to_s == "edit"
144
+ "edit_#{item_resource}_#{suffix}(#{name})"
145
+ else
146
+ if name.include?('::') && !@namespace_model
147
+ namespace = singular_name.split('/')[0..-2]
148
+ "[:#{namespace.join(', :')}, #{name}]"
149
+ else
150
+ name
151
+ end
152
+ end
153
+ end
154
+
155
+ def item_url
156
+ if action? :show
157
+ item_path(:full_url => true, :instance_variable => true)
158
+ else
159
+ items_url
160
+ end
161
+ end
162
+
163
+ def items_url
164
+ if action? :index
165
+ item_resource.pluralize + '_url'
166
+ else
167
+ "root_url"
168
+ end
169
+ end
170
+
171
+
172
+ def plural_name
173
+ name.underscore.pluralize
174
+ end
175
+
176
+ def form_partial?
177
+ actions? :new, :edit
178
+ end
179
+
180
+ def all_actions
181
+ %w[index show new create edit update destroy parse_save_from_excel]
182
+ end
183
+
184
+ def action?(name)
185
+ controller_actions.include? name.to_s
186
+ end
187
+
188
+ def actions?(*names)
189
+ names.all? { |name| action? name }
190
+ end
191
+
192
+ def add_gem(name, options = {})
193
+ gemfile_content = File.read(destination_path("Gemfile"))
194
+ File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
195
+ gem name, options unless gemfile_content.include? name
196
+ end
197
+
198
+ def destination_path(path)
199
+ File.join(destination_root, path)
200
+ end
201
+
202
+
203
+ # If you use the NamedBase inheritance, a 'name' parameter has to follow the 'rails g integratedscaffold'. Won't work otherwise. If you don't want this, use ::Base
204
+
205
+
206
+ end
207
+ #endd of class
208
+
209
+ end
210
+ module The_silver_spoon
211
+ class Install < Rails::Generators::Base
212
+
213
+ def self.source_root
214
+ File.expand_path("../templates", __FILE__)
215
+ end
216
+
217
+
218
+ def initialize(*args, &block)
219
+ super
220
+ #now we invokde generators off twitter boootstrap and gritter
221
+ Rails::Generators.invoke('bootstrap:install')
222
+ Rails::Generators.invoke('gritter:locale')
223
+ Rails::Generators.invoke('devise:install')
224
+ Rails::Generators.invoke('devise', ["user"])
225
+ Rails::Generators.invoke('devise:views')
226
+ Rails::Generators.invoke('cancan:ability')
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+ end
236
+
237
+ def create_uploader
238
+ #creates the uploader ruby file using carrierwave
239
+ template 'file_uploader.rb', "app/uploaders/file_uploader.rb"
240
+ end
241
+
242
+ def create_images
243
+
244
+ # copies the standard images into the assets/images folder
245
+ @images=Array.new
246
+ @images= Dir.entries("#{Install.source_root}/assets/images")
247
+ @images.each do |image|
248
+
249
+ if image!=".." and image !="."
250
+ copy_file "assets/images/#{image.to_s}", "app/assets/images/#{image}"
251
+ end
252
+ end
253
+
254
+
255
+ end
256
+
257
+ def create_javascripts
258
+
259
+ # copies the standard javascripts into the assets/javascripts folder - Currently hard-coded
260
+ # TODO : Remove the hardcoding for the javascripts inclusion
261
+
262
+ copy_file "#{Install.source_root}/assets/javascripts/jquery.dataTables.min.js", "app/assets/javascripts/jquery.dataTables.min.js"
263
+
264
+ end
265
+
266
+ def create_stylesheets_exclusions
267
+
268
+ # copies the sequenced css into the assets/stylesheets/exclusions folder
269
+ directory "#{Install.source_root}/assets/stylesheets/exclusions", "app/assets/stylesheets/exclusions"
270
+ end
271
+
272
+ def create_javascript_exclusions
273
+
274
+ # copies the sequenced javascript into the assets/javascripts/exclusions folder
275
+ directory "#{Install.source_root}/assets/javascripts/exclusions", "app/assets/javascripts/exclusions"
276
+ end
277
+
278
+ def create_stylesheet_images
279
+
280
+ # copies the dependent css images into the assets/stylesheets/images folder
281
+ directory "#{Install.source_root}/assets/stylesheets/images", "app/assets/stylesheets/images"
282
+
283
+ end
284
+
285
+
286
+ def create_layouts
287
+ #TODO :remove hardcoding and make a loop for including all files in this folder
288
+ remove_file "app/views/layouts/application.html.erb"
289
+ template "#{Install.source_root}/layouts/application.html.erb", "app/views/layouts/application.html.erb"
290
+ template "#{Install.source_root}/layouts//dummy_data.html.erb", "app/views/layouts/scaffold.html.erb"
291
+ template "#{Install.source_root}/layouts/information_page.html.erb", "app/views/layouts/information_page.html.erb"
292
+ template "#{Install.source_root}/layouts/pageslide_form_at.html.erb", "app/views/layouts/pageslide_form_at.html.erb"
293
+ template "#{Install.source_root}/layouts/welcome.html.erb", "app/views/layouts/welcome.html.erb"
294
+
295
+ end
296
+
297
+
298
+ end
299
+
300
+
301
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "the_silver_spoon/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "the_silver_spoon"
7
+ s.version = TheSilverSpoon::VERSION
8
+ s.authors = ["Ptotem Learnings"]
9
+ s.email = ["info@ptotem.com"]
10
+ s.homepage = "http://www.ptotem.com"
11
+ s.summary = %q{Let your Rails App be born with a silver spoon in its mouth}
12
+ s.description = %q{This gem preps a new Rails app with some of the best Rails gems and Jquery sweetness available( Twitter-Bootstrap, Devise, CanCan, Rails Admin, Spreadsheet, ) Not only does it takes care of the installation of these gems, it also extends your scaffolds to give aesthetically improved views. Further, apart from the standard scaffold views, it also creates an AJAX driven integrated view for your scaffold. It dries up your controllers and makes your models friendlier by adding schema stubs and standard validation options. Expect Cucumber integration in our next version}
13
+
14
+ s.rubyforge_project = "the_silver_spoon"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+
22
+ s.add_dependency 'railties', '3.1.3'
23
+ s.add_dependency 'bootstrap-sass'
24
+ s.add_dependency 'gritter'
25
+ s.add_dependency 'spreadsheet'
26
+ s.add_dependency 'carrierwave'
27
+ s.add_dependency 'devise'
28
+ s.add_dependency 'cancan'
29
+
30
+ # specify any dependencies here; for example:
31
+ # s.add_development_dependency "rspec"
32
+ # s.add_runtime_dependency "rest-client"
33
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_silver_spoon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ptotem Learnings
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: &72683270 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *72683270
25
+ - !ruby/object:Gem::Dependency
26
+ name: bootstrap-sass
27
+ requirement: &72682750 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *72682750
36
+ - !ruby/object:Gem::Dependency
37
+ name: gritter
38
+ requirement: &72681900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *72681900
47
+ - !ruby/object:Gem::Dependency
48
+ name: spreadsheet
49
+ requirement: &72681450 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *72681450
58
+ - !ruby/object:Gem::Dependency
59
+ name: carrierwave
60
+ requirement: &72680780 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *72680780
69
+ - !ruby/object:Gem::Dependency
70
+ name: devise
71
+ requirement: &72679550 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *72679550
80
+ - !ruby/object:Gem::Dependency
81
+ name: cancan
82
+ requirement: &72679040 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *72679040
91
+ description: This gem preps a new Rails app with some of the best Rails gems and Jquery
92
+ sweetness available( Twitter-Bootstrap, Devise, CanCan, Rails Admin, Spreadsheet,
93
+ ) Not only does it takes care of the installation of these gems, it also extends
94
+ your scaffolds to give aesthetically improved views. Further, apart from the standard
95
+ scaffold views, it also creates an AJAX driven integrated view for your scaffold.
96
+ It dries up your controllers and makes your models friendlier by adding schema stubs
97
+ and standard validation options. Expect Cucumber integration in our next version
98
+ email:
99
+ - info@ptotem.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - Rakefile
107
+ - lib/the_silver_spoon.rb
108
+ - lib/the_silver_spoon/version.rb
109
+ - the_silver_spoon.gemspec
110
+ homepage: http://www.ptotem.com
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project: the_silver_spoon
130
+ rubygems_version: 1.8.10
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Let your Rails App be born with a silver spoon in its mouth
134
+ test_files: []