Created
January 4, 2013 04:55
-
-
Save NuckChorris/4450029 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| require 'uri' | |
| require 'wikicloth' | |
| class Wikebooks < WikiCloth::Parser | |
| def initialize (opts) | |
| @root = URI.parse opts[:wiki] | |
| @url = @root.clone | |
| @url.query = "&action=raw&title=#{URI.encode opts[:article]}" | |
| @imgurl = @root.clone | |
| @imgurl.query = 'title=Special:FilePath' | |
| @conn = Net::HTTP.new @url.host, @url.port | |
| req = Net::HTTP::Get.new @url.request_uri | |
| res = @conn.request req | |
| opts[:data] = res.body | |
| super(opts) | |
| end | |
| def to_html (opts = {}) | |
| if opts[:noedit] != false | |
| opts[:noedit] = true | |
| end | |
| super(opts) | |
| end | |
| external_link do |url, text| | |
| "<a href=\"#{url}\">#{text || url}</a>" | |
| end | |
| link_for_resource do |thing, page| | |
| url = @imgurl.clone | |
| url.query << "&file=#{URI.escape page}" | |
| req = Net::HTTP::Get.new url.request_uri | |
| res = @conn.request req | |
| puts "RESOURCE [#{res.code} #{res.message}] #{page}" | |
| puts " ==> #{res['location']}" | |
| "<img src=\"img/#{page}\" class=\"\" />" | |
| end | |
| link_for do |page, text| | |
| text.nil? ? page : text | |
| end | |
| end | |
| Wikebooks.new( | |
| :wiki => "http://www.baka-tsuki.org/project/index.php", | |
| :article => "Sword Art Online:Volume 1 Chapter 3" | |
| ).to_html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment