jello 3 → 5

Sign up to get free protection for your applications and to get access to all the features.
data/.manifest CHANGED
@@ -4,9 +4,10 @@ lib/jello/logger.rb
4
4
  lib/jello/mould.rb
5
5
  lib/jello/pasteboard.rb
6
6
  lib/jello.rb
7
- moulds/grabup.rb
7
+ moulds/fail.rb
8
+ moulds/grabup_fixer.rb
8
9
  moulds/say.rb
9
- moulds/shorten.rb
10
+ moulds/shortener.rb
10
11
  Rakefile.rb
11
12
  README.markdown
12
13
  spec/jello_spec.rb
@@ -23,7 +23,7 @@ the long URL with the shortened one, write a short mould like the following:
23
23
 
24
24
  Jello::Mould.new do |paste|
25
25
 
26
- if paste =~ %r{}^http://.*}
26
+ if paste =~ %r{^http://.*}
27
27
  uri = $&
28
28
  uri.gsub! /#/, '%23'
29
29
  unless uri =~ %r{^http://bit.ly}
@@ -9,7 +9,8 @@ require 'fileutils'
9
9
  begin
10
10
  require 'echoe'
11
11
 
12
- task :package => :'package:install'
12
+ task :package => :'package:package'
13
+ task :install => :'package:install'
13
14
  task :manifest => :'package:manifest'
14
15
  namespace :package do
15
16
  Echoe.new('jello', Jello::Version) do |g|
@@ -18,8 +19,10 @@ begin
18
19
  g.email = ['Jello@elliottcable.com']
19
20
  g.summary = 'A library to watch the OS X pasteboard, and process/modify incoming pastes.'
20
21
  g.url = 'http://github.com/elliottcable/jello'
21
- g.development_dependencies = ['echoe >=3.0.1', 'rspec', 'rcov', 'yard', 'stringray']
22
+ g.development_dependencies = ['elliottcable-echoe >= 3.0.2', 'rspec', 'rcov', 'yard', 'stringray']
22
23
  g.manifest_name = '.manifest'
24
+ g.retain_gemspec = true
25
+ g.rakefile_name = 'Rakefile.rb'
23
26
  g.ignore_pattern = /^\.git\/|^meta\/|\.gemspec/
24
27
  end
25
28
 
@@ -30,18 +33,10 @@ begin
30
33
  puts "\nThe library files are present"
31
34
  end
32
35
  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
36
  end
42
37
 
43
38
  rescue LoadError
44
- desc 'You need the `echoe` gem to package Jello'
39
+ desc 'You need the `elliottcable-echoe` gem to package Jello'
45
40
  task :package
46
41
  end
47
42
 
@@ -72,7 +67,7 @@ begin
72
67
  # release the fix as it's own gem at some point in the near future.
73
68
  require 'stringray/core_ext/spec/rake/verify_rcov'
74
69
  RCov::VerifyTask.new(:verify) do |t|
75
- t.threshold = 65.0
70
+ t.threshold = 50.0
76
71
  t.index_html = File.join('meta', 'coverage', 'index.html')
77
72
  t.require_exact_threshold = false
78
73
  end
@@ -132,7 +127,7 @@ end
132
127
 
133
128
  desc 'Check everything over before commiting'
134
129
  task :aok => [:'documentation:generate', :'documentation:open',
135
- :'package:manifest', :'package:gemspec',
130
+ :'package:manifest', :'package:package',
136
131
  :'coverage:run', :'coverage:verify', :'coverage:open']
137
132
 
138
133
  task :ci => [:'documentation:generate', :'coverage:run', :'coverage:verify']
data/bin/jello CHANGED
@@ -21,8 +21,8 @@ utilized.
21
21
 
22
22
  The follow moulds are included for your enjoyment:
23
23
  - jello say
24
- - jello grabup
25
- - jello shorten
24
+ - jello grabup_fixer
25
+ - jello shortener
26
26
 
27
27
  == Usage ==
28
28
  `jello [options] <mould> (<mould> <mould> …)`
@@ -32,6 +32,10 @@ The follow moulds are included for your enjoyment:
32
32
  options[:verbose] = v
33
33
  end
34
34
 
35
+ opts.on("-d", "--[no-]debug", "Run extremely verbosely") do |d|
36
+ $-d = d
37
+ end
38
+
35
39
  opts.on("-f", "--[no-]feedback", "Feedback on successful process") do |f|
36
40
  options[:feedback] = f
37
41
  end
@@ -39,10 +43,41 @@ The follow moulds are included for your enjoyment:
39
43
  opts.on("-p", "--period PERIOD", "Period over which to cycle watcher process") do |p|
40
44
  options[:period] = p
41
45
  end
46
+
47
+ opts.on("-D", "--[no-]daemonize", "Fork the process") do |D|
48
+ options[:daemonize] = D
49
+ end
50
+
51
+ opts.on_tail("--help", "Show this help") do
52
+ puts opts
53
+ exit
54
+ end
55
+ opts.on_tail("--version", "Show version") do
56
+ puts "I'm Jello #{Jello::Version}!"
57
+ exit
58
+ end
42
59
  end.parse!
43
60
 
44
61
  ARGV.each do |mould|
45
62
  require Jello::Mould.find(mould)
46
63
  end
47
64
 
65
+ # http://github.com/chneukirchen/rack/tree/ed86dfd676dcb46e276b6906f017df514e5632f9/bin/rackup#L153-164
66
+ if options[:daemonize]
67
+ if RUBY_VERSION < "1.9"
68
+ exit if fork
69
+ Process.setsid
70
+ exit if fork
71
+ Dir.chdir "/"
72
+ File.umask 0000
73
+ STDIN.reopen "/dev/null"
74
+ STDOUT.reopen "/dev/null", "a"
75
+ STDERR.reopen "/dev/null", "a"
76
+ else
77
+ Process.daemon
78
+ end
79
+ end
80
+
81
+ $0 = "jello: #{ARGV.join ', '}"
82
+
48
83
  Jello.start! options
@@ -1,128 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
1
2
 
2
- # Gem::Specification for Jello-3
3
- # Originally generated by Echoe
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{jello}
5
+ s.version = "5"
4
6
 
5
- --- !ruby/object:Gem::Specification
6
- name: jello
7
- version: !ruby/object:Gem::Version
8
- version: "3"
9
- platform: ruby
10
- authors:
11
- - elliottcable
12
- autorequire:
13
- bindir: bin
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["elliottcable"]
9
+ s.date = %q{2008-11-01}
10
+ s.default_executable = %q{jello}
11
+ s.description = %q{A library to watch the OS X pasteboard, and process/modify incoming pastes.}
12
+ s.email = ["Jello@elliottcable.com"]
13
+ s.executables = ["jello"]
14
+ s.extra_rdoc_files = ["bin/jello", "lib/jello/core_ext/kernel.rb", "lib/jello/logger.rb", "lib/jello/mould.rb", "lib/jello/pasteboard.rb", "lib/jello.rb", "README.markdown"]
15
+ s.files = ["bin/jello", "lib/jello/core_ext/kernel.rb", "lib/jello/logger.rb", "lib/jello/mould.rb", "lib/jello/pasteboard.rb", "lib/jello.rb", "moulds/fail.rb", "moulds/grabup_fixer.rb", "moulds/say.rb", "moulds/shortener.rb", "Rakefile.rb", "README.markdown", "spec/jello_spec.rb", ".manifest", "jello.gemspec"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/elliottcable/jello}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jello", "--main", "README.markdown"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{jello}
21
+ s.rubygems_version = %q{1.3.0}
22
+ s.summary = %q{A library to watch the OS X pasteboard, and process/modify incoming pastes.}
14
23
 
15
- date: 2008-10-09 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: []
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
74
27
 
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: []
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_development_dependency(%q<elliottcable-echoe>, [">= 0", "= 3.0.2"])
30
+ s.add_development_dependency(%q<rspec>, [">= 0"])
31
+ s.add_development_dependency(%q<rcov>, [">= 0"])
32
+ s.add_development_dependency(%q<yard>, [">= 0"])
33
+ s.add_development_dependency(%q<stringray>, [">= 0"])
34
+ else
35
+ s.add_dependency(%q<elliottcable-echoe>, [">= 0", "= 3.0.2"])
36
+ s.add_dependency(%q<rspec>, [">= 0"])
37
+ s.add_dependency(%q<rcov>, [">= 0"])
38
+ s.add_dependency(%q<yard>, [">= 0"])
39
+ s.add_dependency(%q<stringray>, [">= 0"])
40
+ end
41
+ else
42
+ s.add_dependency(%q<elliottcable-echoe>, [">= 0", "= 3.0.2"])
43
+ s.add_dependency(%q<rspec>, [">= 0"])
44
+ s.add_dependency(%q<rcov>, [">= 0"])
45
+ s.add_dependency(%q<yard>, [">= 0"])
46
+ s.add_dependency(%q<stringray>, [">= 0"])
47
+ end
48
+ end
@@ -3,7 +3,7 @@ require 'jello/pasteboard'
3
3
  require 'jello/mould'
4
4
 
5
5
  module Jello
6
- Version = 3
6
+ Version = 5
7
7
 
8
8
  def self.start! options = {}
9
9
  options = {:verbose => false, :period => 0.5}.merge(options)
@@ -19,7 +19,12 @@ module Jello
19
19
 
20
20
  puts "#{pasteboard.board} received: [#{initial_paste}]" if options[:verbose]
21
21
  moulds.each do |mould|
22
- modified = mould.on_paste[paste]
22
+ modified = begin
23
+ mould.on_paste[paste]
24
+ rescue => error
25
+ puts " !!> #{error}"
26
+ nil
27
+ end
23
28
  paste = modified if modified.is_a?(String)
24
29
  end
25
30
 
@@ -0,0 +1,3 @@
1
+ Jello::Mould.new do |paste|
2
+ raise 'FAIL'
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'uri'
2
+
3
+ Jello::Mould.new do |paste|
4
+ if paste =~ %r{^http://.*}
5
+ uri = URI.parse paste
6
+
7
+ if uri.host =~ /grabup/
8
+ uri.host = 'grabup.com'
9
+ uri.query = 'direct'
10
+ uri.to_s
11
+ else; nil; end
12
+ end
13
+ end
@@ -0,0 +1,64 @@
1
+ require 'cgi'
2
+ require 'rubygems'
3
+ require 'open-uri'
4
+ require 'JSON'
5
+
6
+ Paths = {
7
+ 'google' => :search,
8
+ /my-site\.name/ => %r{^http://my-site\.name/(.+)\.xhtml$}
9
+ }
10
+
11
+ Jello::Mould.new do |paste, board|
12
+
13
+ if paste =~ %r{^http://.*}
14
+ uri = URI.parse $&
15
+ unless paste =~ %r{^http://tr.im}
16
+ # We're going to add the main part of the domain to the end of the URI
17
+ # as a bullshit parameter, to give visitors some indication of what
18
+ # their destination is. If you're in a character-limited location, such
19
+ # as twitter or a text message, feel free to simply delete this section
20
+ # of the URL by hand after pasting. (⌥⌫ is helpful!)
21
+ #
22
+ # We also check if the URI matches a key of the Paths constant, and
23
+ # process the URI based on the value matched to that key if it matches.
24
+ # Keys can be stringish or regexish, in the latter case, it will run it
25
+ # matches. Values can be stringish or regexish, in the latter case,
26
+ # the last matching group will be used as the parameter.
27
+ base = nil
28
+ matcher = Paths.select {|matcher,baser| uri.to_s =~ (matcher.is_a?(Regexp) ? matcher : /#{matcher}/) } .first
29
+ if matcher
30
+ base = uri.to_s.match( matcher[1] )
31
+ end
32
+
33
+ unless base and (base = base[1])
34
+ base = uri.host.match( /(?:[\w\d\-\.]+\.)?([\w\d\-]+)\.[\w]{2,4}/ )[1]
35
+ end
36
+
37
+ base = URI::unescape(base).gsub(/\s/, '_')
38
+ uri = CGI::escape uri.to_s
39
+
40
+ shortener = URI.parse 'http://tr.im/api/trim_url.json'
41
+
42
+ # Feel free to copy this Mould to your ~/.jello directory and hardcode
43
+ # in your username and password, if you don't feel like having your
44
+ # username and password in your shell history.
45
+ params = {}
46
+ params[:username] = ENV['TRIM_USERNAME'] if ENV['TRIM_USERNAME']
47
+ params[:password] = ENV['TRIM_PASSWORD'] if ENV['TRIM_PASSWORD']
48
+ params[:url] = uri
49
+
50
+ shortener.query = params.to_a.map {|a| a.join '=' }.join('&')
51
+
52
+ begin
53
+ puts " --@ [#{shortener}]" if $DEBUG
54
+ reply = open(shortener).read
55
+ short = JSON.parse reply
56
+ rescue OpenURI::HTTPError => e
57
+ short = {'url' => paste}
58
+ end
59
+ shortened = [short['url'], base].join('?')
60
+ shortened.length < paste.length ? shortened : paste
61
+ end
62
+ end
63
+
64
+ 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: "3"
4
+ version: "5"
5
5
  platform: ruby
6
6
  authors:
7
7
  - elliottcable
@@ -9,18 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-09 00:00:00 -08:00
12
+ date: 2008-11-01 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: echoe
16
+ name: elliottcable-echoe
17
17
  type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 3.0.1
23
+ version: "0"
24
+ - - "="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.2
24
27
  version:
25
28
  - !ruby/object:Gem::Dependency
26
29
  name: rspec
@@ -84,9 +87,10 @@ files:
84
87
  - lib/jello/mould.rb
85
88
  - lib/jello/pasteboard.rb
86
89
  - lib/jello.rb
87
- - moulds/grabup.rb
90
+ - moulds/fail.rb
91
+ - moulds/grabup_fixer.rb
88
92
  - moulds/say.rb
89
- - moulds/shorten.rb
93
+ - moulds/shortener.rb
90
94
  - Rakefile.rb
91
95
  - README.markdown
92
96
  - spec/jello_spec.rb
@@ -1,6 +0,0 @@
1
- Jello::Mould.new do |paste|
2
- if paste =~ %r{^http://www\.grabup\.com/uploads/[0-9a-z]{32}\.png$}
3
- paste.gsub!(%r{^http://www\.}, 'http://')
4
- paste += '?direct'
5
- end
6
- end
@@ -1,37 +0,0 @@
1
- require 'cgi'
2
- require 'rubygems'
3
- require 'open-uri'
4
- require 'JSON'
5
-
6
- Jello::Mould.new do |paste, board|
7
-
8
- if paste =~ %r{^http://.*}
9
- uri = $&
10
- unless paste =~ %r{^http://tr.im}
11
- # We're going to add the main part of the domain to the end of the URI
12
- # as a bullshit parameter, to give visitors some indication of what
13
- # their destination is. If you're in a character-limited location, such
14
- # as twitter or a text message, feel free to simply delete this section
15
- # of the URL by hand after pasting. (⌥⌫ is helpful!)
16
- base = uri.match(%r{^http://([\w\d\.]+\.)?([\w\d]+)\.[\w]{2,4}/})[2]
17
-
18
- uri = CGI::escape uri
19
-
20
- # Feel free to copy this Mould to your ~/.jello directory and hardcode
21
- # in your username and password, if you don't feel like having your
22
- # username and password in your shell history.
23
- params = {}
24
- params[:username] = ENV['TRIM_USERNAME'] if ENV['TRIM_USERNAME']
25
- params[:password] = ENV['TRIM_PASSWORD'] if ENV['TRIM_PASSWORD']
26
- params[:url] = uri
27
-
28
- shortener = 'http://tr.im/api/trim_url.json?' +
29
- params.to_a.map {|a| a.join '=' }.join('&')
30
-
31
- reply = open(shortener).read
32
- short = JSON.parse reply
33
- [short['url'], base].join('?')
34
- end
35
- end
36
-
37
- end