Skip to content

Commit

Permalink
Merge pull request romanlv#4 from CalPolyResDev/master
Browse files Browse the repository at this point in the history
Python 3.4 compatibility, <ul>/<li> support, QR barcode support
  • Loading branch information
romanlv committed Sep 5, 2015
2 parents 5b22d10 + 78612ee commit 78920ee
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 263 deletions.
3 changes: 3 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ N: Joe Yates, G: https://github.com/joeyates


N: Jonathan Apostoles, G: https://github.com/japostoles


N: Thomas E. Willson, G: https://github.com/willson556
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Open source implemenaton of RML (Report Markup Language) from ReportLab
Open source implementation of RML (Report Markup Language) from ReportLab

[RML User Guide](http://www.reportlab.com/docs/rml2pdf-userguide.pdf) (or [beginner tutorial](http://www.reportlab.com/docs/rml-for-idiots.pdf))

Expand Down
44 changes: 20 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import os

from setuptools import find_packages, setup

# http://www.ewencp.org/blog/a-brief-introduction-to-packaging-python/

# http://www.ewencp.org/blog/a-brief-introduction-to-packaging-python/
setup(
name = 'trml2pdf',
version = '0.2',
description =
'''Tiny RML2PDF is a tool to easily create PDF document using special HTML-like markup language.
name='trml2pdf',
version='0.2',
description='''Tiny RML2PDF is a tool to easily create PDF document using special HTML-like markup language.
It can be used as a Python library or as a standalone binary. It converts a RML, an XML dialect that lets you define the precise appearance of a printed document, to a PDF. You can use your existing tools to generate an input file that exactly describes the layout of a printed document, and RML2PDF converts it into PDF. RML is a much more powerfull and flexible alternative to XSL:FO.
The executable read a RML file to the standard input and output a PDF file to the standard output.''',
keywords = 'pdf reportlab',
keywords='pdf reportlab',
platforms=["any"],
license = 'GNU LESSER GENERAL PUBLIC LICENSE',
author = 'Fabien Pinckaers',
author_email = '[email protected]',
maintainer = 'Roman Lyashov',
maintainer_email = '[email protected]',
url = 'http://github.com/romanlv/trml2pdf/',
install_requires = ['reportlab>=2.6'],
dependency_links = [],
license='GNU LESSER GENERAL PUBLIC LICENSE',
author='Fabien Pinckaers',
author_email='[email protected]',
maintainer='Roman Lyashov',
maintainer_email='[email protected]',
url='http://github.com/romanlv/trml2pdf/',
install_requires=['reportlab>=3.2.0', 'six>=1.9.0'],
dependency_links=[],
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Plugins',
Expand All @@ -29,14 +26,13 @@
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
],
entry_points = {
'console_scripts': [
'trml2pdf = trml2pdf.trml2pdf:main',
],
},
entry_points={
'console_scripts': [
'trml2pdf = trml2pdf.trml2pdf:main',
],
},

packages = find_packages(),
include_package_data = True,
packages=find_packages(),
include_package_data=True,
test_suite="tests",
)

26 changes: 11 additions & 15 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import os
import sys

import unittest

from six import text_type

import trml2pdf # dev mode: python setup.py develop


EXAMPLES_DIR = "examples"
EXAMPLES_DIR = "../examples"


#sys.path.append(EXAMPLES_DIR)
# sys.path.append(EXAMPLES_DIR)

class Test(unittest.TestCase):
"""run pdf genration using all files in examples."""
Expand All @@ -18,24 +19,19 @@ def test_run_all(self):

# change current dir, there are relative references to images in rmls
work_dir = os.getcwd()
os.chdir( EXAMPLES_DIR )
os.chdir(EXAMPLES_DIR)
self._run_all_examples()
finally:
os.chdir( work_dir )
os.chdir(work_dir)



def _run_all_examples(self):
for name in os.listdir('.'):
if name.endswith(".rml"):
path = name #'{}/{}'.format(EXAMPLES_DIR, name)
# print 'running: {}'.format(path)
output = trml2pdf.parseString(file(path,'r').read())
path = name # '{}/{}'.format(EXAMPLES_DIR, name)
print('running: {}'.format(path))
output = trml2pdf.parseString(text_type(open(path, "r").read()))
self.assertIsNotNone(output)





if __name__ == "__main__":
unittest.main()
unittest.main()
Binary file added trml2pdf/.trml2pdf.py.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion trml2pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

from trml2pdf import parseString
from .trml2pdf import parseString
25 changes: 14 additions & 11 deletions trml2pdf/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

from reportlab.lib import colors
import re

from reportlab.lib import colors


allcols = colors.getAllNamedColors()

regex_t = re.compile('\(([0-9\.]*),([0-9\.]*),([0-9\.]*)\)')
regex_h = re.compile('#([0-9a-zA-Z][0-9a-zA-Z])([0-9a-zA-Z][0-9a-zA-Z])([0-9a-zA-Z][0-9a-zA-Z])')


def get(col_str):
global allcols
if col_str in allcols.keys():
return allcols[col_str]
res = regex_t.search(col_str, 0)
if res:
return (float(res.group(1)),float(res.group(2)),float(res.group(3)))
res = regex_h.search(col_str, 0)
if res:
return tuple([ float(int(res.group(i),16))/255 for i in range(1,4)])
return colors.red
global allcols
if col_str in list(allcols.keys()):
return allcols[col_str]
res = regex_t.search(col_str, 0)
if res:
return (float(res.group(1)), float(res.group(2)), float(res.group(3)))
res = regex_h.search(col_str, 0)
if res:
return tuple([float(int(res.group(i), 16)) / 255 for i in range(1, 4)])
return colors.red
Loading

0 comments on commit 78920ee

Please sign in to comment.