serve-markdown 0.0.2 → 0.0.8
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 +21 -9
- data/lib/templates/layout.html.erb +6 -2
- 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: 70f81ab3c392f8cef3f886f221c42c6ee423552d733479569908292265c9ec73
|
4
|
+
data.tar.gz: 74f9745faf51df7b27f7280d5a8f3e015667f7fce31eb89f1b413706ef11d366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f24f6c1008f9cbb5ce1fb74934bc730ae51f19a116f179c954c7ffa59ffa9b6087d979f3ce89c30c78507fedbec13dcc543226e2e2e0d1be1cf7ddc5b20146cc
|
7
|
+
data.tar.gz: a24d1b614fe6244f4846694c828cc54ce8846cdc449556ff67cdc7d0a0b07c2d801a31ed2bf9dbfe0f03620028d8989586c88654afaa475b43efa31a657b3ff8
|
data/lib/serve-markdown.rb
CHANGED
@@ -2,6 +2,9 @@ require 'erubi'
|
|
2
2
|
require 'tilt'
|
3
3
|
require 'webrick'
|
4
4
|
require 'optparse'
|
5
|
+
require 'pathname'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'listen'
|
5
8
|
|
6
9
|
@options = {}
|
7
10
|
OptionParser.new do |opts|
|
@@ -15,21 +18,30 @@ OptionParser.new do |opts|
|
|
15
18
|
end
|
16
19
|
end.parse!
|
17
20
|
|
18
|
-
FileUtils.remove_dir('html', force=true)
|
19
|
-
FileUtils.mkdir('html')
|
20
|
-
|
21
21
|
layout_path = Pathname.new('templates/layout.html.erb').exist? ? 'templates/layout.html.erb' : File.join(__dir__, 'templates/layout.html.erb')
|
22
|
-
|
23
22
|
layout = Tilt.new(layout_path)
|
24
|
-
filenames = Dir['*.md'].map { |fn| fn[/(.*)\.md/, 1] } # removes the .md suffix from fns
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
38
|
+
generate_html.call
|
39
|
+
|
40
|
+
listener = Listen.to('.', only: /\.md/) do |modified, added ,removed|
|
41
|
+
generate_html.call
|
42
|
+
end
|
43
|
+
listener.start
|
44
|
+
|
33
45
|
root = File.expand_path 'html'
|
34
46
|
server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
|
35
47
|
trap 'INT' do server.shutdown end
|
@@ -22,15 +22,19 @@
|
|
22
22
|
padding: 1rem;
|
23
23
|
}
|
24
24
|
|
25
|
+
h1, h2, h3, h4, h5, h6 {
|
26
|
+
margin: 1.5rem 0 0.75rem;
|
27
|
+
}
|
28
|
+
|
25
29
|
p {
|
26
|
-
margin:
|
30
|
+
margin: 0.5rem 0 0.25rem;
|
27
31
|
}
|
28
32
|
|
29
33
|
ul, ol {
|
30
34
|
margin-left: 1.5rem;
|
31
35
|
}
|
32
36
|
|
33
|
-
article >
|
37
|
+
article > :first-child {
|
34
38
|
margin-top: 0;
|
35
39
|
}
|
36
40
|
</style>
|
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.8
|
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:
|