aboutsummaryrefslogtreecommitdiffstats
path: root/mkdocs.py
diff options
context:
space:
mode:
authorTom Christie2012-11-16 12:59:19 -0800
committerTom Christie2012-11-16 12:59:19 -0800
commit3cfb23e4aca85f0d9df50b236e0139edff28d457 (patch)
tree70cb46fa12c80c068cfa2651468c95dc0d9f59c8 /mkdocs.py
parent2f2bde69e42825ad55318e5a5745ee9655b3f81b (diff)
parentcba181f4bce6684a45aa869cae0b2cca0c35eee0 (diff)
downloaddjango-rest-framework-3cfb23e4aca85f0d9df50b236e0139edff28d457.tar.bz2
Merge pull request #419 from markotibold/the_feature_nobody_asked_for
./mkdocs.py -p opens a preview in your default browser
Diffstat (limited to 'mkdocs.py')
-rwxr-xr-xmkdocs.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/mkdocs.py b/mkdocs.py
index 8106e8e2..2918f7d3 100755
--- a/mkdocs.py
+++ b/mkdocs.py
@@ -11,6 +11,7 @@ docs_dir = os.path.join(root_dir, 'docs')
html_dir = os.path.join(root_dir, 'html')
local = not '--deploy' in sys.argv
+preview = '-p' in sys.argv
if local:
base_url = 'file://%s/' % os.path.normpath(os.path.join(os.getcwd(), html_dir))
@@ -80,3 +81,15 @@ for (dirpath, dirnames, filenames) in os.walk(docs_dir):
output = re.sub(r'<pre>', r'<pre class="prettyprint lang-py">', output)
output = re.sub(r'<a class="github" href="([^"]*)"></a>', code_label, output)
open(output_path, 'w').write(output.encode('utf-8'))
+
+if preview:
+ import subprocess
+
+ url = 'html/index.html'
+
+ try:
+ subprocess.Popen(["open", url]) # Mac
+ except OSError:
+ subprocess.Popen(["xdg-open", url]) # Linux
+ except:
+ os.startfile(url) # Windows