wiki_lib 0.0.1
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/LICENSE +20 -0
- data/README +25 -0
- data/Rakefile +44 -0
- data/lib/wiki_lib/pm_wiki.rb +118 -0
- data/lib/wiki_lib.rb +5 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/wiki_lib_spec.rb +7 -0
- metadata +74 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Jonathan Stott
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
wiki-lib
|
2
|
+
========
|
3
|
+
|
4
|
+
A simple library for easing interaction with wikis (currently just PMWiki) in ruby,
|
5
|
+
in essence, a wrapper around the mechanize gem.
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'namelessjon-wiki_lib'
|
9
|
+
require 'wiki_lib'
|
10
|
+
|
11
|
+
@pm_wiki = WikiLib::PMWiki.new('http://www.pmwiki.org/wiki', 'namelessjon', 'apassword')
|
12
|
+
|
13
|
+
# get the page
|
14
|
+
@page = @pm_wiki.get_page('PmWiki/FAQ')
|
15
|
+
|
16
|
+
# get the current sandbox text
|
17
|
+
@sandbox = @pm_wiki.get_edit_text('Main/WikiSandbox')
|
18
|
+
|
19
|
+
# upload the reversed sandbox text back to the sandbox
|
20
|
+
@pm_wiki.upload_page('Main/WikiSandbox', @sandbox.reverse, "You're in backwards land, today".reverse)
|
21
|
+
|
22
|
+
COPYRIGHT
|
23
|
+
=========
|
24
|
+
|
25
|
+
Copyright (c) 2008 Jonathan Stott. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rcov/rcovtask'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = "wiki_lib"
|
10
|
+
s.summary = "A simple library to wrap around some common wiki operations"
|
11
|
+
s.email = "jonathan.stott@gmail.com"
|
12
|
+
s.homepage = "http://github.com/namelessjon/wiki_lib"
|
13
|
+
s.description = "A simple library to wrap around some common wiki operations\nCurrently only PMWiki is supported, but more will be added as and when."
|
14
|
+
s.authors = ["Jonathan Stott"]
|
15
|
+
s.add_dependency 'mechanize', '~>0.9'
|
16
|
+
s.autorequire = 'wiki_lib'
|
17
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,spec}/**/*")
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler not available. Install it with: sudo gem install namelessjon-jeweler -s http://gems.github.com"
|
22
|
+
end
|
23
|
+
|
24
|
+
Rake::TestTask.new do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.pattern = 'spec/**/*_spec.rb'
|
27
|
+
t.verbose = false
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
rdoc.rdoc_dir = 'rdoc'
|
32
|
+
rdoc.title = 'wiki-lib'
|
33
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
34
|
+
rdoc.rdoc_files.include('README*')
|
35
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
36
|
+
end
|
37
|
+
|
38
|
+
Rcov::RcovTask.new do |t|
|
39
|
+
t.libs << "spec"
|
40
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
41
|
+
t.verbose = true
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :rcov
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module WikiLib
|
2
|
+
##
|
3
|
+
# Class for interacting with the PMWiki
|
4
|
+
class PMWiki
|
5
|
+
##
|
6
|
+
# Initializes a new PMWiki instance
|
7
|
+
#
|
8
|
+
# @param [String] base_page The base page of the wiki. Probably it's address, but could be a subset of the namespace
|
9
|
+
#
|
10
|
+
# @param [String] username Username used to sign off the edits
|
11
|
+
#
|
12
|
+
# @param [String] password Password used to make edits
|
13
|
+
def initialize(base_page, username, password)
|
14
|
+
@base = base_page
|
15
|
+
@pass = password
|
16
|
+
@user = username
|
17
|
+
@agent = ::WWW::Mechanize.new
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# returns a PMWiki page url
|
22
|
+
#
|
23
|
+
# @param [String] page The name of the page, relative to the base page
|
24
|
+
#
|
25
|
+
# @return [String] The URL
|
26
|
+
def page_url(page)
|
27
|
+
"#{@base}/#{page}"
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# returns a PMWiki page edit url
|
32
|
+
#
|
33
|
+
# @param [String] page The name of the page, relative to the base page
|
34
|
+
#
|
35
|
+
# @return [String] The URL
|
36
|
+
def edit_url(page)
|
37
|
+
"#{page_url(page)}?action=edit"
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Returns the edit text of a PMWiki page
|
42
|
+
#
|
43
|
+
# @param [String] page The page to get the edit text for
|
44
|
+
#
|
45
|
+
# @return [String] The edit text
|
46
|
+
def get_edit_text(page)
|
47
|
+
# get the form, logging in if nessessary
|
48
|
+
form = get_edit_form_with_login(edit_url(page))
|
49
|
+
|
50
|
+
# return the text
|
51
|
+
form['text']
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Returns the full page, parsed by hpricot
|
56
|
+
#
|
57
|
+
# @param [String] page Page to retrieve the raw text for
|
58
|
+
#
|
59
|
+
# @return [Hpricot::Doc] The parsed page
|
60
|
+
def get_page(page)
|
61
|
+
@agent.get(page_url(page))
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Uploads a page to the PM wiki, creating it if needed
|
66
|
+
#
|
67
|
+
# @param [String] page Page to create/update
|
68
|
+
#
|
69
|
+
# @param [String] text Text to place on the new page
|
70
|
+
#
|
71
|
+
# @param [String] summary Edit summary for the edit
|
72
|
+
#
|
73
|
+
# @param [TrueClass, FalseClass] minor tick the minor edit checkbox?
|
74
|
+
def upload_page(page, text, summary, minor=false)
|
75
|
+
# get the form, logging in if nessessary
|
76
|
+
form = get_edit_form_with_login(edit_url(page))
|
77
|
+
|
78
|
+
# fill out our form
|
79
|
+
form['text'] = text
|
80
|
+
form['csum'] = summary
|
81
|
+
form['author'] = @user
|
82
|
+
|
83
|
+
edit.checkboxes.first.check if minor
|
84
|
+
|
85
|
+
# upload
|
86
|
+
@agent.submit(form, form.buttons.first)
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# Deletes a PMWiki page (sets text to delete)
|
91
|
+
#
|
92
|
+
# @param [String] page The page to delete
|
93
|
+
#
|
94
|
+
# @param [String] summary The reason for deletion
|
95
|
+
def delete_page(page, summary)
|
96
|
+
upload_page(page, 'delete', summary)
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
def get_edit_form_with_login(url)
|
101
|
+
# fetch the page
|
102
|
+
page = @agent.get(url)
|
103
|
+
|
104
|
+
# if we find an authform, we are not logged in.
|
105
|
+
if form = page.forms.find { |f| f.name == 'authform' }
|
106
|
+
# fill in the password and submit
|
107
|
+
form['authpw'] = @pass
|
108
|
+
page = @agent.submit(form, form.buttons.first)
|
109
|
+
|
110
|
+
# if we still have an auth form, we're in trouble
|
111
|
+
raise(StandardError, "Authentication Failed") if page.forms.find { |f| f.name == 'authform' }
|
112
|
+
end
|
113
|
+
|
114
|
+
# by now, this should be the right page, so find the last form on it!
|
115
|
+
page.forms.last
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/lib/wiki_lib.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wiki_lib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Stott
|
8
|
+
autorequire: wiki_lib
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-24 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mechanize
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.9"
|
24
|
+
version:
|
25
|
+
description: |-
|
26
|
+
A simple library to wrap around some common wiki operations
|
27
|
+
Currently only PMWiki is supported, but more will be added as and when.
|
28
|
+
email: jonathan.stott@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- LICENSE
|
35
|
+
- README
|
36
|
+
files:
|
37
|
+
- LICENSE
|
38
|
+
- README
|
39
|
+
- Rakefile
|
40
|
+
- lib/wiki_lib.rb
|
41
|
+
- lib/wiki_lib/pm_wiki.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
- spec/wiki_lib_spec.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/namelessjon/wiki_lib
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --charset=UTF-8
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: A simple library to wrap around some common wiki operations
|
72
|
+
test_files:
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/wiki_lib_spec.rb
|