any2html 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/any2html.gemspec +1 -1
- data/bin/any2html +32 -28
- metadata +1 -1
data/any2html.gemspec
CHANGED
data/bin/any2html
CHANGED
@@ -2,40 +2,44 @@
|
|
2
2
|
require 'bluecloth'
|
3
3
|
require 'RedCloth'
|
4
4
|
require 'sinatra'
|
5
|
+
require 'haml'
|
6
|
+
|
7
|
+
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
class Any2html < Sinatra::Application
|
10
|
+
map1 = {
|
11
|
+
BlueCloth => %w(md markdown),
|
12
|
+
RedCloth => %w(textile)
|
13
|
+
}
|
14
|
+
map2 = map1.invert.inject ({}) {|m, (k,v)| k.each{|k1| m[k1] = v};m}
|
15
|
+
rootdir = ARGV[0] || '.'
|
16
|
+
# TODO dry this up
|
17
|
+
files = `find #{rootdir} -name '*.md' -o -name '*.markdown' -o -name '*.textile' `.split(/\n/)
|
18
|
+
$sources = files.inject({}) do |m,file|
|
19
|
+
ext = File.extname(file)[1..-1]
|
20
|
+
if (formatter = map2[ext])
|
21
|
+
m[file.sub(/^\./,'')] = {
|
22
|
+
filepath: file,
|
23
|
+
formatter: formatter
|
24
|
+
}
|
25
|
+
end
|
26
|
+
m
|
23
27
|
end
|
24
|
-
m
|
25
|
-
end
|
26
28
|
|
27
|
-
|
29
|
+
get '/' do
|
30
|
+
haml :index
|
31
|
+
end
|
28
32
|
|
29
|
-
get '
|
30
|
-
|
31
|
-
|
33
|
+
get '*' do
|
34
|
+
file = params[:splat][0]
|
35
|
+
x = $sources[file]
|
36
|
+
x[:html] ||= x[:formatter].new(File.read(x[:filepath])).to_html
|
37
|
+
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
$sources[file][:html] ||= $sources[file][:formatter].new(File.read(file)).to_html
|
36
|
-
end
|
39
|
+
fork { system('open http://localhost:4567') }
|
40
|
+
run!
|
37
41
|
|
38
|
-
|
42
|
+
end
|
39
43
|
__END__
|
40
44
|
|
41
45
|
@@index
|