Class: WikiLib::PMWiki
- Inherits:
-
Object
- Object
- WikiLib::PMWiki
- Defined in:
- lib/wiki_lib/pm_wiki.rb
Overview
Class for interacting with the PMWiki
Instance Method Summary collapse
-
#delete_page(page, summary) ⇒ Object
Deletes a PMWiki page (sets text to delete).
-
#edit_url(page) ⇒ String
returns a PMWiki page edit url.
-
#get_edit_text(page) ⇒ String
Returns the edit text of a PMWiki page.
-
#get_page(page) ⇒ Hpricot::Doc
Returns the full page, parsed by hpricot.
-
#initialize(base_page, username, password) ⇒ PMWiki
constructor
Initializes a new PMWiki instance.
-
#page_url(page) ⇒ String
returns a PMWiki page url.
-
#upload_page(page, text, summary, minor = false) ⇒ Object
Uploads a page to the PM wiki, creating it if needed.
Constructor Details
#initialize(base_page, username, password) ⇒ PMWiki
Initializes a new PMWiki instance
15 16 17 18 19 20 |
# File 'lib/wiki_lib/pm_wiki.rb', line 15 def initialize(base_page, username, password) @base = base_page @pass = password @user = username @agent = ::Mechanize.new end |
Instance Method Details
#delete_page(page, summary) ⇒ Object
Deletes a PMWiki page (sets text to delete)
97 98 99 |
# File 'lib/wiki_lib/pm_wiki.rb', line 97 def delete_page(page, summary) upload_page(page, 'delete', summary) end |
#edit_url(page) ⇒ String
returns a PMWiki page edit url
38 39 40 |
# File 'lib/wiki_lib/pm_wiki.rb', line 38 def edit_url(page) "#{page_url(page)}?action=edit" end |
#get_edit_text(page) ⇒ String
Returns the edit text of a PMWiki page
48 49 50 51 52 53 54 |
# File 'lib/wiki_lib/pm_wiki.rb', line 48 def get_edit_text(page) # get the form, logging in if nessessary form = get_edit_form_with_login(edit_url(page)) # return the text form['text'] end |
#get_page(page) ⇒ Hpricot::Doc
Returns the full page, parsed by hpricot
62 63 64 |
# File 'lib/wiki_lib/pm_wiki.rb', line 62 def get_page(page) @agent.get(page_url(page)) end |
#page_url(page) ⇒ String
returns a PMWiki page url
28 29 30 |
# File 'lib/wiki_lib/pm_wiki.rb', line 28 def page_url(page) "#{@base}/#{page}" end |
#upload_page(page, text, summary, minor = false) ⇒ Object
Uploads a page to the PM wiki, creating it if needed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/wiki_lib/pm_wiki.rb', line 76 def upload_page(page, text, summary, minor=false) # get the form, logging in if nessessary form = get_edit_form_with_login(edit_url(page)) # fill out our form form['text'] = text form['csum'] = summary form['author'] = @user edit.checkboxes.first.check if minor # upload @agent.submit(form, form..first) end |