zing 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,12 +6,19 @@ Is a gem made to eliminate time waste in writing common code in a new or existin
6
6
 
7
7
  == Usage
8
8
 
9
+ gem install zing
10
+ zing -b
11
+
9
12
  It is best to use zing with dindi created project. Take a look at dindi gem.
10
13
 
14
+ == Help
15
+
11
16
  To view zing options:
12
17
 
13
18
  zing -h
14
19
 
20
+ == Example
21
+
15
22
  Create a base CMS:
16
23
 
17
24
  zing -b
data/Rakefile CHANGED
@@ -15,12 +15,13 @@ require 'jeweler'
15
15
  Jeweler::Tasks.new do |gem|
16
16
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
17
  gem.name = "zing"
18
- gem.homepage = "http://github.com/schandra/zing"
18
+ gem.homepage = "http://github.com/samchandra/zing"
19
19
  gem.license = "MIT"
20
20
  gem.summary = %Q{Zing is Sinatra code generator}
21
21
  gem.description = %Q{This gem will generate common code for a new or existing Sinatra project}
22
22
  gem.email = "samuelchandra@yahoo.com"
23
23
  gem.authors = ["Samuel Chandra"]
24
+ gem.files = FileList['lib/**/*', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
24
25
  gem.executables = ["zing"]
25
26
  # dependencies defined in Gemfile
26
27
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
data/bin/zing CHANGED
@@ -2,108 +2,8 @@
2
2
 
3
3
  # script to automate creation of cms for a new/old Sinatra project
4
4
  require 'ostruct'
5
- require 'optparse'
6
- require 'fileutils'
7
5
  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
6
+ require 'zing'
107
7
 
108
8
  # make sure ARGV has values
109
9
  if ARGV.size == 0
@@ -111,11 +11,16 @@ if ARGV.size == 0
111
11
  end
112
12
 
113
13
  # parse option from command line
114
- options = OptionParser.parse(ARGV)
14
+ options = OpenStruct.new
15
+ begin
16
+ Zing::CommandParser.parse(ARGV, options)
17
+ rescue Exception => e
18
+ exit!
19
+ end
115
20
 
116
- # working directory
117
- project_absolute_dir = FileUtils.pwd
118
- app_name = project_absolute_dir.split("/").last
21
+ # default directories path setting
22
+ project_absolute_dir = options.project_absolute_dir
23
+ app_name = options.app_name
119
24
 
120
25
  models_directory = project_absolute_dir + "/models"
121
26
  views_directory = project_absolute_dir + "/views"
@@ -124,7 +29,6 @@ push_directory = project_absolute_dir + "/push"
124
29
  helpers_directory = project_absolute_dir + "/helpers"
125
30
 
126
31
  scss_directory = project_absolute_dir + "/public/sass"
127
-
128
32
  css_directory = project_absolute_dir + "/public/css"
129
33
  images_directory = project_absolute_dir + "/public/images"
130
34
 
@@ -140,360 +44,60 @@ end
140
44
  # This will be the base CMS, the rest will not function without this
141
45
  if options.base
142
46
 
143
- # copy cms images from gem to the app images directory
144
- zing_images = `gem contents zing`.split("\n").select {|e| e.match(/\.png/i)}
145
- FileUtils.cp zing_images, images_directory
146
-
147
- # check if database config exist and connection successful
148
- ZingHelper.connect_db(project_absolute_dir + "/models.rb")
149
-
150
- # create AdminUser table
151
- if ActiveRecord::Base.connection.table_exists?(:admin_users)
152
- puts "exists AdminUser Table"
153
- else
154
- ActiveRecord::Base.connection.create_table :admin_users do |t|
155
- t.string :username, :limit => 40, :null => false
156
- t.string :password, :limit => 40
157
- t.integer :utime, :limit => 16
158
- t.timestamps
159
- end
160
- if ActiveRecord::Base.connection.table_exists?(:admin_users)
161
- puts "passed".green + " AdminUser Table Creation"
162
- else
163
- puts "failed".red + " AdminUser Table Creation"
164
- exit!
165
- end
166
- end
167
-
168
- # create AdminUser model
169
- admin_user_content = <<-admin_user_content
170
- class AdminUser < ActiveRecord::Base
171
- end
172
- admin_user_content
173
- ZingHelper.create_file("#{models_directory}/admin_user.rb", admin_user_content)
174
-
175
- # create cms routes
176
- cms_content = <<-cms_content
177
- class Cms < Sinatra::Base
178
-
179
- get '/cms' do
180
- if session[:authorized]
181
- redirect '/cms/dashboard'
182
- else
183
- redirect '/cms/login'
184
- end
185
- end
186
-
187
- get '/cms/login' do
188
- image_array = ["http://www.buuuk.com/wp-content/uploads/2011/08/ST_bannerNEW.png",
189
- "http://www.buuuk.com/wp-content/uploads/2011/04/weatherlah-banner2d.png",
190
- "http://www.buuuk.com/wp-content/uploads/2011/04/buUuk-banner_New2.png"]
191
- @main_image = image_array[rand(3)]
47
+ begin
48
+ puts "Zinging Base CMS"
192
49
 
193
- haml :login, :layout => false
194
- end
50
+ # copy cms images from gem to the app images directory
51
+ zing_images = `gem contents zing`.split("\n").select {|e| e.match(/\.png/i)}
52
+ FileUtils.cp zing_images, images_directory
195
53
 
196
- post '/cms/login' do
197
- if params[:username] && params[:password]
198
- admin_users = AdminUser.find_all_by_username_and_password(params[:username], params[:password])
199
- if admin_users.size > 0
200
- session[:authorized] = true
201
- redirect '/cms/dashboard'
202
- end
203
- end
54
+ # check if database config exist and connection successful
55
+ Zing::DbHelper.connect_db(project_absolute_dir + "/models.rb")
204
56
 
205
- redirect '/cms/login'
206
- end
57
+ # create AdminUser table
58
+ Zing::DbHelper.create_admin_user_table
207
59
 
208
- get '/cms/logout' do
209
- session[:authorized] = false
210
- redirect '/cms/login'
211
- end
60
+ # copy_file_templates
61
+ Zing::FileHelper.copy_file_templates(options, "options_base")
212
62
 
213
- get '/cms/dashboard' do
214
- haml :dashboard
63
+ rescue Exception => e
64
+ puts "ERROR: #{e.message}".red
65
+ puts ""
66
+ exit!
215
67
  end
216
68
 
217
- end
218
- cms_content
219
- ZingHelper.create_file("#{routes_directory}/cms.rb", cms_content)
220
-
221
- # create login.haml
222
- login_haml_content = <<-login_haml_content
223
- !!! 5
224
- %html
225
- %head
226
- %title= if @page_title then "CMS " + @page_title.humanize else "CMS" end
227
- %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
228
- %meta{:content => "NONE,NOARCHIVE", :name => "robots"}
229
- %link{:href => "http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css", :rel => "stylesheet", :type => "text/css"}
230
- :css
231
- body {
232
- padding-top: 60px;
233
- }
234
- .hero-unit {
235
- padding: 0;
236
- margin-bottom: 10px;
237
- }
238
-
239
- %body
240
-
241
- .topbar
242
- .fill
243
- .container
244
- %a.brand{:href=>"#"}
245
- = $APP_NAME + " CMS"
246
-
247
- %form.pull-right{:action => "/cms/login", :method => "post"}
248
- %input.input-small{:name => "username", :type => "text", :placeholder => "Username"}
249
- %input.input-small{:name => "password", :type => "password", :placeholder => "Password"}
250
- %button.btn{:type => "submit"}Sign in
251
-
252
- .container
253
- .hero-unit
254
- %img{:src => @main_image}
255
-
256
- .row
257
- .span16
258
- %h2 We build custom mobile applications
259
- %p
260
- We help our clients create mobile applications. Our focus is on building apps that deliver real-time, contextually relevant information to mobile touch screens. We are experts in using location, augmented reality and push notification. We don't out-source.
261
- .row
262
- .span4{:style => "text-align: center"}
263
- %img{:src => "http://www.buuuk.com/wp-content/uploads/2011/03/iPhone4Both1.png", :width => "200px", :height => "376px"}
264
- .span4{:style => "text-align: center"}
265
- %img{:src => "http://www.buuuk.com/wp-content/uploads/2011/03/Samsung_Nexus_S_FTKAKI.png", :width => "187px", :height => "344px"}
266
- .span4{:style => "text-align: center"}
267
- %img{:src => "http://www.buuuk.com/wp-content/uploads/2011/03/Blackberry-AMEXmerchantfind3.png", :width => "230px", :height => "363px"}
268
- .span4{:style => "text-align: center"}
269
- %img{:src => "http://www.buuuk.com/wp-content/uploads/2011/03/windows_buuuk2.png", :width => "200px", :height => "362px"}
270
-
271
- .row
272
- .span16
273
- %h2 Platforms
274
- %p From iPhone/iPad, to Android, to BlackBerry, to Windows 7: our portfolio of products is testament to our expertise across multiple platforms. Our services extend beyond just developing apps. We can provide a complete infrastructure for deployment, content management and hosting.
275
-
276
- %footer
277
- %p
278
- = "All rights reserved. &copy; BuUuk " + Time.now.year.to_s
279
-
280
- login_haml_content
281
- ZingHelper.create_file("#{views_directory}/login.haml", login_haml_content)
282
-
283
- # create layout.haml
284
- layout_haml_content = <<-layout_haml_content
285
- !!! 5
286
- %html
287
- %head
288
- %title= if @page_title then "CMS " + @page_title.humanize else "CMS" end
289
- %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
290
- %meta{:content => "NONE,NOARCHIVE", :name => "robots"}
291
- %link{:href => "http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css", :rel => "stylesheet", :type => "text/css"}
292
- :css
293
- body {
294
- padding-top: 60px;
295
- }
296
-
297
- %body
298
-
299
- .topbar
300
- .topbar-inner
301
- .container-fluid
302
- %a.brand{:href=>"/"}
303
- = $APP_NAME + " CMS"
304
- %ul.nav
305
- %li.active
306
- %a{:href => "/cms/dashboard"}Dashboard
307
- %p.pull-right
308
- %a{:href => "/cms/logout"}Logout
309
-
310
- .container-fluid
311
- .sidebar
312
- .well
313
- = haml :sidebar
314
-
315
- .content
316
- = yield
317
-
318
- %footer
319
- %p
320
- = "All rights reserved. &copy; BuUuk " + Time.now.year.to_s
321
-
322
- layout_haml_content
323
- ZingHelper.create_file("#{views_directory}/layout.haml", layout_haml_content)
324
-
325
- sidebar_haml_content = <<-sidebar_haml_content
326
- %h5
327
- CMS Modules
328
- %ul
329
- %li
330
- %a{:href => "#"}Push Notification
331
- %li
332
- %a{:href => "#"}Collection Items
333
- sidebar_haml_content
334
- ZingHelper.create_file("#{views_directory}/sidebar.haml", sidebar_haml_content)
335
-
336
- dashboard_haml_content = <<-dashboard_haml_content
337
- %p
338
- This is the dashboard
339
- dashboard_haml_content
340
- ZingHelper.create_file("#{views_directory}/dashboard.haml", dashboard_haml_content)
341
-
342
69
  end
343
70
 
344
- # PUSH
71
+ # Push
345
72
  #
346
73
  # create push folder if not exist
347
74
  if options.push
348
75
 
349
- puts "Zinging push CMS"
350
- ZingHelper.create_directory(push_directory)
76
+ begin
77
+ puts "Zinging push CMS"
351
78
 
352
- # check if database config exist and connection successful
353
- ZingHelper.connect_db(project_absolute_dir + "/models.rb")
79
+ Zing::FileHelper.create_directory(push_directory)
354
80
 
355
- # create Token table
356
- if ActiveRecord::Base.connection.table_exists?(:tokens)
357
- puts "exists Token Table"
358
- else
359
- ActiveRecord::Base.connection.create_table :tokens do |t|
360
- t.string :udid, :limit => 40, :null => false
361
- t.string :owner, :limit => 40
362
- t.string :token, :limit => 128, :null => false
363
- t.boolean :buuuk, :default => 0
364
- t.boolean :valid_udid, :default => 1
365
- t.string :carrier
366
- t.integer :utime, :limit => 16
367
- t.string :network_code, :limit => 12
368
- t.string :country_code, :limit => 12
369
- t.string :device, :limit => 32
370
- t.string :country
371
- t.string :version, :limit => 16
372
- t.timestamps
373
- end
374
- if ActiveRecord::Base.connection.table_exists?(:tokens)
375
- puts "passed".green + " Token Table Creation"
376
- else
377
- puts "failed".red + " Token Table Creation"
378
- exit!
379
- end
380
- end
381
-
382
- # create Notification table
383
- if ActiveRecord::Base.connection.table_exists?(:notifications)
384
- puts "exists Notification Table"
385
- else
386
- ActiveRecord::Base.connection.create_table :notifications do |t|
387
- t.string :message
388
- t.string :btn_name, :limit => 64
389
- t.string :sound, :limit => 64
390
- t.string :url
391
- t.string :category, :limit => 64
392
- t.string :carrier, :limit => 64
393
- t.string :test_udids, :limit => 512
394
- t.integer :utime, :limit => 16
395
- t.timestamps
396
- end
397
- if ActiveRecord::Base.connection.table_exists?(:notifications)
398
- puts "passed".green + " Notification Table Creation"
399
- else
400
- puts "failed".red + " Notification Table Creation"
401
- exit!
402
- end
403
- end
404
-
405
- # create ApnLog table
406
- if ActiveRecord::Base.connection.table_exists?(:apn_logs)
407
- puts "exists ApnLog Table"
408
- else
409
- ActiveRecord::Base.connection.create_table :apn_logs do |t|
410
- t.integer :notification_id
411
- t.integer :notification_size, :limit => 16
412
- t.text :log_text
413
- t.integer :utime, :limit => 16
414
- t.timestamps
415
- end
416
- if ActiveRecord::Base.connection.table_exists?(:apn_logs)
417
- puts "passed".green + " ApnLog Table Creation"
418
- else
419
- puts "failed".red + " ApnLog Table Creation"
420
- exit!
421
- end
422
- end
423
-
424
- # create Token model
425
- token_content = <<-token_class
426
- class Token < ActiveRecord::Base
427
- end
428
- token_class
429
- ZingHelper.create_file("#{models_directory}/token.rb", token_content)
430
-
431
- # create Notification model
432
- notification_content = <<-notification_class
433
- class Notification < ActiveRecord::Base
434
- end
435
- notification_class
436
- ZingHelper.create_file("#{models_directory}/notification.rb", notification_content)
437
-
438
- # create ApnLog model
439
- apn_log_content = <<-apn_log_class
440
- class ApnLog < ActiveRecord::Base
441
- end
442
- apn_log_class
443
- ZingHelper.create_file("#{models_directory}/apn_log.rb", apn_log_content)
444
-
445
- # create the Push class
446
- push_class_content = <<-push_class
447
- gem "apns", "=0.9.0"
448
- require "apns"
449
-
450
- class Push
451
-
452
- def self.push_new_alert(notification, token_array)
453
-
454
- notification_id = notification.id
455
- message = notification.message
456
- button_name = notification.btn_name
457
- sound = notification.sound
458
- url = notification.url
459
- test_udids = notification.test_udids
460
-
461
- # apn setting
462
- APNS.host = "gateway.push.apple.com"
463
- APNS.pem = "#{app_name}_push_certificate.pem"
81
+ # check if database config exist and connection successful
82
+ Zing::DbHelper.connect_db(project_absolute_dir + "/models.rb")
464
83
 
465
- # always overide token_array if test udids exist
466
- if token_array.size > 0 and test_udids and test_udids.size > 0
467
- token_array = Token.find_all_by_udid(test_udids).map(&:token).compact
468
- end
84
+ # create Token Table
85
+ Zing::DbHelper.create_token_table
86
+ # create Notification Table
87
+ Zing::DbHelper.create_notification_table
88
+ # create ApnLog Table
89
+ Zing::DbHelper.create_apn_log_table
469
90
 
470
- apn_notifications = []
471
- if token_array.size > 0
472
- token_array.each do |token|
473
- apn_notifications << APNS::Notification.new(
474
- token,
475
- :alert => {:body => message,"action-loc-key" => button_name},
476
- :sound => sound,
477
- :other => {:url => url}
478
- )
479
- end
91
+ # copy file templates
92
+ Zing::FileHelper.copy_file_templates(options, "options_push")
480
93
 
481
- APNS.send_notifications(apn_notifications)
94
+ # completion
95
+ puts "Dont forget to place your '".yellow + "#{app_name}_push_certificate.pem".red + "' file in '".yellow + "/push".red + "' folder".yellow
482
96
 
483
- # Log the push
484
- ApnLog.create(
485
- :notification_id => notification_id,
486
- :log_text => apn_notifications.inspect,
487
- :utime => Time.now.to_i
488
- )
489
- end
490
-
491
- end
492
-
493
- end
494
- push_class
495
- ZingHelper.create_file("#{push_directory}/push.rb", push_class_content)
97
+ rescue Exception => e
98
+ puts "ERROR: #{e.message}".red
99
+ puts ""
100
+ exit!
101
+ end
496
102
 
497
- # completion
498
- puts "Dont forget to place your '".yellow + "#{app_name}_push_certificate.pem".red + "' file in '".yellow + "/push".red + "' folder".yellow
499
103
  end
data/lib/zing.rb CHANGED
@@ -0,0 +1,3 @@
1
+ require File.dirname(__FILE__) + "/zing/command_parser"
2
+ require File.dirname(__FILE__) + "/zing/file_helper"
3
+ require File.dirname(__FILE__) + "/zing/db_helper"
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ require 'optparse'
4
+ require 'fileutils'
5
+
6
+ module Zing
7
+
8
+ module CommandParser
9
+
10
+ def self.parse(args, options)
11
+
12
+ # prepare parsing of command line arguments
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = "Usage: zing [options]"
15
+
16
+ opts.separator " "
17
+ opts.separator "Specific options:"
18
+
19
+ opts.on("-b", "--base",
20
+ "Zing base CMS") do |lib|
21
+ options.base = true
22
+ end
23
+
24
+ opts.on("-p", "--push",
25
+ "Zing push module on top of base CMS") do |lib|
26
+ options.push = true
27
+ end
28
+
29
+ opts.on("-m", "--model MODEL_NAME",
30
+ "Zing CRUD for individual MODEL_NAME, use commas for multiple models") do |ver|
31
+ if ver.split(",").class == Array
32
+ options.model = ver.split(",").map(&:strip)
33
+ elsif ver.class == String
34
+ options.model = var
35
+ else
36
+ options.model = nil
37
+ end
38
+ end
39
+
40
+ # No argument, shows at tail. This will print an options summary.
41
+ # Try it and see!
42
+ opts.on_tail("-h", "--help", "Show this message") do
43
+ puts opts
44
+ raise
45
+ end
46
+
47
+ end
48
+
49
+ opts.parse!(args)
50
+
51
+ # NOTE:
52
+ # We assume that zing is run at the root app folder
53
+ #
54
+ # set current dir as project absolute dir
55
+ options.project_absolute_dir = FileUtils.pwd
56
+
57
+ # set app name as the project folder
58
+ options.project_name = FileUtils.pwd.split("/").last
59
+ options.app_name = options.project_name
60
+
61
+ rescue Exception => e
62
+ if e.message.match(/invalid option/i) or e.message.match(/missing argument/i)
63
+ puts "ERROR: #{e.message}".red
64
+ puts ""
65
+ puts opts
66
+ end
67
+ raise
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,129 @@
1
+ # encoding: utf-8
2
+
3
+ module Zing
4
+ module DbHelper
5
+
6
+ def self.connect_db(models_file_path)
7
+ begin
8
+
9
+ if File.exist?(models_file_path)
10
+
11
+ # check if db connection can be made
12
+ require models_file_path
13
+ if ActiveRecord::Base.connection and ActiveRecord::Base.connected?
14
+ puts "passed".green + " Database Connection"
15
+ else
16
+ puts "errors".red + " Database Connection not exist"
17
+ raise
18
+ end
19
+ else
20
+ raise
21
+ end
22
+
23
+ rescue
24
+ puts "ERROR: Are you sure DB is properly configured in #{models_file_path}?".red
25
+ raise
26
+ end
27
+ end
28
+
29
+ def self.create_admin_user_table
30
+
31
+ if ActiveRecord::Base.connection.table_exists?(:admin_users)
32
+ puts "exists".yellow + " AdminUser Table"
33
+ else
34
+ ActiveRecord::Base.connection.create_table :admin_users do |t|
35
+ t.string :username, :limit => 40, :null => false
36
+ t.string :password, :limit => 40
37
+ t.integer :utime, :limit => 16
38
+ t.timestamps
39
+ end
40
+ if ActiveRecord::Base.connection.table_exists?(:admin_users)
41
+ puts "passed".green + " AdminUser Table Creation"
42
+ else
43
+ puts "failed".red + " AdminUser Table Creation"
44
+ raise
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ def self.create_token_table
51
+
52
+ if ActiveRecord::Base.connection.table_exists?(:tokens)
53
+ puts "exists".yellow + " Token Table"
54
+ else
55
+ ActiveRecord::Base.connection.create_table :tokens do |t|
56
+ t.string :udid, :limit => 40, :null => false
57
+ t.string :owner, :limit => 40
58
+ t.string :token, :limit => 255, :null => false
59
+ t.boolean :buuuk, :default => 0
60
+ t.boolean :valid_udid, :default => 1
61
+ t.string :carrier
62
+ t.integer :utime, :limit => 16
63
+ t.string :network_code, :limit => 12
64
+ t.string :country_code, :limit => 12
65
+ t.string :device, :limit => 32
66
+ t.string :country
67
+ t.string :version, :limit => 16
68
+ t.timestamps
69
+ end
70
+ if ActiveRecord::Base.connection.table_exists?(:tokens)
71
+ puts "passed".green + " Token Table Creation"
72
+ else
73
+ puts "failed".red + " Token Table Creation"
74
+ raise
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ def self.create_notification_table
81
+
82
+ if ActiveRecord::Base.connection.table_exists?(:notifications)
83
+ puts "exists".yellow + " Notification Table"
84
+ else
85
+ ActiveRecord::Base.connection.create_table :notifications do |t|
86
+ t.string :message
87
+ t.string :btn_name, :limit => 64
88
+ t.string :sound, :limit => 64
89
+ t.string :url
90
+ t.string :category, :limit => 64
91
+ t.string :carrier, :limit => 64
92
+ t.string :test_udids, :limit => 512
93
+ t.integer :utime, :limit => 16
94
+ t.timestamps
95
+ end
96
+ if ActiveRecord::Base.connection.table_exists?(:notifications)
97
+ puts "passed".green + " Notification Table Creation"
98
+ else
99
+ puts "failed".red + " Notification Table Creation"
100
+ raise
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ def self.create_apn_log_table
107
+
108
+ if ActiveRecord::Base.connection.table_exists?(:apn_logs)
109
+ puts "exists".yellow + " ApnLog Table"
110
+ else
111
+ ActiveRecord::Base.connection.create_table :apn_logs do |t|
112
+ t.integer :notification_id
113
+ t.integer :notification_size, :limit => 16
114
+ t.text :log_text
115
+ t.integer :utime, :limit => 16
116
+ t.timestamps
117
+ end
118
+ if ActiveRecord::Base.connection.table_exists?(:apn_logs)
119
+ puts "passed".green + " ApnLog Table Creation"
120
+ else
121
+ puts "failed".red + " ApnLog Table Creation"
122
+ raise
123
+ end
124
+ end
125
+
126
+ end
127
+
128
+ end
129
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ require 'erb'
4
+
5
+ module Zing
6
+ module FileHelper
7
+
8
+ def self.create_directory(dir_path)
9
+ if File.exist?(dir_path)
10
+ puts "exists".yellow + " #{dir_path}"
11
+ else
12
+ FileUtils.mkdir_p(dir_path)
13
+ puts "create".green + " #{dir_path}"
14
+ end
15
+ end
16
+
17
+ def self.create_file(file_path, file_content)
18
+ if File.exist?(file_path)
19
+ puts "exists".yellow + " #{file_path}"
20
+ else
21
+ File.open("#{file_path}", "w") do |file|
22
+ file.puts file_content
23
+ end
24
+ puts "create".green + " #{file_path}"
25
+ end
26
+ end
27
+
28
+ def self.copy_file_templates(options, feature)
29
+ project_absolute_dir = options.project_absolute_dir
30
+
31
+ # get the template directories based on the params used
32
+ directories = if feature[/options_base/i]
33
+ Dir.glob(File.dirname(__FILE__) + "/file_templates/base/**")
34
+ elsif feature[/options_push/i]
35
+ Dir.glob(File.dirname(__FILE__) + "/file_templates/push/**")
36
+ else
37
+ []
38
+ end
39
+
40
+ # traverse each directory and copy the template files
41
+ directories.each do |dir_name|
42
+
43
+ dir_name_last = dir_name.split("/").last
44
+
45
+ Dir.glob("#{dir_name}/*").each do |file|
46
+
47
+ filename = file.split("/").last.gsub(".erb", "")
48
+
49
+ # read file as ERB templates
50
+ content = File.open(file, "r").read
51
+ template = ERB.new content
52
+
53
+ # file copy location
54
+ file_location = "#{project_absolute_dir}/#{dir_name_last}/#{filename}"
55
+
56
+ # write the contents of each file to the project directory
57
+ create_file(file_location, template.result(binding))
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,2 @@
1
+ class AdminUser < ActiveRecord::Base
2
+ end
@@ -0,0 +1,41 @@
1
+ class Cms < Sinatra::Base
2
+
3
+ get '/cms' do
4
+ if session[:authorized]
5
+ redirect '/cms/dashboard'
6
+ else
7
+ redirect '/cms/login'
8
+ end
9
+ end
10
+
11
+ get '/cms/login' do
12
+ image_array = ["http://www.buuuk.com/wp-content/uploads/2011/08/ST_bannerNEW.png",
13
+ "http://www.buuuk.com/wp-content/uploads/2011/04/weatherlah-banner2d.png",
14
+ "http://www.buuuk.com/wp-content/uploads/2011/04/buUuk-banner_New2.png"]
15
+ @main_image = image_array[rand(3)]
16
+
17
+ haml :login, :layout => false
18
+ end
19
+
20
+ post '/cms/login' do
21
+ if params[:username] && params[:password]
22
+ admin_users = AdminUser.find_all_by_username_and_password(params[:username], params[:password])
23
+ if admin_users.size > 0
24
+ session[:authorized] = true
25
+ redirect '/cms/dashboard'
26
+ end
27
+ end
28
+
29
+ redirect '/cms/login'
30
+ end
31
+
32
+ get '/cms/logout' do
33
+ session[:authorized] = false
34
+ redirect '/cms/login'
35
+ end
36
+
37
+ get '/cms/dashboard' do
38
+ haml :dashboard
39
+ end
40
+
41
+ end
@@ -0,0 +1,6 @@
1
+ .row-fluid
2
+ %h1
3
+ Dashboard
4
+
5
+ %h6
6
+ Please select an action from the modules menu on your left
@@ -0,0 +1,45 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title= if @page_title then "CMS " + @page_title.humanize else "CMS" end
5
+ %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
6
+ %meta{:content => "NONE,NOARCHIVE", :name => "robots"}
7
+ %link{:href => "http://twitter.github.com/bootstrap/assets/css/bootstrap.css", :rel => "stylesheet", :type => "text/css"}
8
+ :css
9
+ body {
10
+ padding-top: 60px;
11
+ padding-bottom: 40px;
12
+ }
13
+
14
+ .sidebar-nav {
15
+ padding: 9px 0;
16
+ }
17
+
18
+
19
+ %body
20
+ .navbar.navbar-fixed-top
21
+ .navbar-inner
22
+ .container-fluid
23
+ %a.brand{:href=>"/"}
24
+ = $APP_NAME + " CMS"
25
+ .nav-collapse
26
+ %ul.nav
27
+ %li
28
+ %a{:href => "/cms/dashboard"}Dashboard
29
+ %p.navbar-text.pull-right
30
+ %a{:href => "/cms/logout"}Logout
31
+
32
+ .container-fluid
33
+ .row-fluid
34
+ .span3
35
+ .well.sidebar-nav
36
+ = haml :"sidebar", :layout => false
37
+
38
+ .span9
39
+ = yield
40
+
41
+ %hr
42
+
43
+ %footer
44
+ %p
45
+ = "All rights reserved. &copy; BuUuk " + Time.now.year.to_s
@@ -0,0 +1,64 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title= if @page_title then "CMS " + @page_title.humanize else "CMS" end
5
+ %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
6
+ %meta{:content => "NONE,NOARCHIVE", :name => "robots"}
7
+ %link{:href => "http://twitter.github.com/bootstrap/assets/css/bootstrap.css", :rel => "stylesheet", :type => "text/css"}
8
+ :css
9
+ body {
10
+ padding-top: 60px;
11
+ padding-bottom: 40px;
12
+ }
13
+
14
+ #main_image {
15
+ margin-bottom: 20px;
16
+ }
17
+
18
+ #platform_image {
19
+ margin-top: 20px;
20
+ }
21
+
22
+ %body
23
+
24
+ .navbar.navbar-fixed-top
25
+ .navbar-inner
26
+ .container
27
+ %a.brand{:href=>"#"}
28
+ = $APP_NAME + " CMS"
29
+
30
+ %form#login_form.navbar-form.pull-right{:action => "/cms/login", :method => "post"}
31
+ %input#login_username.input-small{:name => "username", :type => "text", :placeholder => "Username"}
32
+ %input#login_password.input-small{:name => "password", :type => "password", :placeholder => "Password"}
33
+ %button.btn{:type => "submit"}Sign in
34
+
35
+ .container
36
+ #main_image.row
37
+ .span12
38
+ %img{:src => @main_image}
39
+
40
+ .row
41
+ .span12
42
+ %h2 We build custom mobile applications
43
+ %p
44
+ We help our clients create mobile applications. Our focus is on building apps that deliver real-time, contextually relevant information to mobile touch screens. We are experts in using location, augmented reality and push notification. We don't out-source.
45
+ #platform_image.row
46
+ .span3{:style => "text-align: center"}
47
+ %img{:src => "http://www.buuuk.com/wp-content/uploads/2011/03/iPhone4Both1.png", :width => "200px", :height => "376px"}
48
+ .span3{:style => "text-align: center"}
49
+ %img{:src => "http://www.buuuk.com/wp-content/uploads/2011/03/Samsung_Nexus_S_FTKAKI.png", :width => "187px", :height => "344px"}
50
+ .span3{:style => "text-align: center"}
51
+ %img{:src => "http://www.buuuk.com/wp-content/uploads/2011/03/Blackberry-AMEXmerchantfind3.png", :width => "230px", :height => "363px"}
52
+ .span3{:style => "text-align: center"}
53
+ %img{:src => "http://www.buuuk.com/wp-content/uploads/2011/03/windows_buuuk2.png", :width => "200px", :height => "362px"}
54
+
55
+ .row
56
+ .span12
57
+ %h2 Platforms
58
+ %p From iPhone/iPad, to Android, to BlackBerry, to Windows 7: our portfolio of products is testament to our expertise across multiple platforms. Our services extend beyond just developing apps. We can provide a complete infrastructure for deployment, content management and hosting.
59
+
60
+ %hr
61
+
62
+ %footer
63
+ %p
64
+ = "All rights reserved. &copy; BuUuk " + Time.now.year.to_s
@@ -0,0 +1,10 @@
1
+ %ul.nav.nav-list
2
+ %li.nav-header
3
+ %i.icon-th-large
4
+ Modules
5
+ %li.nav-heder
6
+ %a{:href => "#"}
7
+ Push Notification
8
+ %li
9
+ %a{:href => "#"}
10
+ Collection Items
@@ -0,0 +1,2 @@
1
+ class ApnLog < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class Notification < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class Token < ActiveRecord::Base
2
+ end
@@ -0,0 +1,47 @@
1
+ gem "apns", "=0.9.0"
2
+ require "apns"
3
+
4
+ class Push
5
+
6
+ def self.push_new_alert(notification, token_array)
7
+
8
+ notification_id = notification.id
9
+ message = notification.message
10
+ button_name = notification.btn_name
11
+ sound = notification.sound
12
+ url = notification.url
13
+ test_udids = notification.test_udids
14
+
15
+ # apn setting
16
+ APNS.host = "gateway.push.apple.com"
17
+ APNS.pem = "#{app_name}_push_certificate.pem"
18
+
19
+ # always overide token_array if test udids exist
20
+ if token_array.size > 0 and test_udids and test_udids.size > 0
21
+ token_array = Token.find_all_by_udid(test_udids).map(&:token).compact
22
+ end
23
+
24
+ apn_notifications = []
25
+ if token_array.size > 0
26
+ token_array.each do |token|
27
+ apn_notifications << APNS::Notification.new(
28
+ token,
29
+ :alert => {:body => message,"action-loc-key" => button_name},
30
+ :sound => sound,
31
+ :other => {:url => url}
32
+ )
33
+ end
34
+
35
+ APNS.send_notifications(apn_notifications)
36
+
37
+ # Log the push
38
+ ApnLog.create(
39
+ :notification_id => notification_id,
40
+ :log_text => apn_notifications.inspect,
41
+ :utime => Time.now.to_i
42
+ )
43
+ end
44
+
45
+ end
46
+
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-01 00:00:00.000000000Z
12
+ date: 2012-02-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
16
- requirement: &70352378913100 !ruby/object:Gem::Requirement
16
+ requirement: &70254638713380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70352378913100
24
+ version_requirements: *70254638713380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &70352378912280 !ruby/object:Gem::Requirement
27
+ requirement: &70254638712040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70352378912280
35
+ version_requirements: *70254638712040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70352378910860 !ruby/object:Gem::Requirement
38
+ requirement: &70254638710260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70352378910860
46
+ version_requirements: *70254638710260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70352378909940 !ruby/object:Gem::Requirement
49
+ requirement: &70254638708520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70352378909940
57
+ version_requirements: *70254638708520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70352378908900 !ruby/object:Gem::Requirement
60
+ requirement: &70254638707480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70352378908900
68
+ version_requirements: *70254638707480
69
69
  description: This gem will generate common code for a new or existing Sinatra project
