github-markdown-server 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f1f3e1b6c0b783128c49522e43ed9a0adad443c
4
- data.tar.gz: 9b81373d11efa51e007e87e495ad1a65fecc640a
3
+ metadata.gz: b494d220af9950651041ea55cf4d4b20280ced3e
4
+ data.tar.gz: 7e6c5f2599a92bd9a76d2b068458d2d1eee31dae
5
5
  SHA512:
6
- metadata.gz: 6c6de876abe5323c3fcb788827e2a76c9c244da3afa336ea5fdb649c5aeaee12bb28dec649a43563ed95df8724f3c733c27a7228631ca016eb63b3c01e884b95
7
- data.tar.gz: a998e171e149d42f06941a553335791c7faeb70f20570616e61f87f18c7863678d12f3c36d3d1dd977ce3d8df18b968814e8d73f6e46a8e24ac143c51fb1b0f9
6
+ metadata.gz: 13a669ea9878cd574e06cd36b33f8468032c0ceb5741e947caa8a6f033fa40bb0070ded07f419dd558265dd3db8be3792104a1458311401123259bd991dcd938
7
+ data.tar.gz: 09fe4e4def06aa10f73b1b7028ce9a7375c6a477e513c26f0427da45a1fc7dec98fb0fbc846824d8f696b6a38a303a95ae3a13beffc668a31f6a4914230c44aa
data/README.md CHANGED
@@ -13,12 +13,16 @@ github-markdown-server README.md
13
13
 
14
14
  This will start a server serving in the current directory and all child directories and open a browser (on a mac) showing README.md converted to html. If you navigate to a directory name only child directories and .md files are shown in a directory listing. If there is a README.md file in that directory it will be appended to the directory listing.
15
15
 
16
+ If you are deep down inside a git repository and you want to serve the whole repository (so that relative links will work) then this command will do that for you.
17
+
18
+ ```shell
19
+ github-markdown-server -d $(git rev-parse --show-toplevel) somefile.md
20
+ ```
21
+
16
22
  ## Contrib
17
23
 
18
24
  There is a [contrib](contrib/) directory with an emacs lisp file which will start a server and open a file for you. It'll keep track of which servers it has started and reuse an existing server if a file you want to preview is under that server's serving directory.
19
25
 
20
- There is also a small python script (called `p`) which will work with files and produce paths and urls.
21
-
22
26
  ## Contributing
23
27
 
24
28
  Please feel free to send me pull requests! This is my first Ruby project and it always feels like my first time when I write Emacs Lisp.
@@ -9,11 +9,14 @@
9
9
 
10
10
  (defvar github-markdown-servers '() "The servers we have running.")
11
11
  (defvar github-markdown-server-port 7494 "The next available server port.")
12
+ (defvar github-markdown-server-browser "Google Chrome" "Application to use with osx's open -a to open files.")
12
13
 
13
14
  (defun git-base (&optional file-name)
14
15
  "Get the base of a git repository for FILE-NAME (or the current buffer)."
15
16
  (interactive (buffer-file-name))
16
- (shell-command-to-string (concat "p -t -g " (shell-quote-argument buffer-file-name))))
17
+ (shell-command-to-string
18
+ (concat "git -C " (shell-quote-argument (directory-file-name file-name))
19
+ " rev-parse --show-toplevel 2>/dev/null")))
17
20
 
18
21
  (defun github-markdown-serve (&optional file-name)
19
22
  "Get the base of a git repository for FILE-NAME (or the current buffer)."
@@ -44,18 +47,26 @@
44
47
  (substring file-name (length (car server))))))))
