Skip to content

Commit

Permalink
* More updates in preparation for use as a GemPlugin
Browse files Browse the repository at this point in the history
* A start on the CLI support
  • Loading branch information
mattmccray committed May 21, 2008
1 parent 8adaa15 commit a650d61
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 39 deletions.
125 changes: 107 additions & 18 deletions bin/comatose
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,109 @@
#!/usr/bin/env ruby
# Command line

puts "It's still early, so this doesn't really do anything -- yet."
puts
puts "Soon, you will be able to initialize comatose support in your app by running:"
puts
puts " $> comatose --rails ."
puts
puts "Or, upgrade you're current install:"
puts
puts " $> comatose --update ."
puts
puts "Or, freeze as plugin:"
puts
puts " $> comatose --freeze ."
puts
puts "And maybe other wacky things too... Not sure yet. :-)"
puts
require 'rubygems'
require 'optparse'

args = ARGV
options = {
:action => :gem
}

begin
OptionParser.new do |opts|
opts.banner = "Usage: comatose [options] RAILS_ROOT"

opts.on("-g", "--gem", "Initialize to run from gem (DEFAULT)") do |s|
options[:action] = :gem
puts "GEM"
end

opts.on("-p", "--plugin", "Install as plugin") do |s|
options[:action] = :plugin
puts "PLUGIN"
end

opts.on("-u", "--update", "Update current installation (CURRENTLY UNIMPLEMENTED)") do |s|
options[:action] = :update
puts "UPDATE"
end

opts.separator ""
opts.separator "Common options:"

# No argument, shows at tail. This will print an options summary.
# Try it and see!
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end

# Another typical switch to print the version.
opts.on_tail("--version", "Show version") do
require 'comatose/version'
puts Comatose::VERSION_STRING
exit
end

end.parse!(args)
rescue OptionParser::ParseError => e
puts e
end

if args.length == 0
puts "No action taken."
exit
end

RAILS_ROOT = File.expand_path( args.last )

class String
def /(string)
File.join(self, string)
end
end

unless File.directory?(RAILS_ROOT) and File.exists?( RAILS_ROOT / 'config'/ 'boot.rb' )
puts "Not a valid rails application path."
exit
end

comatose_initializer_path = RAILS_ROOT / 'config' / 'initializers' / 'comatose.rb'

unless File.exists?( comatose_initializer_path )
File.open(comatose_initializer_path, 'w') do |f|
f.write <<-EOT
require 'comatose'
# 1.) You should add the following snippet to your environment.rb too, probably...
#
# gem 'comatose'
#
# 2.) Following is an example configuration block for Comatose:
#
Comatose.configure do |config|
# Includes AuthenticationSystem in the ComatoseController
#config.includes << :authenticated_system
# admin
#config.admin_title = "My Content"
#config.admin_sub_title = "Content for the rest of us..."
# Includes AuthenticationSystem in the ComatoseAdminController
#config.admin_includes << :authenticated_system
# Calls :login_required as a before_filter
#config.admin_authorization = :login_required
# Returns the author name (login, in this case) for the current user
#config.admin_get_author do
# current_user.login
#end
# See the getting started guide at http://comatose.rubyforge.org for more...
end
EOT
end
else
puts "Comatose initializer already exists (at #{comatose_initializer_path})"
end

puts "Done."

8 changes: 0 additions & 8 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
require 'support/class_options'
require 'acts_as_versioned'
require 'redcloth' unless defined?(RedCloth)
require 'liquid' unless defined?(Liquid)

require 'comatose'
require 'text_filters'

require 'support/inline_rendering'
require 'support/route_mapper'
10 changes: 10 additions & 0 deletions lib/comatose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ def self.load_extensions

end

require 'acts_as_versioned'
require 'redcloth' unless defined?(RedCloth)
require 'liquid' unless defined?(Liquid)

require 'support/class_options'
require 'text_filters'

require 'comatose/configuration'
require 'comatose/comatose_drop'
require 'comatose/processing_context'
require 'comatose/page_wrapper'
require 'comatose/version'

require 'support/inline_rendering'
require 'support/route_mapper'

require 'dispatcher' unless defined?(::Dispatcher)
::Dispatcher.to_prepare :comatose do
Comatose.config.after_setup.call
Expand Down
2 changes: 1 addition & 1 deletion lib/comatose/comatose_drop.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Comatose

class ComatoseDrop < Liquid::Drop
class ComatoseDrop < ::Liquid::Drop

private :initialize

Expand Down
6 changes: 3 additions & 3 deletions lib/comatose/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def initialize

def validate!
# Rips through the config and validates it's, er, valid
raise ConfigurationError.new "admin_get_author must be a Proc or Symbol" unless @admin_get_author.is_a? Proc or @admin_get_author.is_a? Symbol
raise ConfigurationError.new "admin_authorization must be a Proc or Symbol" unless @admin_authorization.is_a? Proc or @admin_authorization.is_a? Symbol
raise ConfigurationError.new "authorization must be a Proc or Symbol" unless @authorization.is_a? Proc or @authorization.is_a? Symbol
raise ConfigurationError.new( "admin_get_author must be a Proc or Symbol" ) unless @admin_get_author.is_a? Proc or @admin_get_author.is_a? Symbol
raise ConfigurationError.new( "admin_authorization must be a Proc or Symbol" ) unless @admin_authorization.is_a? Proc or @admin_authorization.is_a? Symbol
raise ConfigurationError.new( "authorization must be a Proc or Symbol" ) unless @authorization.is_a? Proc or @authorization.is_a? Symbol
true
end

Expand Down
9 changes: 0 additions & 9 deletions rails/init.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Init for gem version of Comatose

require 'support/class_options'
require 'acts_as_versioned'
require 'redcloth' unless defined?(RedCloth)
require 'liquid' unless defined?(Liquid)

require 'comatose'
require 'text_filters'

require 'support/inline_rendering'
require 'support/route_mapper'

0 comments on commit a650d61

Please sign in to comment.