any2html 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/any2html.gemspec +1 -1
  2. data/bin/any2html +29 -20
  3. metadata +1 -1
@@ -5,7 +5,7 @@ require 'any2html'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "any2html"
8
- s.version = '0.0.4'
8
+ s.version = '0.0.5'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.required_ruby_version = '>= 1.9.0'
11
11
 
@@ -6,26 +6,31 @@ require 'haml'
6
6
  require 'textile_extensions'
7
7
  RedCloth.send(:include, RailsGuides::TextileExtensions)
8
8
 
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
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
- x[:html] ||= x[:formatter].new(File.read(x[:filepath])).to_html
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: any2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: