serve-markdown 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/serve-markdown.rb +19 -11
- data/lib/templates/layout.html.erb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f48fba715db18e07cdc029e00b220546a50c6c9d799c213db2181e013253325
|
4
|
+
data.tar.gz: 9c35284b8a3c2fbfc8e1a1e3e641b32ec2fa9daaf4d22d4ec71fd459a7c4f811
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9842af1c56699638cfd994230688ba4bbc359a225919a1bb4601a5662c69d353a7c4a7783e683b321db5cdc9c284bfcba1393f4945f34fe215d6a23c1fbb899
|
7
|
+
data.tar.gz: b46ed3289ed9bdf644f654caf1583d7889c1603cd861d6b447bbf83c8ac742da9463a9f7db7fbe3974e05abb9116720ccf7f3d32c6801c766290289ad143fc7c
|
data/lib/serve-markdown.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'fileutils'
|
3
1
|
require 'erubi'
|
4
2
|
require 'tilt'
|
5
3
|
require 'webrick'
|
6
4
|
require 'optparse'
|
5
|
+
require 'pathname'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'listen'
|
7
8
|
|
8
9
|
@options = {}
|
9
10
|
OptionParser.new do |opts|
|
@@ -17,21 +18,28 @@ OptionParser.new do |opts|
|
|
17
18
|
end
|
18
19
|
end.parse!
|
19
20
|
|
20
|
-
FileUtils.remove_dir('html', force=true)
|
21
|
-
FileUtils.mkdir('html')
|
22
|
-
|
23
21
|
layout_path = Pathname.new('templates/layout.html.erb').exist? ? 'templates/layout.html.erb' : File.join(__dir__, 'templates/layout.html.erb')
|
24
|
-
|
25
22
|
layout = Tilt.new(layout_path)
|
26
|
-
filenames = Dir['*.md'].map { |fn| fn[/(.*)\.md/, 1] } # removes the .md suffix from fns
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
generate_html = Proc.new do
|
25
|
+
FileUtils.remove_dir('html', force=true)
|
26
|
+
FileUtils.mkdir('html')
|
27
|
+
|
28
|
+
filenames = Dir['*.md'].map { |fn| fn[/(.*)\.md/, 1] } # removes the .md suffix from fns
|
29
|
+
|
30
|
+
filenames.map { |fn| ["#{fn}.md", "#{fn}.html"] }.each do |md_fn, html_fn|
|
31
|
+
contents = Tilt.new(md_fn).render
|
32
|
+
File.open(File.join('html', html_fn), 'w') do |file|
|
33
|
+
file.write layout.render(Object.new, contents: contents, filenames: filenames)
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
38
|
+
listener = Listen.to('.') do |modified, added ,removed|
|
39
|
+
generate_html.call
|
40
|
+
end
|
41
|
+
listener.start
|
42
|
+
|
35
43
|
root = File.expand_path 'html'
|
36
44
|
server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
|
37
45
|
trap 'INT' do server.shutdown end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serve-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radek Osmulski
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: listen
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
69
83
|
description: A simple solution for serving markdown files from current directory.
|
70
84
|
email: rosmulski@gmail.com
|
71
85
|
executables:
|