sheet 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,8 +36,13 @@ automatically open a url when opening your sheet:
36
36
  url: http://example/com
37
37
  ```
38
38
 
39
- Make sure that's you don't have trailing lines and sheet will
40
- automatically open that url for you
39
+ You can open mulitple urls at once by specifying each url in a new line.
40
+
41
+ ```yaml
42
+
43
+ url: https://github.com/oscardelben
44
+ url: http://example.com
45
+ ```
41
46
 
42
47
  Please note that to open urls, sheet will use the `open` command on mac
43
48
  os x and `xdg-open` in linux. Patches welcome for other systems.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.0
data/lib/sheet.rb CHANGED
@@ -9,7 +9,7 @@ require 'sheet/copy'
9
9
  class Sheet
10
10
 
11
11
  SHEETS_DIR = '~/.sheets/'.freeze
12
-
12
+
13
13
  class << self
14
14
  # Utility to write to standard output
15
15
  def write(message)
@@ -50,7 +50,11 @@ class Sheet
50
50
  # @return [String]
51
51
  # Used to check the preferred editor for the user
52
52
  def editor
53
- exec("echo $EDITOR").chomp
53
+ e = exec("echo $EDITOR").chomp
54
+ if e == ""
55
+ e = exec("echo $VISUAL").chomp
56
+ end
57
+ e
54
58
  end
55
59
 
56
60
  # If we're using mac, we should use open to open urls.
@@ -75,7 +79,12 @@ class Sheet
75
79
  # Utility to check wherever a command is available in the user
76
80
  # system
77
81
  def command_available?(cmd)
78
- %x!type #{cmd}!.chomp.length > 0
82
+ %x!type #{cmd}!.chomp.length > 0 rescue false
83
+ end
84
+
85
+ # Returns true if ~/.sheets exists
86
+ def sheets_directory_exists?
87
+ File.directory?(Sheet.sheets_dir)
79
88
  end
80
89
 
81
90
  end
data/lib/sheet/list.rb CHANGED
@@ -3,7 +3,11 @@ class Sheet
3
3
  class List
4
4
 
5
5
  def list
6
- Sheet.exec("ls #{Sheet.sheets_dir}", true)
6
+ if Sheet.sheets_directory_exists?
7
+ Sheet.exec("ls -1 #{Sheet.sheets_dir}", true)
8
+ else
9
+ Sheet.write("No sheet found. Create a new sheet with `sheet new <name>`")
10
+ end
7
11
  end
8
12
  end
9
13
  end
data/lib/sheet/open.rb CHANGED
@@ -19,26 +19,22 @@ class Sheet
19
19
  private
20
20
 
21
21
  def process_sheet_content
22
- if contains_url_format? && cmd = Sheet.open_command
23
- # TODO: check if open is available
24
- Sheet.exec "#{cmd} #{extract_url}"
22
+ if !sheet_urls.empty? && cmd = Sheet.open_command
23
+ sheet_urls.each do |url|
24
+ Sheet.exec "#{cmd} #{url.chomp.sub(/url: /,'')}"
25
+ end
25
26
  else
26
27
  Sheet.write sheet_content
27
28
  end
28
29
  end
29
30
 
30
- def contains_url_format?
31
- sheet_content.split("\n").size == 1 &&
32
- sheet_content =~ /^url:\s*http.+$/
33
- end
34
-
35
- def extract_url
36
- sheet_content.match(/(http.+)$/)[1]
37
- end
38
-
39
31
  def sheet_content
40
32
  @sheet_content ||= File.read(Sheet.sheet_path(name))
41
33
  end
42
34
 
35
+ def sheet_urls
36
+ @sheet_urls ||= sheet_content.split("\n").reject {|line| line !~ /^url:/ }
37
+ end
38
+
43
39
  end
44
40
  end
data/lib/sheet/write.rb CHANGED
@@ -3,11 +3,12 @@ class Sheet::Write
3
3
 
4
4
  attr_accessor :name
5
5
 
6
- def initialize(name)
6
+ def initialize(name=nil)
7
7
  @name = name
8
8
  end
9
9
 
10
10
  def write
11
+ return Sheet.write("Please specify a name") unless name
11
12
  create_dir_if_doesnt_exist
12
13
  if editor_is_set?
13
14
  Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}", true)
@@ -23,7 +24,7 @@ class Sheet::Write
23
24
  end
24
25
 
25
26
  def create_dir_if_doesnt_exist
26
- if ! File.directory?(Sheet.sheets_dir)
27
+ if ! Sheet.sheets_directory_exists?
27
28
  Dir.mkdir(Sheet.sheets_dir)
28
29
  end
29
30
  end
data/sheet.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sheet"
8
- s.version = "0.1.5"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oscar Del Ben"]
12
- s.date = "2012-04-18"
12
+ s.date = "2012-05-01"
13
13
  s.description = "sheets allows you to store and browse snippets of text from your command line."
14
14
  s.email = "info@oscardelben.com"
15
15
  s.executables = ["sheet"]
@@ -3,11 +3,28 @@ require 'spec_helper'
3
3
 
4
4
  describe Sheet::List do
5
5
 
6
- it 'calls system ls' do
7
- cmd = "ls #{Sheet.sheets_dir}"
8
- Sheet.should_receive(:exec).with(cmd, true)
6
+ context 'when sheets directory exists' do
7
+ before do
8
+ Sheet.stub(:sheets_directory_exists?) { true }
9
+ end
9
10
 
10
- Sheet::List.new.list
11
+ it 'calls system ls' do
12
+ cmd = "ls -1 #{Sheet.sheets_dir}"
13
+ Sheet.should_receive(:exec).with(cmd, true)
14
+
15
+ Sheet::List.new.list
16
+ end
11
17
  end
12
18
 
19
+ context 'when sheets directory doesn\'t exist' do
20
+ before do
21
+ Sheet.stub(:sheets_directory_exists?) { false }
22
+ end
23
+
24
+ it 'shows a message' do
25
+ Sheet.should_receive(:write).with("No sheet found. Create a new sheet with `sheet new <name>`")
26
+
27
+ Sheet::List.new.list
28
+ end
29
+ end
13
30
  end
@@ -17,18 +17,19 @@ describe Sheet::Open do
17
17
  Sheet.stub(:sheet_exists?).with('git') { true }
18
18
  s.stub(:sheet_content) { message }
19
19
  s.open
20
- end
21
-
22
- it "should open a url" do
20
+ end
21
+
22
+ it "should open all urls" do
23
23
  Sheet.stub(:open_command) { 'open' }
24
- message = "url: http://example.com"
24
+ message = "url: http://example.com\nurl: http://google.com"
25
25
  Sheet.should_receive(:exec).with('open http://example.com')
26
-
26
+ Sheet.should_receive(:exec).with('open http://google.com')
27
+
27
28
  s = Sheet::Open.new('git')
28
29
  Sheet.stub(:sheet_exists?).with('git') { true }
29
30
  s.stub(:sheet_content) { message }
30
31
  s.open
31
- end
32
+ end
32
33
 
33
34
  it "should fallback to showing the content if an open command is not present" do
34
35
  Sheet.stub(:open_command) { nil}
@@ -4,6 +4,15 @@ describe Sheet::Write do
4
4
 
5
5
  let (:editor) { 'vim' }
6
6
 
7
+ before do
8
+ Sheet.stub(:sheets_directory_exists?) { true }
9
+ end
10
+
11
+ it 'shows an error message if no argument is passed' do
12
+ Sheet.should_receive(:write).with('Please specify a name')
13
+ Sheet::Write.new.write
14
+ end
15
+
7
16
  it 'opens a new file for writing' do
8
17
  cmd = "#{editor} #{Sheet.sheet_path('tmux')}"
9
18
  Sheet.should_receive(:exec).with(cmd, true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  prerelease:
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-04-18 00:00:00.000000000 Z
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  segments:
123
123
  - 0
124
- hash: -175941379873315490
124
+ hash: 2528826102062921257
125
125
  required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  none: false
127
127
  requirements: