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