예제 #1
0
파일: test_query.py 프로젝트: StetHD/nevow
 def test_listOfTagPatternGenerator(self):
     """
     Querying a list which contains a tag for patterns gives back the tag if
     the tag has a matching pattern special.
     """
     patterns = IQ([tags.div(pattern="foo", bar="baz")]).patternGenerator("foo")
     for i in xrange(3):
         self.assertEqual(patterns.next().attributes['bar'], "baz")
예제 #2
0
파일: test_query.py 프로젝트: StetHD/nevow
    def _testQuery(self, container, expected):
        pattern = IQ(container).onePattern('foo')

        # The pattern node has had its pattern special removed - put it back,
        # so we can perform a comparison
        self.assertEqual(pattern.pattern, None)
        pattern.pattern = 'foo'

        self.assertEqual(str(pattern), str(expected))
예제 #3
0
 def test_listOfTagPatternGenerator(self):
     """
     Querying a list which contains a tag for patterns gives back the tag if
     the tag has a matching pattern special.
     """
     patterns = IQ([tags.div(pattern="foo",
                             bar="baz")]).patternGenerator("foo")
     for i in xrange(3):
         self.assertEqual(patterns.next().attributes['bar'], "baz")
예제 #4
0
    def _testQuery(self, container, expected):
        pattern = IQ(container).onePattern('foo')

        # The pattern node has had its pattern special removed - put it back,
        # so we can perform a comparison
        self.assertEqual(pattern.pattern, None)
        pattern.pattern = 'foo'

        self.assertEqual(str(pattern), str(expected))
예제 #5
0
 def _testTooManyPatterns(self, obj):
     """
     Test that the L{IQ} adapter for C{obj} provides a L{onePattern} method
     which raises L{stan.TooManyNodes} if passed a pattern name for which
     there are multiple pattern nodes.
     """
     self.assertRaises(stan.TooManyNodes, IQ(obj).onePattern, 'foo')
예제 #6
0
 def test_onePatternTag(self):
     """
     A L{Tag} returned from L{IQ.onePattern} is represented in the flattened
     output.
     """
     self.assertStringEqual(
         self.flatten(IQ(div(pattern="foo")).onePattern("foo")),
         "<div></div>")
예제 #7
0
def startMenu(translator, navigation, tag):
    """
    Drop-down menu-style navigation view.

    For each primary navigation element available, a copy of the I{tab}
    pattern will be loaded from the tag.  It will have its I{href} slot
    filled with the URL for that navigation item.  It will have its I{name}
    slot filled with the user-visible name of the navigation element.  It
    will have its I{kids} slot filled with a list of secondary navigation
    for that element.

    For each secondary navigation element available beneath each primary
    navigation element, a copy of the I{subtabs} pattern will be loaded
    from the tag.  It will have its I{kids} slot filled with a self-similar
    structure.

    @type translator: L{IWebTranslator} provider
    @type navigation: L{list} of L{Tab}

    @rtype: {nevow.stan.Tag}
    """
    setTabURLs(navigation, translator)
    getp = IQ(tag).onePattern

    def fillSlots(tabs):
        for tab in tabs:
            if tab.children:
                kids = getp('subtabs').fillSlots('kids',
                                                 fillSlots(tab.children))
            else:
                kids = ''

            yield dictFillSlots(
                getp('tab'), dict(href=tab.linkURL, name=tab.name, kids=kids))

    return tag.fillSlots('tabs', fillSlots(navigation))
예제 #8
0
 def testContextMissing(self):
     self.assertRaises(
         stan.NodeNotFound,
         IQ(context.WovenContext(tag=notEnough)).patternGenerator, 'foo')
예제 #9
0
 def testContextGenerators(self):
     self.verify(
         IQ(context.WovenContext(tag=multiple)).patternGenerator('foo'))
예제 #10
0
 def testTagGenerators(self):
     self.verify(IQ(multiple).patternGenerator('foo'))
예제 #11
0
 def testXmlMissing(self):
     self.assertRaises(stan.NodeNotFound,
                       IQ(stan.xml('<html>hello</html>')).patternGenerator,
                       'foo')
예제 #12
0
 def testLoaderGenerators(self):
     self.verify(IQ(loaders.stan(multiple)).patternGenerator('foo'))
예제 #13
0
 def testClonableDefault(self):
     orig = tags.p["Hello"]
     gen = IQ(flat.precompile(notEnough)).patternGenerator('foo', orig)
     new = gen.next()
     self.assertEquals(new.tagName, 'p')
     self.assertNotIdentical(orig, new)
예제 #14
0
 def test_listNotEnough(self):
     P = flat.precompile(notEnough)
     self.assertRaises(stan.NodeNotFound, IQ(P).onePattern, 'foo')
예제 #15
0
 def test_loaderNotEnough(self):
     L = loaders.stan(notEnough)
     self.assertRaises(stan.NodeNotFound, IQ(L).onePattern, 'foo')
예제 #16
0
 def test_contextNotEnough(self):
     self.assertRaises(stan.NodeNotFound,
                       IQ(context.WovenContext(tag=notEnough)).onePattern,
                       'foo')