70
70
  email: samuelchandra@yahoo.com
71
71
  executables:
@@ -75,7 +75,6 @@ extra_rdoc_files:
75
75
  - LICENSE.txt
76
76
  - README.rdoc
77
77
  files:
78
- - .document
79
78
  - Gemfile
80
79
  - Gemfile.lock
81
80
  - LICENSE.txt
@@ -83,15 +82,23 @@ files:
83
82
  - Rakefile
84
83
  - VERSION
85
84
  - bin/zing
86
- - images/background-v2.png
87
- - images/background-white.png
88
- - images/bg_footer_bottom.png
89
- - images/bg_footer_top.png
90
85
  - lib/zing.rb
86
+ - lib/zing/command_parser.rb
87
+ - lib/zing/db_helper.rb
88
+ - lib/zing/file_helper.rb
89
+ - lib/zing/file_templates/base/models/admin_user.rb.erb
90
+ - lib/zing/file_templates/base/routes/cms.rb.erb
91
+ - lib/zing/file_templates/base/views/dashboard.haml.erb
92
+ - lib/zing/file_templates/base/views/layout.haml.erb
93
+ - lib/zing/file_templates/base/views/login.haml.erb
94
+ - lib/zing/file_templates/base/views/sidebar.haml.erb
95
+ - lib/zing/file_templates/push/models/apn_log.rb.erb
96
+ - lib/zing/file_templates/push/models/notification.rb.erb
97
+ - lib/zing/file_templates/push/models/token.rb.erb
98
+ - lib/zing/file_templates/push/push/push.rb.erb
91
99
  - test/helper.rb
