bowline 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +1 -0
  2. data/History.txt +4 -0
  3. data/MIT-LICENSE +20 -0
  4. data/Manifest.txt +58 -0
  5. data/README.txt +136 -0
  6. data/Rakefile +25 -0
  7. data/assets/jquery.bowline.js +96 -0
  8. data/assets/jquery.chain.js +2348 -0
  9. data/assets/jquery.js +3549 -0
  10. data/bin/bowline-gen +6 -0
  11. data/bowline.gemspec +45 -0
  12. data/examples/account.rb +31 -0
  13. data/examples/example.js +24 -0
  14. data/examples/tweets.rb +28 -0
  15. data/examples/twitter.html +39 -0
  16. data/examples/users.rb +37 -0
  17. data/lib/bowline.rb +42 -0
  18. data/lib/bowline/binders.rb +177 -0
  19. data/lib/bowline/binders/collection.rb +27 -0
  20. data/lib/bowline/binders/singleton.rb +25 -0
  21. data/lib/bowline/commands/console.rb +27 -0
  22. data/lib/bowline/commands/generate.rb +1 -0
  23. data/lib/bowline/commands/run.rb +11 -0
  24. data/lib/bowline/ext/array.rb +5 -0
  25. data/lib/bowline/ext/class.rb +51 -0
  26. data/lib/bowline/ext/object.rb +12 -0
  27. data/lib/bowline/ext/string.rb +9 -0
  28. data/lib/bowline/gem_dependency.rb +42 -0
  29. data/lib/bowline/generators.rb +59 -0
  30. data/lib/bowline/generators/application.rb +58 -0
  31. data/lib/bowline/generators/binder.rb +25 -0
  32. data/lib/bowline/generators/migration.rb +51 -0
  33. data/lib/bowline/generators/model.rb +20 -0
  34. data/lib/bowline/initializer.rb +596 -0
  35. data/lib/bowline/jquery.rb +31 -0
  36. data/lib/bowline/observer.rb +43 -0
  37. data/lib/bowline/tasks/app.rake +90 -0
  38. data/lib/bowline/tasks/bowline.rb +8 -0
  39. data/lib/bowline/tasks/database.rake +167 -0
  40. data/lib/bowline/tasks/log.rake +9 -0
  41. data/lib/bowline/tasks/misk.rake +3 -0
  42. data/templates/Rakefile +7 -0
  43. data/templates/binder.rb +9 -0
  44. data/templates/config/application.yml +1 -0
  45. data/templates/config/boot.rb +13 -0
  46. data/templates/config/database.yml +4 -0
  47. data/templates/config/environment.rb +12 -0
  48. data/templates/config/manifest +18 -0
  49. data/templates/config/tiapp.xml +24 -0
  50. data/templates/gitignore +15 -0
  51. data/templates/migration.rb +7 -0
  52. data/templates/model.rb +4 -0
  53. data/templates/public/index.html +25 -0
  54. data/templates/public/javascripts/application.js +0 -0
  55. data/templates/public/stylesheets/application.css +0 -0
  56. data/templates/script/console +3 -0
  57. data/templates/script/init +18 -0
  58. data/templates/script/run +3 -0
  59. metadata +155 -0
