Sha256: 82602e8c160be47aa43483cadd5a5358888eb8c229d36001c8abe804ce77a478

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require File.join(File.dirname(__FILE__),'init')
include WikiCloth

class WikiParser < WikiCloth::Parser

  include_resource do |resource,options|
    case resource
    when "date"
      Time.now.to_s
    else
      params[resource].nil? ? "" : params[resource]
    end
  end

  url_for do |page|
    "javascript:alert('You clicked on: #{page}');"
  end

  link_attributes_for do |page|
    { :href => url_for(page) }
  end

end

@wiki = WikiCloth::Parser.new({ 
  :data => "\n  {{test}}\n\n<nowiki>{{test}}</nowiki> ''Hello {{test}}!''\n",
  :params => { "test" => "World" } })
puts @wiki.to_html

@wiki = WikiParser.new({ 
  :params => { "PAGENAME" => "Testing123" }, 
  :data => "[[Hello World]] From {{ PAGENAME }} on {{ date }}" 
})
puts @wiki.to_html

Dir.glob("sample_documents/*.wiki").each do |x|

  start_time = Time.now
  out_name = "#{x}.html"
  data = File.open(x, READ_MODE) { |x| x.read }

  tmp = WikiCloth::Parser.new({
    :data => data,
    :params => { "PAGENAME" => "HelloWorld" }
  })
  out = tmp.to_html
  out = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" dir=\"ltr\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><link rel=\"stylesheet\" href=\"default.css\" type=\"text/css\" /></head><body>#{out}</body></html>"

  File.open(out_name, "w") { |x| x.write(out) }
  end_time = Time.now
  puts "#{out_name}: Completed (#{end_time - start_time} sec) | External Links: #{tmp.external_links.size} -- References: #{tmp.references.size}"

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wikicloth-0.8.3 run_tests.rb
wikicloth-0.8.2 run_tests.rb
wikicloth-0.8.1 run_tests.rb
wikicloth-0.8.0 run_tests.rb
wikicloth-0.7.1 run_tests.rb
wikicloth-0.6.3 run_tests.rb