ghpreview 0.0.1 → 0.0.2
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.
- data/lib/ghpreview/previewer.rb +9 -5
- data/lib/ghpreview/version.rb +1 -1
- metadata +1 -1
data/lib/ghpreview/previewer.rb
CHANGED
|
@@ -14,6 +14,7 @@ module GHPreview
|
|
|
14
14
|
@md_filepath = md_filepath
|
|
15
15
|
@md_filename = md_filepath.split('/').last
|
|
16
16
|
@md_filedir = md_filepath.split('/').unshift('.').uniq[0..-2].join('/')
|
|
17
|
+
@http = HTTPClient.new
|
|
17
18
|
generate_template_with_fingerprinted_stylesheet_links
|
|
18
19
|
|
|
19
20
|
options[:watch] ? listen : open
|
|
@@ -31,22 +32,25 @@ module GHPreview
|
|
|
31
32
|
html = markdown_to_html
|
|
32
33
|
html = wrap_content_with_full_document(html)
|
|
33
34
|
File.open(HTML_FILEPATH, 'w') { |f| f << html }
|
|
34
|
-
|
|
35
|
+
if RUBY_PLATFORM =~ /linux/
|
|
36
|
+
command = 'xdg-open'
|
|
37
|
+
else
|
|
38
|
+
command = 'open'
|
|
39
|
+
end
|
|
40
|
+
`#{command} #{HTML_FILEPATH}`
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
private
|
|
38
44
|
|
|
39
45
|
def markdown_to_html
|
|
40
46
|
markdown = File.read(@md_filepath)
|
|
41
|
-
|
|
42
|
-
message = client.post API_URI, body: markdown, header: {'Content-Type' => 'text/plain'}
|
|
47
|
+
message = @http.post API_URI, body: markdown, header: {'Content-Type' => 'text/plain'}
|
|
43
48
|
message.body
|
|
44
49
|
end
|
|
45
50
|
|
|
46
51
|
def generate_template_with_fingerprinted_stylesheet_links
|
|
47
52
|
if stale_template?(STYLED_TEMPLATE_FILEPATH)
|
|
48
|
-
|
|
49
|
-
stylesheet_links = uri.read.split("\n").select do |line|
|
|
53
|
+
stylesheet_links = @http.get(HOMEPAGE).body.split("\n").select do |line|
|
|
50
54
|
line =~ /https:.*github.*\.css/
|
|
51
55
|
end.join
|
|
52
56
|
|
data/lib/ghpreview/version.rb
CHANGED