serve-markdown 0.0.1 → 0.0.7

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: 1edbb083cdd62ab0f2317c02629ec5060f8b1e9ef76f71b72e78b2c8268da302
4
- data.tar.gz: 87caf4bb6ecd9691ec1d4c89ee093bd6b0cd2d9261cf534f34d7f6ba96b20bde
3
+ metadata.gz: 6cdd5ff50d5415aa6dac398268d2d7eea6f3d22b2278cd36ba056efe6a54902f
4
+ data.tar.gz: 7becb1de2232c60840e33c98ee44640f398e0acac83e1865ecc5dca6203c91a2
5
5
  SHA512:
6
- metadata.gz: bfac33440296c6d4881f498516147dbceb357899a60ee403331fbcaddda0dbe0319390e495f20489bb73594735980b084f7bea5f72650282cd7555220811b304
7
- data.tar.gz: 2facffa84365faa1a461951db34fd62ae3d8ff6fc9d7eaaa772150136f747c6d96eb0b2a5be51aa429c0a4aefe2c1b3732b1b2a573f2aab2a96f587050d832aa
6
+ metadata.gz: 995cd7c64860c8e36514dfa90c11ad5e3423395328a399b48afba3b06c5c3c3db55a63b430990dc8528b22601dd4c69aacbe1b97a59b28486c19ab1da1573a45
7
+ data.tar.gz: 1127aadd5352f85df09e757e0660b55ccfffedc1dac3ce4bdca8f7c746521e7458e44e6d08b110a60b200eb62a2581874731a05ad0b90f569a63a4c169d36921
@@ -1,21 +1,47 @@
1
1
  require 'erubi'
2
2
  require 'tilt'
3
- require 'fileutils'
4
3
  require 'webrick'
4
+ require 'optparse'
5
+ require 'pathname'
6
+ require 'fileutils'
7
+ require 'listen'
8
+
9
+ @options = {}
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: markdown-serve [options]"
12
+ opts.on("-h", "--help", "Prints this help") do
13
+ puts opts; exit
14
+ end
15
+
16
+ opts.on("-o", "--output-templates", "Output templates to local directory") do
17
+ FileUtils.cp_r File.join(__dir__, 'templates'), '.'; exit
18
+ end
19
+ end.parse!
20
+
21
+ layout_path = Pathname.new('templates/layout.html.erb').exist? ? 'templates/layout.html.erb' : File.join(__dir__, 'templates/layout.html.erb')
22
+ layout = Tilt.new(layout_path)
5
23
 
6
- FileUtils.remove_dir('html', force=true)
7
- FileUtils.mkdir('html')
24
+ generate_html = Proc.new do
25
+ FileUtils.remove_dir('html', force=true)
26
+ FileUtils.mkdir('html')
8
27
 
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
28
+ filenames = Dir['*.md'].map { |fn| fn[/(.*)\.md/, 1] } # removes the .md suffix from fns
11
29
 
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)
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
16
35
  end
17
36
  end
18
37
 
38
+ generate_html.call
39
+
40
+ listener = Listen.to('.') do |modified, added ,removed|
41
+ generate_html.call
42
+ end
43
+ listener.start
44
+
19
45
  root = File.expand_path 'html'
20
46
  server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
21
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.1
4
+ version: 0.0.7
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: