mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-04 07:57:52 +03:00
Add a 'boxes' module. (Empty for now.)
This commit is contained in:
parent
2648ab7298
commit
531c8ec669
27
weasy/boxes.py
Normal file
27
weasy/boxes.py
Normal file
@ -0,0 +1,27 @@
|
||||
# coding: utf8
|
||||
|
||||
# WeasyPrint converts web documents (HTML, CSS, ...) to PDF.
|
||||
# Copyright (C) 2011 Simon Sapin
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import re
|
||||
from . import css
|
||||
|
||||
|
||||
def dom_to_box(element, parent_box=None):
|
||||
"""Converts a DOM element (and its children) into a box (with children)."""
|
||||
# TODO
|
||||
|
@ -17,12 +17,22 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os.path
|
||||
from lxml import html
|
||||
from cssutils.helper import path2url
|
||||
from attest import Tests
|
||||
|
||||
|
||||
def resource_filename(basename):
|
||||
return os.path.join(os.path.dirname(__file__), 'resources', basename)
|
||||
|
||||
|
||||
def parse_html(filename):
|
||||
"""Parse an HTML file from the test resources and resolve relative URL."""
|
||||
document = html.parse(path2url(resource_filename(filename))).getroot()
|
||||
return document
|
||||
|
||||
|
||||
all = Tests('.'.join((__name__, mod, 'suite'))
|
||||
for mod in ('test_css',
|
||||
'test_css_properties'))
|
||||
'test_css_properties',
|
||||
'test_boxes'))
|
||||
|
42
weasy/tests/test_boxes.py
Normal file
42
weasy/tests/test_boxes.py
Normal file
@ -0,0 +1,42 @@
|
||||
# coding: utf8
|
||||
|
||||
# WeasyPrint converts web documents (HTML, CSS, ...) to PDF.
|
||||
# Copyright (C) 2011 Simon Sapin
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from attest import Tests, assert_hook
|
||||
from cssutils.css import PropertyValue
|
||||
|
||||
from . import parse_html
|
||||
from .. import boxes
|
||||
from .. import css
|
||||
|
||||
|
||||
|
||||
suite = Tests()
|
||||
|
||||
|
||||
@suite.test
|
||||
def test_box_tree():
|
||||
document = parse_html('doc1.html')
|
||||
css.annotate_document(document)
|
||||
# Make sure the HTML4 stylesheet is applied.
|
||||
# TODO: this should be in test_css*
|
||||
assert document.head.style.display == 'none'
|
||||
|
||||
box_tree = boxes.dom_to_box(document)
|
||||
|
||||
# TODO
|
@ -18,22 +18,24 @@
|
||||
|
||||
import os.path
|
||||
from attest import Tests, assert_hook
|
||||
from lxml import html
|
||||
#from lxml.html import html5parser as html # API is the same as lxml.html
|
||||
import cssutils
|
||||
from cssutils.helper import path2url
|
||||
|
||||
from .. import css
|
||||
|
||||
from . import resource_filename
|
||||
from . import resource_filename, parse_html
|
||||
|
||||
|
||||
suite = Tests()
|
||||
|
||||
def parse_html(filename):
|
||||
"""Parse an HTML file from the test resources and resolve relative URL."""
|
||||
document = html.parse(path2url(resource_filename(filename))).getroot()
|
||||
return document
|
||||
|
||||
@suite.test
|
||||
def test_style_dict():
|
||||
style = css.StyleDict({
|
||||
'margin-left': cssutils.css.PropertyValue('12px'),
|
||||
'display': cssutils.css.PropertyValue('block')
|
||||
})
|
||||
assert style.display == 'block'
|
||||
assert style.margin_left == 12
|
||||
|
||||
|
||||
@suite.test
|
||||
|
Loading…
Reference in New Issue
Block a user