Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76834 - in website/public_html/beta: generated/state site-tools/boost_site
From: dnljms_at_[hidden]
Date: 2012-02-01 18:25:30


Author: danieljames
Date: 2012-02-01 18:25:29 EST (Wed, 01 Feb 2012)
New Revision: 76834
URL: http://svn.boost.org/trac/boost/changeset/76834

Log:
Website: Use common link transformation function.
Text files modified:
   website/public_html/beta/generated/state/feed-pages.txt | 2 +-
   website/public_html/beta/site-tools/boost_site/pages.py | 13 +++----------
   website/public_html/beta/site-tools/boost_site/site_tools.py | 18 ++----------------
   website/public_html/beta/site-tools/boost_site/util.py | 18 ++++++++++++++++++
   4 files changed, 24 insertions(+), 27 deletions(-)

Modified: website/public_html/beta/generated/state/feed-pages.txt
==============================================================================
--- website/public_html/beta/generated/state/feed-pages.txt (original)
+++ website/public_html/beta/generated/state/feed-pages.txt 2012-02-01 18:25:29 EST (Wed, 01 Feb 2012)
@@ -1838,7 +1838,7 @@
 -id
 "version_1_49_0
 -last_modified
-.1327967249.28
+.1328002611.72
 -location
 "users/history/version_1_49_0.html
 -page_state

Modified: website/public_html/beta/site-tools/boost_site/pages.py
==============================================================================
--- website/public_html/beta/site-tools/boost_site/pages.py (original)
+++ website/public_html/beta/site-tools/boost_site/pages.py 2012-02-01 18:25:29 EST (Wed, 01 Feb 2012)
@@ -230,16 +230,9 @@
         if 'released' not in self.flags and self.documentation:
             doc_matcher = re.compile('^/(?:libs/|doc/html/)')
             doc_prefix = self.documentation.rstrip('/')
-
-
- for child in values['description_fragment'].childNodes:
- if child.__class__.__name__ == 'Element':
- for anchor in child.getElementsByTagName('a'):
- if anchor.hasAttribute('href') and doc_matcher.match(
- anchor.getAttribute('href')):
- anchor.setAttribute('href', doc_prefix +
- anchor.getAttribute('href'))
-
+ boost_site.util.transform_links(values['description_fragment'],
+ lambda x: doc_matcher.match(x) and \
+ doc_prefix + x or x)
 
         self.description_xml = boost_site.util.fragment_to_string(values['description_fragment'])
 

Modified: website/public_html/beta/site-tools/boost_site/site_tools.py
==============================================================================
--- website/public_html/beta/site-tools/boost_site/site_tools.py (original)
+++ website/public_html/beta/site-tools/boost_site/site_tools.py 2012-02-01 18:25:29 EST (Wed, 01 Feb 2012)
@@ -3,7 +3,7 @@
 # Distributed under the Boost Software License, Version 1.0.
 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 
-import os, sys, subprocess, glob, re, time, xml.dom.minidom, codecs, urlparse
+import os, sys, subprocess, glob, re, time, xml.dom.minidom, codecs
 import boost_site.templite, boost_site.pages, boost_site.boostbook_parser, boost_site.util
 from boost_site.settings import settings
 
@@ -158,7 +158,7 @@
     # Placing the description in a root element to make it well formed xml.
     description = xml.dom.minidom.parseString(
         '<x>%s</x>' % page.description_xml.encode('utf-8'))
- base_links(description, page_link)
+ boost_site.util.base_links(description, page_link)
     node.appendChild(rss_feed.createTextNode(
         boost_site.util.fragment_to_string(description.firstChild)))
     item.appendChild(node)
@@ -168,19 +168,5 @@
         'quickbook': qbk_file,
         'last_modified': page.last_modified
     })
-
-def base_links(node, base_link):
- base_element_links(node, base_link, 'a', 'href')
- base_element_links(node, base_link, 'img', 'src')
-
-def base_element_links(node, base_link, tag_name, attribute):
- if node.nodeType == node.ELEMENT_NODE or \
- node.nodeType == node.DOCUMENT_NODE:
- for x in node.getElementsByTagName(tag_name):
- x.setAttribute(attribute,
- urlparse.urljoin(base_link, x.getAttribute(attribute)))
- elif node.nodeType == node.DOCUMENT_FRAGMENT_NODE:
- for x in node.childNodes:
- base_element_links(x, base_link, tag_name, attribute)
  
 ################################################################################

Modified: website/public_html/beta/site-tools/boost_site/util.py
==============================================================================
--- website/public_html/beta/site-tools/boost_site/util.py (original)
+++ website/public_html/beta/site-tools/boost_site/util.py 2012-02-01 18:25:29 EST (Wed, 01 Feb 2012)
@@ -3,6 +3,8 @@
 # Distributed under the Boost Software License, Version 1.0.
 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 
+import urlparse
+
 def htmlencode(text):
     return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&rt;')
 
@@ -14,3 +16,19 @@
     http://bugs.python.org/issue9883
     """
     return ''.join(x.toxml('utf-8').decode('utf-8') for x in fragment.childNodes)
+
+def base_links(node, base_link):
+ transform_links(node, lambda x: urlparse.urljoin(base_link,x))
+
+def transform_links(node, func):
+ transform_links_impl(node, 'a', 'href', func)
+ transform_links_impl(node, 'img', 'src', func)
+
+def transform_links_impl(node, tag_name, attribute, func):
+ if node.nodeType == node.ELEMENT_NODE or \
+ node.nodeType == node.DOCUMENT_NODE:
+ for x in node.getElementsByTagName(tag_name):
+ x.setAttribute(attribute, func(x.getAttribute(attribute)))
+ elif node.nodeType == node.DOCUMENT_FRAGMENT_NODE:
+ for x in node.childNodes:
+ transform_links_impl(x, tag_name, attribute, func)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk