Commits

Steve Losh committed 9a93d6e

Initial structure.

  • Participants
  • Parent commits 78c7d43

Comments (0)

Files changed (16)

+bookmarkdown
+MIT/X11 License
+===============
+
+Copyright (C) 2011 by Steve Losh and contributors.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this
+software and associated documentation files (the "Software"), to deal in the Software
+without restriction, including without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be included in all copies
+or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+Bookmarkdown
+============
+
+Source (Mercurial):
+Source (Git):
+Issues:
+License:
+

bookmarkdown/__init__.py

Empty file added.

bookmarkdown/bookmarkdown

+#!/usr/bin/env python
+
+# {{{
+import os
+import baker
+import markdown
+from jinja2 import Environment, PackageLoader
+
+env = Environment(loader=PackageLoader('bookmarkdown', 'templates'))
+# }}}
+
+# Utilities ------------------------------------------------------------------------
+def mkdirs(path):
+    def _md(acc, next):
+        target = os.path.join(acc, next)
+        os.path.exists(target) or os.mkdir(target)
+        return target
+    reduce(_md, os.path.split(path), '')
+
+
+# Guts -----------------------------------------------------------------------------
+def _build_html_file(filename, template, context={}):
+    source = '%s.markdown' % filename
+
+    if not os.path.exists(source):
+        return
+
+    with open(source, 'r') as f:
+        content = markdown.markdown(f.read())
+
+    out = env.get_template('%s.html' % template).render(content=content, **context)
+    target = os.path.join('build', 'html', '%s.html' % filename)
+
+    with open(target, 'w') as f:
+        f.write(out)
+
+
+def _build_html():
+    mkdirs(os.path.join('build', 'html', 'chapters'))
+
+    _build_html_file('acknowledgements', 'single')
+    _build_html_file('license', 'single')
+    _build_html_file('preface', 'single')
+
+    for filename in os.listdir('chapters'):
+        if filename.endswith('.markdown'):
+            _build_html_file(os.path.join('chapters', filename), 'chapter')
+
+def _build_pdf():
+    mkdirs(os.path.join('build', 'pdf'))
+
+
+# Commands -------------------------------------------------------------------------
+@baker.command
+def pdf():
+    '''Build the PDF version of the book.'''
+    _build_pdf()
+
+@baker.command
+def html():
+    '''Build the HTML version of the book.'''
+    _build_html()
+
+@baker.command
+def build():
+    '''Build all versions of the book.'''
+    _build_html()
+    _build_pdf()
+
+@baker.command
+def serve(address='127.0.0.1', port=8000):
+    '''Serve the rendered book with a local webserver.
+
+    :param address: The address to bind the server to (default: 127.0.0.1)
+    :param port: The port to bind the server to (default: 8000)
+
+    '''
+    import SimpleHTTPServer, SocketServer
+
+    os.chdir(os.path.join('build', 'html'))
+    server = SocketServer.TCPServer((address, port),
+                                    SimpleHTTPServer.SimpleHTTPRequestHandler)
+
+    print "Serving book at http://%s:%d" % (address, port)
+    server.serve_forever()
+
+@baker.command
+def watch():
+    '''Watch the source files and rebuild the book when changed.'''
+    pass
+
+
+# Entry ----------------------------------------------------------------------------
+if __name__ == '__main__':
+    baker.run()

bookmarkdown/templates/base.html

+<!DOCTYPE html>
+
+<html>
+    <head>
+        <link href="/static/style.less" rel="stylesheet" />
+        <script type="text/javascript" src="/static/less.js"></script>
+    </head>
+
+    <body>
+        <header>
+            <h1>Book Title</h1>
+        </header>
+
+        <section class="content">
+            {% block content %}{% endblock %}
+        </section>
+
+        <footer>
+        </footer>
+    </body>
+</html>

bookmarkdown/templates/chapter.html

+{% extends "base.html" %}
+
+{% block content %}
+    Chapter foo:
+    {{ content }}
+{% endblock %}

bookmarkdown/templates/single.html

+{% extends "base.html" %}
+
+{% block content %}
+    {{ content }}
+{% endblock %}
+baker
+jinja2
+python-markdown

sample/acknowledgements.markdown

+I has some content!
+
+*ack*

sample/chapters/01-history.markdown

Empty file added.

sample/chapters/02-basic.markdown

Empty file added.

sample/chapters/03-advanced.markdown

Empty file added.

sample/license.markdown

+license *here*

sample/preface.markdown

+*preface*
+
+derp.
+"""blatter"""
+
+setup_info = dict(
+    name="bookmarkdown",
+    description="Write books in Markdown.",
+    version="0.0.1",
+
+    author='Steve Losh',
+    author_email='steve@stevelosh.com',
+    license='MIT License',
+    url='http://bitbucket.org/sjl/bookmarkdown/',
+
+    packages=['bookmarkdown'],
+
+    scripts = ['bookmarkdown/bookmarkdown'],
+
+    install_requires = [
+        'python-markdown',
+        'baker',
+        'Jinja2',],
+
+     classifiers=[
+        'Development Status :: 5 - Production/Stable',
+        'Environment :: Console',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: MIT License',
+        'Natural Language :: English',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
+        'Topic :: Internet :: WWW/HTTP :: Site Management',
+        'Topic :: Software Development :: Pre-processors',
+        'Topic :: Text Processing :: Markup :: HTML',
+        'Topic :: Utilities',
+        ]
+    )
+
+try:
+    from setuptools import setup
+    del setup_info['scripts']
+except ImportError:
+    for unsupported in ('entry_points', 'install_requires'):
+        del setup_info[unsupported]
+    from distutils.core import setup
+
+setup(**setup_info)