def test_presenter_notes(self): g = Generator(os.path.join(DATA_DIR, 'test.md')) svars = g.get_slide_vars("<h1>heading</h1>\n<p>foo</p>\n" "<h1>Presenter Notes</h1>\n<p>bar</p>\n") self.assertEqual(svars['presenter_notes'], "<p>bar</p>") # Check that presenter notes work even if the slide has no heading. # For example, if it is only an image: g = Generator(os.path.join(DATA_DIR, 'test.md')) svars = g.get_slide_vars("<p>foo</p>\n" "<h1>Presenter Notes</h1>\n<p>bar</p>\n")
def rst2html(): rst = request.form.get('rst', '') with open('/tmp/presentacion.rst','w') as tmpfile: tmpfile.write(rst) theme = request.form.get('theme') if theme == 'slides': g = LandSlide("/tmp/presentacion.rst", embed=True) html = g.render() else: if theme == 'basic': theme = None html = _rst2html(rst, theme=theme) return html
def test_get_template_vars(self): g = Generator(os.path.join(DATA_DIR, 'test.md')) svars = g.get_template_vars([{'title': "slide1", 'level': 1}, {'title': "slide2", 'level': 1}, {'title': None, 'level': 1}, ]) self.assertEqual(svars['head_title'], 'slide1')
def test_add_user_assets(self): base_dir = os.path.join(DATA_DIR, 'test.md') g = Generator(base_dir, logger=self.logtest) g.add_user_css(os.path.join(DATA_DIR, 'test.css')) g.add_user_js(os.path.join(DATA_DIR, 'test.js')) self.assertEqual(g.user_css[0]['contents'], '* {color: red;}') self.assertEqual(g.user_js[0]['contents'], "alert('foo');")
def test_get_slide_vars(self): g = Generator(os.path.join(DATA_DIR, 'test.md')) svars = g.get_slide_vars("<h1>heading</h1>\n<p>foo</p>\n<p>bar</p>\n") self.assertEqual(svars['title'], 'heading') self.assertEqual(svars['level'], 1) self.assertEqual(svars['header'], '<h1>heading</h1>') self.assertEqual(svars['content'], '<p>foo</p>\n<p>bar</p>') self.assertEqual(svars['source'], {}) self.assertEqual(svars['classes'], [])
class Generator(): CSS = "https://www.googledrive.com/host/0B8Dd5LtC555uNTJQXzZKdDN4aWc" def __init__(self, rst_file, out): self.dir = data.get_data_dir() self.out_file = os.path.join(self.dir, out) self.gen = LandslideGenerator(rst_file, destination_file=self.out_file) def add_css(self): css = os.path.join(self.dir, 'report.css') data.download(self.CSS, css) self.gen.add_user_css([css]) def generate(self): self.add_css() self.gen.write() log_api.conf_logger(__name__).warning('Generated HTML in ' + self.out_file)
def open_slides(): slides_path = file_in_dir('slides.md') output_path = 'pipped-slides.html' Generator( slides_path, **{ 'embed': True, 'relative': True, 'destination_file': output_path, 'theme': file_in_dir('avalanche'), }).execute() call(['open', output_path])
def run(input_file, options): generator = Generator(input_file, options.destination_file, options.theme, direct=options.direct, debug=options.debug, verbose=options.verbose, embed=options.embed, encoding=options.encoding, logger=log) generator.execute()
def test_process_macros(self): g = Generator(os.path.join(DATA_DIR, 'test.md')) # Notes r = g.process_macros('<p>foo</p>\n<p>.notes: bar</p>\n<p>baz</p>') self.assertEqual(r[0].find('<p class="notes">bar</p>'), 11) self.assertEqual(r[1], [u'has_notes']) # FXs content = '<p>foo</p>\n<p>.fx: blah blob</p>\n<p>baz</p>' r = g.process_macros(content) self.assertEqual(r[0], '<p>foo</p>\n<p>baz</p>') self.assertEqual(r[1][0], 'blah') self.assertEqual(r[1][1], 'blob')
def test_macro_alert(self): g = Generator(os.path.join(DATA_DIR, 'test.md')) # .info r = g.process_macros('<p>foo</p>\n<p>.info: bar</p>\n<p>baz</p>') self.assertEqual(r[0].find('<p class="alert alert-info">bar</p>'), 11) self.assertEqual(r[1], [u'has_alert']) # .danger r = g.process_macros('<p>foo</p>\n<p>.danger: bar</p>\n<p>baz</p>') self.assertEqual(r[0].find('<p class="alert alert-danger">bar</p>'), 11) self.assertEqual(r[1], [u'has_alert'])
def test_register_macro(self): g = Generator(os.path.join(DATA_DIR, 'test.md')) class SampleMacro(macro.Macro): pass g.register_macro(SampleMacro) self.assertTrue(SampleMacro in g.macros) def plop(foo): pass self.assertRaises(TypeError, g.register_macro, plop)
def test_inputencoding(self): path = os.path.join(DATA_DIR, 'encoding.rst') g = Generator(path, encoding='koi8_r') content = g.render() # check that the string is utf_8 self.assertTrue(re.findall(u'русский', content, flags=re.UNICODE)) g.execute() with codecs.open(g.destination_file, encoding='utf_8') as file_object: file_contents = file_object.read() # check that the file was properly encoded in utf_8 self.assertTrue(re.findall(u'русский', file_contents, flags=re.UNICODE))
def test_process_animation_macros(self): g = Generator(os.path.join(DATA_DIR, 'test.md')) r = g.process_macros('''<ul class="xx"> <li>Markdown .fx:rollIn</li> <li>ReStructured Text</li> <li>Textile</li> </ul>''') self.assertEqual(r[0], '''<ul class="rollIn xx"> <li class="building">Markdown </li> <li class="tobuild">ReStructured Text</li> <li class="tobuild">Textile</li> </ul>''')
def test_get_toc(self): base_dir = os.path.join(DATA_DIR, 'test.md') g = Generator(base_dir, logger=self.logtest) g.add_toc_entry('Section 1', 1, 1) g.add_toc_entry('Section 1.1', 2, 2) g.add_toc_entry('Section 1.2', 2, 3) g.add_toc_entry('Section 2', 1, 4) g.add_toc_entry('Section 2.1', 2, 5) g.add_toc_entry('Section 3', 1, 6) toc = g.toc self.assertEqual(len(toc), 3) self.assertEqual(toc[0]['title'], 'Section 1') self.assertEqual(len(toc[0]['sub']), 2) self.assertEqual(toc[0]['sub'][1]['title'], 'Section 1.2') self.assertEqual(toc[1]['title'], 'Section 2') self.assertEqual(len(toc[1]['sub']), 1) self.assertEqual(toc[2]['title'], 'Section 3') self.assertEqual(len(toc[2]['sub']), 0)
def test_unicode(self): g = Generator(os.path.join(DATA_DIR, 'test.md')) g.execute() s = g.render() self.assertTrue(s.find('<pre>') != -1) self.assertEqual(len(re.findall('<pre><span', s)), 3)
def __init__(self, rst_file, out): self.dir = data.get_data_dir() self.out_file = os.path.join(self.dir, out) self.gen = LandslideGenerator(rst_file, destination_file=self.out_file)
def run(input_file, options): """ Runs the Generator using parsed options. """ options.logger = log generator = Generator(input_file, **options.__dict__) generator.execute()
def test_skip_presenter_notes(self): g = Generator(os.path.join(DATA_DIR, 'test.md'), presenter_notes=False) svars = g.get_slide_vars("<h1>heading</h1>\n<p>foo</p>\n" "<h1>Presenter Notes</h1>\n<p>bar</p>\n") self.assertEqual(svars['presenter_notes'], None)