jello 1
Sign up to get free protection for your applications and to get access to all the features.
- data/.manifest +8 -0
- data/Jello.gemspec +79 -0
- data/README.mkdn +49 -0
- data/Rakefile +91 -0
- data/examples/grabup_fixer.rb +12 -0
- data/examples/say.rb +6 -0
- data/examples/shorten.rb +22 -0
- data/lib/jello.rb +45 -0
- data/lib/jello/pasteboard.rb +12 -0
- metadata +78 -0
data/.manifest
ADDED
data/Jello.gemspec
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
|
2
|
+
# Gem::Specification for Jello-1
|
3
|
+
# Originally generated by Echoe
|
4
|
+
|
5
|
+
--- !ruby/object:Gem::Specification
|
6
|
+
name: jello
|
7
|
+
version: !ruby/object:Gem::Version
|
8
|
+
version: "1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- elliottcable
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
|
15
|
+
date: 2008-08-14 00:00:00 -08:00
|
16
|
+
default_executable:
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: echoe
|
20
|
+
type: :development
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: "0"
|
27
|
+
version:
|
28
|
+
description: A library to watch the OS X pasteboard, and process/modify incoming pastes.
|
29
|
+
email:
|
30
|
+
- Jello@elliottcable.com
|
31
|
+
executables: []
|
32
|
+
|
33
|
+
extensions: []
|
34
|
+
|
35
|
+
extra_rdoc_files:
|
36
|
+
- lib/jello/pasteboard.rb
|
37
|
+
- lib/jello.rb
|
38
|
+
- README.mkdn
|
39
|
+
files:
|
40
|
+
- examples/grabup_fixer.rb
|
41
|
+
- examples/say.rb
|
42
|
+
- examples/shorten.rb
|
43
|
+
- lib/jello/pasteboard.rb
|
44
|
+
- lib/jello.rb
|
45
|
+
- Rakefile
|
46
|
+
- README.mkdn
|
47
|
+
- .manifest
|
48
|
+
- Jello.gemspec
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/elliottcable/jello
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --line-numbers
|
54
|
+
- --inline-source
|
55
|
+
- --title
|
56
|
+
- Jello
|
57
|
+
- --main
|
58
|
+
- README.mkdn
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "1.2"
|
72
|
+
version:
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project: jello
|
76
|
+
rubygems_version: 1.2.0
|
77
|
+
specification_version: 2
|
78
|
+
summary: A library to watch the OS X pasteboard, and process/modify incoming pastes.
|
79
|
+
test_files: []
|
data/README.mkdn
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Jello
|
2
|
+
=====
|
3
|
+
|
4
|
+
Because everybody likes "paste & jello" sandwiches, right? I know I did when I
|
5
|
+
was a kid.
|
6
|
+
|
7
|
+
Jello is a simple library to watch the OS X pasteboard and do something on
|
8
|
+
every paste.
|
9
|
+
|
10
|
+
require 'jello'
|
11
|
+
|
12
|
+
Jello.new do |paste|
|
13
|
+
system "say 'You pasted #{paste}'"
|
14
|
+
end
|
15
|
+
|
16
|
+
For example, to watch for URLs copied, and then shorten the URL and replace
|
17
|
+
the long URL with the shortened one:
|
18
|
+
|
19
|
+
require 'open-uri'
|
20
|
+
require 'jello'
|
21
|
+
|
22
|
+
Jello.new :verbose => true do |paste, board|
|
23
|
+
|
24
|
+
case paste
|
25
|
+
|
26
|
+
when %r%^http://.*%
|
27
|
+
uri = $&
|
28
|
+
uri.gsub! /#/, '%23'
|
29
|
+
next if uri =~ %r%^http://bit.ly%
|
30
|
+
|
31
|
+
shortener = 'http://bit.ly/api?url=' + uri
|
32
|
+
|
33
|
+
short = open(shortener).gets.chomp
|
34
|
+
board.puts short
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end.start
|
39
|
+
|
40
|
+
|
41
|
+
A few things to note:
|
42
|
+
|
43
|
+
- In the block context, `#puts` and `#gets` are commandeered for the
|
44
|
+
pasteboard object — use `STDOUT.puts` and `STDIN.gets` respectively if you
|
45
|
+
need terminal interaction in the block context to be safe.
|
46
|
+
|
47
|
+
- Creating a Jello block doesn't actually do anything by itself - you need to
|
48
|
+
act on the paste itself. Test against contents and conditionally run code,
|
49
|
+
whatever you want.
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
($:.unshift File.expand_path(File.join( File.dirname(__FILE__), 'lib' ))).uniq!
|
2
|
+
require 'jello'
|
3
|
+
require 'extlib/string'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
require 'spec/rake/verify_rcov'
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'echoe'
|
11
|
+
|
12
|
+
namespace :echoe do
|
13
|
+
Echoe.new('Jello', Jello::Version) do |g|
|
14
|
+
g.name = 'jello'
|
15
|
+
g.author = ['elliottcable']
|
16
|
+
g.email = ['Jello@elliottcable.com']
|
17
|
+
g.summary = 'A library to watch the OS X pasteboard, and process/modify incoming pastes.'
|
18
|
+
g.url = 'http://github.com/elliottcable/jello'
|
19
|
+
g.dependencies = []
|
20
|
+
g.manifest_name = '.manifest'
|
21
|
+
g.ignore_pattern = ['.git', 'meta', 'jello.gemspec']
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'tests packaged files to ensure they are all present'
|
25
|
+
task :verify => :package do
|
26
|
+
# An error message will be displayed if files are missing
|
27
|
+
if system %(ruby -e "require 'rubygems'; require 'pkg/jello-#{Jello::VERSION}/lib/jello'")
|
28
|
+
puts "\nThe library files are present"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
task :copy_gemspec => [:package] do
|
33
|
+
pkg = Dir['pkg/*'].select {|dir| File.directory? dir}.last
|
34
|
+
mv File.join(pkg, pkg.gsub(/^pkg\//,'').gsub(/\-\d+$/,'.gemspec')), './'
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'builds a gemspec as GitHub wants it'
|
38
|
+
task :gemspec => [:package, :copy_gemspec, :clobber_package]
|
39
|
+
|
40
|
+
# desc 'Run specs, clean tree, update manifest, run coverage, and install gem!'
|
41
|
+
desc 'Clean tree, update manifest, and install gem!'
|
42
|
+
task :magic => [:clean, :manifest, :copy_gemspec, :install]
|
43
|
+
end
|
44
|
+
|
45
|
+
# desc 'Echoe won't let you run tasks until you generate manifest, and it won't let you run any task that isn't named "manifest". Fail, but, w/e # Invisible
|
46
|
+
task :manifest => [:'echoe:manifest']
|
47
|
+
|
48
|
+
rescue LoadError; ensure
|
49
|
+
task :default # No effect # Invisible
|
50
|
+
|
51
|
+
# Runs specs, generates rcov, and opens rcov in your browser.
|
52
|
+
namespace :rcov do
|
53
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
54
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
55
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
56
|
+
t.libs = ['lib']
|
57
|
+
t.rcov = true
|
58
|
+
t.rcov_dir = 'meta' / 'coverage'
|
59
|
+
end
|
60
|
+
|
61
|
+
Spec::Rake::SpecTask.new(:plain) do |t|
|
62
|
+
t.spec_opts = ["--format", "specdoc"]
|
63
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
64
|
+
t.libs = ['lib']
|
65
|
+
t.rcov = true
|
66
|
+
t.rcov_opts = ['--exclude-only', '".*"', '--include-file', '^lib']
|
67
|
+
t.rcov_dir = 'meta' / 'coverage'
|
68
|
+
end
|
69
|
+
|
70
|
+
RCov::VerifyTask.new(:verify) do |t|
|
71
|
+
t.threshold = 100
|
72
|
+
t.index_html = 'meta' / 'coverage' / 'index.html'
|
73
|
+
end
|
74
|
+
|
75
|
+
task :open do
|
76
|
+
system 'open ' + 'meta' / 'coverage' / 'index.html' if PLATFORM['darwin']
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
namespace :git do
|
81
|
+
task :status do
|
82
|
+
`git status`
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
desc 'Check everything over before commiting'
|
87
|
+
task :aok => [:'echoe:manifest', :'rcov:run', :'rcov:verify', :'rcov:ratio', :'rcov:open', :'git:status']
|
88
|
+
|
89
|
+
# desc 'Task run during continuous integration' # Invisible
|
90
|
+
task :cruise => [:'rcov:plain', :'rcov:verify', :'rcov:ratio']
|
91
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq!
|
4
|
+
require 'jello'
|
5
|
+
|
6
|
+
Jello.new :verbose => ARGV.include?('-v') do |paste, board|
|
7
|
+
next unless paste =~ %r{^http://www\.grabup\.com/uploads/[0-9a-z]{32}\.png$}
|
8
|
+
|
9
|
+
url = paste.gsub /#/, '%23'
|
10
|
+
shortened_url = open("http://bit.ly/api?url=#{url}%3Fdirect").gets.chomp
|
11
|
+
board.puts shortened_url
|
12
|
+
end.start
|
data/examples/say.rb
ADDED
data/examples/shorten.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq!
|
4
|
+
require 'jello'
|
5
|
+
|
6
|
+
Jello.new :verbose => true do |paste, board|
|
7
|
+
|
8
|
+
case paste
|
9
|
+
|
10
|
+
when %r%^http://.*%
|
11
|
+
uri = $&
|
12
|
+
uri.gsub! /#/, '%23'
|
13
|
+
next if uri =~ %r%^http://bit.ly%
|
14
|
+
|
15
|
+
shortener = 'http://bit.ly/api?url=' + uri
|
16
|
+
|
17
|
+
short = open(shortener).gets.chomp
|
18
|
+
board.puts short
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end.start
|
data/lib/jello.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'jello/pasteboard'
|
2
|
+
|
3
|
+
class Jello < Pasteboard
|
4
|
+
Version = 1
|
5
|
+
|
6
|
+
def initialize opts = {}, &block
|
7
|
+
@opts = {:verbose => false, :period => 0.2}.merge(opts)
|
8
|
+
@on_paste = block
|
9
|
+
@last_pasted = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_paste &block
|
13
|
+
raise LocalJumpError, "no block given" unless block_given?
|
14
|
+
@on_paste = block
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
STDOUT.puts 'Watching pasteboard' if @opts[:verbose]
|
19
|
+
begin
|
20
|
+
while true
|
21
|
+
|
22
|
+
if (paste = self.gets) != @last_pasted
|
23
|
+
STDOUT.puts "Processing [#{paste}]" if @opts[:verbose]
|
24
|
+
|
25
|
+
if @on_paste.arity == 1
|
26
|
+
@on_paste[paste]
|
27
|
+
else
|
28
|
+
@on_paste[paste, self]
|
29
|
+
end
|
30
|
+
|
31
|
+
@last_pasted = paste
|
32
|
+
end
|
33
|
+
|
34
|
+
sleep @opts[:period]
|
35
|
+
end
|
36
|
+
rescue Interrupt
|
37
|
+
STDOUT.puts "\nClosing pasteboard watcher..." if @opts[:verbose]
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def stop
|
43
|
+
raise Interrupt # …
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jello
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- elliottcable
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-14 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: echoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: A library to watch the OS X pasteboard, and process/modify incoming pastes.
|
26
|
+
email:
|
27
|
+
- Jello@elliottcable.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- lib/jello/pasteboard.rb
|
34
|
+
- lib/jello.rb
|
35
|
+
- README.mkdn
|
36
|
+
files:
|
37
|
+
- examples/grabup_fixer.rb
|
38
|
+
- examples/say.rb
|
39
|
+
- examples/shorten.rb
|
40
|
+
- lib/jello/pasteboard.rb
|
41
|
+
- lib/jello.rb
|
42
|
+
- Rakefile
|
43
|
+
- README.mkdn
|
44
|
+
- .manifest
|
45
|
+
- Jello.gemspec
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/elliottcable/jello
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --line-numbers
|
51
|
+
- --inline-source
|
52
|
+
- --title
|
53
|
+
- Jello
|
54
|
+
- --main
|
55
|
+
- README.mkdn
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "1.2"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project: jello
|
73
|
+
rubygems_version: 1.2.0
|
74
|
+
signing_key:
|
75
|
+
specification_version: 2
|
76
|
+
summary: A library to watch the OS X pasteboard, and process/modify incoming pastes.
|
77
|
+
test_files: []
|
78
|
+
|