45
48
  (progn
46
49
  (if server
47
- (progn (message (concat "re-starting server on port " (number-to-string (cdr server)))))
50
+ (message (concat "re-starting github-markdown-server on port:" (number-to-string (cdr server))))
48
51
  (progn
49
- (message "starting server"))
50
- (setq server (cons base github-markdown-server-port))
51
- ))
52
- (call-process-shell-command (concat "github-markdown-server"
53
- " --directory=" (shell-quote-argument (car server))
54
- " --port=" (number-to-string (cdr server))
55
- " " (shell-quote-argument file-name)) nil 0)
52
+ ;; find the next available port
53
+ (while (< 0 (length (shell-command-to-string
54
+ (concat "lsof -n -i4TCP:" (number-to-string github-markdown-server-port) " | grep LISTEN"))))
55
+ (setq github-markdown-server-port (+ github-markdown-server-port 1)))
56
+
57
+ (message (concat "starting github-markdown-server on port:" (number-to-string (cdr server))))
58
+ (setq server (cons base github-markdown-server-port))))
59
+ (call-process-shell-command
60
+ (concat "github-markdown-server"
61
+ " --directory=" (shell-quote-argument (car server))
62
+ " --port=" (number-to-string (cdr server))
63
+ " " (shell-quote-argument file-name))
64
+ nil 0)
56
65
  (if (not server)
57
- (progn (add-to-list 'github-markdown-servers server)
58
- (setq github-markdown-server-port (+ github-markdown-server-port 1))))))))
66
+ (progn
67
+ (add-to-list 'github-markdown-servers server)
68
+ (setq github-markdown-server-port (+ github-markdown-server-port 1))))))
69
+ (message ""))))
59
70
 
60
71
  (defun view-file-in-browser (&optional file-name)
61
72
  "Open up file on github or via a local markdown server.
@@ -65,9 +76,17 @@ Prefix arg \[universal-argument] to not run local server."
65
76
  (if (and (not current-prefix-arg) (string-match "\.md$" file-name))
66
77
  (github-markdown-serve file-name)
67
78
  (call-process-shell-command
68
- (concat "open "
69
- (shell-quote-argument
70
- (shell-command-to-string (concat "p -u -t " (shell-quote-argument file-name))))) nil 0)))
79
+ (concat "open -a " (shell-quote-argument github-markdown-server-browser) " \"$("
80
+ "perl -e 'use File::Basename; $f = shift @ARGV; $d = dirname($f); $b = basename($f); "
81
+ "$o = `git -C $d config --get remote.origin.url`; "
82
+ "if ($o =~ qr(!git(@|://)github.com[:/]!)) { "
83
+ " $o =~ s!git(@|://)github.com[:/](.*).git$!https://github.com/$2!; "
84
+ "} else { $o = \"\" }"
85
+ "$p = `git -C $d rev-parse --show-prefix`; "
86
+ "chomp($o, $p); "
87
+ "if ($o) { print \"$o/blob/master/$p$b\n\"; } else { print \"file://$f\" }' "
88
+ (shell-quote-argument (buffer-file-name)) ")\"")
89
+ nil 0)))
71
90
 