@@ -0,0 +1,31 @@
1
+ module Bowline
2
+ class JQuery
3
+ # Equivalent to: $.foo()
4
+ def method_missing(sym, args)
5
+ self.class.dollar.send(sym, *args)
6
+ end
7
+
8
+ class << self
9
+ # Equivalent to: $('#item_id')
10
+ def for_element(el)
11
+ Bowline::js.send("jQuery", el)
12
+ end
13
+
14
+ # For binding global events
15
+ # Equivalent to: $('body').bind()
16
+ def bind(event, fun, data)
17
+ for_element("body").bind(event, data, fun)
18
+ end
19
+
20
+ # Equivalent to: $
21
+ def dollar
22
+ Bowline::js.send("jQuery")
23
+ end
24
+
25
+ # Equivalent to: $.bowline
26
+ def bowline
27
+ dollar.bowline
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ # o = Observer.new
2
+ # o.append('greet') {
3
+ # puts 'hi'
4
+ # }
5
+ # o.call('greet')
6
+ #
7
+ # def greet(who)
8
+ # puts "Hi #{who}"
9
+ # end
10
+ # o.append('greet', method(:greet), 'Alex')
11
+ # o.call('greet')
12
+
13
+ module Bowline
14
+ class Observer
15
+ def initialize
16
+ @listeners = {}
17
+ end
18
+
19
+ # Append block/method to listeners
20
+ def append(event, method = nil, *args, &block)
21
+ (@listeners[event.to_s] ||= []) << [method||block, args]
22
+ end
23
+
24
+ # Like append, but adds it to the body too
25
+ def on(event, method = nil, &block)
26
+ append(event, method, &block)
27
+ JQuery.bind(event.to_s, method(:call), event)
28
+ end
29
+
30
+ # Call event
31
+ def call(event)
32
+ event = event.to_s
33
+ @listeners[event].each do |callback|
34
+ callback[0].call(*callback[1])
35
+ end
36
+ @listeners.delete(event)
37
+ end
38
+
39
+ def clear
40
+ @listeners = {}
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,90 @@
1
+ require 'fileutils'
2
+ namespace :app do
3
+ desc "Bundles up app into executables"
4
+ task :bundle => ["bundle:windows", "bundle:linux", "bundle:osx"]
5
+
6
+ namespace :bundle do
7
+ task :windows => :environment do
8
+ end
9
+
10
+ task :linux => :environment do
11
+ end
12
+
13
+ task :osx => :environment do
14
+ build_path = File.join(APP_ROOT, 'build')
15
+ titanium_path = ENV['TIPATH']
16
+ raise 'You need to provide TIPATH' unless titanium_path
17
+ titanium_path = File.expand_path(titanium_path)
18
+
19
+ titanium_path = File.join(titanium_path, 'build', 'osx')
20
+ build_path = File.join(build_path, 'osx')
21
+ FileUtils.rm_rf(build_path)
22
+
23
+ build_path = File.join(build_path, "#{APP_NAME}.app", 'Contents')
24
+ FileUtils.mkdir_p(build_path)
25
+
26
+ exec_path = File.join(build_path, 'MacOS')
27
+ FileUtils.mkdir_p(exec_path)
28
+
29
+ FileUtils.cd(titanium_path) do
30
+ FileUtils.cp_r('runtime/template/kboot', File.join(exec_path, APP_NAME))
31
+ FileUtils.cp_r('runtime/installer', build_path)
32
+ FileUtils.cp_r('modules', build_path)
33
+ FileUtils.cp_r('runtime', build_path)
34
+ # FileUtils.cp_r('Frameworks', build_path) # todo
35
+ end
36
+
37
+ # Todo - put this in config?
38
+ File.open(File.join(build_path, 'Info.plist'), 'w+') do |f|
39
+ f.write <<-EOF
40
+ <?xml version="1.0" encoding="UTF-8"?>
41
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
42
+ <plist version="1.0">
43
+ <dict>
44
+ <key>CFBundleDevelopmentRegion</key>
45
+ <string>English</string>
46
+ <key>CFBundleExecutable</key>
47
+ <string>#{APP_NAME}</string>
48
+ <key>CFBundleIconFile</key>
49
+ <string>titanium.icns</string>
50
+ <key>CFBundleIdentifier</key>
51
+ <string>com.titaniumapp.testapp</string>
52
+ <key>CFBundleInfoDictionaryVersion</key>
53
+ <string>6.0</string>
54
+ <key>CFBundleName</key>
55
+ <string>#{APP_NAME}</string>
56
+ <key>CFBundlePackageType</key>
57
+ <string>APPL</string>
58
+ <key>CFBundleSignature</key>
59
+ <string>WRUN</string>
60
+ <key>CFBundleVersion</key>
61
+ <string>0.4</string>
62
+ <key>NSMainNibFile</key>
63
+ <string>MainMenu</string>
64
+ <key>NSPrincipalClass</key>
65
+ <string>NSApplication</string>
66
+ </dict>
67
+ </plist>
68
+ EOF
69
+ end
70
+
71
+ resources_path = File.join(build_path, 'Resources')
72
+ FileUtils.mkdir_p(resources_path)
73
+
74
+ english_path = File.join(resources_path, 'English.lproj')
75
+ FileUtils.mkdir_p(english_path)
76
+ FileUtils.cd(build_path) do
77
+ FileUtils.cp_r('runtime/template/MainMenu.nib', english_path)
78
+ FileUtils.cp_r('runtime/template/titanium.icns', english_path)
79
+ end
80
+
81
+ dirs = Dir[File.join(APP_ROOT, '*')] - [File.join(APP_ROOT, 'build')]
82
+ FileUtils.cp_r(dirs, resources_path)
83
+
84
+ FileUtils.cd(resources_path) do
85
+ FileUtils.mv(File.join('config', 'manifest'), build_path)
86
+ FileUtils.mv(File.join('config', 'tiapp.xml'), build_path)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,8 @@
1
+ $VERBOSE = nil
2
+
3
+ # Load Rails rakefile extensions
4
+ Dir["#{File.dirname(__FILE__)}/*.rake"].each { |ext| load ext }
5
+
6
+ # Load any custom rakefile extensions
7
+ Dir["#{APP_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
8
+ Dir["#{APP_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,167 @@
1
+ namespace :db do
2
+ task :load_config do
3
+ require 'active_record'
4
+ $config = Bowline::Configuration.new.database_configuration
5
+ end
6
+
7
+ desc 'Create the database defined in config/database.yml'
8
+ task :create => :load_config do
9
+ create_database($config)
10
+ end
11
+
12
+ def create_database(config)
13
+ begin
14
+ if config['adapter'] =~ /sqlite/
15
+ if File.exist?(config['database'])
16
+ $stderr.puts "#{config['database']} already exists"
17
+ else
18
+ begin
19
+ # Create the SQLite database
20
+ ActiveRecord::Base.establish_connection(config)
21
+ ActiveRecord::Base.connection
22
+ rescue
23
+ $stderr.puts $!, *($!.backtrace)
24
+ $stderr.puts "Couldn't create database for #{config.inspect}"
25
+ end
26
+ end
27
+ return # Skip the else clause of begin/rescue
28
+ else
29
+ ActiveRecord::Base.establish_connection(config)
30
+ ActiveRecord::Base.connection
31
+ end
32
+ rescue
33
+ case config['adapter']
34
+ when 'mysql'
35
+ @charset = ENV['CHARSET'] || 'utf8'
36
+ @collation = ENV['COLLATION'] || 'utf8_general_ci'
37
+ begin
38
+ ActiveRecord::Base.establish_connection(config.merge('database' => nil))
39
+ ActiveRecord::Base.connection.create_database(config['database'], :charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation))
40
+ ActiveRecord::Base.establish_connection(config)
41
+ rescue
42
+ $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation} (if you set the charset manually, make sure you have a matching collation)"
43
+ end
44
+ when 'postgresql'
45
+ @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
46
+ begin
47
+ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
48
+ ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
49
+ ActiveRecord::Base.establish_connection(config)
50
+ rescue
51
+ $stderr.puts $!, *($!.backtrace)
52
+ $stderr.puts "Couldn't create database for #{config.inspect}"
53
+ end
54
+ end
55
+ else
56
+ $stderr.puts "#{config['database']} already exists"
57
+ end
58
+ end
59
+
60
+ desc 'Drops the database'
61
+ task :drop => :load_config do
62
+ begin
63
+ drop_database($config)
64
+ rescue Exception => e
65
+ puts "Couldn't drop #{$config['database']} : #{e.inspect}"
66
+ end
67
+ end
68
+
69
+ desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking db:schema:dump. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
70
+ task :migrate => :environment do
71
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
72
+ ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
73
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
74
+ end
75
+
76
+ namespace :migrate do
77
+ desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
78
+ task :redo => :environment do
79
+ if ENV["VERSION"]
80
+ Rake::Task["db:migrate:down"].invoke
81
+ Rake::Task["db:migrate:up"].invoke
82
+ else
83
+ Rake::Task["db:rollback"].invoke
84
+ Rake::Task["db:migrate"].invoke
85
+ end
86
+ end
87
+
88
+ desc 'Resets your database using your migrations for the current environment'
89
+ task :reset => ["db:drop", "db:create", "db:migrate"]
90
+
91
+ desc 'Runs the "up" for a given migration VERSION.'
92
+ task :up => :environment do
93
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
94
+ raise "VERSION is required" unless version
95
+ ActiveRecord::Migrator.run(:up, "db/migrate/", version)
96
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
97
+ end
98
+
99
+ desc 'Runs the "down" for a given migration VERSION.'
100
+ task :down => :environment do
101
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
102
+ raise "VERSION is required" unless version
103
+ ActiveRecord::Migrator.run(:down, "db/migrate/", version)
104
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
105
+ end
106
+ end
107
+
108
+ desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
109
+ task :rollback => :environment do
110
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
111
+ ActiveRecord::Migrator.rollback('db/migrate/', step)
112
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
113
+ end
114
+
115
+ desc 'Drops and recreates the database from db/schema.rb for the current environment.'
116
+ task :reset => ['db:drop', 'db:create', 'db:schema:load']
117
+
118
+ desc "Retrieves the current schema version number"
119
+ task :version => :environment do
120
+ puts "Current version: #{ActiveRecord::Migrator.current_version}"
121
+ end
122
+
123
+ desc "Raises an error if there are pending migrations"
124
+ task :abort_if_pending_migrations => :environment do
125
+ if defined? ActiveRecord
126
+ pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
127
+
128
+ if pending_migrations.any?
129
+ puts "You have #{pending_migrations.size} pending migrations:"
130
+ pending_migrations.each do |pending_migration|
131
+ puts ' %4d %s' % [pending_migration.version, pending_migration.name]
132
+ end
133
+ abort %{Run "rake db:migrate" to update your database then try again.}
134
+ end
135
+ end
136
+ end
137
+
138
+ namespace :schema do
139
+ desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
140
+ task :dump => :environment do
141
+ require 'active_record/schema_dumper'
142
+ File.open(ENV['SCHEMA'] || "#{APP_ROOT}/db/schema.rb", "w") do |file|
143
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
144
+ end
145
+ Rake::Task["db:schema:dump"].reenable
146
+ end
147
+
148
+ desc "Load a schema.rb file into the database"
149
+ task :load => :environment do
150
+ file = ENV['SCHEMA'] || "#{APP_ROOT}/db/schema.rb"
151
+ load(file)
152
+ end
153
+ end
154
+ end
155
+
156
+ def drop_database(config)
157
+ case config['adapter']
158
+ when 'mysql'
159
+ ActiveRecord::Base.establish_connection(config)
160
+ ActiveRecord::Base.connection.drop_database config['database']
161
+ when /^sqlite/
162
+ FileUtils.rm(File.join(APP_ROOT, config['database']))
163
+ when 'postgresql'
164
+ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
165
+ ActiveRecord::Base.connection.drop_database config['database']
166
+ end
167
+ end
@@ -0,0 +1,9 @@
1
+ namespace :log do
2
+ desc "Truncates all *.log files in log/ to zero bytes"
3
+ task :clear do
4
+ FileList["log/*.log"].each do |log_file|
5
+ f = File.open(log_file, "w")
6
+ f.close
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ task :environment do
2
+ require(File.join(APP_ROOT, 'config', 'environment'))
3
+ end
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/foo.rake, and they will automatically be available to Rake.
3
+
4
+ require File.join(File.dirname(__FILE__), *%w[config boot])
5
+
6
+ require 'rake'
7
+ require 'bowline/tasks/bowline'
@@ -0,0 +1,9 @@
1
+ <%- with_modules(modules) do -%>
2
+ class <%= class_name %>
3
+ class << self
4
+ def index
5
+ end
6
+ end
7
+
8
+ end
9
+ <%- end -%>
@@ -0,0 +1 @@
1
+ key: value
@@ -0,0 +1,13 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ APP_ROOT = File.join(File.dirname(__FILE__), "..") unless defined?(APP_ROOT)
5
+
6
+ bowline_path = File.join(APP_ROOT, *%w[vendor bowline lib bowline.rb])
7
+
8
+ if File.exist?(bowline_path)
9
+ require bowline_path
10
+ else
11
+ require "rubygems"
12
+ require "bowline"
13
+ end
@@ -0,0 +1,4 @@
1
+ adapter: sqlite3
2
+ database: db/application.sqlite3
3
+ pool: 5
4
+ timeout: 5000
@@ -0,0 +1,12 @@
1
+ # Bootstrap the Bowline environment, frameworks, and default configuration
2
+ require File.join(File.dirname(__FILE__), 'boot')
3
+
4
+ Bowline::Initializer.run do |config|
5
+ config.name = <%= full_name.inspect %>
6
+
7
+ # config.gem "net-mdns", :lib => 'net/dns/mdns'
8
+ # config.gem "rack"
9
+ # config.gem "rubyzip", :lib => 'zip/zip'
10
+
11
+ config.frameworks += [:active_record, :active_resource]
12
+ end
@@ -0,0 +1,18 @@
1
+ runtime: 0.4
2
+ api:0.4
3
+ python:0.4
4
+ javascript:0.4
5
+ ruby:0.4
6
+ tiapp:0.4
7
+ tiui:0.4
8
+ tinetwork:0.4
9
+ tigrowl:0.4
10
+ tifilesystem:0.4
11
+ timedia:0.4
12
+ tidesktop:0.4
13
+ tiplatform:0.4
14
+ tiprocess:0.4
15
+ tinotification:0.4
16
+ timonkey:0.4
17
+ tianalytics:0.4
18
+ tidatabase:0.4
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ti:app xmlns:ti="http://ti.appcelerator.org" xmlns:appc="http://www.appcelerator.org">
3
+ <id><%= app_id %></id>
4
+ <name><%= name %></name>
5
+ <version>0.1</version>
6
+ <window>
7
+ <id>initial</id>
8
+ <title>Bowline</title>
9
+ <url>app://public/index.html</url>
10
+ <width>750</width>
11
+ <height>800</height>
12
+ <fullscreen>false</fullscreen>
13
+ <!--
14
+ <minimizable>true</minimizable>
15
+ <maximizable>false</maximizable>
16
+ <max-width>900</max-width>
17
+ <max-height>800</max-height>
18
+ <min-width>400</min-width>
19
+ <min-height>300</min-height>
20
+ -->
21
+ <closeable>true</closeable>
22
+ <chrome>true</chrome>
23
+ </window>
24
+ </ti:app>