Skip to content

Commit

Permalink
switched to using launchy to launch browser to observe system defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Gauthier committed Apr 22, 2010
1 parent dfddaa2 commit 50b4b3c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Rakefile
Expand Up @@ -19,6 +19,7 @@ begin

# Testing
s.test_files = FileList["test/**/*_test.rb"]
s.add_dependency 'launchy', '~> 0.3.5'
s.add_development_dependency 'mocha', '~> 0.9.5'
end

Expand All @@ -32,4 +33,4 @@ Rake::TestTask.new do |t|
t.verbose = false
end

task :default => :test
task :default => :test
26 changes: 11 additions & 15 deletions lib/rubygems/commands/read_command.rb
@@ -1,3 +1,4 @@
require 'launchy'
# ReadCommand will open a gem's rdoc
class Gem::Commands::ReadCommand < Gem::Command
include OpenGem::CommonOptions
Expand Down Expand Up @@ -40,22 +41,17 @@ def generate_rdoc spec
Gem::DocManager.new(spec).generate_rdoc
end

def rdoc_reader
options[:command] || case RUBY_PLATFORM.downcase
when /darwin/ then 'open'
when /mswin/ then 'explorer'
when /linux/ then 'firefox'
else 'firefox' # Come on, if you write ruby, you probably have firefox installed ;)
end
end

def read_gem(path)
command_parts = Shellwords.shellwords(rdoc_reader)
command_parts << path
success = system(*command_parts)
if !success
raise Gem::CommandLineError, "Could not run '#{rdoc_reader} #{path}', exit code: #{$?.exitstatus}"
if options[:command]
command_parts = Shellwords.shellwords(options[:command])
command_parts << path
success = system(*command_parts)
if !success
raise Gem::CommandLineError, "Could not run '#{rdoc_reader} #{path}', exit code: #{$?.exitstatus}"
end
else
Launchy::Browser.run("file://"+path)
end
end

end
end
12 changes: 8 additions & 4 deletions open_gem.gemspec
@@ -1,6 +1,6 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
Expand All @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Adam Sanderson"]
s.date = %q{2009-10-09}
s.date = %q{2010-04-22}
s.description = %q{ Open a gem's source directory with either the default editor, or a specified command.
}
s.email = %q{netghost@gmail.com}
Expand All @@ -31,7 +31,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{opengem}
s.rubygems_version = %q{1.3.5}
s.rubygems_version = %q{1.3.6}
s.summary = %q{Gem Command to easily open a ruby gem with the editor of your choice.}
s.test_files = [
"test/open_command_test.rb"
Expand All @@ -42,11 +42,15 @@ Gem::Specification.new do |s|
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<launchy>, ["~> 0.3.5"])
s.add_development_dependency(%q<mocha>, ["~> 0.9.5"])
else
s.add_dependency(%q<launchy>, ["~> 0.3.5"])
s.add_dependency(%q<mocha>, ["~> 0.9.5"])
end
else
s.add_dependency(%q<launchy>, ["~> 0.3.5"])
s.add_dependency(%q<mocha>, ["~> 0.9.5"])
end
end

0 comments on commit 50b4b3c

Please sign in to comment.