leander 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +46 -0
- data/bin/leander +87 -0
- data/lib/index.rb +37 -0
- data/lib/webpage.rb +17 -0
- metadata +84 -0
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Leander
|
2
|
+
|
3
|
+
Leander is a command line HTML clipping utility written in Ruby.
|
4
|
+
|
5
|
+
## Why?
|
6
|
+
|
7
|
+
I wrote this to replace my old method of bookmarking - "xclip -o | perl -pi -e 's:$:\\n\\n:g' >> ~/.bookmarks".
|
8
|
+
|
9
|
+
This provides a nicer way to search for links and get some context when the time comes to retrieve one.
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
I've tested this with ruby 1.8.7 on Arch Linux. I offer no guarantees to its performance.
|
14
|
+
The simplest way to install is probably 'gem install leander', although that may be flakey.
|
15
|
+
|
16
|
+
## Help
|
17
|
+
usage: leander 'query' OR leander
|
18
|
+
query bookmarks or store a bookmark from URL on STDIN
|
19
|
+
|
20
|
+
specific options
|
21
|
+
--show-html print out the HTML stored for each URL provided
|
22
|
+
--hide-url hide URL : useful with --show-html to pipe output to a browser
|
23
|
+
-h, --help Show this message
|
24
|
+
|
25
|
+
#### Reccomended Usage
|
26
|
+
I use Xmonad, and I use leander like this:
|
27
|
+
|
28
|
+
((modMask .|. shiftMask, xK_t), spawn "xclip -o | leander")
|
29
|
+
|
30
|
+
Combined with Vimperator's 'yy' command to yank the current URL, it's pretty slick.
|
31
|
+
|
32
|
+
sntahoesnthaoeu
|
33
|
+
|
34
|
+
#### The Name
|
35
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
36
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
37
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
38
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
39
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
40
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
41
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
42
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
43
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
44
|
+
http://en.wikipedia.org/wiki/Leander_(clipper)
|
45
|
+
|
46
|
+
I AM TESTING OUT GIT WIP
|
data/bin/leander
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'optparse/time'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
require 'webpage.rb'
|
8
|
+
require 'index.rb'
|
9
|
+
|
10
|
+
class Bookmarker
|
11
|
+
attr_accessor :index, :options
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
@index = BmIndex.new
|
15
|
+
@options = options
|
16
|
+
end
|
17
|
+
|
18
|
+
def operate(query)
|
19
|
+
if @options.delete
|
20
|
+
@index.leander_remove(query)
|
21
|
+
else
|
22
|
+
@index.search(query, @options.show_html, @options.hide_url)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
if ARGV.empty?
|
28
|
+
url = ARGF.read
|
29
|
+
|
30
|
+
if validate_url(url)
|
31
|
+
wp = Webpage.new(url)
|
32
|
+
@index.store_webpage wp
|
33
|
+
else
|
34
|
+
puts 'This doesn\'t look like a nice URL. Please use URLs that look like http://domain.tld'
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
else
|
39
|
+
query = ARGV.join(' ')
|
40
|
+
operate(query)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_url(url)
|
45
|
+
(url =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix) != nil
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def self.parse(args)
|
50
|
+
options = OpenStruct.new
|
51
|
+
options.show_html = false
|
52
|
+
options.hide_url = false
|
53
|
+
options.delete = false
|
54
|
+
|
55
|
+
opts = OptionParser.new do |opts|
|
56
|
+
opts.banner = "usage: leander 'query' OR leander \n query bookmarks or store a bookmark from URL on STDIN"
|
57
|
+
|
58
|
+
opts.separator ""
|
59
|
+
opts.separator "specific options"
|
60
|
+
|
61
|
+
opts.on("-d", "--delete", "deletes all documents matching the given query from the index") do |ext|
|
62
|
+
options.delete = true
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.on("--show-html",
|
66
|
+
"print out the HTML stored for each URL provided") do |ext|
|
67
|
+
options.show_html = true
|
68
|
+
end
|
69
|
+
|
70
|
+
opts.on("--hide-url", "hide URL : useful with --show-html to pipe output to a browser") do |ext|
|
71
|
+
options.hide_url = true
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
75
|
+
puts opts
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
|
79
|
+
opts.parse!(args)
|
80
|
+
return options
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
options = Bookmarker.parse(ARGV)
|
86
|
+
bm = Bookmarker.new(options)
|
87
|
+
bm.run
|
data/lib/index.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'ferret'
|
2
|
+
require 'highline/import'
|
3
|
+
|
4
|
+
require 'webpage.rb'
|
5
|
+
|
6
|
+
include Ferret
|
7
|
+
|
8
|
+
class BmIndex
|
9
|
+
attr_accessor :index
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@index = Index::Index.new(:path => "#{ENV['HOME']}/.leander.idx")
|
13
|
+
end
|
14
|
+
|
15
|
+
def store_webpage(wp)
|
16
|
+
@index << {
|
17
|
+
:url => wp.url,
|
18
|
+
:doc => wp.doc
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def leander_remove query
|
23
|
+
@index.search_each(query) do |id, score|
|
24
|
+
agrees = HighLine.agree("Are you sure you want to delete #{@index[id][:url]} Y/n?") { |q| q.default = 'yes'}
|
25
|
+
if agrees then @index.delete(id) end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def search(query, show_html = false, hide_url = false)
|
30
|
+
@index.search_each(query) do |id, score|
|
31
|
+
doc = Nokogiri::HTML.parse(@index[id][:doc])
|
32
|
+
puts @index[id][:url] + "\t" + doc.css('title').inner_text.strip unless hide_url
|
33
|
+
|
34
|
+
if show_html then puts @index[id][:doc] end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/webpage.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
class Webpage
|
5
|
+
attr_reader :url, :doc
|
6
|
+
def initialize url
|
7
|
+
@url = url
|
8
|
+
@doc = Nokogiri::HTML(open(url))
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_title
|
12
|
+
puts @doc.class
|
13
|
+
exit
|
14
|
+
return @doc.css('title').content
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leander
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Sorrell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-28 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ferret
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: nokogiri
|
27
|
+
type: :runtime
|
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: highline
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: leander is a command-line webpage clipper
|
46
|
+
email: seansorrell@gmail.com
|
47
|
+
executables:
|
48
|
+
- leander
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files: []
|
52
|
+
|
53
|
+
files:
|
54
|
+
- README.md
|
55
|
+
- lib/index.rb
|
56
|
+
- lib/webpage.rb
|
57
|
+
has_rdoc: false
|
58
|
+
homepage: http://github.com/rudle/leander
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.1
|
80
|
+
signing_key:
|
81
|
+
specification_version: 2
|
82
|
+
summary: leander is a command-line webpage clipper
|
83
|
+
test_files: []
|
84
|
+
|