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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c691699f2e33e8a596ef9116689833a5a4c0c93691729c499f7da428b97118b
4
- data.tar.gz: 683a16bde104677e77da09d5b5d74ecf5dd154b7fceaabcd6c2bab33af9f1cb7
3
+ metadata.gz: 70f81ab3c392f8cef3f886f221c42c6ee423552d733479569908292265c9ec73
4
+ data.tar.gz: 74f9745faf51df7b27f7280d5a8f3e015667f7fce31eb89f1b413706ef11d366
5
5
  SHA512:
6
- metadata.gz: 2569839ff4f92d7149c88885f75c89280600e567635a70db4295a8d9e43fc20860f4b0d443d28c6a117724db63a3ee4e54cb4b81822ff80b6668820db12488ac
7
- data.tar.gz: 6868251b6ce37557733cc453c3b5ff71d4258e31bef70ae16fb3c8e8e550b9a60cd9cea49f9e6b8422dab896e506f8f32c61ae25fb54bc91c0f015d68ceac3a6
6
+ metadata.gz: f24f6c1008f9cbb5ce1fb74934bc730ae51f19a116f179c954c7ffa59ffa9b6087d979f3ce89c30c78507fedbec13dcc543226e2e2e0d1be1cf7ddc5b20146cc
7
+ data.tar.gz: a24d1b614fe6244f4846694c828cc54ce8846cdc449556ff67cdc7d0a0b07c2d801a31ed2bf9dbfe0f03620028d8989586c88654afaa475b43efa31a657b3ff8
@@ -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
- filenames.map { |fn| ["#{fn}.md", "#{fn}.html"] }.each do |md_fn, html_fn|
27
- contents = Tilt.new(md_fn).render
28
- File.open(File.join('html', html_fn), 'w') do |file|
29
- file.write layout.render(Object.new, contents: contents, filenames: filenames)
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: 1rem 0;
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 > p:first-child {
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.2
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: