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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8804248602a257f65d7bb03f5d4d0518fd8f8163e329600951dde935a14e75dd
4
- data.tar.gz: 7bdee4a6fd2c8bac1a4df934b158090b08f0f2f987ef30d5d9e9a133d35a846a
3
+ metadata.gz: 9f48fba715db18e07cdc029e00b220546a50c6c9d799c213db2181e013253325
4
+ data.tar.gz: 9c35284b8a3c2fbfc8e1a1e3e641b32ec2fa9daaf4d22d4ec71fd459a7c4f811
5
5
  SHA512:
6
- metadata.gz: bae0a38db1d2c8c743256c461d79c8210c3183d9f3ac2e3eab625bfa7a2478868894a396445ea6f216de3d4c89feaf8dce58cc9981a63f94127bddfc8ab869f3
7
- data.tar.gz: 13535771dc81ed5876335f02e990c6315de5f1e44cdb4589eb1053979f975ddca2fe0ddd65fa1629df1652263e794ea08a9228051b7a5845c0f7b8f7101ca81f
6
+ metadata.gz: c9842af1c56699638cfd994230688ba4bbc359a225919a1bb4601a5662c69d353a7c4a7783e683b321db5cdc9c284bfcba1393f4945f34fe215d6a23c1fbb899
7
+ data.tar.gz: b46ed3289ed9bdf644f654caf1583d7889c1603cd861d6b447bbf83c8ac742da9463a9f7db7fbe3974e05abb9116720ccf7f3d32c6801c766290289ad143fc7c
@@ -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
- filenames.map { |fn| ["#{fn}.md", "#{fn}.html"] }.each do |md_fn, html_fn|
29
- contents = Tilt.new(md_fn).render
30
- File.open(File.join('html', html_fn), 'w') do |file|
31
- 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
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
@@ -22,7 +22,7 @@
22
22
  padding: 1rem;
23
23
  }
24
24
 
25
- p {
25
+ p, h1 {
26
26
  margin: 1rem 0;
27
27
  }
28
28
 
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.3
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: