zing 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "colorize"
6
+ gem "compass"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.6.4"
14
+ gem "rcov", ">= 0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ chunky_png (1.2.5)
5
+ colorize (0.5.8)
6
+ compass (0.11.5)
7
+ chunky_png (~> 1.2)
8
+ fssm (>= 0.2.7)
9
+ sass (~> 3.1)
10
+ fssm (0.2.7)
11
+ git (1.2.5)
12
+ jeweler (1.6.4)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ rake (0.9.2.2)
17
+ rcov (0.9.11)
18
+ sass (3.1.11)
19
+ shoulda (2.11.3)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ colorize
27
+ compass
28
+ jeweler (~> 1.6.4)
29
+ rcov
30
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Samuel Chandra
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,36 @@
1
+ = zing
2
+
3
+ "Zing Went The Strings Of My Heart" - Sinatra 1960
4
+
5
+ Is a gem made to eliminate time waste in writing common code in a new or existing Sinatra project.
6
+
7
+ == Usage
8
+
9
+ It is best to use zing with dindi created project. Take a look at dindi gem.
10
+
11
+ To view zing options:
12
+
13
+ zing -h
14
+
15
+ Create a base CMS:
16
+
17
+ zing -b
18
+
19
+ You might need to make sure that your models.rb is in the project root folder and it contains your
20
+ database setting. After running the command, please make sure to include the new route in config.ru.
21
+
22
+ == Contributing to zing
23
+
24
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
25
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
26
+ * Fork the project
27
+ * Start a feature/bugfix branch
28
+ * Commit and push until you are happy with your contribution
29
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
30
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
31
+
32
+ == Copyright
33
+
34
+ Copyright (c) 2011 Samuel Chandra. See LICENSE.txt for
35
+ further details.
36
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install --path vendor/bundle` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "zing"
18
+ gem.homepage = "http://github.com/schandra/zing"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Zing is Sinatra code generator}
21
+ gem.description = %Q{This gem will generate common code for a new or existing Sinatra project}
22
+ gem.email = "samuelchandra@yahoo.com"
23
+ gem.authors = ["Samuel Chandra"]
24
+ gem.executables = ["zing"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "zing #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
data/bin/zing ADDED
@@ -0,0 +1,629 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # script to automate creation of cms for a new/old Sinatra project
4
+ require 'ostruct'
5
+ require 'optparse'
6
+ require 'fileutils'
7
+ require 'colorize'
8
+
9
+ class OptionParser
10
+
11
+ def self.parse(args)
12
+ # The options specified on the command line will be collected in *options*
13
+ # We set the default value here
14
+ options = OpenStruct.new
15
+ options.project_name = nil
16
+
17
+ opts = OptionParser.new do |opts|
18
+ opts.banner = "Usage: zing [options]"
19
+
20
+ opts.separator " "
21
+ opts.separator "Specific options:"
22
+
23
+ opts.on("-b", "--base",
24
+ "Zing base CMS") do |lib|
25
+ options.base = true
26
+ end
27
+
28
+ opts.on("-p", "--push",
29
+ "Zing push module on top of base CMS") do |lib|
30
+ options.push = true
31
+ end
32
+
33
+ opts.on("-m", "--model MODEL_NAME",
34
+ "Zing CRUD for individual MODEL_NAME, use commas for multiple models") do |ver|
35
+ if ver.split(",").class == Array
36
+ options.model = ver.split(",").map(&:strip)
37
+ elsif ver.class == String
38
+ options.model = var
39
+ else
40
+ options.model = nil
41
+ end
42
+ end
43
+
44
+ # No argument, shows at tail. This will print an options summary.
45
+ # Try it and see!
46
+ opts.on_tail("-h", "--help", "Show this message") do
47
+ puts opts
48
+ exit!
49
+ end
50
+
51
+ end
52
+
53
+ opts.parse!(args)
54
+ options
55
+
56
+ rescue Exception => e
57
+ if e.message.match(/invalid option/i) or e.message.match(/missing argument/i)
58
+ puts "ERROR: #{e.message}".red
59
+ puts ""
60
+ puts opts
61
+ end
62
+ exit!
63
+ end
64
+
65
+ end
66
+
67
+ class ZingHelper
68
+
69
+ def self.create_directory(dir_path)
70
+ if File.exist?(dir_path)
71
+ puts "exists #{dir_path}"
72
+ else
73
+ FileUtils.mkdir_p(dir_path)
74
+ puts "create".green + " #{dir_path}"
75
+ end
76
+ end
77
+
78
+ def self.create_file(file_path, file_content)
79
+ if File.exist?(file_path)
80
+ puts "exists #{file_path}"
81
+ else
82
+ File.open("#{file_path}", "w") do |file|
83
+ file.puts file_content
84
+ end
85
+ puts "create".green + " #{file_path}"
86
+ end
87
+ end
88
+
89
+ def self.connect_db(models_file_path)
90
+ if File.exist?(models_file_path)
91
+ # check if db connection can be made
92
+ require models_file_path
93
+ if ActiveRecord::Base.connection and ActiveRecord::Base.connected?
94
+ puts "passed".green + " Database Connection"
95
+ else
96
+ puts "errors".red + " Database Connection not exist"
97
+ exit!
98
+ end
99
+ else
100
+ puts "ERROR: Are you sure DB is properly configured in #{models_file_path}?".red
101
+ exit!
102
+ end
103
+ end
104
+
105
+
106
+ end
107
+
108
+ # make sure ARGV has values
109
+ if ARGV.size == 0
110
+ puts "ERROR: Parameters needed. Run with -h to view options".red
111
+ end
112
+
113
+ # parse option from command line
114
+ options = OptionParser.parse(ARGV)
115
+
116
+ # working directory
117
+ project_absolute_dir = FileUtils.pwd
118
+ app_name = project_absolute_dir.split("/").last
119
+
120
+ models_directory = project_absolute_dir + "/models"
121
+ views_directory = project_absolute_dir + "/views"
122
+ routes_directory = project_absolute_dir + "/routes"
123
+ push_directory = project_absolute_dir + "/push"
124
+ helpers_directory = project_absolute_dir + "/helpers"
125
+ scss_directory = project_absolute_dir + "/public/sass"
126
+ images_directory = project_absolute_dir + "/public/images"
127
+
128
+ # check if config.ru and app_name.rb exist
129
+ unless File.exist?(project_absolute_dir + "/config.ru") and
130
+ File.exist?(project_absolute_dir + "/#{app_name}.rb")
131
+ puts "ERROR: Are you in the project directory before trying to Zing?".red
132
+ exit!
133
+ end
134
+
135
+ # Base
136
+ #
137
+ # This will be the base CMS, the rest will not function without this
138
+ if options.base
139
+
140
+ # run compass create to setup blueprint and stuff
141
+ compass_create_result = system("compass create --sass-dir public/sass --css-dir public/stylesheets --images-dir public/images --javascripts-dir public/javascripts --using blueprint/semantic")
142
+ if compass_create_result
143
+ puts "passed".green + " compass create"
144
+ else
145
+ puts "failed".red + " compass create"
146
+ exit!
147
+ end
148
+
149
+ # copy cms images from gem to the app images folder
150
+ zing_images = `gem contents zing`.split("\n").select {|e| e.match(/\.png/i)}
151
+ FileUtils.cp zing_images,images_directory
152
+
153
+ # check if database config exist and connection successful
154
+ ZingHelper.connect_db(project_absolute_dir + "/models.rb")
155
+
156
+ # create AdminUser table
157
+ if ActiveRecord::Base.connection.table_exists?(:admin_users)
158
+ puts "exists AdminUser Table"
159
+ else
160
+ ActiveRecord::Base.connection.create_table :admin_users do |t|
161
+ t.string :username, :limit => 40, :null => false
162
+ t.string :password, :limit => 40
163
+ t.integer :utime, :limit => 16
164
+ t.timestamps
165
+ end
166
+ if ActiveRecord::Base.connection.table_exists?(:admin_users)
167
+ puts "passed".green + " AdminUser Table Creation"
168
+ else
169
+ puts "failed".red + " AdminUser Table Creation"
170
+ exit!
171
+ end
172
+ end
173
+
174
+ # create AdminUser model
175
+ admin_user_content = <<-admin_user_content
176
+ class AdminUser < ActiveRecord::Base
177
+ end
178
+ admin_user_content
179
+ ZingHelper.create_file("#{models_directory}/admin_user.rb", admin_user_content)
180
+
181
+ # create cms routes
182
+ cms_content = <<-cms_content
183
+ class Cms < Sinatra::Base
184
+
185
+ get '/cms' do
186
+ if session[:authorized]
187
+ redirect '/cms/dashboard'
188
+ else
189
+ redirect '/cms/login'
190
+ end
191
+ end
192
+
193
+ get '/cms/login' do
194
+ haml :login, :layout => false
195
+ end
196
+
197
+ post '/cms/login' do
198
+ if params[:username] && params[:password]
199
+ admin_users = AdminUser.find_all_by_username_and_password(params[:username], params[:password])
200
+ if admin_users.size > 0
201
+ session[:authorized] = true
202
+ redirect '/cms/dashboard'
203
+ end
204
+ end
205
+
206
+ redirect '/cms/login'
207
+ end
208
+
209
+ get '/cms/dashboard' do
210
+ haml :dashboard
211
+ end
212
+
213
+ end
214
+ cms_content
215
+ ZingHelper.create_file("#{routes_directory}/cms.rb", cms_content)
216
+
217
+ # create application.scss
218
+ application_scss_content = <<-application_scss_content
219
+ @import "compass";
220
+ @import "blueprint";
221
+
222
+ @import "partials/base";
223
+ @import "partials/page";
224
+ @import "partials/form";
225
+
226
+ .top_wrapper {
227
+ background: white url('../images/background-v2.png') 0 0 repeat-x;
228
+ }
229
+
230
+ .footer_wrapper {
231
+ background: url('../images/bg_footer_top.png') #F8F8F8 repeat-x;
232
+ }
233
+
234
+ .bottom_wrapper {
235
+ background: url('../images/bg_footer_bottom.png') white repeat-x;
236
+ height: 40px;
237
+ }
238
+
239
+ #main{
240
+ @include container;
241
+
242
+ #header {
243
+ @include column(24);
244
+ height: 91px;
245
+
246
+ .logo {
247
+ @include column(11);
248
+ @include prepend(1);
249
+ display:block;
250
+ position:relative;
251
+ top: 16px;
252
+ }
253
+
254
+ .topnav {
255
+ @include column(11);
256
+ @include append(1);
257
+ text-align: right;
258
+ display:block;
259
+ position:relative;
260
+
261
+ }
262
+ }
263
+
264
+ #content{
265
+ @include column(22);
266
+ @include append(1);
267
+ @include prepend(1);
268
+ @include prepend-top(-20px);
269
+ @include append-bottom(10px);
270
+ background: url('../images/background-white.png') 0 0 no-repeat;
271
+ // @include column-grid-background;
272
+
273
+ #login {
274
+ @include prepend-top(70px);
275
+ @include append-bottom(60px);
276
+ @include column(10);
277
+ @include prepend(7);
278
+ @include append(7);
279
+ }
280
+
281
+ #page_title {
282
+ @include prepend-top(20px);
283
+ @include column(22);
284
+ // @include column-grid-background;
285
+ }
286
+
287
+ #page_content {
288
+ @include column(22);
289
+ // @include column-grid-background;
290
+ }
291
+
292
+ }
293
+
294
+ }
295
+
296
+ #footer{
297
+ @include container;
298
+
299
+ #upper_footer {
300
+ @include column(24);
301
+ overflow: hidden;
302
+ height: 60px;
303
+
304
+ .copyright{
305
+ @include column(15);
306
+ text-align: right;
307
+ display:block;
308
+ position:relative;
309
+ top: 25px;
310
+ }
311
+
312
+ .bottom_logo {
313
+ @include column(7, true);
314
+ @include append(1);
315
+ text-align: right;
316
+ display:block;
317
+ position:relative;
318
+ top: 14px;
319
+
320
+ h1 {
321
+ color:rgb(219, 220, 221);
322
+ }
323
+ }
324
+
325
+ }
326
+
327
+ #lower_footer {
328
+
329
+ }
330
+
331
+ }
332
+ application_scss_content
333
+ ZingHelper.create_file("#{scss_directory}/application.scss", application_scss_content)
334
+
335
+ # create login.haml
336
+ login_haml_content = <<-login_haml_content
337
+ !!! 5
338
+ %html
339
+ %head
340
+ %title= if @page_title then "CMS " + @page_title.humanize else "CMS" end
341
+ %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
342
+ %meta{:content => "NONE,NOARCHIVE", :name => "robots"}
343
+ %link{:href => "/stylesheets/screen.css", :media => "screen, projection", :rel => "stylesheet", :type => "text/css"}
344
+ %link{:href => "/stylesheets/print.css", :media => "print", :rel => "stylesheet", :type => "text/css"}
345
+ /[if lt IE 8]
346
+ %link{:href => "/stylesheets/ie.css", :media => "screen, projection", :rel => "stylesheet", :type => "text/css"}
347
+ %link{:href => "/stylesheets/application.css", :media => "screen, projection", :rel => "stylesheet", :type => "text/css"}
348
+
349
+ %body.bp
350
+ .top_wrapper
351
+ #main
352
+ #header
353
+ .logo
354
+ %h1
355
+ = $APP_NAME + " CMS"
356
+
357
+ #content
358
+ %form#login.bp{:action => "/cms/login", :method => "post"}
359
+ %fieldset
360
+ %legend Login
361
+ %p
362
+ %label{:for => "username"} Username
363
+ %br
364
+ %input#username.title{:name => "username", :type => "text", :value => ""}
365
+ %p
366
+ %label{:for => "password"} Password
367
+ %br
368
+ %input#password.title{:name => "password", :type => "password", :value => ""}
369
+ %p
370
+ %input{:type => "submit", :value => "Submit"}
371
+
372
+ .footer_wrapper
373
+ #footer
374
+ #upper_footer
375
+ .copyright
376
+ = "All rights reserved. &copy; " + Time.now.year.to_s + " " + $APP_NAME + "."
377
+
378
+ .bottom_logo
379
+ %h1
380
+ = $APP_NAME + " CMS"
381
+
382
+ #lower_footer
383
+
384
+ .bottom_wrapper
385
+ login_haml_content
386
+ ZingHelper.create_file("#{views_directory}/login.haml", login_haml_content)
387
+
388
+ # create layout.haml
389
+ layout_haml_content = <<-layout_haml_content
390
+ !!! 5
391
+ %html
392
+ %head
393
+ %title= if @page_title then "CMS " + @page_title.humanize else "CMS" end
394
+ %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
395
+ %meta{:content => "NONE,NOARCHIVE", :name => "robots"}
396
+ %link{:href => "/stylesheets/screen.css", :media => "screen, projection", :rel => "stylesheet", :type => "text/css"}
397
+ %link{:href => "/stylesheets/print.css", :media => "print", :rel => "stylesheet", :type => "text/css"}
398
+ /[if lt IE 8]
399
+ %link{:href => "/stylesheets/ie.css", :media => "screen, projection", :rel => "stylesheet", :type => "text/css"}
400
+ %link{:href => "/stylesheets/application.css", :media => "screen, projection", :rel => "stylesheet", :type => "text/css"}
401
+
402
+ %body.bp
403
+ .top_wrapper
404
+ #main
405
+ #header
406
+ .logo
407
+ %h1
408
+ = $APP_NAME + " CMS"
409
+
410
+ #content
411
+ #page_title
412
+ %h2
413
+ = @page_title
414
+
415
+ #page_nav
416
+ = page_navigation(@page_title) if respond_to? "page_navigation"
417
+
418
+ #page_content
419
+ = yield
420
+
421
+ .footer_wrapper
422
+ #footer
423
+ #upper_footer
424
+ .copyright
425
+ = "All rights reserved. &copy; " + Time.now.year.to_s + " " + $APP_NAME + "."
426
+
427
+ .bottom_logo
428
+ %h1
429
+ = $APP_NAME + " CMS"
430
+
431
+ #lower_footer
432
+
433
+ .bottom_wrapper
434
+ layout_haml_content
435
+ ZingHelper.create_file("#{views_directory}/layout.haml", layout_haml_content)
436
+
437
+ dashboard_haml_content = <<-dashboard_haml_content
438
+ %p
439
+ This is the dashboard
440
+ dashboard_haml_content
441
+ ZingHelper.create_file("#{views_directory}/dashboard.haml", dashboard_haml_content)
442
+
443
+ # add View Partial
444
+ # check if helpers folder exist
445
+ ZingHelper.create_directory(helpers_directory)
446
+
447
+ view_partial_content = <<-view_partial_content
448
+ module ViewPartial
449
+ def page_navigation(current_page)
450
+ haml :page_navigation
451
+ end
452
+ end
453
+ view_partial_content
454
+ ZingHelper.create_file("#{helpers_directory}/view_partial.rb", view_partial_content)
455
+
456
+ # page_navigation.haml
457
+ page_navigation_haml = <<-page_navigation_haml
458
+ %p
459
+ %ul
460
+ %li page_navigation
461
+ page_navigation_haml
462
+ ZingHelper.create_file("#{views_directory}/page_navigation.haml", page_navigation_haml)
463
+
464
+ # compass compile scss
465
+ compass_compile_result = system("compass compile")
466
+ if compass_compile_result
467
+ puts "passed".green + " compass compile"
468
+ else
469
+ puts "failed".red + " compass compile"
470
+ exit!
471
+ end
472
+ end
473
+
474
+ # PUSH
475
+ #
476
+ # create push folder if not exist
477
+ if options.push
478
+
479
+ puts "Zinging push CMS"
480
+ ZingHelper.create_directory(push_directory)
481
+
482
+ # check if database config exist and connection successful
483
+ ZingHelper.connect_db(project_absolute_dir + "/models.rb")
484
+
485
+ # create Token table
486
+ if ActiveRecord::Base.connection.table_exists?(:tokens)
487
+ puts "exists Token Table"
488
+ else
489
+ ActiveRecord::Base.connection.create_table :tokens do |t|
490
+ t.string :udid, :limit => 40, :null => false
491
+ t.string :owner, :limit => 40
492
+ t.string :token, :limit => 128, :null => false
493
+ t.boolean :buuuk, :default => 0
494
+ t.boolean :valid_udid, :default => 1
495
+ t.string :carrier
496
+ t.integer :utime, :limit => 16
497
+ t.string :network_code, :limit => 12
498
+ t.string :country_code, :limit => 12
499
+ t.string :device, :limit => 32
500
+ t.string :country
501
+ t.string :version, :limit => 16
502
+ t.timestamps
503
+ end
504
+ if ActiveRecord::Base.connection.table_exists?(:tokens)
505
+ puts "passed".green + " Token Table Creation"
506
+ else
507
+ puts "failed".red + " Token Table Creation"
508
+ exit!
509
+ end
510
+ end
511
+
512
+ # create Notification table
513
+ if ActiveRecord::Base.connection.table_exists?(:notifications)
514
+ puts "exists Notification Table"
515
+ else
516
+ ActiveRecord::Base.connection.create_table :notifications do |t|
517
+ t.string :message
518
+ t.string :btn_name, :limit => 64
519
+ t.string :sound, :limit => 64
520
+ t.string :url
521
+ t.string :category, :limit => 64
522
+ t.string :carrier, :limit => 64
523
+ t.string :test_udids, :limit => 512
524
+ t.integer :utime, :limit => 16
525
+ t.timestamps
526
+ end
527
+ if ActiveRecord::Base.connection.table_exists?(:notifications)
528
+ puts "passed".green + " Notification Table Creation"
529
+ else
530
+ puts "failed".red + " Notification Table Creation"
531
+ exit!
532
+ end
533
+ end
534
+
535
+ # create ApnLog table
536
+ if ActiveRecord::Base.connection.table_exists?(:apn_logs)
537
+ puts "exists ApnLog Table"
538
+ else
539
+ ActiveRecord::Base.connection.create_table :apn_logs do |t|
540
+ t.integer :notification_id
541
+ t.integer :notification_size, :limit => 16
542
+ t.text :log_text
543
+ t.integer :utime, :limit => 16
544
+ t.timestamps
545
+ end
546
+ if ActiveRecord::Base.connection.table_exists?(:apn_logs)
547
+ puts "passed".green + " ApnLog Table Creation"
548
+ else
549
+ puts "failed".red + " ApnLog Table Creation"
550
+ exit!
551
+ end
552
+ end
553
+
554
+ # create Token model
555
+ token_content = <<-token_class
556
+ class Token < ActiveRecord::Base
557
+ end
558
+ token_class
559
+ ZingHelper.create_file("#{models_directory}/token.rb", token_content)
560
+
561
+ # create Notification model
562
+ notification_content = <<-notification_class
563
+ class Notification < ActiveRecord::Base
564
+ end
565
+ notification_class
566
+ ZingHelper.create_file("#{models_directory}/notification.rb", notification_content)
567
+
568
+ # create ApnLog model
569
+ apn_log_content = <<-apn_log_class
570
+ class ApnLog < ActiveRecord::Base
571
+ end
572
+ apn_log_class
573
+ ZingHelper.create_file("#{models_directory}/apn_log.rb", apn_log_content)
574
+
575
+ # create the Push class
576
+ push_class_content = <<-push_class
577
+ gem "apns", "=0.9.0"
578
+ require "apns"
579
+
580
+ class Push
581
+
582
+ def self.push_new_alert(notification, token_array)
583
+
584
+ notification_id = notification.id
585
+ message = notification.message
586
+ button_name = notification.btn_name
587
+ sound = notification.sound
588
+ url = notification.url
589
+ test_udids = notification.test_udids
590
+
591
+ # apn setting
592
+ APNS.host = "gateway.push.apple.com"
593
+ APNS.pem = "#{app_name}_push_certificate.pem"
594
+
595
+ # always overide token_array if test udids exist
596
+ if token_array.size > 0 and test_udids and test_udids.size > 0
597
+ token_array = Token.find_all_by_udid(test_udids).map(&:token).compact
598
+ end
599
+
600
+ apn_notifications = []
601
+ if token_array.size > 0
602
+ token_array.each do |token|
603
+ apn_notifications << APNS::Notification.new(
604
+ token,
605
+ :alert => {:body => message,"action-loc-key" => button_name},
606
+ :sound => sound,
607
+ :other => {:url => url}
608
+ )
609
+ end
610
+
611
+ APNS.send_notifications(apn_notifications)
612
+
613
+ # Log the push
614
+ ApnLog.create(
615
+ :notification_id => notification_id,
616
+ :log_text => apn_notifications.inspect,
617
+ :utime => Time.now.to_i
618
+ )
619
+ end
620
+
621
+ end
622
+
623
+ end
624
+ push_class
625
+ ZingHelper.create_file("#{push_directory}/push.rb", push_class_content)
626
+
627
+ # completion
628
+ puts "Dont forget to place your '".yellow + "#{app_name}_push_certificate.pem".red + "' file in '".yellow + "/push".red + "' folder".yellow
629
+ end
Binary file
Binary file
Binary file
Binary file
data/lib/zing.rb ADDED
File without changes
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'zing'
16
+
17
+ class Test::Unit::TestCase
18
+ end
data/test/test_zing.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestZing < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
data/zing.gemspec ADDED
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "zing"
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Samuel Chandra"]
12
+ s.date = "2011-12-04"
13
+ s.description = "This gem will generate common code for a new or existing Sinatra project"
14
+ s.email = "samuelchandra@yahoo.com"
15
+ s.executables = ["zing"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/zing",
29
+ "images/background-v2.png",
30
+ "images/background-white.png",
31
+ "images/bg_footer_bottom.png",
32
+ "images/bg_footer_top.png",
33
+ "lib/zing.rb",
34
+ "test/helper.rb",
35
+ "test/test_zing.rb",
36
+ "zing.gemspec"
37
+ ]
38
+ s.homepage = "http://github.com/schandra/zing"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.10"
42
+ s.summary = "Zing is Sinatra code generator"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<colorize>, [">= 0"])
49
+ s.add_runtime_dependency(%q<compass>, [">= 0"])
50
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<colorize>, [">= 0"])
56
+ s.add_dependency(%q<compass>, [">= 0"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<colorize>, [">= 0"])
64
+ s.add_dependency(%q<compass>, [">= 0"])
65
+ s.add_dependency(%q<shoulda>, [">= 0"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
68
+ s.add_dependency(%q<rcov>, [">= 0"])
69
+ end
70
+ end
71
+
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Samuel Chandra
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorize
16
+ requirement: &70110395421300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70110395421300
25
+ - !ruby/object:Gem::Dependency
26
+ name: compass
27
+ requirement: &70110395420520 !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: *70110395420520
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &70110395419760 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70110395419760
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70110395419060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70110395419060
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70110395418140 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70110395418140
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &70110395417240 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70110395417240
80
+ description: This gem will generate common code for a new or existing Sinatra project
81
+ email: samuelchandra@yahoo.com
82
+ executables:
83
+ - zing
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - LICENSE.txt
87
+ - README.rdoc
88
+ files:
89
+ - .document
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - bin/zing
97
+ - images/background-v2.png
98
+ - images/background-white.png
99
+ - images/bg_footer_bottom.png
100
+ - images/bg_footer_top.png
101
+ - lib/zing.rb
102
+ - test/helper.rb
103
+ - test/test_zing.rb
104
+ - zing.gemspec
105
+ homepage: http://github.com/schandra/zing
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -1889167521807105773
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 1.8.10
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Zing is Sinatra code generator
133
+ test_files: []