mdopen 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/mdopen.rb +11 -7
  3. data/lib/mdopen/version.rb +1 -1
  4. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0e59eb873a884be0c8deb48888c4067aa3d9cfe6
4
- data.tar.gz: f46cb2dbd470217c55248f7e4f4f05759ca19331
2
+ SHA256:
3
+ metadata.gz: 2269634ac426dc7e2850c5df8bcb7ba19f312ea618f182bc51d8b229235df18b
4
+ data.tar.gz: 79c5d03e4c8d811c3625bf9eff9abec4567c470aeb66c2fff77a9bc4a3e5d71b
5
5
  SHA512:
6
- metadata.gz: 41becfc2f69aa54d628fdda51e1ba9ec77e4ceb010f40b2d914fe4d2162a0bc226c29baa6b12e4a8f3b0891b90aadb03e073dee53f5ec81626c8e553b0dc36de
7
- data.tar.gz: d4315ee964fc4d3e1f80b50245b245d6222dc81d2ae3efd719f57360cea537c10197d124b8228511879fb0344b2e1dc1d5f3bfbb775222fff1fead65ae883afd
6
+ metadata.gz: 4c8a3e8b1d8e9b215b37b5b6bc5538e4f1d9ae75e76c4c92763d54506ffe7ebee639591bc13f19e6ea1ba02b1e4edc52cd13252d47097d0f802b756f78af002e
7
+ data.tar.gz: 7eb80bb5adf92c4eca17234d46aa5177c69a31a12d265a6c939f67f72c0b683e806672712a0074ea3ebec54c496b062c9ff26fb7e5824c7a0955e554a85f5a54
@@ -8,16 +8,18 @@ module Mdopen
8
8
  class << self
9
9
  def preview(md_file)
10
10
  content = md2html(md_file)
11
- html_file_path = tmp_path
12
- erb_render(content, html_file_path)
11
+ tmp_file = new_tmpfile
12
+ html_file_path = tmp_file.path
13
+ erb_render(content, tmp_file)
13
14
  system "#{open_cmd} file://#{html_file_path}"
14
15
  end
15
16
 
16
- def erb_render(content, html_file_path)
17
+ def erb_render(content, tmp_file)
17
18
  template_path = File.join(__dir__, 'templates/github.html.erb')
18
19
  template = Tilt::ERBTemplate.new(template_path)
19
20
  output = template.render(self, content: content)
20
- File.write(html_file_path, output)
21
+ tmp_file.write(output)
22
+ tmp_file.close
21
23
  end
22
24
 
23
25
  def md2html(md_file)
@@ -45,10 +47,12 @@ module Mdopen
45
47
  end
46
48
  end
47
49
 
48
- def tmp_path
50
+ def new_tmpfile
49
51
  filename = tmp_filename
50
- tmp = Tempfile.new([filename, ".html"])
51
- tmp.path
52
+ tmp_file = Tempfile.new([filename, '.html'])
53
+ # prevent tempfile from deleting by GC
54
+ ObjectSpace.undefine_finalizer(tmp_file)
55
+ tmp_file
52
56
  end
53
57
 
54
58
  def tmp_filename
@@ -1,3 +1,3 @@
1
1
  module Mdopen
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdopen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - B1nj0y
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-15 00:00:00.000000000 Z
11
+ date: 2019-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: os
@@ -116,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.5.2
119
+ rubygems_version: 3.0.3
121
120
  signing_key:
122
121
  specification_version: 4
123
122
  summary: mdopen is a command to preview a markdown file.