Skip to content
Browse files

modified open so that multiple urls can be opened at once

  • Loading branch information...
1 parent 6a5625f commit 23114009cb690504ff7ba7cb58137716401496bb @salemine salemine committed Apr 30, 2012
Showing with 16 additions and 18 deletions.
  1. +9 −12 lib/sheet/open.rb
  2. +7 −6 spec/sheet/open_spec.rb
View
21 lib/sheet/open.rb
@@ -19,26 +19,23 @@ def open
private
def process_sheet_content
- if contains_url_format? && cmd = Sheet.open_command
+ if !sheet_urls.empty? && cmd = Sheet.open_command
# TODO: check if open is available
- Sheet.exec "#{cmd} #{extract_url}"
+ sheet_urls.each do |url|
+ Sheet.exec "#{cmd} #{url.chomp.gsub(/url: /,'')}"
+ end
else
Sheet.write sheet_content
end
end
- def contains_url_format?
- sheet_content.split("\n").size == 1 &&
- sheet_content =~ /^url:\s*http.+$/
- end
-
- def extract_url
- sheet_content.match(/(http.+)$/)[1]
- end
-
def sheet_content
@sheet_content ||= File.read(Sheet.sheet_path(name))
end
-
+
+ def sheet_urls
+ @sheet_urls ||= sheet_content.split("\n").reject {|line| line !~ /^url:/ }
+ end
+
end
end
View
13 spec/sheet/open_spec.rb
@@ -17,18 +17,19 @@
Sheet.stub(:sheet_exists?).with('git') { true }
s.stub(:sheet_content) { message }
s.open
- end
-
- it "should open a url" do
+ end
+
+ it "should open all urls" do
Sheet.stub(:open_command) { 'open' }
- message = "url: http://example.com"
+ message = "url: http://example.com\nurl: http://google.com"
Sheet.should_receive(:exec).with('open http://example.com')
-
+ Sheet.should_receive(:exec).with('open http://google.com')
+
s = Sheet::Open.new('git')
Sheet.stub(:sheet_exists?).with('git') { true }
s.stub(:sheet_content) { message }
s.open
- end
+ end
it "should fallback to showing the content if an open command is not present" do
Sheet.stub(:open_command) { nil}

0 comments on commit 2311400

Please sign in to comment.
Something went wrong with that request. Please try again.