mdexport 0.0.4 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/mdexport +1 -1
- data/lib/file.rb +9 -0
- data/lib/mdexport.rb +108 -57
- data/lib/string.rb +1 -1
- metadata +22 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c04a31d10dcad1ab0c7e39c781c4a2311edb0495
|
4
|
+
data.tar.gz: 076fa1ea74a9bd53fdd57e0b4e41c141ef0b95b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b615f810e58e15004eacb010c5c4dc6b698da8a44a8c4e9a7de81946948b915dfdab0022a7210b5ca0c35487b89671f0170064ae17d7304613a61c807de9de7
|
7
|
+
data.tar.gz: 0820c5d8afe7e82ef7fa96afbcfa7e56fa22c5534ededd6dbc93859160bc731dc7cdc404e68507c96da693668a0dbce45a351e547d97ba57514915fd2dffa4ea
|
data/bin/mdexport
CHANGED
data/lib/file.rb
ADDED
data/lib/mdexport.rb
CHANGED
@@ -1,93 +1,144 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'fileutils'
|
4
3
|
require 'filewatcher'
|
5
4
|
require 'string'
|
5
|
+
require 'file'
|
6
6
|
require 'markdown'
|
7
7
|
require 'mustache'
|
8
|
+
require 'commander'
|
9
|
+
require 'rubygems'
|
8
10
|
|
9
11
|
class Mdexport
|
12
|
+
include Commander::Methods
|
10
13
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
def run
|
15
|
+
program :name, 'mdexport'
|
16
|
+
program :version, '0.0.5'
|
17
|
+
program :description, 'mdexport is a command line that exports markdown files into html files.'
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
default_command :run
|
20
|
+
|
21
|
+
command :run do |c|
|
22
|
+
c.syntax = 'mdexport [--path /path/to/folder] [--watch] [--clean] [--output /path/to/output_file]'
|
23
|
+
c.description = 'Exports the markdown files from folder to html files.'
|
24
|
+
c.option '--path STRING', String, 'Path to folder that contains the markdown files.'
|
25
|
+
c.option '--output STRING', String, 'Path to output file.'
|
26
|
+
c.option '--watch', 'Watch markdown file changes.'
|
27
|
+
c.option '--clean', 'Clean html files on folder.'
|
28
|
+
c.option '--merge', 'Merge markdown files in a given output file.'
|
29
|
+
|
30
|
+
c.action do |args, opt|
|
31
|
+
opt.default :path => '.'
|
32
|
+
opt.default :output => nil
|
33
|
+
opt.default :watch => false
|
34
|
+
opt.default :clean => false
|
35
|
+
opt.default :merge => false
|
22
36
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
37
|
+
opt.path = File.expand_path opt.path
|
38
|
+
opt.output = File.expand_path opt.output if opt.output
|
39
|
+
|
40
|
+
check_path(opt.path)
|
41
|
+
#check_path(opt.output) if opt.output
|
27
42
|
|
28
|
-
if
|
29
|
-
|
30
|
-
|
43
|
+
error "Incompatible params: merge, output." if opt.merge == true && opt.output == nil
|
44
|
+
error "Incompatible params: clean, watch." if opt.clean == true && opt.watch == true
|
45
|
+
error "Incompatible params: output, watch." if opt.output != nil && opt.watch == true
|
46
|
+
|
47
|
+
process opt.path, opt.clean, opt.watch, opt.output, opt.merge
|
31
48
|
end
|
32
49
|
end
|
50
|
+
|
51
|
+
run!
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def check_path(path)
|
57
|
+
error "Invalid path '#{path}'." unless File.exist?(path)
|
58
|
+
end
|
59
|
+
|
60
|
+
def error(message)
|
61
|
+
puts message; exit 1
|
62
|
+
end
|
33
63
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
pattern = "#{folder}/**/*.md"
|
64
|
+
def process(path, clean, watch, output, merge)
|
65
|
+
extension = clean ? "html" : "md"
|
66
|
+
pattern = "#{path}/**/*.#{extension}"
|
39
67
|
|
40
68
|
files = Dir[pattern] || Array.new
|
41
69
|
|
42
70
|
if files.size == 0
|
43
|
-
|
71
|
+
type = clean ? "html" : "markdown"
|
72
|
+
error "There is no #{type} files to process."
|
44
73
|
end
|
45
|
-
|
74
|
+
|
75
|
+
content = ""
|
76
|
+
|
46
77
|
files.each do |file_path|
|
47
|
-
if
|
48
|
-
|
49
|
-
FileUtils.rm(html_file) if File.exist?(html_file)
|
78
|
+
if clean
|
79
|
+
File.remove(file_path)
|
50
80
|
else
|
51
|
-
|
81
|
+
file_content = File.read(file_path)
|
82
|
+
|
83
|
+
if merge
|
84
|
+
content += file_content
|
85
|
+
else
|
86
|
+
content += Markdown.render(file_content)
|
87
|
+
end
|
88
|
+
|
89
|
+
unless output
|
90
|
+
generate_html(content, file_path.html)
|
91
|
+
content = ""
|
92
|
+
end
|
52
93
|
end
|
53
94
|
end
|
54
95
|
|
55
|
-
if
|
56
|
-
|
57
|
-
|
58
|
-
|
96
|
+
if output != nil
|
97
|
+
generate_file(content, output)
|
98
|
+
end
|
99
|
+
|
100
|
+
if watch
|
101
|
+
FileWatcher.new(pattern).watch do |file_path, event|
|
102
|
+
if [:changed, :new].include? event
|
103
|
+
file_content = File.read(file_path)
|
104
|
+
content = Markdown.render(file_content)
|
105
|
+
generate_html(content, file_path.html)
|
106
|
+
refresh_page(file_path.basename)
|
107
|
+
elsif event.to_sym == :delete
|
108
|
+
File.remove(file_path.html)
|
109
|
+
end
|
59
110
|
end
|
60
111
|
end
|
61
112
|
end
|
62
113
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
repeat with aWindow in windowList
|
68
|
-
set tabList to every tab of aWindow
|
69
|
-
repeat with atab in tabList
|
70
|
-
if (URL of atab contains "#{keyword}") then
|
71
|
-
tell atab to do javascript "window.location.reload()"
|
72
|
-
end if
|
73
|
-
end repeat
|
74
|
-
end repeat
|
75
|
-
end tell
|
76
|
-
ENDGAME
|
77
|
-
}
|
114
|
+
def refresh_page keyword
|
115
|
+
template = File.read("lib/templates/refresh.mustache")
|
116
|
+
command = Mustache.render(template, :keyword => keyword)
|
117
|
+
system(command)
|
78
118
|
end
|
79
|
-
|
80
|
-
def self.generate_html_for(file_path)
|
81
|
-
file_content = File.read(file_path)
|
82
|
-
html_body = Markdown.render(file_content)
|
83
119
|
|
84
|
-
|
120
|
+
def generate_html(content, path)
|
121
|
+
title = get_title(content) || path.basename
|
122
|
+
|
85
123
|
template = File.read("lib/templates/page.mustache")
|
86
|
-
content = Mustache.render(template, :title => title, :yield =>
|
124
|
+
content = Mustache.render(template, :title => title, :yield => content)
|
125
|
+
|
126
|
+
generate_file(content, path)
|
127
|
+
end
|
128
|
+
|
129
|
+
def generate_file(content, path)
|
130
|
+
File.remove(path)
|
131
|
+
File.write(path, content)
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_title(content)
|
135
|
+
title = nil
|
87
136
|
|
88
|
-
|
89
|
-
|
90
|
-
|
137
|
+
if content =~ /<[hH][1-6].*?>(\w.*?)<\/.*?[hH][1-6]>/
|
138
|
+
title = Regexp.last_match[1]
|
139
|
+
end
|
140
|
+
|
141
|
+
title
|
91
142
|
end
|
92
143
|
|
93
144
|
end # end class
|
data/lib/string.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdexport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Madson Cardoso
|
@@ -38,6 +38,26 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.6.8
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: commander
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.3'
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 4.3.4
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '4.3'
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 4.3.4
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: mustache
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,6 +107,7 @@ extensions: []
|
|
87
107
|
extra_rdoc_files: []
|
88
108
|
files:
|
89
109
|
- bin/mdexport
|
110
|
+
- lib/file.rb
|
90
111
|
- lib/markdown.rb
|
91
112
|
- lib/mdexport.rb
|
92
113
|
- lib/string.rb
|