예제 #17
0
 def test_contextTagQuery(self):
     T = simple.clone(deep=False)
     T.pattern = "outer"
     C = context.WovenContext(tag=T)
     new = IQ(C).onePattern('outer')
     self.assertEquals(new.tagName, 'html')
예제 #18
0
 def test_tagNotEnough(self):
     self.assertRaises(stan.NodeNotFound, IQ(notEnough).onePattern, 'foo')
예제 #19
0
 def test_loaderQuery(self):
     L = loaders.stan(simple)
     new = IQ(L).onePattern('foo')
     self.assertEquals(new.tagName, 'div')
예제 #20
0
 def test_loaderTooMany(self):
     L = loaders.stan(tooMany)
     self.assertRaises(stan.TooManyNodes, IQ(L).onePattern, 'foo')
예제 #21
0
 def testListGenerators(self):
     self.verify(IQ(flat.precompile(multiple)).patternGenerator('foo'))
예제 #22
0
 def test_listTooMany(self):
     P = flat.precompile(tooMany)
     self.assertRaises(stan.TooManyNodes, IQ(P).onePattern, 'foo')
예제 #23
0
 def testListMissing(self):
     self.assertRaises(stan.NodeNotFound,
                       IQ(flat.precompile(notEnough)).patternGenerator,
                       'foo')
예제 #24
0
 def testNonClonableDefault(self):
     gen = IQ(flat.precompile(notEnough)).patternGenerator('foo', 'bar')
     new = gen.next()
     self.assertEquals(new, 'bar')
예제 #25
0
 def testTagMissing(self):
     self.assertRaises(stan.NodeNotFound,
                       IQ(loaders.stan(notEnough)).patternGenerator, 'foo')
예제 #26
0
 def test_listQuery(self):
     P = flat.precompile(simple)
     new = IQ(P).onePattern('foo')
     self.assertEquals(new.tagName, 'div')
예제 #27
0
 def testNonClonableDefault(self):
     gen = IQ(flat.precompile(notEnough)).patternGenerator('foo', 'bar')
     new = gen.next()
     self.assertEquals(new, 'bar')
예제 #28
0
 def testLoaderPatterns(self):
     self.verify(IQ(loaders.stan(multiple)).allPatterns('foo'))
예제 #29
0
 def testTagPatterns(self):
     self.verify(IQ(multiple).allPatterns('foo'))
예제 #30
0
def applicationNavigation(ctx, translator, navigation):
    """
    Horizontal, primary-only navigation view.

    For the navigation element currently being viewed, copies of the
    I{selected-app-tab} and I{selected-tab-contents} patterns will be
    loaded from the tag.  For all other navigation elements, copies of the
    I{app-tab} and I{tab-contents} patterns will be loaded.

    For either case, the former pattern will have its I{name} slot filled
    with the name of the navigation element and its I{tab-contents} slot
    filled with the latter pattern.  The latter pattern will have its
    I{href} slot filled with a link to the corresponding navigation
    element.

    The I{tabs} slot on the tag will be filled with all the
    I{selected-app-tab} or I{app-tab} pattern copies.

    @type ctx: L{nevow.context.WebContext}
    @type translator: L{IWebTranslator} provider
    @type navigation: L{list} of L{Tab}

    @rtype: {nevow.stan.Tag}
    """
    setTabURLs(navigation, translator)
    selectedTab = getSelectedTab(navigation, url.URL.fromContext(ctx))

    getp = IQ(ctx.tag).onePattern
    tabs = []

    for tab in navigation:
        if tab == selectedTab or selectedTab in tab.children:
            p = 'selected-app-tab'
            contentp = 'selected-tab-contents'
        else:
            p = 'app-tab'
            contentp = 'tab-contents'

        childTabs = []
        for subtab in tab.children:
            try:
                subtabp = getp("subtab")
            except NodeNotFound:
                continue
            childTabs.append(
                dictFillSlots(
                    subtabp, {
                        'name': subtab.name,
                        'href': subtab.linkURL,
                        'tab-contents': getp("subtab-contents")
                    }))
        tabs.append(
            dictFillSlots(
                getp(p), {
                    'name': tab.name,
                    'tab-contents': getp(contentp).fillSlots(
                        'href', tab.linkURL),
                    'subtabs': childTabs
                }))

    ctx.tag.fillSlots('tabs', tabs)
    return ctx.tag
예제 #31
0
 def testClonableDefault(self):
     orig = tags.p["Hello"]
     gen = IQ(flat.precompile(notEnough)).patternGenerator('foo', orig)
     new = gen.next()
     self.assertEquals(new.tagName, 'p')
     self.assertNotIdentical(orig, new)
예제 #32
0
 def testContextPatterns(self):
     self.verify(IQ(context.WovenContext(tag=multiple)).allPatterns('foo'))
예제 #33
0
 def testListPatterns(self):
     self.verify(IQ(flat.precompile(multiple)).allPatterns('foo'))
예제 #34
0
 def test_contextTagTooMany(self):
     tooMany = tags.html(pattern="foo")[tags.div(pattern="foo")]
     self.assertRaises(stan.TooManyNodes,
                       IQ(context.WovenContext(tag=tooMany)).onePattern,
                       'foo')