reefer 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2010 Adam Mckaig
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,44 @@
1
+ Reefer is a tiny Ruby interface to a hosted Etherpad. Currently, there
2
+ is very little functionality. In future, it may provide a more complete
3
+ API. You may consider that an invitation for patches...
4
+
5
+
6
+ Command-line Usage
7
+ ------------------
8
+
9
+ Fetch the current contents of a pad:
10
+
11
+ $ reefer --url http://piratepad.net/anything
12
+ <b>alpha</b> <i>bravo</i> <u>charlie</u> <s>delta</s>
13
+
14
+ Fetch a previous revision:
15
+
16
+ $ reefer --url http://piratepad.net/anything --revision 6
17
+ alpha bravo
18
+
19
+
20
+ Module Usage
21
+ ------------
22
+
23
+ Fetch the current contents of a pad:
24
+
25
+ >>> Reefer::Pad.new("http://piratepad.net/anything").to_html
26
+ "<b>alpha</b> <i>bravo</i> <u>charlie</u> <s>delta</s>"
27
+
28
+ Fetch a previos version:
29
+
30
+ >>> Reefer::Pad.new("http://piratepad.net/anything").revision(6).to_html
31
+ "alpha bravo"
32
+
33
+
34
+ Requirements
35
+ ------------
36
+ * Ruby 1.9
37
+ * Nokogiri
38
+ * Trollop
39
+ * RSpec
40
+
41
+
42
+ License
43
+ -------
44
+ Reefer is free software, available under the MIT license.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ require "rake"
5
+ require "spec/rake/spectask"
6
+
7
+ desc "Run all RSpec tests"
8
+ Spec::Rake::SpecTask.new("spec") do |t|
9
+ t.spec_files = FileList["spec/reefer/*.rb"]
10
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ require "trollop"
5
+ require "pathname"
6
+ require "optparse"
7
+
8
+ # find lib/reefer.rb relatively, to support symlinking
9
+ here = File.dirname(Pathname.new(__FILE__).realpath)
10
+ require File.join(here, "..", "lib", "reefer.rb")
11
+
12
+ opts = Trollop::options do
13
+ opt :url, "Etherpad URL", :type => String, :required => true
14
+ opt :revision, "Revision number", :type => :int
15
+ end
16
+
17
+ opts[:revision] ||= :latest
18
+ pad = Reefer::Pad.new(opts[:url])
19
+ rev = pad.revision(opts[:revision])
20
+
21
+ puts rev.contents.to_html
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ module Reefer
5
+ Version = "0.1.1"
6
+ end
7
+
8
+ here = File.dirname(__FILE__)
9
+ require here + "/reefer/errors.rb"
10
+ require here + "/reefer/pad.rb"
11
+ require here + "/reefer/fetch.rb"
12
+ require here + "/reefer/revision.rb"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ module Reefer
5
+ class InvalidPadName < Exception
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ require "open-uri"
5
+
6
+ module Reefer
7
+ class << self
8
+ def fetch(url)
9
+ open(url)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ require "uri"
5
+
6
+ module Reefer
7
+ class Pad
8
+ attr_reader :domain, :name
9
+
10
+ def initialize(url)
11
+ url = URI.parse(url)
12
+ @domain = url.host
13
+ @name = url.path
14
+
15
+ # remove the leading slash (which is always present), but explode
16
+ # if any more are present. pad names can't contain them.
17
+ @name.gsub!(/^\//, "")
18
+ raise InvalidPadName\
19
+ if @name.index("/")
20
+ end
21
+
22
+ def revision(version)
23
+ Revision.new(self, version)
24
+ end
25
+
26
+ def to_html
27
+ revision(:latest).to_html
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ require "nokogiri"
5
+
6
+ module Reefer
7
+ class Revision
8
+ attr_reader :pad, :version
9
+
10
+ def initialize(pad, version)
11
+ @pad = pad
12
+ @version = version
13
+ end
14
+
15
+ def url(format=:html)
16
+ "http://#{@pad.domain}/ep/pad/export/#{@pad.name}/#{name}?format=#{format}"
17
+ end
18
+
19
+ def name
20
+ if @version.is_a?(Numeric)
21
+ "rev.#{@version}"
22
+ else
23
+ @version
24
+ end
25
+ end
26
+
27
+ def fetch
28
+ Reefer::fetch(url)
29
+ end
30
+
31
+ def contents
32
+ doc = Nokogiri::HTML(fetch)
33
+ nodes = doc.css("body").children
34
+
35
+ # remove trailing <br> from the body.
36
+ # (etherpad keeps adding them on save.)
37
+ while nodes[-1].name == "br"
38
+ nodes.pop
39
+ end
40
+
41
+ nodes
42
+ end
43
+
44
+ def to_html
45
+ contents.to_html.strip
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
5
+ <meta http-equiv="Content-Language" content="en-us" />
6
+ <title></title>
7
+ </head>
8
+ <body>
9
+ alpha, <b>bravo</b>, <i>charlie</i>, <u>delta</u>
10
+ <br/><br/>
11
+ </body>
12
+ </html>
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
5
+ <meta http-equiv="Content-Language" content="en-us" />
6
+ <title></title>
7
+ </head>
8
+ <body>
9
+ alpha, bravo
10
+ <br/><br/>
11
+ </body>
12
+ </html>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
5
+ <meta http-equiv="Content-Language" content="en-us" />
6
+ <title></title>
7
+ </head>
8
+ <body>
9
+
10
+
11
+
12
+ <br/><br/>
13
+ <br/><br/>
14
+ </body>
15
+ </html>
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ require "lib/reefer.rb"
5
+
6
+ # stub out the url fetching.
7
+ module Reefer
8
+ class << self
9
+ def fetch(url)
10
+ File.open("spec/examples/" + EXAMPLES[url]).read
11
+ end
12
+ end
13
+ end
14
+
15
+ EXAMPLES = {
16
+ "http://example.com/ep/pad/export/test/latest?format=html" => "latest",
17
+ "http://example.com/ep/pad/export/test/rev.10?format=html" => "rev10",
18
+ "http://example.com/ep/pad/export/whitespace/latest?format=html" => "whitespace"
19
+ }
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ require "spec/helper.rb"
5
+
6
+ describe Reefer::Pad do
7
+ it "extracts the domain and pad name from an url" do
8
+ pad = Reefer::Pad.new("http://example.com/test")
9
+ pad.domain.should == "example.com"
10
+ pad.name.should == "test"
11
+ end
12
+
13
+ it "raises for invalid pad urls" do
14
+ lambda do
15
+ Reefer::Pad.new("http://example.com/this/is/not/valid")
16
+ end.should raise_error Reefer::InvalidPadName
17
+ end
18
+
19
+ it "returns a numeric Revision" do
20
+ pad = Reefer::Pad.new("http://example.com/test")
21
+ pad.revision(1).class.should == Reefer::Revision
22
+ end
23
+
24
+ it "returns the latest Revision" do
25
+ pad = Reefer::Pad.new("http://example.com/test")
26
+ pad.revision(:latest).version.should == :latest
27
+ end
28
+
29
+ it "ignores irrelevant url fragments" do
30
+ pad = Reefer::Pad.new("http://example.com/test#what?a=b&c=d;e=f")
31
+ pad.domain.should == "example.com"
32
+ pad.name.should == "test"
33
+ end
34
+
35
+ it "returns the HTML of the latest revision" do
36
+ pad = Reefer::Pad.new("http://example.com/test")
37
+ pad.to_html.should == "alpha, <b>bravo</b>, <i>charlie</i>, <u>delta</u>"
38
+ end
39
+
40
+ it "strips whitespace from HTML output" do
41
+ Reefer::Pad.new("http://example.com/whitespace").to_html.should == ""
42
+ end
43
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: et ts=2 sw=2
3
+
4
+ require "spec/helper.rb"
5
+
6
+ describe Reefer::Revision do
7
+ it "returns the URL"
8
+ it "retrieves the HTML source"
9
+ it "parses the HTML into a node array"
10
+ it "ignores trailing <br> elements"
11
+ it "renders the content back into HTML"
12
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reefer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Adam Mckaig
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-03 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "Reefer is a tiny Ruby interface to a hosted Etherpad. "
23
+ email: adam.mckaig@gmail.com
24
+ executables:
25
+ - reefer
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README
32
+ - LICENSE
33
+ - Rakefile
34
+ - lib/reefer.rb
35
+ - lib/reefer/pad.rb
36
+ - lib/reefer/revision.rb
37
+ - lib/reefer/fetch.rb
38
+ - lib/reefer/errors.rb
39
+ - bin/reefer
40
+ - spec/examples/rev10
41
+ - spec/examples/latest
42
+ - spec/examples/whitespace
43
+ - spec/helper.rb
44
+ - spec/reefer/pad.rb
45
+ - spec/reefer/revision.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/adammck/reefer
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.7
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Ruby interface to Etherpad
80
+ test_files: []
81
+