Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some code for html export

  • Loading branch information...
commit 2002a81934e09c3d93db98968b088a0a7970633f 1 parent d78e9fa
@danchoi authored
View
2  Gemfile
@@ -1,4 +1,2 @@
source :rubygems
-gem "couchrest"
-gem "sinatra"
gem "haml"
View
15 Gemfile.lock
@@ -1,25 +1,10 @@
GEM
remote: http://rubygems.org/
specs:
- couchrest (1.0.1)
- json (>= 1.4.6)
- mime-types (>= 1.15)
- rest-client (>= 1.5.1)
haml (3.0.25)
- json (1.5.1)
- mime-types (1.16)
- rack (1.2.1)
- rest-client (1.6.1)
- mime-types (>= 1.16)
- sinatra (1.1.2)
- rack (~> 1.1)
- tilt (~> 1.2)
- tilt (1.2.2)
PLATFORMS
ruby
DEPENDENCIES
- couchrest
haml
- sinatra
View
6 lib/export_template.html.haml
@@ -0,0 +1,6 @@
+!!!
+%html
+ %head
+ %body
+ %h2= title
+ %pre= body
View
14 lib/soywiki.rb
@@ -3,9 +3,10 @@
module Soywiki
VERSION = '0.2.2'
WIKI_WORD = /\b([a-z][\w_]+\.)?[A-Z][a-z]+[A-Z]\w*\b/
-
+ HYPERLINK = %r|\bhttps?://[^ >)\n\]]+|
def self.run
+ puts ARGV.inspect
if %W( -v --version -h --help).include?(ARGV.first)
puts "soywiki #{Soywiki::VERSION}"
puts "by Daniel Choi dhchoi@gmail.com"
@@ -23,6 +24,7 @@ def self.run
exit
elsif ARGV.first == '--html'
self.html_export
+ exit
else
vim = ENV['SOYWIKI_VIM'] || 'vim'
vimscript = File.expand_path("../soywiki.vim", __FILE__)
@@ -33,12 +35,10 @@ def self.run
def self.html_export
require 'soywiki/html'
- Dir["*/*"].each do |file|
- if file.gsub("/", '.') =~ WIKI_WORD
- html = Soywiki::Html.generate( File.read(file) )
- puts html
- end
-
+ Html.export
end
end
+if __FILE__ == $0
+ Soywiki.run
+end
View
2  lib/soywiki.vim
@@ -4,8 +4,6 @@
" This regex matches namedspaced WikiWords and unqualified WikiWords
let s:wiki_link_pattern = '\C\m\<\([a-z][[:alnum:]_]\+\.\)\?[A-Z][a-z]\+[A-Z]\w*\>'
-
-
let s:http_link_pattern = 'https\?:[^ >)\]]\+'
let s:rename_links_command = 'soywiki-rename '
let s:find_pages_linking_in_command = 'soywiki-pages-linking-in '
View
62 lib/soywiki/html.rb
@@ -1,7 +1,65 @@
+require 'haml'
module Soywiki
- class Html
- def initialize(text)
+ module Html
+
+ def self.href_wiki_links(text)
+ text = text.gsub(WIKI_WORD) {|match|
+ href = if match =~ /\w\./ # namespace
+ "../#{match.gsub(".", "/")}.html"
+ else
+ match + '.html'
+ end
+ %{<a href="#{href}">#{match}</a>}
+ }
+ return text
+ end
+
+ def self.href_hyperlinks(text)
+ text = text.gsub(HYPERLINK) {|match|
+ %{<a href="#{match}">#{match}</a>}
+ }
+ return text
+ end
+
+ def self.process(t)
+ href_hyperlinks(href_wiki_links(t))
+ end
+
+ def self.generate(text)
+ title = text.split("\n")[0]
+ body = process(text.split("\n")[1..-1].join("\n").strip)
+ template = File.read(File.join(File.dirname(__FILE__), '..', 'export_template.html.haml'))
+ Haml::Engine.new(template).render(nil, :body => body, :title => title)
end
+ # index.html has a list of all the pages
+ def self.index_page
+ end
+
+ # make an index.html for each subdir?
+ # Or use main?
+
+ # TODO put sidebar with basic nav
+
+ def self.export
+ target_dir = "html"
+ `mkdir -p #{target_dir}`
+ `rm -rf #{target_dir}/*`
+ Dir["*/*"].each do |file|
+ next if file =~ /^html\//
+ if file.gsub("/", '.') =~ WIKI_WORD
+ subdir = target_dir + '/' + file.split('/')[0]
+ `mkdir -p #{subdir}`
+ outfile = target_dir + '/' + file + '.html'
+ html = Soywiki::Html.generate( File.read(file) )
+ File.open(outfile, 'w') {|f| f.write html}
+ puts "Writing #{outfile}"
+ end
+ end
+
+ end
+
+
end
end
+
View
2  soywiki.gemspec
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency 'couchrest'
+ s.add_dependency 'haml'
end
Please sign in to comment.
Something went wrong with that request. Please try again.