maccman-bowline 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +58 -0
- data/README.txt +113 -0
- data/Rakefile +24 -0
- data/assets/jquery.bowline.js +96 -0
- data/assets/jquery.chain.js +2348 -0
- data/assets/jquery.js +3549 -0
- data/bin/bowline-gen +6 -0
- data/bowline.gemspec +42 -0
- data/examples/account_binder.rb +29 -0
- data/examples/example.js +24 -0
- data/examples/twitter.html +43 -0
- data/examples/twitter_binder.rb +40 -0
- data/examples/twitter_login.html +29 -0
- data/examples/users_binder.rb +39 -0
- data/lib/bowline.rb +42 -0
- data/lib/bowline/binders.rb +177 -0
- data/lib/bowline/binders/collection.rb +27 -0
- data/lib/bowline/binders/singleton.rb +25 -0
- data/lib/bowline/commands/console.rb +27 -0
- data/lib/bowline/commands/generate.rb +1 -0
- data/lib/bowline/commands/run.rb +13 -0
- data/lib/bowline/ext/array.rb +5 -0
- data/lib/bowline/ext/class.rb +51 -0
- data/lib/bowline/ext/object.rb +12 -0
- data/lib/bowline/ext/string.rb +9 -0
- data/lib/bowline/gem_dependency.rb +42 -0
- data/lib/bowline/generators.rb +59 -0
- data/lib/bowline/generators/application.rb +49 -0
- data/lib/bowline/generators/binder.rb +25 -0
- data/lib/bowline/generators/migration.rb +51 -0
- data/lib/bowline/generators/model.rb +20 -0
- data/lib/bowline/initializer.rb +596 -0
- data/lib/bowline/jquery.rb +31 -0
- data/lib/bowline/observer.rb +43 -0
- data/lib/bowline/tasks/app.rake +70 -0
- data/lib/bowline/tasks/bowline.rb +8 -0
- data/lib/bowline/tasks/database.rake +167 -0
- data/lib/bowline/tasks/log.rake +9 -0
- data/lib/bowline/tasks/misk.rake +3 -0
- data/templates/Rakefile +7 -0
- data/templates/binder.rb +9 -0
- data/templates/config/application.yml +1 -0
- data/templates/config/boot.rb +21 -0
- data/templates/config/database.yml +4 -0
- data/templates/config/environment.rb +12 -0
- data/templates/config/manifest +18 -0
- data/templates/config/tiapp.xml +24 -0
- data/templates/gitignore +15 -0
- data/templates/migration.rb +7 -0
- data/templates/model.rb +4 -0
- data/templates/public/index.html.erb +23 -0
- data/templates/public/javascripts/application.js +0 -0
- data/templates/public/stylesheets/application.css +0 -0
- data/templates/script/console +3 -0
- data/templates/script/init +11 -0
- data/templates/script/run +3 -0
- metadata +143 -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,70 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
namespace :app do
|
3
|
+
desc "Bundles up app into executables"
|
4
|
+
task :bundle do
|
5
|
+
build_path = File.join(APP_ROOT, 'build')
|
6
|
+
titanium_path = ENV['TIPATH']
|
7
|
+
raise 'You need to provide TIPATH' unless titanium_path
|
8
|
+
titanium_path = File.expand_path(titanium_path)
|
9
|
+
|
10
|
+
titanium_path = File.join(titanium_path, 'build', 'osx')
|
11
|
+
build_path = File.join(build_path, 'osx')
|
12
|
+
FileUtils.rm_rf(build_path)
|
13
|
+
|
14
|
+
build_path = File.join(build_path, 'testapp.app', 'Contents')
|
15
|
+
FileUtils.mkdir_p(build_path)
|
16
|
+
|
17
|
+
FileUtils.cd(titanium_path) do
|
18
|
+
# todo MacOS
|
19
|
+
# FileUtils.cp_r('installer', build_path)
|
20
|
+
FileUtils.cp_r('modules', build_path)
|
21
|
+
FileUtils.cp_r('runtime', build_path)
|
22
|
+
# FileUtils.cp_r('Frameworks', build_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
File.open(File.join(build_path, 'Info.plist'), 'w+') do |f|
|
26
|
+
f.write <<-EOF
|
27
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
28
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
29
|
+
<plist version="1.0">
|
30
|
+
<dict>
|
31
|
+
<key>CFBundleDevelopmentRegion</key>
|
32
|
+
<string>English</string>
|
33
|
+
<key>CFBundleExecutable</key>
|
34
|
+
<string>testapp</string>
|
35
|
+
<key>CFBundleIconFile</key>
|
36
|
+
<string>titanium.icns</string>
|
37
|
+
<key>CFBundleIdentifier</key>
|
38
|
+
<string>com.titaniumapp.testapp</string>
|
39
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
40
|
+
<string>6.0</string>
|
41
|
+
<key>CFBundleName</key>
|
42
|
+
<string>Titanium Test App</string>
|
43
|
+
<key>CFBundlePackageType</key>
|
44
|
+
<string>APPL</string>
|
45
|
+
<key>CFBundleSignature</key>
|
46
|
+
<string>WRUN</string>
|
47
|
+
<key>CFBundleVersion</key>
|
48
|
+
<string>0.4</string>
|
49
|
+
<key>NSMainNibFile</key>
|
50
|
+
<string>MainMenu</string>
|
51
|
+
<key>NSPrincipalClass</key>
|
52
|
+
<string>NSApplication</string>
|
53
|
+
</dict>
|
54
|
+
</plist>
|
55
|
+
EOF
|
56
|
+
end
|
57
|
+
|
58
|
+
resources_path = File.join(build_path, 'Resources')
|
59
|
+
FileUtils.mkdir_p(resources_path)
|
60
|
+
|
61
|
+
dirs = Dir[File.join(APP_ROOT, '*')] - [File.join(APP_ROOT, 'build')]
|
62
|
+
|
63
|
+
FileUtils.cp_r(dirs, resources_path)
|
64
|
+
|
65
|
+
FileUtils.cd(resources_path) do
|
66
|
+
FileUtils.mv(File.join('config', 'manifest'), build_path)
|
67
|
+
FileUtils.mv(File.join('config', 'tiapp.xml'), build_path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
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
|
data/templates/Rakefile
ADDED
@@ -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'
|
data/templates/binder.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
key: value
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
if defined?(Titanium)
|
5
|
+
# Hack for load paths - Titanium doesn't add .
|
6
|
+
app_resources = Titanium.App.appURLToPath("app://index.html")
|
7
|
+
APP_ROOT = File.dirname(app_resources)
|
8
|
+
else
|
9
|
+
APP_ROOT = File.join(File.dirname(__FILE__), "..")
|
10
|
+
end
|
11
|
+
$LOAD_PATH << APP_ROOT
|
12
|
+
$LOAD_PATH.uniq!
|
13
|
+
|
14
|
+
bowline_path = File.join(APP_ROOT, *%w[vendor bowline lib bowline.rb])
|
15
|
+
|
16
|
+
if File.exist?(bowline_path)
|
17
|
+
require bowline_path
|
18
|
+
else
|
19
|
+
require "rubygems"
|
20
|
+
require "bowline"
|
21
|
+
end
|
@@ -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 = <%= name.camel_case.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>
|