lib/radiant/extension/script.rb in radiant-0.6.9 vs lib/radiant/extension/script.rb in radiant-0.7.0

- old
+ new

@@ -11,10 +11,22 @@ end def uninstall Uninstaller.new(self).uninstall end + + def inspect +%{ +Name: #{name} +Description: + #{description} +Author: #{author.first_name} #{author.last_name} <#{author.email}> +Source code: #{repository_url} +Download: #{download_url} +Install type: #{install_type} +}.strip + end end class Action def rake(command) `rake #{command} RAILS_ENV=#{RAILS_ENV}` @@ -111,13 +123,31 @@ File.open(File.join(Dir.tmpdir, self.filename), 'w') {|f| f.write open(self.url).read } end end class Git < Checkout + def project_in_git? + @in_git ||= File.directory?(".git") + end + def checkout_command "git clone #{url} #{name}" end + + def checkout + if project_in_git? + system "git submodule add #{url} vendor/extensions/#{name}" + system "cd vendor/extensions/#{name}; git submodule init && git submodule update" + else + super + system "cd #{path}; git submodule init && git submodule update" + end + end + + def copy_to_vendor_extensions + super unless project_in_git? + end end class Subversion < Checkout def checkout_command "svn checkout #{url} #{name}" @@ -143,34 +173,34 @@ class Tarball < Download def filename "#{self.name}.tar" end - + def unpack output = `cd #{Dir.tmpdir}; tar xvf #{filename}` self.path = File.join(Dir.tmpdir, output.split(/\n/).first.split('/').first) end end - + class Gzip < Tarball def filename @unpacked ? super : "#{self.name}.tar.gz" end - + def unpack system "cd #{Dir.tmpdir}; gunzip #{self.filename}" @unpacked = true super end end - + class Bzip2 < Tarball def filename @unpacked ? super : "#{self.name}.tar.bz2" end - + def unpack system "cd #{Dir.tmpdir}; bunzip2 #{self.filename}" @unpacked = true super end @@ -187,12 +217,17 @@ module Radiant class Extension module Script class << self def execute(args) - command = args.shift - const_get(command.camelize).new(args) + command = args.shift || 'help' + begin + const_get(command.camelize).new(args) + rescue ArgumentError => e + puts e.message + Help.new [command] + end end end module Util attr_accessor :extension_name, :extension @@ -243,9 +278,70 @@ find_extension && extension.uninstall else puts "#{extension} is not installed." end end + end + + class Info + include Util + + def initialize(args=[]) + raise ArgumentError, "You must specify an extension to get info on" if args.blank? + self.extension_name = to_extension_name(args.shift) + find_extension and puts extension.inspect + end + end + + class Help + def initialize(args=[]) + command = args.shift + command = 'help' unless self.class.instance_methods(false).include?(command) + send(command) + end + + def help + $stdout.puts %{Usage: script/extension command [arguments] + + Available commands: + #{command_names} + + For help on an individual command: + script/extension help command + + You may install extensions from another registry by setting the REGISTRY_URL + By default the REGISTRY_URL is set to http://ext.radiantcms.org + + Code for the registry application may be found at: + http://github.com/radiant/radiant-extension-registry/ + } + end + + def install + $stdout.puts %{Usage: script/extension install extension_name + + Installs an extension from information in the global registry. + } + end + + def uninstall + $stdout.puts %{Usage: script/extension uninstall extension_name + + Removes a previously installed extension from the current project. + } + end + + def info + $stdout.puts %{Usage: script/extension info extension_name + + Displays registry information about the extension. + } + end + + private + def command_names + (Radiant::Extension::Script.constants - ['Util']).sort.map {|n| n.underscore }.join(", ") + end end end end end