spontaneous 0.2.0.alpha4 → 0.2.0.alpha5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/spot +25 -15
- data/lib/spontaneous/capistrano/deploy.rb +1 -1
- data/lib/spontaneous/cli/assets.rb +6 -7
- data/lib/spontaneous/cli/console.rb +13 -23
- data/lib/spontaneous/cli/generate.rb +30 -0
- data/lib/spontaneous/cli/init.rb +48 -0
- data/lib/spontaneous/cli/media.rb +1 -1
- data/lib/spontaneous/cli/migrate.rb +22 -0
- data/lib/spontaneous/cli/server.rb +16 -17
- data/lib/spontaneous/cli/site.rb +13 -17
- data/lib/spontaneous/cli/sync.rb +5 -4
- data/lib/spontaneous/cli/user.rb +7 -7
- data/lib/spontaneous/cli.rb +62 -123
- data/lib/spontaneous/generators/site/Gemfile.tt +6 -6
- data/lib/spontaneous/generators/site/config/schema.yml +2 -0
- data/lib/spontaneous/generators/site.rb +4 -1
- data/lib/spontaneous/version.rb +1 -1
- data/spontaneous.gemspec +7 -6
- metadata +9 -8
- data/lib/spontaneous/cli/adapter.rb +0 -13
- data/lib/spontaneous/cli/base.rb +0 -144
- data/lib/spontaneous/cli/tasks.rb +0 -9
data/bin/spot
CHANGED
@@ -3,21 +3,31 @@
|
|
3
3
|
require 'rubygems' unless defined?(Gem) # Useful only on --dev mode
|
4
4
|
require 'bundler'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
# Are we in the root of a Spontaneous site?
|
7
|
+
# If so then we want to use the bundled version of Spontaneous and its
|
8
|
+
# dependencies
|
9
|
+
if File.exist?("config/schema.yml")
|
10
|
+
begin
|
11
|
+
Bundler.setup(:default)
|
12
|
+
rescue Bundler::GemfileNotFound
|
13
|
+
# We're operating outside of a site dir, probably generating a site
|
14
|
+
# so load the Spontaneous gem Gemfile
|
15
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
|
16
|
+
retry
|
17
|
+
rescue Bundler::GemNotFound => e
|
18
|
+
STDERR.puts e.message
|
19
|
+
STDERR.puts "Try running `bundle install`."
|
20
|
+
exit!
|
21
|
+
end
|
22
|
+
else
|
23
|
+
# If spot is being run outside of a site, then we want to use the global
|
24
|
+
# gem files
|
25
|
+
spot_path = File.expand_path('../../lib', __FILE__)
|
26
|
+
if File.directory?(spot_path) && !$:.include?(spot_path)
|
27
|
+
$:.unshift(spot_path)
|
28
|
+
end
|
17
29
|
end
|
18
30
|
|
19
|
-
|
20
|
-
$:.unshift(spot_path) if File.directory?(spot_path) && !$:.include?(spot_path)
|
31
|
+
require 'spontaneous'
|
21
32
|
|
22
|
-
|
23
|
-
Spontaneous::Cli::Runner.start(ARGV)
|
33
|
+
Spontaneous::Cli::Root.start(ARGV)
|
@@ -29,7 +29,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
task :bundle_assets do
|
32
|
-
run "cd #{release_path} &&
|
32
|
+
run "cd #{release_path} && ./bin/spot assets compile --destination=#{release_path}"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module Spontaneous
|
2
2
|
module Cli
|
3
|
-
class Assets < ::
|
4
|
-
Spontaneous
|
3
|
+
class Assets < ::Thor
|
4
|
+
include Spontaneous::Cli::TaskUtils
|
5
|
+
|
5
6
|
namespace :assets
|
6
7
|
default_task :compile
|
7
8
|
|
8
9
|
|
9
|
-
|
10
|
-
# desc "Syncs up"
|
11
|
-
# end
|
10
|
+
desc "compile", "Compiles assets for the Spontaneous UI"
|
12
11
|
|
13
|
-
desc "#{namespace}:compile", "Compiles assets for the Spontaneous UI"
|
14
12
|
method_option :destination, :type => :string, :aliases => "-d", :required => true, :desc => "Compile assets into DESTINATION"
|
13
|
+
|
15
14
|
def compile
|
16
15
|
prepare(:compile)
|
17
16
|
# options[:mode] = :console
|
@@ -20,7 +19,7 @@ module Spontaneous
|
|
20
19
|
spec = Bundler.load.specs.find{|s| s.name == "spontaneous" }
|
21
20
|
p spec.full_gem_path
|
22
21
|
|
23
|
-
compiler = Spontaneous::Asset::AppCompiler.new(spec.full_gem_path, options.destination)
|
22
|
+
compiler = ::Spontaneous::Asset::AppCompiler.new(spec.full_gem_path, options.destination)
|
24
23
|
compiler.compile
|
25
24
|
end
|
26
25
|
end
|
@@ -2,34 +2,26 @@
|
|
2
2
|
|
3
3
|
# require 'watchr'
|
4
4
|
|
5
|
-
module Spontaneous::Cli
|
6
|
-
class Console < ::
|
7
|
-
Spontaneous
|
5
|
+
module ::Spontaneous::Cli
|
6
|
+
class Console < ::Thor
|
7
|
+
include Spontaneous::Cli::TaskUtils
|
8
8
|
include Thor::Actions
|
9
|
-
namespace :console
|
10
9
|
|
10
|
+
namespace :console
|
11
11
|
default_task :open
|
12
12
|
|
13
|
-
desc "
|
13
|
+
desc "open", "Gives you console access to the current site"
|
14
14
|
def open
|
15
|
-
|
16
|
-
# script.watch('(lib|schema)/.*\\.rb') { puts 'reload!' } # doesn't block
|
17
|
-
# Thread.new do
|
18
|
-
# Watchr::Controller.new(script, Watchr.handler.new).run
|
19
|
-
# end
|
15
|
+
prepare! :console
|
20
16
|
|
21
|
-
|
22
|
-
ENV["SPOT_MODE"] = "console"
|
23
|
-
prepare :console
|
24
17
|
ARGV.clear
|
25
18
|
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
|
26
|
-
require 'irb'
|
27
|
-
boot!
|
28
19
|
|
20
|
+
require 'irb'
|
29
21
|
require 'irb/completion'
|
30
22
|
require 'irb/ext/save-history'
|
31
23
|
|
32
|
-
history_file = Spontaneous.root / ".irb_history"
|
24
|
+
history_file = ::Spontaneous.root / ".irb_history"
|
33
25
|
|
34
26
|
IRB.setup(nil)
|
35
27
|
IRB.conf[:SAVE_HISTORY] = 100
|
@@ -38,8 +30,7 @@ module Spontaneous::Cli
|
|
38
30
|
irb = IRB::Irb.new
|
39
31
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
40
32
|
|
41
|
-
irb.context.evaluate((<<-
|
42
|
-
|
33
|
+
irb.context.evaluate((<<-CONTEXT), __LINE__)
|
43
34
|
module Readline
|
44
35
|
module History
|
45
36
|
def self.write_log(line)
|
@@ -57,16 +48,15 @@ module Spontaneous::Cli
|
|
57
48
|
ln
|
58
49
|
end
|
59
50
|
end
|
60
|
-
|
61
|
-
|
62
|
-
INIT
|
51
|
+
CONTEXT
|
63
52
|
|
64
53
|
trap("SIGINT") do
|
65
54
|
irb.signal_handle
|
66
55
|
end
|
67
|
-
|
56
|
+
|
57
|
+
catch("IRB_EXIT") do
|
68
58
|
irb.eval_input
|
69
59
|
end
|
70
60
|
end
|
71
61
|
end # Console
|
72
|
-
end # Spontaneous::Cli
|
62
|
+
end # ::Spontaneous::Cli
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'public_suffix'
|
4
|
+
|
5
|
+
module Spontaneous::Cli
|
6
|
+
class Generate < ::Thor
|
7
|
+
include Spontaneous::Cli::TaskUtils
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
namespace :generate
|
11
|
+
|
12
|
+
default_task :site
|
13
|
+
|
14
|
+
desc "site [DOMAIN]", "Generates a site skeleton. Usage: spot generate <site domain name>"
|
15
|
+
def site(*args)
|
16
|
+
require File.expand_path('../../../spontaneous', __FILE__)
|
17
|
+
::Spontaneous::Generators::Site.start(args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(method, *args)
|
21
|
+
if PublicSuffix.valid?(method.to_s)
|
22
|
+
args.unshift(method.to_s)
|
23
|
+
self.send(:site, *args)
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end # Generate
|
29
|
+
end # Spontaneous::Cli
|
30
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Spontaneous::Cli
|
4
|
+
class Init < ::Thor
|
5
|
+
include Spontaneous::Cli::TaskUtils
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
namespace :init
|
9
|
+
|
10
|
+
default_task :init
|
11
|
+
|
12
|
+
desc :init, "Creates databases and initialises a new Spontaneous site"
|
13
|
+
def init
|
14
|
+
prepare :init
|
15
|
+
site = ::Spontaneous::Site.instantiate(Dir.pwd, options.environment, :back)
|
16
|
+
require File.expand_path('../../../spontaneous', __FILE__)
|
17
|
+
Sequel.extension :migration
|
18
|
+
connection_params = ::Spontaneous.db_settings
|
19
|
+
connection_params[:user] = 'root'
|
20
|
+
database = connection_params.delete(:database)
|
21
|
+
password = connection_params.delete(:password)
|
22
|
+
catch(:error) do
|
23
|
+
Sequel.connect(connection_params) do |connection|
|
24
|
+
["", "_test"].map { |ext| "#{database}#{ext}"}.each do |db|
|
25
|
+
begin
|
26
|
+
say " >> Creating database `#{db}`"
|
27
|
+
connection.run("CREATE DATABASE `#{db}` CHARACTER SET UTF8")
|
28
|
+
rescue => e
|
29
|
+
say " >>> Unable to create #{connection_params[:adapter]} database `#{db}`:\n > #{e}", :red
|
30
|
+
# throw :error
|
31
|
+
end
|
32
|
+
begin
|
33
|
+
connection.run("USE `#{db}`")
|
34
|
+
connection.logger = nil
|
35
|
+
say " >> Running migrations..."
|
36
|
+
Sequel::Migrator.apply(connection, ::Spontaneous.gem_dir('db/migrations'))
|
37
|
+
say " >> Done"
|
38
|
+
rescue => e
|
39
|
+
say " >>> Error running migrations on database `#{db}`:\n > #{e}", :red
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
boot!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end # Init
|
48
|
+
end # Spontaneous::Cli
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Spontaneous::Cli
|
4
|
+
class Migrate < ::Thor
|
5
|
+
include Spontaneous::Cli::TaskUtils
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
namespace :migrate
|
9
|
+
default_task :apply
|
10
|
+
|
11
|
+
desc :apply, "Runs Spontaneous migrations"
|
12
|
+
def apply
|
13
|
+
prepare! :migrate
|
14
|
+
Sequel.extension :migration
|
15
|
+
connection_params = ::Spontaneous.db_settings
|
16
|
+
say " >> Running migrations..."
|
17
|
+
Sequel::Migrator.apply(Spontaneous.database, ::Spontaneous.gem_dir('db/migrations'))
|
18
|
+
say " >> Done"
|
19
|
+
end
|
20
|
+
|
21
|
+
end # Migrate
|
22
|
+
end # Spontaneous::Cli
|
@@ -1,31 +1,34 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'spontaneous'
|
3
|
+
# require 'spontaneous'
|
4
4
|
require 'simultaneous'
|
5
5
|
require 'foreman'
|
6
6
|
require 'foreman/engine'
|
7
7
|
|
8
8
|
module Spontaneous
|
9
9
|
module Cli
|
10
|
-
class Server < ::
|
11
|
-
|
10
|
+
class Server < ::Thor
|
11
|
+
include Spontaneous::Cli::TaskUtils
|
12
|
+
|
13
|
+
namespace :server
|
12
14
|
default_task :start
|
13
15
|
|
14
16
|
class_option :no_browser, :type => :boolean, :default => false, :aliases => "-b", :desc => "Don't launch browser"
|
15
17
|
|
16
|
-
desc "
|
18
|
+
desc "start", "Starts Spontaneous in development mode"
|
17
19
|
def start
|
20
|
+
# I can do this programatically in the latest version of Foreman
|
18
21
|
File.open(".Procfile", 'wb') do |procfile|
|
19
|
-
procfile.write(%(back: #{binary} server
|
20
|
-
procfile.write(%(front: #{binary} server
|
21
|
-
procfile.write(%(simultaneous: #{binary} server
|
22
|
+
procfile.write(%(back: #{binary} server back --root=#{options.site}\n))
|
23
|
+
procfile.write(%(front: #{binary} server front --root=#{options.site}\n))
|
24
|
+
procfile.write(%(simultaneous: #{binary} server simultaneous --root=#{options.site}\n))
|
22
25
|
procfile.flush
|
23
26
|
engine = ::Foreman::Engine.new(procfile.path)
|
24
27
|
engine.start
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
|
-
desc "
|
31
|
+
desc "front", "Starts Spontaneous in front/public mode"
|
29
32
|
# method_option :adapter, :type => :string, :aliases => "-a", :desc => "Rack Handler (default: autodetect)"
|
30
33
|
method_option :host, :type => :string, :aliases => "-h", :desc => "Bind to HOST address"
|
31
34
|
method_option :port, :type => :numeric, :aliases => "-p", :desc => "Use PORT"
|
@@ -33,7 +36,7 @@ module Spontaneous
|
|
33
36
|
start_server(:front)
|
34
37
|
end
|
35
38
|
|
36
|
-
desc "
|
39
|
+
desc "back", "Starts Spontaneous in back/CMS mode"
|
37
40
|
# method_option :adapter, :type => :string, :aliases => "-a", :desc => "Rack Handler (default: autodetect)"
|
38
41
|
method_option :host, :type => :string, :aliases => "-h", :desc => "Bind to HOST address"
|
39
42
|
method_option :port, :type => :numeric, :aliases => "-p", :desc => "Use PORT"
|
@@ -41,11 +44,10 @@ module Spontaneous
|
|
41
44
|
start_server(:back)
|
42
45
|
end
|
43
46
|
|
44
|
-
desc "
|
47
|
+
desc "simultaneous", "Launches the Simultaneous server"
|
45
48
|
method_option :connection, :type => :string, :aliases => "-c", :desc => "Use CONNECTION"
|
46
49
|
def simultaneous
|
47
|
-
prepare
|
48
|
-
boot!
|
50
|
+
prepare! :start
|
49
51
|
connection = options[:connection] || ::Spontaneous.config.simultaneous_connection
|
50
52
|
fork {
|
51
53
|
ENV.delete("BUNDLE_GEMFILE")
|
@@ -63,11 +65,8 @@ module Spontaneous
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def start_server(mode)
|
66
|
-
prepare mode
|
67
|
-
|
68
|
-
require File.expand_path(File.dirname(__FILE__) + "/adapter")
|
69
|
-
boot!
|
70
|
-
Spontaneous::Cli::Adapter.start(options)
|
68
|
+
prepare! :server, mode
|
69
|
+
Spontaneous::Server.run!(options)
|
71
70
|
end
|
72
71
|
|
73
72
|
end
|
data/lib/spontaneous/cli/site.rb
CHANGED
@@ -2,7 +2,8 @@ require 'spontaneous/cli'
|
|
2
2
|
|
3
3
|
module Spontaneous
|
4
4
|
module Cli
|
5
|
-
class Site < ::
|
5
|
+
class Site < ::Thor
|
6
|
+
include Spontaneous::Cli::TaskUtils
|
6
7
|
namespace :site
|
7
8
|
|
8
9
|
default_task :browse
|
@@ -98,26 +99,23 @@ module Spontaneous
|
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
101
|
-
desc "
|
102
|
+
desc "dump", "Dumps the current site to an archive on the local machine"
|
102
103
|
def dump
|
103
|
-
prepare :dump
|
104
|
-
boot!
|
104
|
+
prepare! :dump
|
105
105
|
Dump.start
|
106
106
|
end
|
107
107
|
|
108
|
-
desc "
|
108
|
+
desc "load", "Uploads a dump of the current site to a remote server"
|
109
109
|
def load
|
110
|
-
prepare :load
|
111
|
-
boot!
|
110
|
+
prepare! :load
|
112
111
|
Load.start
|
113
112
|
end
|
114
113
|
|
115
|
-
desc "
|
114
|
+
desc "publish", "Publishes the site"
|
116
115
|
method_option :pages, :type => :array, :desc => "List of pages to publish"
|
117
116
|
method_option :logfile, :type => :string, :desc => "Location of logfile"
|
118
117
|
def publish
|
119
|
-
prepare :publish
|
120
|
-
boot!
|
118
|
+
prepare! :publish
|
121
119
|
::Site.publishing_method = :immediate
|
122
120
|
::Spontaneous::Logger.setup(:logfile => options.logfile) if options.logfile
|
123
121
|
say "Creating revision #{::Site.revision}", :green, true
|
@@ -130,22 +128,20 @@ module Spontaneous
|
|
130
128
|
end
|
131
129
|
end
|
132
130
|
|
133
|
-
desc "
|
131
|
+
desc "render", "Re-renders the current content"
|
134
132
|
def render
|
135
|
-
prepare :render
|
136
|
-
boot!
|
133
|
+
prepare! :render
|
137
134
|
::Site.publishing_method = :immediate
|
138
135
|
::Site.rerender
|
139
136
|
end
|
140
137
|
|
141
|
-
desc "
|
138
|
+
desc "revision", "Shows the site status"
|
142
139
|
def revision
|
143
|
-
prepare :revision
|
144
|
-
boot!
|
140
|
+
prepare! :revision
|
145
141
|
say "Site is at revision #{::Site.revision}", :green
|
146
142
|
end
|
147
143
|
|
148
|
-
desc "
|
144
|
+
desc "browse", "Launces a browser pointing to the current development CMS"
|
149
145
|
def browse
|
150
146
|
prepare :browse
|
151
147
|
require 'launchy'
|
data/lib/spontaneous/cli/sync.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
|
2
2
|
module Spontaneous
|
3
3
|
module Cli
|
4
|
-
class Sync < ::
|
5
|
-
Spontaneous
|
4
|
+
class Sync < ::Thor
|
5
|
+
include Spontaneous::Cli::TaskUtils
|
6
|
+
|
6
7
|
namespace :sync
|
7
8
|
default_task :down
|
8
9
|
|
@@ -28,12 +29,12 @@ module Spontaneous
|
|
28
29
|
desc "Syncs up"
|
29
30
|
end
|
30
31
|
|
31
|
-
desc "
|
32
|
+
desc "down", "Makes the local copy a clone of the production server"
|
32
33
|
def down
|
33
34
|
Down.start
|
34
35
|
end
|
35
36
|
|
36
|
-
desc "
|
37
|
+
desc "up", "Makes the local copy a clone of the production server"
|
37
38
|
def up
|
38
39
|
Down.start
|
39
40
|
end
|
data/lib/spontaneous/cli/user.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
|
2
|
-
module Spontaneous
|
2
|
+
module ::Spontaneous
|
3
3
|
module Cli
|
4
|
-
class User < ::
|
5
|
-
Spontaneous
|
6
|
-
namespace :user
|
4
|
+
class User < ::Thor
|
5
|
+
include Spontaneous::Cli::TaskUtils
|
6
|
+
# namespace :user
|
7
7
|
|
8
8
|
default_task :add
|
9
9
|
|
@@ -23,11 +23,11 @@ module Spontaneous
|
|
23
23
|
def add
|
24
24
|
prepare :adduser, :console
|
25
25
|
boot!
|
26
|
-
users = Spontaneous::Permissions::User.count
|
26
|
+
users = ::Spontaneous::Permissions::User.count
|
27
27
|
attrs = {}
|
28
28
|
width = 14
|
29
29
|
valid_login = /^[a-z0-9_]{3,}$/
|
30
|
-
levels = Spontaneous::Permissions::UserLevel.all.map(&:to_s)
|
30
|
+
levels = ::Spontaneous::Permissions::UserLevel.all.map(&:to_s)
|
31
31
|
level = nil
|
32
32
|
|
33
33
|
say("\nAll fields are required:\n", :green)
|
@@ -88,7 +88,7 @@ module Spontaneous
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
user = Spontaneous::Permissions::User.new(attrs)
|
91
|
+
user = ::Spontaneous::Permissions::User.new(attrs)
|
92
92
|
|
93
93
|
if user.save
|
94
94
|
user.update(:level => level)
|
data/lib/spontaneous/cli.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
require 'thor'
|
2
|
-
require 'thor/
|
2
|
+
require 'thor/group'
|
3
3
|
|
4
4
|
module Spontaneous
|
5
5
|
module Cli
|
6
|
-
|
6
|
+
module TaskUtils
|
7
|
+
# include Thor::Actions
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
protected
|
14
|
-
|
15
|
-
def boot!
|
16
|
-
begin
|
17
|
-
require File.expand_path('config/boot.rb')
|
18
|
-
rescue Spontaneous::SchemaModificationError => error
|
19
|
-
fix_schema(error)
|
9
|
+
def self.included(base)
|
10
|
+
base.class_eval do
|
11
|
+
def self.banner(task, namespace = true, subcommand = false)
|
12
|
+
"#{basename} #{task.formatted_usage(self, true, subcommand)}"
|
13
|
+
end
|
20
14
|
end
|
15
|
+
base.class_option :site, :type => :string, :aliases => ["-s", "--root"], :desc => "Site root dir"
|
16
|
+
base.class_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development, :desc => "Spontaneous Environment"
|
17
|
+
base.class_option :mode, :type => :string, :aliases => "-m", :default => :back, :desc => "Spontaneous mode ('front' or 'back')"
|
18
|
+
base.class_option :help, :type => :boolean, :desc => "Show help usage"
|
21
19
|
end
|
22
20
|
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
23
24
|
def fix_schema(error)
|
24
25
|
modification = error.modification
|
25
26
|
actions = modification.actions
|
@@ -42,14 +43,14 @@ module Spontaneous
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
def prepare(task, mode =
|
46
|
+
def prepare(task, mode = "console")
|
46
47
|
if options.help?
|
47
48
|
help(task.to_s)
|
48
49
|
raise SystemExit
|
49
50
|
end
|
50
|
-
ENV["SPOT_ENV"] ||= options.environment.to_s
|
51
|
+
ENV["SPOT_ENV"] ||= options.environment.to_s ||
|
51
52
|
ENV["RACK_ENV"] = ENV["SPOT_ENV"] # Also set this for middleware
|
52
|
-
ENV["SPOT_MODE"] = mode.to_s
|
53
|
+
ENV["SPOT_MODE"] = mode.to_s
|
53
54
|
chdir(options.site)
|
54
55
|
unless File.exist?('config/boot.rb')
|
55
56
|
puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb\n=> Are you sure this is a Spontaneous site?"
|
@@ -57,6 +58,19 @@ module Spontaneous
|
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
61
|
+
def prepare!(task, mode = "console")
|
62
|
+
prepare(task, mode)
|
63
|
+
boot!
|
64
|
+
end
|
65
|
+
|
66
|
+
def boot!
|
67
|
+
begin
|
68
|
+
require File.expand_path('config/boot.rb')
|
69
|
+
rescue Spontaneous::SchemaModificationError => error
|
70
|
+
fix_schema(error)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
60
74
|
def chdir(dir)
|
61
75
|
return unless dir
|
62
76
|
begin
|
@@ -69,116 +83,41 @@ module Spontaneous
|
|
69
83
|
end
|
70
84
|
end
|
71
85
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
86
|
+
autoload :Console, "spontaneous/cli/console"
|
87
|
+
autoload :Site, "spontaneous/cli/site"
|
88
|
+
autoload :Init, "spontaneous/cli/init"
|
89
|
+
autoload :User, "spontaneous/cli/user"
|
90
|
+
autoload :Generate, "spontaneous/cli/generate"
|
91
|
+
autoload :Server, "spontaneous/cli/server"
|
92
|
+
autoload :Media, "spontaneous/cli/media"
|
93
|
+
autoload :Sync, "spontaneous/cli/sync"
|
94
|
+
autoload :Migrate, "spontaneous/cli/migrate"
|
95
|
+
autoload :Assets, "spontaneous/cli/assets"
|
96
|
+
|
97
|
+
class Root < ::Thor
|
98
|
+
register Spontaneous::Cli::Console, "console", "console", "Gives you console access to the current site"
|
99
|
+
register Spontaneous::Cli::User, "user", "user [ACTION]", "Administer site users"
|
100
|
+
register Spontaneous::Cli::Generate, "generate", "generate [OBJECT]", "Generates things"
|
101
|
+
register Spontaneous::Cli::Site, "site", "site [ACTION]", "Run site-wide actions"
|
102
|
+
register Spontaneous::Cli::Init, "init", "init", "Creates databases and initialises a new Spontaneous site"
|
103
|
+
register Spontaneous::Cli::Server, "server", "server [ACTION]", "Launch development server(s)"
|
104
|
+
register Spontaneous::Cli::Media, "media", "media [ACTION]", "Manage site media"
|
105
|
+
register Spontaneous::Cli::Sync, "sync", "sync [DIRECTION]", "Sync database and media to and from the production server"
|
106
|
+
register Spontaneous::Cli::Migrate, "migrate", "migrate", "Runs Spontaneous migrations"
|
107
|
+
register Spontaneous::Cli::Assets, "assets", "assets [ACTION]", "Manage Spontaneous assets"
|
108
|
+
|
109
|
+
desc :browse, "Launces a browser pointing to the current development CMS"
|
110
|
+
def browse
|
111
|
+
prepare! :browse
|
112
|
+
require 'launchy'
|
113
|
+
::Launchy.open("http://localhost:#{::Spontaneous::Site.config.port}/@spontaneous")
|
114
|
+
end
|
78
115
|
|
79
|
-
desc
|
116
|
+
desc :version, "Show the version of Spontaneous in use"
|
80
117
|
def version
|
81
|
-
require
|
118
|
+
require "spontaneous/version"
|
82
119
|
say "Spontaneous #{Spontaneous::VERSION}"
|
83
120
|
end
|
84
|
-
|
85
|
-
desc "list [SEARCH]", "List the available tasks (--substring means .*SEARCH)"
|
86
|
-
method_options :substring => :boolean, :group => :string, :all => :boolean, :debug => :boolean
|
87
|
-
def list(search="")
|
88
|
-
initialize_thorfiles
|
89
|
-
|
90
|
-
search = ".*#{search}" if options["substring"]
|
91
|
-
search = /^#{search}.*/i
|
92
|
-
group = options[:group] || "standard"
|
93
|
-
|
94
|
-
klasses = Thor::Base.subclasses.select do |k|
|
95
|
-
(options[:all] || k.group == group) && k.namespace =~ search
|
96
|
-
end
|
97
|
-
|
98
|
-
display_klasses(false, false, klasses)
|
99
|
-
end
|
100
|
-
|
101
|
-
# Override Thor#help so it can give information about any class and any method.
|
102
|
-
#
|
103
|
-
desc "help [TASK]", "Describe available tasks or one specific task"
|
104
|
-
def help(task = nil, subcommand = false)
|
105
|
-
task ? self.class.task_help(shell, task) : self.class.help(shell, subcommand)
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
# Override Thor#help so it can give information about any class and any method.
|
110
|
-
#
|
111
|
-
def help(meth = nil)
|
112
|
-
if meth && !self.respond_to?(meth)
|
113
|
-
initialize_thorfiles(meth)
|
114
|
-
klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
|
115
|
-
klass.start(["-h", task].compact, :shell => self.shell)
|
116
|
-
else
|
117
|
-
list
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# If a task is not found on Thor::Runner, method missing is invoked and
|
122
|
-
# Thor::Runner is then responsable for finding the task in all classes.
|
123
|
-
#
|
124
|
-
def method_missing(meth, *args)
|
125
|
-
meth = meth.to_s
|
126
|
-
initialize_thorfiles(meth)
|
127
|
-
klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
|
128
|
-
args.unshift(task) if task
|
129
|
-
klass.start(args, :shell => self.shell)
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
|
134
|
-
# Display information about the given klasses. If with_module is given,
|
135
|
-
# it shows a table with information extracted from the yaml file.
|
136
|
-
#
|
137
|
-
def display_klasses(with_modules=false, show_internal=false, klasses=Thor::Base.subclasses)
|
138
|
-
klasses -= [Thor, Thor::Runner, Thor::Group] unless show_internal
|
139
|
-
|
140
|
-
raise Error, "No tasks available" if klasses.empty?
|
141
|
-
show_modules if with_modules && !thor_yaml.empty?
|
142
|
-
|
143
|
-
list = Hash.new { |h,k| h[k] = [] }
|
144
|
-
groups = klasses.select { |k| k.ancestors.include?(Thor::Group) }
|
145
|
-
|
146
|
-
# Get classes which inherit from Thor
|
147
|
-
(klasses - groups).each { |k| list[k.namespace.split(":").first] += k.printable_tasks(false) }
|
148
|
-
|
149
|
-
list.delete("thor")
|
150
|
-
|
151
|
-
# Order namespaces with default coming first
|
152
|
-
list = list.sort{ |a,b| a[0].sub(/^default/, '') <=> b[0].sub(/^default/, '') }
|
153
|
-
list.each { |n, tasks| display_tasks(n, tasks) unless tasks.empty? }
|
154
|
-
end
|
155
|
-
|
156
|
-
def display_tasks(namespace, list) #:nodoc:
|
157
|
-
list.sort!{ |a,b| a[0] <=> b[0] }
|
158
|
-
|
159
|
-
say shell.set_color(namespace, :blue, true)
|
160
|
-
say "-" * namespace.size
|
161
|
-
|
162
|
-
print_table(list, :truncate => true)
|
163
|
-
say
|
164
|
-
end
|
165
|
-
|
166
|
-
def initialize_thorfiles(relevant_to=nil, skip_lookup=false)
|
167
|
-
thorfiles(relevant_to, skip_lookup).each do |f|
|
168
|
-
Thor::Util.load_thorfile(f, nil, options[:debug]) unless Thor::Base.subclass_files.keys.include?(File.expand_path(f))
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def thorfiles(*args)
|
173
|
-
task_dir = File.expand_path('../cli', __FILE__)
|
174
|
-
Dir["#{task_dir}/*.rb"]
|
175
|
-
end
|
176
121
|
end
|
177
|
-
|
178
|
-
autoload :Adapter, "spontaneous/cli/adapter"
|
179
|
-
autoload :Base, "spontaneous/cli/base"
|
180
|
-
autoload :Site, "spontaneous/cli/site"
|
181
|
-
autoload :User, "spontaneous/cli/user"
|
182
122
|
end
|
183
123
|
end
|
184
|
-
|
@@ -1,8 +1,8 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
3
|
## choose your poison:
|
4
|
-
# gem 'pg', '~> 0.
|
5
|
-
gem 'mysql2', '~> 0.
|
4
|
+
# gem 'pg', '~> 0.14.0'
|
5
|
+
gem 'mysql2', '~> 0.3'
|
6
6
|
|
7
7
|
# Deploy with Capistrano
|
8
8
|
gem 'capistrano', '~> 2.9'
|
@@ -19,10 +19,10 @@ gem 'capistrano', '~> 2.9'
|
|
19
19
|
gem 'spontaneous', :git => "git://github.com/SpontaneousCMS/spontaneous.git"
|
20
20
|
gem 'simultaneous', :git => "git://github.com/SpontaneousCMS/simultaneous.git"
|
21
21
|
|
22
|
-
group :production do
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
# group :production do
|
23
|
+
# gem 'thin', '~> 1.3.1'
|
24
|
+
# gem 'unicorn', '~> 4.2'
|
25
|
+
# end
|
26
26
|
|
27
27
|
|
28
28
|
# source gemfiles from Plugins & Features
|
data/lib/spontaneous/version.rb
CHANGED
data/spontaneous.gemspec
CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
|
|
14
14
|
## If your rubyforge_project name is different, then edit it and comment out
|
15
15
|
## the sub! line in the Rakefile
|
16
16
|
s.name = 'spontaneous'
|
17
|
-
s.version = '0.2.0.
|
18
|
-
s.date = '2012-10-
|
17
|
+
s.version = '0.2.0.alpha5'
|
18
|
+
s.date = '2012-10-16'
|
19
19
|
s.rubyforge_project = 'spontaneous'
|
20
20
|
|
21
21
|
## Make sure your summary is short. The description may be as long
|
@@ -75,7 +75,7 @@ Gem::Specification.new do |s|
|
|
75
75
|
s.add_dependency('stringex', ["= 1.3"])
|
76
76
|
s.add_dependency('therubyracer', ['~> 0.9.10'])
|
77
77
|
s.add_dependency('thin', ["~> 1.2"])
|
78
|
-
s.add_dependency('thor', ["~> 0.
|
78
|
+
s.add_dependency('thor', ["~> 0.16.0"])
|
79
79
|
s.add_dependency('uglifier', ["~> 1.3.0"])
|
80
80
|
s.add_dependency('oj', ["~> 1.4"])
|
81
81
|
|
@@ -286,15 +286,15 @@ Gem::Specification.new do |s|
|
|
286
286
|
lib/spontaneous/capistrano/sync.rb
|
287
287
|
lib/spontaneous/change.rb
|
288
288
|
lib/spontaneous/cli.rb
|
289
|
-
lib/spontaneous/cli/adapter.rb
|
290
289
|
lib/spontaneous/cli/assets.rb
|
291
|
-
lib/spontaneous/cli/base.rb
|
292
290
|
lib/spontaneous/cli/console.rb
|
291
|
+
lib/spontaneous/cli/generate.rb
|
292
|
+
lib/spontaneous/cli/init.rb
|
293
293
|
lib/spontaneous/cli/media.rb
|
294
|
+
lib/spontaneous/cli/migrate.rb
|
294
295
|
lib/spontaneous/cli/server.rb
|
295
296
|
lib/spontaneous/cli/site.rb
|
296
297
|
lib/spontaneous/cli/sync.rb
|
297
|
-
lib/spontaneous/cli/tasks.rb
|
298
298
|
lib/spontaneous/cli/user.rb
|
299
299
|
lib/spontaneous/collections/box_set.rb
|
300
300
|
lib/spontaneous/collections/change_set.rb
|
@@ -349,6 +349,7 @@ Gem::Specification.new do |s|
|
|
349
349
|
lib/spontaneous/generators/site/config/environments/production.rb.tt
|
350
350
|
lib/spontaneous/generators/site/config/front.ru
|
351
351
|
lib/spontaneous/generators/site/config/indexes.rb.tt
|
352
|
+
lib/spontaneous/generators/site/config/schema.yml
|
352
353
|
lib/spontaneous/generators/site/config/user_levels.yml
|
353
354
|
lib/spontaneous/generators/site/lib/site.rb.tt
|
354
355
|
lib/spontaneous/generators/site/lib/tasks/site.rake.tt
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spontaneous
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.
|
4
|
+
version: 0.2.0.alpha5
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -450,7 +450,7 @@ dependencies:
|
|
450
450
|
requirements:
|
451
451
|
- - ~>
|
452
452
|
- !ruby/object:Gem::Version
|
453
|
-
version: 0.
|
453
|
+
version: 0.16.0
|
454
454
|
type: :runtime
|
455
455
|
prerelease: false
|
456
456
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -458,7 +458,7 @@ dependencies:
|
|
458
458
|
requirements:
|
459
459
|
- - ~>
|
460
460
|
- !ruby/object:Gem::Version
|
461
|
-
version: 0.
|
461
|
+
version: 0.16.0
|
462
462
|
- !ruby/object:Gem::Dependency
|
463
463
|
name: uglifier
|
464
464
|
requirement: !ruby/object:Gem::Requirement
|
@@ -864,15 +864,15 @@ files:
|
|
864
864
|
- lib/spontaneous/capistrano/sync.rb
|
865
865
|
- lib/spontaneous/change.rb
|
866
866
|
- lib/spontaneous/cli.rb
|
867
|
-
- lib/spontaneous/cli/adapter.rb
|
868
867
|
- lib/spontaneous/cli/assets.rb
|
869
|
-
- lib/spontaneous/cli/base.rb
|
870
868
|
- lib/spontaneous/cli/console.rb
|
869
|
+
- lib/spontaneous/cli/generate.rb
|
870
|
+
- lib/spontaneous/cli/init.rb
|
871
871
|
- lib/spontaneous/cli/media.rb
|
872
|
+
- lib/spontaneous/cli/migrate.rb
|
872
873
|
- lib/spontaneous/cli/server.rb
|
873
874
|
- lib/spontaneous/cli/site.rb
|
874
875
|
- lib/spontaneous/cli/sync.rb
|
875
|
-
- lib/spontaneous/cli/tasks.rb
|
876
876
|
- lib/spontaneous/cli/user.rb
|
877
877
|
- lib/spontaneous/collections/box_set.rb
|
878
878
|
- lib/spontaneous/collections/change_set.rb
|
@@ -927,6 +927,7 @@ files:
|
|
927
927
|
- lib/spontaneous/generators/site/config/environments/production.rb.tt
|
928
928
|
- lib/spontaneous/generators/site/config/front.ru
|
929
929
|
- lib/spontaneous/generators/site/config/indexes.rb.tt
|
930
|
+
- lib/spontaneous/generators/site/config/schema.yml
|
930
931
|
- lib/spontaneous/generators/site/config/user_levels.yml
|
931
932
|
- lib/spontaneous/generators/site/lib/site.rb.tt
|
932
933
|
- lib/spontaneous/generators/site/lib/tasks/site.rake.tt
|
@@ -1385,7 +1386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1385
1386
|
version: 1.3.1
|
1386
1387
|
requirements: []
|
1387
1388
|
rubyforge_project: spontaneous
|
1388
|
-
rubygems_version: 1.8.
|
1389
|
+
rubygems_version: 1.8.24
|
1389
1390
|
signing_key:
|
1390
1391
|
specification_version: 2
|
1391
1392
|
summary: Spontaneous is a next-generation Ruby CMS
|
data/lib/spontaneous/cli/base.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'thor'
|
4
|
-
|
5
|
-
module Spontaneous
|
6
|
-
module Cli
|
7
|
-
class Base < ::Spontaneous::Cli::Thor
|
8
|
-
Spontaneous = ::Spontaneous
|
9
|
-
include Thor::Actions
|
10
|
-
namespace :default
|
11
|
-
|
12
|
-
class InvalidGenerator < Error
|
13
|
-
attr_reader :name
|
14
|
-
def initialize(name)
|
15
|
-
@name = name
|
16
|
-
super()
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
desc :console, "Gives you console access to the current site"
|
27
|
-
def console
|
28
|
-
ENV["SPOT_MODE"] = "console"
|
29
|
-
prepare :console
|
30
|
-
ARGV.clear
|
31
|
-
require 'irb'
|
32
|
-
boot!
|
33
|
-
IRB.setup(nil)
|
34
|
-
irb = IRB::Irb.new
|
35
|
-
IRB.conf[:MAIN_CONTEXT] = irb.context
|
36
|
-
irb.context.evaluate("require 'irb/completion'", 0)
|
37
|
-
irb.context.evaluate("require '#{File.expand_path(File.dirname(__FILE__) + '/console')}'", 0)
|
38
|
-
# irb.context.evaluate("include Spontaneous", 0)
|
39
|
-
trap("SIGINT") do
|
40
|
-
irb.signal_handle
|
41
|
-
end
|
42
|
-
catch(:IRB_EXIT) do
|
43
|
-
irb.eval_input
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
desc :generate, "Executes the Spontaneous generator with given options."
|
48
|
-
def generate(*args)
|
49
|
-
require File.expand_path('../../../spontaneous', __FILE__)
|
50
|
-
ARGV.shift
|
51
|
-
generator_name = ARGV.shift
|
52
|
-
generator = nil
|
53
|
-
d = Spontaneous::Generators
|
54
|
-
case generator_name
|
55
|
-
when ''
|
56
|
-
raise InvalidGenerator.new(generator_name)
|
57
|
-
when 'site'
|
58
|
-
generator = d::Site
|
59
|
-
when 'page'
|
60
|
-
prepare(:generator)
|
61
|
-
boot!
|
62
|
-
generator = d::Page
|
63
|
-
when /[a-zA-Z0-9-]+(\.[a-z]+)+/
|
64
|
-
# generator called as 'spot generate domain.com'
|
65
|
-
ARGV.unshift(generator_name)
|
66
|
-
generator = d::Site
|
67
|
-
else
|
68
|
-
raise InvalidGenerator.new(generator_name)
|
69
|
-
end
|
70
|
-
generator.start(ARGV) if generator
|
71
|
-
rescue InvalidGenerator => e
|
72
|
-
say "Unrecognised generator '#{e.name}'. Available options are:\n\n #{available_generators.join("\n ")}\n"
|
73
|
-
end
|
74
|
-
|
75
|
-
desc :browse, "Launces a browser pointing to the current development CMS"
|
76
|
-
def browse
|
77
|
-
prepare :browse
|
78
|
-
require 'launchy'
|
79
|
-
boot!
|
80
|
-
::Launchy.open("http://localhost:#{Site.config.port}/@spontaneous")
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
desc :init, "Creates databases and initialises a new Spontaneous site"
|
85
|
-
def init
|
86
|
-
prepare :init
|
87
|
-
site = Spontaneous::Site.instantiate(Dir.pwd, options.environment, :back)
|
88
|
-
require File.expand_path('../../../spontaneous', __FILE__)
|
89
|
-
Sequel.extension :migration
|
90
|
-
connection_params = Spontaneous.db_settings
|
91
|
-
connection_params[:user] = 'root'
|
92
|
-
database = connection_params.delete(:database)
|
93
|
-
password = connection_params.delete(:password)
|
94
|
-
catch(:error) do
|
95
|
-
Sequel.connect(connection_params) do |connection|
|
96
|
-
["", "_test"].map { |ext| "#{database}#{ext}"}.each do |db|
|
97
|
-
begin
|
98
|
-
say " >> Creating database `#{db}`"
|
99
|
-
connection.run("CREATE DATABASE `#{db}` CHARACTER SET UTF8")
|
100
|
-
rescue => e
|
101
|
-
say " >>> Unable to create #{connection_params[:adapter]} database `#{db}`:\n > #{e}", :red
|
102
|
-
# throw :error
|
103
|
-
end
|
104
|
-
begin
|
105
|
-
connection.run("USE `#{db}`")
|
106
|
-
connection.logger = nil
|
107
|
-
say " >> Running migrations..."
|
108
|
-
Sequel::Migrator.apply(connection, Spontaneous.gem_dir('db/migrations'))
|
109
|
-
say " >> Done"
|
110
|
-
rescue => e
|
111
|
-
say " >>> Error running migrations on database `#{db}`:\n > #{e}", :red
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
boot!
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
desc :migrate, "Runs migrations"
|
120
|
-
def migrate
|
121
|
-
prepare :init
|
122
|
-
boot!
|
123
|
-
Sequel.extension :migration
|
124
|
-
connection_params = Spontaneous.db_settings
|
125
|
-
say " >> Running migrations..."
|
126
|
-
Sequel::Migrator.apply(Spontaneous.database, Spontaneous.gem_dir('db/migrations'))
|
127
|
-
say " >> Done"
|
128
|
-
end
|
129
|
-
|
130
|
-
private
|
131
|
-
|
132
|
-
|
133
|
-
def available_generators
|
134
|
-
Spontaneous::Generators.available.map do |g|
|
135
|
-
g.name.demodulize.underscore
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end # Base
|
143
|
-
end # Cli
|
144
|
-
end # Spontaneous
|