splat 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2010 Mark Ryall
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2010 Mark Ryall
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -1,31 +1,72 @@
1
- = splat
2
-
3
- small gem to provide an adapter for various platform specific features
4
-
5
- == installation
6
-
7
- gem install splat
8
-
9
- == instantiate
10
-
11
- splat = Splat.new
12
-
13
- == platform
14
-
15
- puts spat.platform
16
- puts splat.supported? ? 'supported' : 'not supported'
17
-
18
- == clipboard
19
-
20
- splat.clipboard = "some new content"
21
-
22
- this will do nothing if the platform is not supported (win32 and macosx for the moment)
23
-
24
- == launcher
25
-
26
- splat.launch 'http://google.com'
27
-
28
- == Future plans for world domination
29
-
30
- * detect remaining platforms
31
- * determine 1.9 compatibility
1
+ = splat
2
+
3
+ small gem to provide an adapter for various platform specific features.
4
+
5
+ This is done by adding the following methods to String:
6
+
7
+ * to_editor
8
+ * to_browser
9
+ * to_clipboard
10
+ * to_speech
11
+ * to_launcher
12
+ * to_player
13
+ * to_os_path
14
+
15
+ == installation
16
+
17
+ gem install splat
18
+
19
+ == load
20
+
21
+ require 'splat'
22
+
23
+ == launch editor
24
+
25
+ 'current content'.to_editor
26
+
27
+
28
+
29
+ == browser automation
30
+
31
+ 'http://www.google.com'.to_browser
32
+
33
+ Returns a watir compatible browser - uses safariwatir on mac os x and watir (ie) on windows.
34
+
35
+ == clipboard
36
+
37
+ 'some new content'.to_clipboard
38
+
39
+ Copies the string to the os clipboard
40
+
41
+ == default application launcher
42
+
43
+ 'http://google.com'.to_launcher
44
+ 'textfile.txt'.to_launcher
45
+ 'audiofile.mp3'.to_launcher
46
+
47
+ Launches the referenced content with the default system application
48
+
49
+ == audio player
50
+
51
+ 'audio.mp3'.to_player
52
+
53
+ Uses 'afplay' on mac os x and requires mpg123 on windows.
54
+
55
+ == text to speech
56
+
57
+ "I'm afraid. I'm afraid, Dave. Dave, my mind is going.".to_speech
58
+
59
+ Uses 'say' on mac os x and win32 sapi on windows
60
+
61
+ == path cleaning
62
+
63
+ 'c:/a/path/that/might/upset/some/windows.application'.to_os_path
64
+
65
+ This will simply replace '/' characters with '\' on windows and otherwise leave the path as is.
66
+
67
+ Note that this is only necessary for passing a path to native windows applications
68
+
69
+ == Future plans for world domination
70
+
71
+ * detect remaining platforms
72
+ * determine 1.9 compatibility
data/lib/splat.rb CHANGED
@@ -1,76 +1,66 @@
1
- class Splat
2
- attr_reader :platform
1
+ require 'tempfile'
3
2
 
4
- def try_load feature, params
5
- begin
6
- params.each {|gem, req| require req }
7
- yield
8
- rescue Exception
9
- puts "for #{feature} support with splat on #{@platform}:"
10
- params.each {|gem, req| puts " * gem install #{gem}" }
11
- end
12
- end
13
-
14
- def initialize
15
- @path_cleaner = Object.new
16
- def @path_cleaner.clean path
17
- path
18
- end
19
- case Config::CONFIG['host_os']
20
- when /mswin|win32|dos|cygwin|mingw/i
21
- @platform = :win32
22
- try_load 'clipboard', 'win32-clipboard' => 'win32/clipboard' do
23
- require 'splat/win32_clipboard'
24
- @clipboard = Splat::Win32Clipboard.new
25
- end
26
- require 'splat/win32_launcher'
27
- @launcher = Splat::Win32Launcher.new
28
- require 'splat/win32_player'
29
- @player = Splat::Win32Player.new
30
- try_load 'browser automation', 'watir' => 'watir' do
31
- @browser_class = Watir::IE
32
- end
33
- def @path_cleaner.clean path
34
- path.to_s.gsub('/','\\')
35
- end
36
- when /darwin/i
37
- @platform = :macosx
38
- require 'splat/darwin_clipboard'
39
- @clipboard = Splat::DarwinClipboard.new
40
- require 'splat/darwin_launcher'
41
- @launcher = Splat::DarwinLauncher.new
42
- require 'splat/darwin_player'
43
- @player = Splat::DarwinPlayer.new
44
- try_load 'browser automation', 'rb-appscript' => 'appscript', 'safariwatir' => 'safariwatir' do
45
- @browser_class = Watir::Safari
46
- end
47
- else
48
- @platform = :unknown
49
- puts "I have no idea how to cope with \"#{Config::CONFIG['host_os']}\""
50
- end
3
+ class String
4
+ def splat_unsupported
5
+ $stderr.puts 'platform not supported'
51
6
  end
52
7
 
53
- def supported?
54
- @platform != :unknown
55
- end
8
+ alias :to_browser :splat_unsupported
9
+ alias :to_clipboard :splat_unsupported
10
+ alias :to_speech :splat_unsupported
11
+ alias :to_launcher :splat_unsupported
12
+ alias :to_player :splat_unsupported
13
+ alias :to_os_path :to_s
56
14
 
