elliottcable-jello 2 → 3

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 CHANGED
@@ -4,9 +4,9 @@ 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/grabup_fixer.rb
8
8
  moulds/say.rb
9
- moulds/shorten.rb
9
+ moulds/shortener.rb
10
10
  Rakefile.rb
11
11
  README.markdown
12
12
  spec/jello_spec.rb
data/README.markdown CHANGED
@@ -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}
data/Rakefile.rb CHANGED
@@ -132,7 +132,7 @@ end
132
132
 
133
133
  desc 'Check everything over before commiting'
134
134
  task :aok => [:'documentation:generate', :'documentation:open',
135
- :'package:manifest',
135
+ :'package:manifest', :'package:gemspec',
136
136
  :'coverage:run', :'coverage:verify', :'coverage:open']
137
137
 
138
138
  task :ci => [:'documentation:generate', :'coverage:run', :'coverage:verify']
data/bin/jello CHANGED
@@ -4,11 +4,41 @@
4
4
 
5
5
  options = Hash.new
6
6
  OptionParser.new do |opts|
7
- opts.banner = "Usage: jello [options] <mould> (<mould> …)"
7
+ opts.banner = "\
8
+ = Jello =
9
+
10
+ Moulds may be any string that matches a part of a path of a Ruby file relative\
11
+ to one of the entries in the Jello search path:
12
+ - ~/.jello
13
+ - /etc/jello
14
+ - <`gem contents jello`>/moulds
15
+
16
+ If a file matches earlier in the search path, later ones that also match will\
17
+ be ignored.
18
+
19
+ A directory may match, in which case all Ruby files in that directory will be\
20
+ utilized.
21
+
22
+ The follow moulds are included for your enjoyment:
23
+ - jello say
24
+ - jello grabup
25
+ - jello shorten
26
+
27
+ == Usage ==
28
+ `jello [options] <mould> (<mould> <mould> …)`
29
+ "
8
30
 
9
31
  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
10
32
  options[:verbose] = v
11
33
  end
34
+
35
+ opts.on("-f", "--[no-]feedback", "Feedback on successful process") do |f|
36
+ options[:feedback] = f
37
+ end
38
+
39
+ opts.on("-p", "--period PERIOD", "Period over which to cycle watcher process") do |p|
40
+ options[:period] = p
41
+ end
12
42
  end.parse!
13
43
 
14
44
  ARGV.each do |mould|
data/jello.gemspec CHANGED
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Jello-2
2
+ # Gem::Specification for Jello-3
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: jello
7
7
  version: !ruby/object:Gem::Version
8
- version: "2"
8
+ version: "3"
9
9
  platform: ruby
10
10
  authors:
11
11
  - elliottcable
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-09-29 00:00:00 -08:00
15
+ date: 2008-10-09 00:00:00 -08:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -87,9 +87,9 @@ files:
87
87
  - lib/jello/mould.rb
88
88
  - lib/jello/pasteboard.rb
89
89
  - lib/jello.rb
90
- - moulds/grabup.rb
90
+ - moulds/grabup_fixer.rb
91
91
  - moulds/say.rb
92
- - moulds/shorten.rb
92
+ - moulds/shortener.rb
93
93
  - Rakefile.rb
94
94
  - README.markdown
95
95
  - spec/jello_spec.rb
data/lib/jello.rb CHANGED
@@ -3,10 +3,13 @@ require 'jello/pasteboard'
3
3
  require 'jello/mould'
4
4
 
5
5
  module Jello
6
- Version = 2
6
+ Version = 3
7
7
 
8
8
  def self.start! options = {}
9
9
  options = {:verbose => false, :period => 0.5}.merge(options)
10
+ raise ArgumentError, 'period must be capable of becoming a Numeric Float' unless
11
+ options[:period].respond_to? :to_f
12
+ options[:period] = options[:period].to_f
10
13
 
11
14
  forever do
12
15
 
@@ -16,11 +19,13 @@ module Jello
16
19
 
17
20
  puts "#{pasteboard.board} received: [#{initial_paste}]" if options[:verbose]
18
21
  moulds.each do |mould|
19
- paste = mould.on_paste[paste]
22
+ modified = mould.on_paste[paste]
23
+ paste = modified if modified.is_a?(String)
20
24
  end
21
25
 
22
26
  if paste.is_a?(String) and paste != initial_paste
23
27
  puts " --> [#{paste}]" if options[:verbose]
28
+ print "\a" if options[:feedback]
24
29
  pasteboard.puts paste
25
30
  end
26
31
  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,58 @@
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
+ reply = open(shortener).read
53
+ short = JSON.parse reply
54
+ [short['url'], base].join('?')
55
+ end
56
+ end
57
+
58
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elliottcable-jello
3
3
  version: !ruby/object:Gem::Version
4
- version: "2"
4
+ version: "3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - elliottcable
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
- date: 2008-09-29 01:00:00 -07:00
11
+ date: 2008-10-09 01:00:00 -07:00
12
12
  default_executable:
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
@@ -83,9 +83,9 @@ files:
83
83
  - lib/jello/mould.rb
84
84
  - lib/jello/pasteboard.rb
85
85
  - lib/jello.rb
86
- - moulds/grabup.rb
86
+ - moulds/grabup_fixer.rb
87
87
  - moulds/say.rb
88
- - moulds/shorten.rb
88
+ - moulds/shortener.rb
89
89
  - Rakefile.rb
90
90
  - README.markdown
91
91
  - spec/jello_spec.rb
data/moulds/grabup.rb DELETED
@@ -1,8 +0,0 @@
1
- require 'open-uri'
2
-
3
- Jello::Mould.new do |paste|
4
- if paste =~ %r{^http://www\.grabup\.com/uploads/[0-9a-z]{32}\.png$}
5
- paste.gsub!(%r{^http://www\.}, 'http://')
6
- paste += '?direct'
7
- end
8
- end
data/moulds/shorten.rb DELETED
@@ -1,19 +0,0 @@
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