Skip to content

Commit

Permalink
Refactor and test remark rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Oct 13, 2013
1 parent 654f469 commit 94a88a1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 25 deletions.
41 changes: 22 additions & 19 deletions remarkable/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,38 @@
import logging

from docopt import docopt

from jinja2 import Environment, PackageLoader

import remarkable

log = logging.getLogger(__name__)


def main():
arguments = docopt(__doc__, version=remarkable.__version__)
debug = arguments['--debug']
logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
log.debug('arguments: %s', arguments)
def render_template(template_name, context):
return Environment(
loader=PackageLoader('remarkable', 'templates')
).get_template(template_name).render(context)

if arguments['remark']:
file_name = arguments['<path-to-markdown-file>']
html_file_name = '%s.html' % file_name

html = render_remark(open(file_name).read())
with open(html_file_name, 'w') as html_file:
html_file.write(html)
log.info('Created %s' % html_file_name)
def remark(arguments):
file_name = arguments['<path-to-markdown-file>']
html_file_name = '%s.html' % file_name

html = render_template(
'remark.html',
dict(markdown=open(file_name).read())
)
with open(html_file_name, 'w') as html_file:
html_file.write(html)
log.info('Created %s' % html_file_name)

def render_remark(markdown):
return render_template('remark.html', markdown=markdown)

def main():
arguments = docopt(__doc__, version=remarkable.__version__)

def render_template(template_name, context):
return Environment(
loader=PackageLoader('remarkable', 'templates')
).get_template(template_name).render(context)
logging.basicConfig(
level=logging.DEBUG if arguments['--debug'] else logging.INFO
)
log.debug('arguments: %s', arguments)
if arguments['remark']:
remark(arguments)
56 changes: 50 additions & 6 deletions tests/test_remarkable.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
import sys
import os

from remarkable import cli
from . import BaseTestCase

from remarkable import remarkable

MARKDOWN = """
name: inverse
layout: true
class: center, middle, inverse
---
# Application To Platform
.footnote[
[How we used Python to scale Yola]
(https://github.com/michaeljoseph/application-to-platform)
]
---
layout: false
background-image: url(https://raw.github.com/michaeljoseph/application-to-platform/gh-pages/images/yola-logo.png)
.large[
![avatar](https://raw.github.com/michaeljoseph/application-to-platform/gh-pages/images/avatar.png)
michaeljoseph @github @twitter
]
???
.small[
# excuses
- false pretences: backup speaker
- 4 day talk
- crappy slides: squirrel (show remark / reveal)
- we're hiring, let me convince you / swimming the recruitment and hiring manager infested nerdpool during the break
we have business cards
]
---
"""


class TestRemarkable(BaseTestCase):

def test_something(self):
self.assertEquals(
'Hello World!',
remarkable(),
)
def setUp(self):
self.example_file = 'atp.md'
with open(self.example_file, 'w') as f:
f.write(MARKDOWN)

def tearDown(self):
os.remove(self.example_file)
os.remove('%s.html' % self.example_file)

def test_remark(self):
sys.argv = 'remarkable remark atp.md'.split(' ')
cli.main()
self.assertTrue(os.path.exists('%s.html' % self.example_file))

0 comments on commit 94a88a1

Please sign in to comment.