serve-markdown 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1edbb083cdd62ab0f2317c02629ec5060f8b1e9ef76f71b72e78b2c8268da302
4
+ data.tar.gz: 87caf4bb6ecd9691ec1d4c89ee093bd6b0cd2d9261cf534f34d7f6ba96b20bde
5
+ SHA512:
6
+ metadata.gz: bfac33440296c6d4881f498516147dbceb357899a60ee403331fbcaddda0dbe0319390e495f20489bb73594735980b084f7bea5f72650282cd7555220811b304
7
+ data.tar.gz: 2facffa84365faa1a461951db34fd62ae3d8ff6fc9d7eaaa772150136f747c6d96eb0b2a5be51aa429c0a4aefe2c1b3732b1b2a573f2aab2a96f587050d832aa
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'serve-markdown'
@@ -0,0 +1,22 @@
1
+ require 'erubi'
2
+ require 'tilt'
3
+ require 'fileutils'
4
+ require 'webrick'
5
+
6
+ FileUtils.remove_dir('html', force=true)
7
+ FileUtils.mkdir('html')
8
+
9
+ layout = Tilt.new(File.join(__dir__, 'templates/layout.html.erb'))
10
+ filenames = Dir['*.md'].map { |fn| fn[/(.*)\.md/, 1] } # removing the .md suffix from fns
11
+
12
+ filenames.map { |fn| ["#{fn}.md", "#{fn}.html"] }.each do |md_fn, html_fn|
13
+ contents = Tilt.new(md_fn).render
14
+ File.open(File.join('html', html_fn), 'w') do |file|
15
+ file.write layout.render(Object.new, contents: contents, filenames: filenames)
16
+ end
17
+ end
18
+
19
+ root = File.expand_path 'html'
20
+ server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
21
+ trap 'INT' do server.shutdown end
22
+ server.start
@@ -0,0 +1,50 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title></title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ section, article, aside, footer, header, nav {
15
+ display: block;
16
+ }
17
+
18
+ #grid {
19
+ display: grid;
20
+ grid-template: 1fr / max-content minmax(auto, 57ch);
21
+ grid-gap: 2rem;
22
+ padding: 1rem;
23
+ }
24
+
25
+ p {
26
+ margin: 1rem 0;
27
+ }
28
+
29
+ ul, ol {
30
+ margin-left: 1.5rem;
31
+ }
32
+
33
+ article > p:first-child {
34
+ margin-top: 0;
35
+ }
36
+ </style>
37
+ </head>
38
+ <body>
39
+ <main id='grid'>
40
+ <nav>
41
+ <% filenames.each do |fn| %>
42
+ <a href="<%= fn %>.html"><%= fn.gsub('_', ' ') %></a><br>
43
+ <% end %>
44
+ </nav>
45
+ <article>
46
+ <%= contents %>
47
+ </article>
48
+ </main>
49
+ </body>
50
+ </html>
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: serve-markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Radek Osmulski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: erubi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tilt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pandoc-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webrick
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ description: A simple solution for serving markdown files from current directory.
70
+ email: rosmulski@gmail.com
71
+ executables:
72
+ - serve-markdown
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - bin/serve-markdown
77
+ - lib/serve-markdown.rb
78
+ - lib/templates/layout.html.erb
79
+ homepage: https://rubygems.org/gems/serve-markdown
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.1.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Serve markdown files from current directory on localhost.
102
+ test_files: []