57
- def clipboard= content
58
- @clipboard.content = content if @clipboard
59
- end
60
-
61
- def browser
62
- @browser_class.new if @browser_class
15
+ def to_editor
16
+ tmp_file = Tempfile.new('splat')
17
+ tmp_file.close
18
+ begin
19
+ File.open(tmp_file.path, 'w') { |out| out.print self }
20
+ editor = ENV["EDITOR"] || "notepad"
21
+ system("#{editor} #{tmp_file.path}")
22
+ return unless $?.to_i == 0
23
+ File.read(tmp_file.path)
24
+ ensure
25
+ tmp_file.unlink
26
+ end
63
27
  end
28
+ end
64
29
 
65
- def launch content
66
- @launcher.launch content if @launcher
30
+ module Splat
31
+ def self.platform
32
+ @platform
67
33
  end
68
34
 
69
- def play path
70
- @player.play path if @player
35
+ def self.try_load feature, dependencies={}
36
+ begin
37
+ dependencies.each {|gem_name, require_parameter| require require_parameter }
38
+ require "splat/#{@platform}_#{feature}"
39
+ rescue Exception => e
40
+ $stderr.puts e
41
+ $stderr.puts "for #{feature} support with splat on #{@platform}:"
42
+ dependencies.each {|gem_name, require_parameter| $stderr.puts " * gem install #{gem_name}" }
43
+ end
71
44
  end
72
45
 
73
- def clean_path path
74
- @path_cleaner.clean path
46
+ case Config::CONFIG['host_os']
47
+ when /mswin|win32|dos|cygwin|mingw/i
48
+ @platform = :win32
49
+ try_load 'tts', 'win32-sapi' => 'win32/sapi5'
50
+ try_load 'clipboard', 'win32-clipboard' => 'win32/clipboard'
51
+ try_load 'launcher'
52
+ try_load 'player'
53
+ try_load 'browser', 'watir' => 'watir'
54
+ try_load 'os_path'
55
+ when /darwin/i
56
+ @platform = :darwin
57
+ try_load 'tts'
58
+ try_load 'clipboard'
59
+ try_load 'launcher'
60
+ try_load 'player'
61
+ try_load 'browser', 'rb-appscript' => 'appscript', 'safariwatir' => 'safariwatir'
62
+ else
63
+ @platform = :unknown
64
+ puts "I have no idea how to cope with \"#{Config::CONFIG['host_os']}\""
75
65
  end
76
- end
66
+ end
@@ -0,0 +1,7 @@
1
+ class String
2
+ def to_browser
3
+ @browser = Watir::Safari.new
4
+ @browser.goto self
5
+ @browser
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
- class Splat::DarwinClipboard
2
- def content= text
3
- `echo "#{text}" | pbcopy`
4
- end
5
- end
1
+ class String
2
+ def to_clipboard
3
+ IO.popen('pbcopy','w') { |clipboard| clipboard.print self }
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
- class Splat::DarwinLauncher
2
- def launch text
3
- `open #{text}`
4
- end
5
- end
1
+ class String
2
+ def to_launcher
3
+ `open #{self}`
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
- class Splat::DarwinPlayer
2
- def play path
3
- `afplay #{path}`
1
+ class String
2
+ def to_player
3
+ `afplay #{self}`
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def to_speech
3
+ `say "#{self}"`
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class String
2
+ def to_browser
3
+ @browser = Watir::IE.new
4
+ @browser.goto self
5
+ @browser
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
- class Splat::Win32Clipboard
2
- def content= text
3
- Win32::Clipboard.set_data(text)
4
- end
5
- end
1
+ class String
2
+ def to_clipboard
3
+ Win32::Clipboard.set_data(self)
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
- class Splat::Win32Launcher
2
- def launch text
3
- `start #{text}`
4
- end
5
- end
1
+ class String
2
+ def to_launcher
3
+ `start #{self}`
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def to_os_path
3
+ self.gsub('/','\\')
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
- class Splat::Win32Player
2
- def play path
3
- `mpg123 -q #{path}`
1
+ class String
2
+ def to_player
3
+ `mpg123 -q #{self}`
4
4
  end
5
- end
5
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def to_speech
3
+ Win32::SpVoice.new.Speak(self)
4
+ end
5
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 9
9
- version: 0.0.9
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Ryall
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-07 00:00:00 +11:00
17
+ date: 2010-04-11 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -22,7 +22,9 @@ description: |
22
22
  An adapter to get access to the following features across different platforms:
23
23
 
24
24
  * the clipboard
25
- * an application launcher
25
+ * a default application launcher
26
+ * a media player
27
+ * text to speech
26
28
 
27
29
  email: mark@ryall.name
28
30
  executables: []
@@ -32,12 +34,17 @@ extensions: []
32
34
  extra_rdoc_files: []
33
35
 
34
36
  files:
37
+ - lib/splat/darwin_browser.rb
35
38
  - lib/splat/darwin_clipboard.rb
36
39
  - lib/splat/darwin_launcher.rb
37
40
  - lib/splat/darwin_player.rb
41
+ - lib/splat/darwin_tts.rb
42
+ - lib/splat/win32_browser.rb
38
43
  - lib/splat/win32_clipboard.rb
39
44
  - lib/splat/win32_launcher.rb
45
+ - lib/splat/win32_os_path.rb
40
46
  - lib/splat/win32_player.rb
47
+ - lib/splat/win32_tts.rb
41
48
  - lib/splat.rb
42
49
  - README.rdoc
43
50
  - MIT-LICENSE