any2html 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/any2html.gemspec +1 -1
- data/bin/any2html +29 -20
- metadata +1 -1
data/any2html.gemspec
CHANGED
data/bin/any2html
CHANGED
@@ -6,26 +6,31 @@ require 'haml'
|
|
6
6
|
require 'textile_extensions'
|
7
7
|
RedCloth.send(:include, RailsGuides::TextileExtensions)
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
9
|
+
map1 = {
|
10
|
+
->(x){BlueCloth.new(x).to_html} => %w(md markdown),
|
11
|
+
->(x){
|
12
|
+
t = RedCloth.new(x)
|
13
|
+
t.hard_breaks = false
|
14
|
+
t.to_html(:notestuff, :plusplus, :code)
|
15
|
+
} => %w(textile)
|
16
|
+
}
|
17
|
+
map2 = map1.invert.inject ({}) {|m, (k,v)| k.each{|k1| m[k1] = v};m}
|
18
|
+
rootdir = ARGV[0] || '.'
|
19
|
+
# TODO dry this up
|
20
|
+
files = `find #{rootdir.sub(/\/$/, '')} -name '*.md' -o -name '*.markdown' -o -name '*.textile' `.split(/\n/)
|
21
|
+
$sources = files.inject({}) do |m,file|
|
22
|
+
ext = File.extname(file)[1..-1]
|
23
|
+
if (formatter = map2[ext])
|
24
|
+
m[file.sub(/^\./,'')] = {
|
25
|
+
filepath: file,
|
26
|
+
formatter: formatter
|
27
|
+
}
|
27
28
|
end
|
29
|
+
m
|
30
|
+
end
|
28
31
|
|
32
|
+
|
33
|
+
class Any2html < Sinatra::Application
|
29
34
|
get '/' do
|
30
35
|
haml :index
|
31
36
|
end
|
@@ -33,10 +38,14 @@ class Any2html < Sinatra::Application
|
|
33
38
|
get '*' do
|
34
39
|
file = params[:splat][0]
|
35
40
|
x = $sources[file]
|
36
|
-
|
41
|
+
if x
|
42
|
+
x[:html] ||= x[:formatter].call(File.read(x[:filepath]))
|
43
|
+
else
|
44
|
+
"No content for #{x.inspect}"
|
45
|
+
end
|
37
46
|
end
|
38
47
|
|
39
|
-
fork { system('open http://localhost:4567') }
|
48
|
+
fork { system('open http://localhost:4567 &') }
|
40
49
|
run!
|
41
50
|
|
42
51
|
end
|