Ejemplo n.º 1
0
def _something_to_lcg(something):
    if isinstance(something, basestring):
        result = lcg.TextContent(something)
    elif isinstance(something, (list, tuple,)):
        result = lcg.Container([_something_to_lcg(s) for s in something],
                               orientation=lcg.Orientation.HORIZONTAL)
    elif isinstance(something, lcg.Content):
        result = something
    else:
        result = something.lcg()
    return result
Ejemplo n.º 2
0
 def mknode(item):
     # Caution - make the same uri transformation as above to get same
     # results in all cases (such as for '/').
     item_uri = '/' + item.id().strip('/')
     if item_uri == uri:
         # Note, the document title should not override the menu item title.
         # Only the main page heading is affected, but the ContentNode's
         # title matches the MenuItem's title.
         title = document.title() or item.title()
         if title and document.subtitle():
             title = lcg.concat(title, ' :: ', document.subtitle())
         heading = lcg.TextContent(title)
         content = document.content()
         if isinstance(content, (list, tuple)):
             content = lcg.Container([c for c in content if c is not None])
         variants = document.variants()
         if variants is None:
             variants = item.variants()
         globals_ = document.globals()
     else:
         variants = item.variants()
         heading = None
         content = None
         globals_ = None
     if variants is None:
         variants = all_variants
     node = lcg.ContentNode(item_uri, title=item.title(), heading=heading,
                            descr=item.descr(), content=content,
                            variants=[lcg.Variant(v) for v in variants],
                            active=item.active(), foldable=item.foldable(),
                            hidden=item.hidden() or lang not in variants,
                            children=[mknode(i) for i in item.submenu()],
                            resource_provider=resource_provider,
                            globals=globals_)
     nodes[item_uri] = node
     return node
Ejemplo n.º 3
0
 def _lcg(self):
     return lcg.TextContent(u"£")
Ejemplo n.º 4
0
    def __init__(self, id, title=None, brief_title=None, heading=None,
                 descr=None, children=(), hidden=False, active=True,
                 foldable=False, resource_provider=None, globals=None,
                 cover_image=None, metadata=None, variants=(), **kwargs):
        """Initialize the instance.

        Arguments:

          id -- a unique textual identifier of this node (as a string).
          title -- the title of this node (as a unicode string).
          brief_title -- the brief (shorter) form of title of this node (as a
            unicode string).  If given, this title will be used to refer to
            this node from places, where brevity matters.  If None, the 'title'
            will be used instead.
          heading -- content to be used as node heading.  By default (when
            None), the content is created automatically as TextContent(title),
            but you may pass any lcg.Content instance when some more fancy
            content is desired.
          descr -- a short textual description of this node (as a uni code
            string).  Additional information, which may determine the content
            of the node in addition to the title.
          children -- a sequence of child nodes in the hierarchy.
          hidden -- a boolean flag indicating, that this node should not appear
            in the automatically generated Indexes (Tables of Contents).  Such
            a node will usually be refered explicitely.
          active -- a boolean flag indicating, that this node is active.  Usage
            of this flag may be application specific and there is currently no
            difference in behavior of LCG in respect to this flag, except for
            marking the items by css class 'inactive' on export.
          foldable -- iff true, the node's submenu will be presented as a
            foldable in foldable tree presentations which support it.
          resource_provider -- a 'ResourceProvider' instance or None.
          globals -- node global variables as a dictionary keyed by variable
            names.  The variables are allowed to contain nested dictionaries.
            The variables are used for substitution by `Substitution'
            instances, but they may be also used for other purposes depending
            on the application.
          cover_image -- 'lcg.Resource' instance to be used as a cover image.
          metadata -- an instance of 'lcg.Metadata' defining the publication
            meta data; Only relevant for the root node of the publication.
          variants -- available language variants of this node as a sequence of
            'Variant' instances.  Each item may define a language specific
            variant of language dependent attributes, such as 'content',
            'page_header', 'page_footer' etc. (see 'Variant' constructor
            arguments for a complete list).  These variant specific values will
            take precedence over the same attributes passed directly as
            'ContentNode' arguments (see below).
          content, page_header, first_page_header,
          page_footer, left_page_footer,
          right_page_footer, page_background,
          presentation -- default variants of node content and parameters may
            be passed directly as node keyword arguments.  The names and
            meaning of the arguments match the names of 'lcg.Variant'
            constructor arguments.  These defaults are used when no matching
            variant is found in 'variants' for given export language, when that
            variant does not define given attribute (such as 'page_footer') or
            when 'lang' is not passed to the methods obtaining given content or
            parameter.  The most typical usage is for language independent
            content, which consists of localizable texts (see
            'lcg.Localizable') or for content of undefined language --
            'ContentNode' doesn't force you to define the language of the
            content.

        """
        assert isinstance(id, basestring), repr(id)
        assert isinstance(hidden, bool), hidden
        assert isinstance(active, bool), active
        assert isinstance(foldable, bool), foldable
        assert is_sequence_of(variants, Variant)
        assert is_sequence_of(children, ContentNode)
        assert cover_image is None or isinstance(cover_image, lcg.Image), cover_image
        assert metadata is None or isinstance(metadata, Metadata)
        assert heading is None or isinstance(heading, lcg.Content), heading
        self._id = id
        self._parent = None  # parent
        self._title = title if title is not None else brief_title or id
        self._heading = heading or lcg.TextContent(self._title)
        self._brief_title = brief_title or title
        self._descr = descr
        self._hidden = hidden
        self._active = active
        self._foldable = foldable
        for child in children:
            child._set_parent(self)
        self._children = tuple(children)
        self._resource_provider = resource_provider
        if globals is None:
            self._globals = {}
        else:
            self._globals = copy.copy(globals)
        self._metadata = metadata
        self._variants = tuple(v.lang() for v in variants)
        self._variants_dict = dict((v.lang(), v) for v in variants)
        self._default_variant = Variant('--', **kwargs)
        self._cover_image = cover_image
        for variant in tuple(variants) + (self._default_variant,):
            if variant.content():
                variant.content().set_parent(self)
        self._empty_content = lcg.Content()
        # if __debug__:
        #    seen = {}
        #    for n in self.linear():
        #        nid = n.id()
        #        assert nid not in seen, \
        #               "Duplicate node id: %s, %s" % (n, seen[nid])
        #        seen[nid] = n
        self._used_content_resources = []
Ejemplo n.º 5
0
    ],
    'nemeth': ['nemeth.ctb']
}
braille_hyphenation_tables = {'en': 'hyph_en_US.dic', 'cs': 'hyph_cs_CZ.dic'}
braille_math_rules = 'nemeth'  # 'nemeth', 'czech'

page_width = lcg.UFont(35)
page_height = lcg.UFont(29)
inner_margin = lcg.UFont(0)
outer_margin = lcg.UFont(0)
top_margin = lcg.UFont(0)
bottom_margin = lcg.UFont(0)

left_page_footer = lcg.Container((
    lcg.PageNumber(),
    lcg.TextContent(' '),
    lcg.Container((lcg.PageHeading(), ),
                  halign=lcg.HorizontalAlignment.CENTER),
))
right_page_footer = lcg.Container((
    lcg.Container((lcg.PageHeading(), ),
                  halign=lcg.HorizontalAlignment.CENTER),
    lcg.TextContent(' '),
    lcg.PageNumber(),
))

debug_device_output_en = {
    # whitespace
    u'\n': u'\n',
    u'\f': u'\n\f\n',
    u' ': u' ',
Ejemplo n.º 6
0
def variables(resolver):
    return dict(love=lcg.TextContent("make love"),
                war=lcg.TextContent("not war"))