72
91
  (provide 'github-markdown-server)
73
92
  ;;; github-markdown-server ends here
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.version = GithubMarkdownServer::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Alex K (wtwf.com)']
9
- s.email = 'ruby@mail.wtwf.com'
9
+ s.email = 'wtwf.com'
10
10
  s.homepage = 'https://github.com/arkarkark/github-markdown-server'
11
11
  s.summary = %q{Use your favorite editor to edit a markdown file, Run the server and open the file. Saving in your editor updates instantly in the browser.}
12
12
  s.description = %q{Runs a webserver to preview Github markdown with live.js updating.}
@@ -1,3 +1,3 @@
1
1
  module GithubMarkdownServer
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-markdown-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex K (wtwf.com)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-28 00:00:00.000000000 Z
11
+ date: 2014-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-markdown-preview
@@ -73,7 +73,7 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '10.3'
75
75
  description: Runs a webserver to preview Github markdown with live.js updating.
76
- email: ruby@mail.wtwf.com
76
+ email: wtwf.com
77
77
  executables:
78
78
  - github-markdown-server
79
79
  extensions: []
@@ -84,7 +84,6 @@ files:
84
84
  - README.md
85
85
  - bin/github-markdown-server
86
86
  - contrib/github-markdown-server.el
87
- - contrib/p
88
87
  - data/image/favicon.ico
89
88
  - data/js/live.js
90
89
  - github-markdown-server.gemspec
data/contrib/p DELETED
@@ -1,116 +0,0 @@
1
- #!/usr/bin/python
2
- # Created by: Alex K (wtwf.com)Tue Dec 7 16:50:41 2004
3
- # Last Modified: Time-stamp: <Thu Nov 27 03:08:53 PST 2014>
4
-
5
- """
6
- Turn a path into an absolute path or url.
7
-
8
- -g, --git print out the root directory of this git repository
9
- -h, --help print out this message
10
- -p, --path show a full absolute path to the file
11
- -t, --trim do not append a newline to the file
12
- -u, --url show a url to the file (https://github.com/... or file:///)
13
- -s, --server show a utl to a local github-markdown-server
14
- --port use this port for github-markdown-server url (default 7474)
15
- --host use this host for github-markdown-server url (default localhost)
16
- """
17
-
18
- __author__ = 'wtwf.com (Alex K)'
19
-
20
- import getopt
21
- import logging
22
- import os
23
- import re
24
- import sys
25
-
26
- def Usage(code, msg=''):
27
- """Show a usage message."""
28
- if code:
29
- fd = sys.stderr
30
- else:
31
- fd = sys.stdout
32
- PROGRAM = os.path.basename(sys.argv[0]) # pylint: disable=invalid-name,unused-variable
33
- print >> fd, __doc__ % locals()
34
- if msg:
35
- print >> fd, msg
36
- sys.exit(code)
37
-
38
- def Main():
39
- """Run."""
40
- logging.basicConfig()
41
- logging.getLogger().setLevel(logging.DEBUG)
42
- try:
43
- opts, args = getopt.getopt(sys.argv[1:], 'ghpstu',
44
- 'git,help,host=,path,port=,server,trim,url'.split(','))
45
- except getopt.error, msg:
46
- Usage(1, msg)
47
-
48
- if not args:
49
- Usage(1)
50
-
51
- output = 'path'
52
- trim = False
53
- port = 7474
54
- host = 'localhost'
55
- for opt, arg in opts:
56
- if opt in ('-g', '--git'):
57
- output = 'git'
58
- if opt in ('-h', '--help'):
59
- Usage(0)
60
- if opt in ('--host',):
61
- host = arg
62
- if opt in ('-p', '--path'):
63
- output = 'path'
64
- if opt in ('--port',):
65
- port = int(arg)
66
- if opt in ('-s', '--server'):
67
- output = 'github-markdown-server'
68
- if opt in ('-t', '--trim'):
69
- trim = True
70
- if opt in ('-u', '--url'):
71
- output = 'url'
72
-
73
- for arg in args:
74
- arg = os.path.abspath(arg)
75
- if output != 'path':
76
- arg = ConvertToUrl(arg, output, port, host)
77
- if trim:
78
- sys.stdout.write(arg) # for python 3 we could do print(arg, end='',flush=True)
79
- else:
80
- print arg
81
-
82
- def ConvertToUrl(arg, output, port, host):
83
- """Try to turn this into a url."""
84
- directory = arg
85
- base_url = None
86
- while directory != '/' and not base_url:
87
- directory = os.path.dirname(directory)
88
- config_filename = os.path.join(directory, '.git', 'config')
89
- if os.path.exists(config_filename):
90
- if output == 'git':
91
- return directory
92
- for line in open(config_filename):
93
- match = re.search(r'url = git@github.com:(.*)\.git', line)
94
- if match:
95
- base_url = 'https://github.com/%s/blob/master/' % match.group(1)
96
- break
97
-
98
- if output == 'git':
99
- return ''
100
- if output == 'github-markdown-server':
101
- if base_url:
102
- basename = arg[len(directory) + 1:]
103
- arg = 'http://%s:%d/%s' % (host, port, basename)
104
- else:
105
- basename = os.path.basename(arg)
106
- arg = 'http://%s:%d/%s' % (host, port, basename)
107
- else:
108
- if base_url:
109
- arg = base_url + arg[len(directory) + 1:]
110
- else:
111
- arg = 'file://' + arg
112
-
113
- return arg
114
-
115
- if __name__ == '__main__':
116
- Main()