~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/lazr/doc/menus.txt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2009-08-05 22:33:21 UTC
  • mfrom: (9024.4.6 cached-menus)
  • Revision ID: launchpad@pqm.canonical.com-20090805223321-955e8jrno5krkfgb
[r=sinzui][ui=none][bug=409022] Cache Link objects in the request to
        avoid them being reconstructed every time a template does
        something like context/menu:facet/foo

Show diffs side-by-side

added added

removed removed

Lines of Context:
809
809
        linked: True
810
810
 
811
811
 
 
812
=== Absolute links ===
 
813
 
 
814
Absolute urls can be made with a full url, including the host part, or
 
815
as a url path beginning with '/'.
 
816
 
 
817
Sometimes the target will be within Launchpad. Other times, the link
 
818
will be to an external site.
 
819
 
 
820
When the link is to a page in Launchpad, we need to treat it the same as
 
821
a normal relative link.  That is, we need to compute 'linked' and
 
822
'selected' as for relative links. The usual use-case is computing an
 
823
absolute link to a page inside launchpad using canonical_url.  In this
 
824
case, the host and protocol part of the url will be the same for the
 
825
canonical_url as for the current request.  This is what we will use to
 
826
see if we have a link to a page within Launchpad.
 
827
 
 
828
    >>> class AbsoluteUrlTargetTestFacets(FacetMenu):
 
829
    ...     links = ['foo', 'bar', 'baz', 'spoo']
 
830
    ...
 
831
    ...     def foo(self):
 
832
    ...         target = ''
 
833
    ...         text = 'Foo'
 
834
    ...         return Link(target, text)
 
835
    ...
 
836
    ...     def bar(self):
 
837
    ...         target = 'ftp://barlink.example.com/barbarbar'
 
838
    ...         text = 'External bar'
 
839
    ...         return Link(target, text)
 
840
    ...
 
841
    ...     def baz(self):
 
842
    ...         target = 'http://launchpad.dev/joy-of-cooking/+baz'
 
843
    ...         text = 'Baz'
 
844
    ...         return Link(target, text)
 
845
    ...
 
846
    ...     def spoo(self):
 
847
    ...         target = '/joy-of-cooking/+spoo'
 
848
    ...         text = 'Spoo'
 
849
    ...         return Link(target, text)
 
850
 
 
851
    >>> print canonical_url(cookbook)
 
852
    http://launchpad.dev/joy-of-cooking
 
853
 
 
854
    >>> request_url = URI('http://launchpad.dev/joy-of-cooking')
 
855
 
 
856
    >>> facets = AbsoluteUrlTargetTestFacets(cookbook)
 
857
    >>> for link in facets.iterlinks(request_url):
 
858
    ...     print link.url, link.linked
 
859
    http://launchpad.dev/joy-of-cooking False
 
860
    ftp://barlink.example.com/barbarbar True
 
861
    http://launchpad.dev/joy-of-cooking/+baz True
 
862
    http://launchpad.dev/joy-of-cooking/+spoo True
 
863
 
 
864
 
812
865
==== The current view's menu ====
813
866
 
814
867
The linked state of a link may be determined from the menu adapted