jello 1 → 2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.manifest +10 -5
- data/README.markdown +73 -0
- data/Rakefile.rb +138 -0
- data/bin/jello +18 -0
- data/jello.gemspec +128 -0
- data/lib/jello.rb +22 -30
- data/lib/jello/core_ext/kernel.rb +24 -0
- data/lib/jello/logger.rb +5 -0
- data/lib/jello/mould.rb +77 -0
- data/lib/jello/pasteboard.rb +108 -10
- data/moulds/grabup.rb +8 -0
- data/moulds/say.rb +3 -0
- data/moulds/shorten.rb +19 -0
- data/{examples/say.rb → spec/jello_spec.rb} +1 -5
- metadata +63 -14
- data/Jello.gemspec +0 -79
- data/README.mkdn +0 -49
- data/Rakefile +0 -91
- data/examples/grabup_fixer.rb +0 -12
- data/examples/shorten.rb +0 -22
data/.manifest
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
bin/jello
|
2
|
+
lib/jello/core_ext/kernel.rb
|
3
|
+
lib/jello/logger.rb
|
4
|
+
lib/jello/mould.rb
|
4
5
|
lib/jello/pasteboard.rb
|
5
6
|
lib/jello.rb
|
6
|
-
|
7
|
-
|
7
|
+
moulds/grabup.rb
|
8
|
+
moulds/say.rb
|
9
|
+
moulds/shorten.rb
|
10
|
+
Rakefile.rb
|
11
|
+
README.markdown
|
12
|
+
spec/jello_spec.rb
|
8
13
|
.manifest
|
data/README.markdown
ADDED
@@ -0,0 +1,73 @@
|
|
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::Mould.new do |paste|
|
13
|
+
system "say 'You pasted #{paste}'"
|
14
|
+
end
|
15
|
+
|
16
|
+
Jello.start!
|
17
|
+
|
18
|
+
For example, to watch for URLs copied, and then shorten the URL and replace
|
19
|
+
the long URL with the shortened one, write a short mould like the following:
|
20
|
+
|
21
|
+
require 'open-uri'
|
22
|
+
require 'jello'
|
23
|
+
|
24
|
+
Jello::Mould.new do |paste|
|
25
|
+
|
26
|
+
if paste =~ %r{}^http://.*}
|
27
|
+
uri = $&
|
28
|
+
uri.gsub! /#/, '%23'
|
29
|
+
unless uri =~ %r{^http://bit.ly}
|
30
|
+
shortener = 'http://bit.ly/api?url=' + uri
|
31
|
+
open(shortener).gets.chomp
|
32
|
+
else
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
Jello.start! :verbose => true
|
40
|
+
|
41
|
+
Moulds can even be stacked:
|
42
|
+
|
43
|
+
require 'jello'
|
44
|
+
|
45
|
+
Jello::Mould.new do |paste|
|
46
|
+
paste += '123'
|
47
|
+
end
|
48
|
+
|
49
|
+
Jello::Mould.new do |paste|
|
50
|
+
paste += '456'
|
51
|
+
end
|
52
|
+
|
53
|
+
Jello.start! :verbose => true
|
54
|
+
|
55
|
+
Jello also provides a binary - if you have some moulds you use often, you can
|
56
|
+
throw them in your `~/.jello/` folder (as .rb files), and then run jello with
|
57
|
+
them:
|
58
|
+
|
59
|
+
# Assuming ~/.jello/ contains foo.rb, bar.rb, and gaz/{one,two}.rb
|
60
|
+
$ jello foo bar gaz
|
61
|
+
# Now foo.rb, bar.rb, one.rb, and two.rb would be executed on incoming
|
62
|
+
# pastes
|
63
|
+
|
64
|
+
Finally, you can use pasteboards other than the general one (see `man pbcopy`
|
65
|
+
for more information about this):
|
66
|
+
|
67
|
+
require 'jello'
|
68
|
+
|
69
|
+
Jello::Mould.new do Jello::Pasteboard::Find |paste|
|
70
|
+
paste.gsub! /abc/, 'def'
|
71
|
+
end
|
72
|
+
|
73
|
+
Jello.start!
|
data/Rakefile.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
($:.unshift File.expand_path(File.join( File.dirname(__FILE__), 'lib' ))).uniq!
|
2
|
+
require 'jello'
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
# =======================
|
7
|
+
# = Gem packaging tasks =
|
8
|
+
# =======================
|
9
|
+
begin
|
10
|
+
require 'echoe'
|
11
|
+
|
12
|
+
task :package => :'package:install'
|
13
|
+
task :manifest => :'package:manifest'
|
14
|
+
namespace :package do
|
15
|
+
Echoe.new('jello', Jello::Version) do |g|
|
16
|
+
g.project = 'jello'
|
17
|
+
g.author = ['elliottcable']
|
18
|
+
g.email = ['Jello@elliottcable.com']
|
19
|
+
g.summary = 'A library to watch the OS X pasteboard, and process/modify incoming pastes.'
|
20
|
+
g.url = 'http://github.com/elliottcable/jello'
|
21
|
+
g.development_dependencies = ['echoe >=3.0.1', 'rspec', 'rcov', 'yard', 'stringray']
|
22
|
+
g.manifest_name = '.manifest'
|
23
|
+
g.ignore_pattern = /^\.git\/|^meta\/|\.gemspec/
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'tests packaged files to ensure they are all present'
|
27
|
+
task :verify => :package do
|
28
|
+
# An error message will be displayed if files are missing
|
29
|
+
if system %(ruby -e "require 'rubygems'; require 'pkg/jello-#{Jello::Version}/lib/jello'")
|
30
|
+
puts "\nThe library files are present"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
task :copy_gemspec => [:package] do
|
35
|
+
pkg = Dir['pkg/*'].select {|dir| File.directory? dir}.last
|
36
|
+
mv File.join(pkg, pkg.gsub(/^pkg\//,'').gsub(/\-\d+$/,'.gemspec')), './'
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'builds a gemspec as GitHub wants it'
|
40
|
+
task :gemspec => [:package, :copy_gemspec, :clobber_package]
|
41
|
+
end
|
42
|
+
|
43
|
+
rescue LoadError
|
44
|
+
desc 'You need the `echoe` gem to package Jello'
|
45
|
+
task :package
|
46
|
+
end
|
47
|
+
|
48
|
+
# =======================
|
49
|
+
# = Spec/Coverage tasks =
|
50
|
+
# =======================
|
51
|
+
begin
|
52
|
+
require 'spec'
|
53
|
+
require 'rcov'
|
54
|
+
require 'spec/rake/spectask'
|
55
|
+
|
56
|
+
task :default => :'coverage:run'
|
57
|
+
task :coverage => :'coverage:run'
|
58
|
+
namespace :coverage do
|
59
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
60
|
+
t.spec_opts = ["--format", "specdoc"]
|
61
|
+
t.spec_opts << "--colour" unless ENV['CI']
|
62
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
63
|
+
t.libs = ['lib']
|
64
|
+
t.rcov = true
|
65
|
+
t.rcov_opts = [ '--include-file', '"^lib"', '--exclude-only', '".*"']
|
66
|
+
t.rcov_dir = File.join('meta', 'coverage')
|
67
|
+
end
|
68
|
+
|
69
|
+
begin
|
70
|
+
require 'spec/rake/verify_rcov'
|
71
|
+
# For the moment, this is the only way I know of to fix RCov. I may
|
72
|
+
# release the fix as it's own gem at some point in the near future.
|
73
|
+
require 'stringray/core_ext/spec/rake/verify_rcov'
|
74
|
+
RCov::VerifyTask.new(:verify) do |t|
|
75
|
+
t.threshold = 65.0
|
76
|
+
t.index_html = File.join('meta', 'coverage', 'index.html')
|
77
|
+
t.require_exact_threshold = false
|
78
|
+
end
|
79
|
+
rescue LoadError
|
80
|
+
desc 'You need the `stringray` gem to verify coverage'
|
81
|
+
task :verify
|
82
|
+
end
|
83
|
+
|
84
|
+
task :open do
|
85
|
+
system 'open ' + File.join('meta', 'coverage', 'index.html') if PLATFORM['darwin']
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
rescue LoadError
|
90
|
+
desc 'You need the `rcov` and `rspec` gems to run specs/coverage'
|
91
|
+
task :coverage
|
92
|
+
end
|
93
|
+
|
94
|
+
# =======================
|
95
|
+
# = Documentation tasks =
|
96
|
+
# =======================
|
97
|
+
begin
|
98
|
+
require 'yard'
|
99
|
+
require 'yard/rake/yardoc_task'
|
100
|
+
|
101
|
+
task :documentation => :'documentation:generate'
|
102
|
+
namespace :documentation do
|
103
|
+
YARD::Rake::YardocTask.new :generate do |t|
|
104
|
+
t.files = ['lib/**/*.rb']
|
105
|
+
t.options = ['--output-dir', File.join('meta', 'documentation'),
|
106
|
+
'--readme', 'README.markdown']
|
107
|
+
end
|
108
|
+
|
109
|
+
YARD::Rake::YardocTask.new :dotyardoc do |t|
|
110
|
+
t.files = ['lib/**/*.rb']
|
111
|
+
t.options = ['--no-output',
|
112
|
+
'--readme', 'README.markdown']
|
113
|
+
end
|
114
|
+
|
115
|
+
task :open do
|
116
|
+
system 'open ' + File.join('meta', 'documentation', 'index.html') if PLATFORM['darwin']
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
rescue LoadError
|
121
|
+
desc 'You need the `yard` gem to generate documentation'
|
122
|
+
task :documentation
|
123
|
+
end
|
124
|
+
|
125
|
+
# =========
|
126
|
+
# = Other =
|
127
|
+
# =========
|
128
|
+
desc 'Removes all meta producs'
|
129
|
+
task :clobber do
|
130
|
+
`rm -rf #{File.expand_path(File.join( File.dirname(__FILE__), 'meta' ))}`
|
131
|
+
end
|
132
|
+
|
133
|
+
desc 'Check everything over before commiting'
|
134
|
+
task :aok => [:'documentation:generate', :'documentation:open',
|
135
|
+
:'package:manifest',
|
136
|
+
:'coverage:run', :'coverage:verify', :'coverage:open']
|
137
|
+
|
138
|
+
task :ci => [:'documentation:generate', :'coverage:run', :'coverage:verify']
|
data/bin/jello
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby -Ku
|
2
|
+
($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq!
|
3
|
+
%w[jello rubygems optparse].each {|dep| require dep }
|
4
|
+
|
5
|
+
options = Hash.new
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: jello [options] <mould> (<mould> …)"
|
8
|
+
|
9
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
10
|
+
options[:verbose] = v
|
11
|
+
end
|
12
|
+
end.parse!
|
13
|
+
|
14
|
+
ARGV.each do |mould|
|
15
|
+
require Jello::Mould.find(mould)
|
16
|
+
end
|
17
|
+
|
18
|
+
Jello.start! options
|
data/jello.gemspec
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
|
2
|
+
# Gem::Specification for Jello-2
|
3
|
+
# Originally generated by Echoe
|
4
|
+
|
5
|
+
--- !ruby/object:Gem::Specification
|
6
|
+
name: jello
|
7
|
+
version: !ruby/object:Gem::Version
|
8
|
+
version: "2"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- elliottcable
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
|
15
|
+
date: 2008-09-29 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: 3.0.1
|
27
|
+
version:
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
type: :development
|
31
|
+
version_requirement:
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: "0"
|
37
|
+
version:
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rcov
|
40
|
+
type: :development
|
41
|
+
version_requirement:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: yard
|
50
|
+
type: :development
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: stringray
|
60
|
+
type: :development
|
61
|
+
version_requirement:
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
description: A library to watch the OS X pasteboard, and process/modify incoming pastes.
|
69
|
+
email:
|
70
|
+
- Jello@elliottcable.com
|
71
|
+
executables:
|
72
|
+
- jello
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
76
|
+
- bin/jello
|
77
|
+
- lib/jello/core_ext/kernel.rb
|
78
|
+
- lib/jello/logger.rb
|
79
|
+
- lib/jello/mould.rb
|
80
|
+
- lib/jello/pasteboard.rb
|
81
|
+
- lib/jello.rb
|
82
|
+
- README.markdown
|
83
|
+
files:
|
84
|
+
- bin/jello
|
85
|
+
- lib/jello/core_ext/kernel.rb
|
86
|
+
- lib/jello/logger.rb
|
87
|
+
- lib/jello/mould.rb
|
88
|
+
- lib/jello/pasteboard.rb
|
89
|
+
- lib/jello.rb
|
90
|
+
- moulds/grabup.rb
|
91
|
+
- moulds/say.rb
|
92
|
+
- moulds/shorten.rb
|
93
|
+
- Rakefile.rb
|
94
|
+
- README.markdown
|
95
|
+
- spec/jello_spec.rb
|
96
|
+
- .manifest
|
97
|
+
- jello.gemspec
|
98
|
+
has_rdoc: true
|
99
|
+
homepage: http://github.com/elliottcable/jello
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options:
|
102
|
+
- --line-numbers
|
103
|
+
- --inline-source
|
104
|
+
- --title
|
105
|
+
- Jello
|
106
|
+
- --main
|
107
|
+
- README.markdown
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: "0"
|
115
|
+
version:
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: "1.2"
|
121
|
+
version:
|
122
|
+
requirements: []
|
123
|
+
|
124
|
+
rubyforge_project: jello
|
125
|
+
rubygems_version: 1.3.0
|
126
|
+
specification_version: 2
|
127
|
+
summary: A library to watch the OS X pasteboard, and process/modify incoming pastes.
|
128
|
+
test_files: []
|
data/lib/jello.rb
CHANGED
@@ -1,45 +1,37 @@
|
|
1
|
+
require 'jello/core_ext/kernel'
|
1
2
|
require 'jello/pasteboard'
|
3
|
+
require 'jello/mould'
|
2
4
|
|
3
|
-
|
4
|
-
Version =
|
5
|
+
module Jello
|
6
|
+
Version = 2
|
5
7
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
8
|
+
def self.start! options = {}
|
9
|
+
options = {:verbose => false, :period => 0.5}.merge(options)
|
10
|
+
|
11
|
+
forever do
|
21
12
|
|
22
|
-
|
23
|
-
|
13
|
+
Moulds.each do |pasteboard, moulds|
|
14
|
+
if (paste = pasteboard.gets) != pasteboard.last
|
15
|
+
initial_paste = paste.dup
|
24
16
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@on_paste[paste, self]
|
17
|
+
puts "#{pasteboard.board} received: [#{initial_paste}]" if options[:verbose]
|
18
|
+
moulds.each do |mould|
|
19
|
+
paste = mould.on_paste[paste]
|
29
20
|
end
|
30
21
|
|
31
|
-
|
22
|
+
if paste.is_a?(String) and paste != initial_paste
|
23
|
+
puts " --> [#{paste}]" if options[:verbose]
|
24
|
+
pasteboard.puts paste
|
25
|
+
end
|
32
26
|
end
|
33
|
-
|
34
|
-
sleep @opts[:period]
|
35
27
|
end
|
36
|
-
|
37
|
-
|
38
|
-
exit
|
28
|
+
|
29
|
+
sleep options[:period]
|
39
30
|
end
|
40
31
|
end
|
41
32
|
|
42
|
-
def stop
|
33
|
+
def self.stop!
|
43
34
|
raise Interrupt # …
|
44
35
|
end
|
36
|
+
|
45
37
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Kernel
|
2
|
+
def forever &block
|
3
|
+
__forever__(&block ||= lambda {})
|
4
|
+
end
|
5
|
+
|
6
|
+
def __forever__
|
7
|
+
begin
|
8
|
+
while true
|
9
|
+
yield
|
10
|
+
end
|
11
|
+
rescue Interrupt
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Execute some code without any warnings
|
17
|
+
def silently
|
18
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
$VERBOSE = old_verbose
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/jello/logger.rb
ADDED
data/lib/jello/mould.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
module Jello
|
2
|
+
|
3
|
+
##
|
4
|
+
# A hash of each pasteboard and the moulds that preform on that pasteboard.
|
5
|
+
Moulds = Pasteboards.inject(Hash.new) {|h,pb| h[pb] = Array.new ; h }
|
6
|
+
|
7
|
+
class Mould
|
8
|
+
|
9
|
+
##
|
10
|
+
# This checks the Jello require paths for a mould by that name. The
|
11
|
+
# following directories are checked, in this order:
|
12
|
+
#
|
13
|
+
# - `$HOME/.jello/*.rb`
|
14
|
+
# - `/etc/jello/*.rb`
|
15
|
+
# - `$JELLO_SRC/moulds/*.rb`
|
16
|
+
#
|
17
|
+
# The first one with a file by the correct name will overide any later
|
18
|
+
# ones.
|
19
|
+
def self.find name
|
20
|
+
[File.join(ENV['HOME'], '.jello'),
|
21
|
+
File.join('etc', 'jello'),
|
22
|
+
File.join( File.dirname(__FILE__), '..', '..', 'moulds' )].each do |dir|
|
23
|
+
dir = File.expand_path(dir)
|
24
|
+
|
25
|
+
if File.directory? dir
|
26
|
+
Dir["#{dir}/**/*.rb"].each do |file|
|
27
|
+
# This should be quite powerful - if you have a directory of
|
28
|
+
# moulds, you can select them all, or you can select all of them
|
29
|
+
# plus a single-file mould of the same name. Or whatever you might
|
30
|
+
# want. Mmmsexy? Mmmsexy.
|
31
|
+
return file if file.gsub(/^#{dir}/, '') =~ /#{name}/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# This takes a block that will be executed on every paste received by
|
42
|
+
# Jello.
|
43
|
+
attr_accessor :on_paste
|
44
|
+
|
45
|
+
##
|
46
|
+
# Acts as both a getter and a setter for the @on_paste attribute. If
|
47
|
+
# passed a block, it sets that block as the @on_paste hook - else it
|
48
|
+
# returns the current hook block.
|
49
|
+
#
|
50
|
+
# @see @on_paste
|
51
|
+
def on_paste &block
|
52
|
+
if block_given?
|
53
|
+
@on_paste = block
|
54
|
+
else
|
55
|
+
@on_paste
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Creates a new Mould. Takes a block to be run on every paste.
|
61
|
+
def initialize pasteboard = nil, &block
|
62
|
+
@pasteboard = pasteboard || Pasteboard::General
|
63
|
+
@on_paste = block
|
64
|
+
|
65
|
+
Moulds[@pasteboard] << self
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# We pass any missing methods on to the Pasteboard.
|
70
|
+
#
|
71
|
+
# @see Jello::Pasteboard
|
72
|
+
def method_missing meth, *args
|
73
|
+
@pasteboard.send meth, *args
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
data/lib/jello/pasteboard.rb
CHANGED
@@ -1,12 +1,110 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
%x[pbpaste].chomp
|
4
|
-
end
|
1
|
+
module Jello
|
2
|
+
Pasteboards = []
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
class Pasteboard
|
5
|
+
|
6
|
+
##
|
7
|
+
# The type of board to connect to. Available are the following:
|
8
|
+
#
|
9
|
+
# - :general [default]
|
10
|
+
# - :ruler
|
11
|
+
# - :find
|
12
|
+
# - :font
|
13
|
+
#
|
14
|
+
# OS X offers various pasteboards for use, depending on what you want to
|
15
|
+
# access. They're synced across the entire system. More information is
|
16
|
+
# available under `man pbpaste`.
|
17
|
+
#
|
18
|
+
# @see #gets
|
19
|
+
# @see #puts
|
20
|
+
attr_reader :board
|
21
|
+
|
22
|
+
##
|
23
|
+
# The type of data to request from the board. Available are the following:
|
24
|
+
#
|
25
|
+
# - :ascii [default]
|
26
|
+
# - :rtf (Rich Text)
|
27
|
+
# - :ps (PostScript)
|
28
|
+
#
|
29
|
+
# You're not guaranteed to receive that type, however - you'll receive it if
|
30
|
+
# it's available, otherwise you'll receive the first in the above list that
|
31
|
+
# is available. More information is available under `man pbpaste`.
|
32
|
+
#
|
33
|
+
# @see #gets
|
34
|
+
attr_accessor :format
|
35
|
+
|
36
|
+
##
|
37
|
+
# The last paste recognized by the pasteboard. If you modify the contents
|
38
|
+
# of the pasteboard, you can save processing time by also updating this
|
39
|
+
# property with said contents, preventing an extra loop.
|
40
|
+
attr_accessor :last
|
41
|
+
|
42
|
+
attr_accessor :current
|
43
|
+
|
44
|
+
##
|
45
|
+
# This creates a new Pasteboard instance, connected to one of the available
|
46
|
+
# Mac OS X pasteboards. You shouldn't use this directly - use one of the
|
47
|
+
# pre-defined constants instead.
|
48
|
+
#
|
49
|
+
# @see #gets
|
50
|
+
# @see #puts
|
51
|
+
def initialize options = {}
|
52
|
+
@board ||= options[:board] || :general
|
53
|
+
@format ||= options[:format] || :ascii
|
54
|
+
|
55
|
+
yield self if block_given?
|
56
|
+
|
57
|
+
@current = ""
|
58
|
+
@last = ""
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# This method gets the latest paste from the selected pasteboard,
|
63
|
+
# of the selected format (if possible - see `#format`).
|
64
|
+
#
|
65
|
+
# @see @board
|
66
|
+
# @see @format
|
67
|
+
def gets
|
68
|
+
@last = @current
|
69
|
+
command = 'pbpaste'
|
70
|
+
command << " -pboard #{@board}" if @board
|
71
|
+
@current = %x[#{command}].chomp
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# This method puts a new entry into the selected pasteboard. Format is
|
76
|
+
# automatically deduced from the headers of your string (see `man pbpaste`
|
77
|
+
# for more info.)
|
78
|
+
#
|
79
|
+
# @see @board
|
80
|
+
def puts something
|
81
|
+
command = 'pbcopy'
|
82
|
+
command << " -pboard #{@board}" if @board
|
83
|
+
command << " -Prefer #{@format}" if @format
|
84
|
+
out = IO::popen command, 'w+'
|
85
|
+
out.print something
|
86
|
+
out.close
|
87
|
+
something
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
##
|
92
|
+
# A pasteboard that stores general text
|
93
|
+
General = new :board => :general
|
94
|
+
|
95
|
+
##
|
96
|
+
# Unknown
|
97
|
+
Ruler = new :board => :ruler
|
98
|
+
|
99
|
+
##
|
100
|
+
# A pasteboard that stores the text used in find dialogues
|
101
|
+
Find = new :board => :find
|
102
|
+
|
103
|
+
##
|
104
|
+
# Unknown
|
105
|
+
Font = new :board => :font
|
106
|
+
|
107
|
+
[General, Ruler, Find, Font].each {|pb| Pasteboards << pb }
|
108
|
+
|
11
109
|
end
|
12
|
-
end
|
110
|
+
end
|
data/moulds/grabup.rb
ADDED
data/moulds/say.rb
ADDED
data/moulds/shorten.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'JSON'
|
3
|
+
|
4
|
+
Jello::Mould.new do |paste, board|
|
5
|
+
|
6
|
+
if paste =~ %r{^http://.*}
|
7
|
+
uri = $&
|
8
|
+
unless paste =~ %r{^http://tr.im}
|
9
|
+
uri.gsub! /#/, '%23' # Fix anchors
|
10
|
+
|
11
|
+
shortener = 'http://tr.im/api/trim_url.json?url=' + uri
|
12
|
+
|
13
|
+
reply = open(shortener).read
|
14
|
+
short = JSON.parse reply
|
15
|
+
short['url']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jello
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "
|
4
|
+
version: "2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- elliottcable
|
@@ -9,13 +9,53 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-29 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: echoe
|
17
17
|
type: :development
|
18
18
|
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.0.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rcov
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: yard
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: stringray
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
19
59
|
version_requirements: !ruby/object:Gem::Requirement
|
20
60
|
requirements:
|
21
61
|
- - ">="
|
@@ -25,24 +65,33 @@ dependencies:
|
|
25
65
|
description: A library to watch the OS X pasteboard, and process/modify incoming pastes.
|
26
66
|
email:
|
27
67
|
- Jello@elliottcable.com
|
28
|
-
executables:
|
29
|
-
|
68
|
+
executables:
|
69
|
+
- jello
|
30
70
|
extensions: []
|
31
71
|
|
32
72
|
extra_rdoc_files:
|
73
|
+
- bin/jello
|
74
|
+
- lib/jello/core_ext/kernel.rb
|
75
|
+
- lib/jello/logger.rb
|
76
|
+
- lib/jello/mould.rb
|
33
77
|
- lib/jello/pasteboard.rb
|
34
78
|
- lib/jello.rb
|
35
|
-
- README.
|
79
|
+
- README.markdown
|
36
80
|
files:
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
81
|
+
- bin/jello
|
82
|
+
- lib/jello/core_ext/kernel.rb
|
83
|
+
- lib/jello/logger.rb
|
84
|
+
- lib/jello/mould.rb
|
40
85
|
- lib/jello/pasteboard.rb
|
41
86
|
- lib/jello.rb
|
42
|
-
-
|
43
|
-
-
|
87
|
+
- moulds/grabup.rb
|
88
|
+
- moulds/say.rb
|
89
|
+
- moulds/shorten.rb
|
90
|
+
- Rakefile.rb
|
91
|
+
- README.markdown
|
92
|
+
- spec/jello_spec.rb
|
44
93
|
- .manifest
|
45
|
-
-
|
94
|
+
- jello.gemspec
|
46
95
|
has_rdoc: true
|
47
96
|
homepage: http://github.com/elliottcable/jello
|
48
97
|
post_install_message:
|
@@ -52,7 +101,7 @@ rdoc_options:
|
|
52
101
|
- --title
|
53
102
|
- Jello
|
54
103
|
- --main
|
55
|
-
- README.
|
104
|
+
- README.markdown
|
56
105
|
require_paths:
|
57
106
|
- lib
|
58
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -63,14 +112,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
112
|
version:
|
64
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
114
|
requirements:
|
66
|
-
- - "
|
115
|
+
- - ">="
|
67
116
|
- !ruby/object:Gem::Version
|
68
117
|
version: "1.2"
|
69
118
|
version:
|
70
119
|
requirements: []
|
71
120
|
|
72
121
|
rubyforge_project: jello
|
73
|
-
rubygems_version: 1.
|
122
|
+
rubygems_version: 1.3.0
|
74
123
|
signing_key:
|
75
124
|
specification_version: 2
|
76
125
|
summary: A library to watch the OS X pasteboard, and process/modify incoming pastes.
|
data/Jello.gemspec
DELETED
@@ -1,79 +0,0 @@
|
|
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
DELETED
@@ -1,49 +0,0 @@
|
|
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
DELETED
@@ -1,91 +0,0 @@
|
|
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
|
data/examples/grabup_fixer.rb
DELETED
@@ -1,12 +0,0 @@
|
|
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/shorten.rb
DELETED
@@ -1,22 +0,0 @@
|
|
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
|