Skip to content

Commit

Permalink
code reformatting to conform to pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Mar 20, 2011
1 parent ee8a8b8 commit 5e736fd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 43 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Expand Up @@ -11,7 +11,7 @@ Landslide requires Python_ v2.5 minimum and these dependencies installed:
* The Jinja2_ template engine
* Pygments_ for code syntax highlighting

One of the syntax handlers above :
One of the syntax handlers above:

* The Markdown_ python library if you intend to write your slides contents using the Markdown_ syntax
* or the docutils_ package if you rather prefer using reStructuredText_.
Expand Down
6 changes: 3 additions & 3 deletions src/landslide/generator.py
Expand Up @@ -50,7 +50,7 @@ class Generator(object):
def __init__(self, source, destination_file='presentation.html',
theme='default', direct=False, debug=False, verbose=True,
embed=False, encoding='utf8', logger=None):
"""Configures this generator from its properties."""
"""Configures the generator."""
self.debug = debug
self.direct = direct
self.encoding = encoding
Expand Down Expand Up @@ -78,8 +78,8 @@ def __init__(self, source, destination_file='presentation.html',
config.read(source)
except Exception, e:
raise RuntimeError(u"Invalid configuration file: %s" % e)
self.source = (config.get('landslide', 'source')
.replace('\r', '').split('\n'))
self.source = config.get('landslide', 'source')\
.replace('\r', '').split('\n')
if config.has_option('landslide', 'theme'):
theme = config.get('landslide', 'theme')
self.log(u"Using configured theme %s" % theme)
Expand Down
5 changes: 2 additions & 3 deletions src/landslide/macro.py
Expand Up @@ -47,8 +47,7 @@ class CodeHighlightingMacro(Macro):
"""
code_blocks_re = re.compile(
r'(<pre.+?>(<code>)?\s?!(\w+?)\n(.*?)(</code>)?</pre>)',
re.UNICODE | re.MULTILINE | re.DOTALL
)
re.UNICODE | re.MULTILINE | re.DOTALL)

html_entity_re = re.compile('&(\w+?);')

Expand Down Expand Up @@ -94,7 +93,7 @@ def process(self, content, source=None):
re.DOTALL | re.UNICODE)

if not images:
return content, []
return content, classes

for image_url in images:
if not image_url or image_url.startswith('data:'):
Expand Down
27 changes: 9 additions & 18 deletions src/landslide/main.py
Expand Up @@ -33,33 +33,29 @@ def _parse_options():
description="Generates an HTML5 or PDF "
"slideshow from Markdown or other formats",
epilog="Note: PDF export requires the `prince` program: "
"http://princexml.com/"
)
"http://princexml.com/")

parser.add_option(
"-b", "--debug",
action="store_true",
dest="debug",
help="Will display any exception trace to stdin",
default=False
)
default=False)

parser.add_option(
"-d", "--destination",
dest="destination_file",
help="The path to the to the destination file: .html or "
".pdf extensions allowed (default: presentation.html)",
metavar="FILE",
default="presentation.html"
)
default="presentation.html")

parser.add_option(
"-e", "--encoding",
dest="encoding",
help="The encoding of your files (defaults to utf8)",
metavar="ENCODING",
default="utf8"
)
default="utf8")

parser.add_option(
"-i", "--embed",
Expand All @@ -68,41 +64,36 @@ def _parse_options():
help="Embed stylesheet and javascript contents, "
"base64-encoded images in presentation to make a "
"standalone document",
default=False
)
default=False)

parser.add_option(
"-t", "--theme",
dest="theme",
help="A theme name, or path to a landlside theme directory",
default='default'
)
default='default')

parser.add_option(
"-o", "--direct-ouput",
action="store_true",
dest="direct",
help="Prints the generated HTML code to stdin; won't work "
"with PDF export",
default=False
)
default=False)

parser.add_option(
"-q", "--quiet",
action="store_false",
dest="verbose",
help="Won't write anything to stdin (silent mode)",
default=False
)
default=False)

parser.add_option(
"-v", "--verbose",
action="store_true",
dest="verbose",
help="Write informational messages to stdin (enabled by "
"default)",
default=True
)
default=True)

(options, args) = parser.parse_args()

Expand Down
37 changes: 19 additions & 18 deletions src/landslide/tests.py
Expand Up @@ -14,17 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import macro
import os
import re
import unittest
import codecs

from generator import Generator
from macro import *
from parser import Parser

from pprint import pprint


SAMPLES_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'samples')
if (not os.path.exists(SAMPLES_DIR)):
Expand Down Expand Up @@ -77,18 +75,22 @@ def test_unicode(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example3', 'slides.rst'))
g.execute()
s = g.render()
self.assertTrue(s.find('<pre>')!=-1)
self.assertTrue(s.find('<pre>') != -1)
self.assertEqual(len(re.findall('<pre><span', s)), 3)

def test_inputencoding(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example3', 'slides.koi8_r.rst'), encoding='koi8_r')
g = Generator(os.path.join(SAMPLES_DIR, 'example3',
'slides.koi8_r.rst'), encoding='koi8_r')
content = g.render()
# check that the string is utf_8
self.assertTrue(re.findall(u'русский',content, flags=re.UNICODE))
self.assertTrue(re.findall(u'русский', content,
flags=re.UNICODE))
g.execute()
file_contents = codecs.open(g.destination_file, encoding='utf_8').read()
file_contents = codecs.open(g.destination_file, encoding='utf_8')\
.read()
# check that the file was properly encoded in utf_8
self.assertTrue(re.findall(u'русский',file_contents, flags=re.UNICODE))
self.assertTrue(re.findall(u'русский', file_contents,
flags=re.UNICODE))

def test_get_template_vars(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example1', 'slides.md'))
Expand All @@ -98,7 +100,6 @@ def test_get_template_vars(self):
])
self.assertEqual(svars['head_title'], 'slide1')


def test_process_macros(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example1', 'slides.md'))
# Notes
Expand All @@ -115,7 +116,7 @@ def test_process_macros(self):
def test_register_macro(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example1', 'slides.md'))

class SampleMacro(Macro):
class SampleMacro(macro.Macro):
pass

g.register_macro(SampleMacro)
Expand Down Expand Up @@ -153,7 +154,7 @@ def foo():
<p>End here.</p>'''

def test_parsing_code_blocks(self):
m = CodeHighlightingMacro(self.logtest)
m = macro.CodeHighlightingMacro(self.logtest)
blocks = m.code_blocks_re.findall(self.sample_html)
self.assertEquals(len(blocks), 3)
self.assertEquals(blocks[0][2], 'python')
Expand All @@ -164,7 +165,7 @@ def test_parsing_code_blocks(self):
self.assertTrue(blocks[2][3].startswith('<foo>'))

def test_descape(self):
m = CodeHighlightingMacro(self.logtest)
m = macro.CodeHighlightingMacro(self.logtest)
self.assertEqual(m.descape('foo'), 'foo')
self.assertEqual(m.descape('&gt;'), '>')
self.assertEqual(m.descape('&lt;'), '<')
Expand All @@ -173,7 +174,7 @@ def test_descape(self):
self.assertEqual(m.descape('&lt;spam&amp;eggs&gt;'), '<spam&eggs>')

def test_process(self):
m = CodeHighlightingMacro(self.logtest)
m = macro.CodeHighlightingMacro(self.logtest)
hl = m.process("<pre><code>!php\n$foo;</code></pre>")
self.assertTrue(hl[0].startswith('<div class="highlight"><pre'))
self.assertEquals(hl[1][0], u'has_code')
Expand All @@ -182,7 +183,7 @@ def test_process(self):
self.assertEqual(m.process(input)[1], [])

def test_process_rst_code_blocks(self):
m = CodeHighlightingMacro(self.logtest)
m = macro.CodeHighlightingMacro(self.logtest)
hl = m.process(self.sample_html)
self.assertTrue(hl[0].startswith('<p>Let me give you this'))
self.assertTrue(hl[0].find('<p>Then this one') > 0)
Expand All @@ -194,7 +195,7 @@ def test_process_rst_code_blocks(self):
class EmbedImagesMacroTest(BaseTestCase):
def test_process(self):
base_dir = os.path.join(SAMPLES_DIR, 'example1', 'slides.md')
m = EmbedImagesMacro(self.logtest, True)
m = macro.EmbedImagesMacro(self.logtest, True)
self.assertRaises(WarningMessage, m.process,
'<img src="toto.jpg"/>', '.')
content, classes = m.process('<img src="monkey.jpg"/>', base_dir)
Expand All @@ -205,15 +206,15 @@ def test_process(self):
class FixImagePathsMacroTest(BaseTestCase):
def test_process(self):
base_dir = os.path.join(SAMPLES_DIR, 'example1', 'slides.md')
m = FixImagePathsMacro(self.logtest, False)
m = macro.FixImagePathsMacro(self.logtest, False)
content, classes = m.process('<img src="monkey.jpg"/>', base_dir)
self.assertTrue(re.match(r'<img src="file://.*?/monkey.jpg" />',
content))


class FxMacroTest(BaseTestCase):
def test_process(self):
m = FxMacro(self.logtest)
m = macro.FxMacro(self.logtest)
content = '<p>foo</p>\n<p>.fx: blah blob</p>\n<p>baz</p>'
r = m.process(content)
self.assertEqual(r[0], '<p>foo</p>\n<p>baz</p>')
Expand All @@ -223,7 +224,7 @@ def test_process(self):

class NotesMacroTest(BaseTestCase):
def test_process(self):
m = NotesMacro(self.logtest)
m = macro.NotesMacro(self.logtest)
r = m.process('<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'])
Expand Down

0 comments on commit 5e736fd

Please sign in to comment.