92
100
  - test/test_zing.rb
93
- - zing.gemspec
94
- homepage: http://github.com/schandra/zing
101
+ homepage: http://github.com/samchandra/zing
95
102
  licenses:
96
103
  - MIT
97
104
  post_install_message:
@@ -106,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
113
  version: '0'
107
114
  segments:
108
115
  - 0
109
- hash: -4145048457769443243
116
+ hash: -2162117329032732296
110
117
  required_rubygems_version: !ruby/object:Gem::Requirement
111
118
  none: false
112
119
  requirements:
@@ -115,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
122
  version: '0'
116
123
  requirements: []
117
124
  rubyforge_project:
118
- rubygems_version: 1.8.15
125
+ rubygems_version: 1.8.10
119
126
  signing_key:
120
127
  specification_version: 3
121
128
  summary: Zing is Sinatra code generator
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
Binary file
Binary file
Binary file
Binary file
data/zing.gemspec DELETED
@@ -1,68 +0,0 @@
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.2.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 = "2012-02-01"
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.15"
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_development_dependency(%q<shoulda>, [">= 0"])
50
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
52
- s.add_development_dependency(%q<rcov>, [">= 0"])
53
- else
54
- s.add_dependency(%q<colorize>, [">= 0"])
55
- s.add_dependency(%q<shoulda>, [">= 0"])
56
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
58
- s.add_dependency(%q<rcov>, [">= 0"])
59
- end
60
- else
61
- s.add_dependency(%q<colorize>, [">= 0"])
62
- s.add_dependency(%q<shoulda>, [">= 0"])
63
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
65
- s.add_dependency(%q<rcov>, [">= 0"])
66
- end
67
- end
68
-