def test_frontpage_staticsite(self): test = staticmockclass(datadir=self.tempdir) test2 = staticmockclass2(datadir=self.tempdir) outfile = self.tempdir+'/index.html' manager.makeresources([test,test2], self.tempdir+'/rsrc') manager.frontpage([test,test2], path=outfile, staticsite=True) t = ET.parse(outfile) header = t.find(".//header/h1/a") self.assertEqual(header.get("href"), 'index.html') headernavlinks = t.findall(".//header/nav/ul/li/a") self.assertEqual(headernavlinks[0].get("href"), 'staticmock/toc/index.html') self.assertEqual(headernavlinks[1].get("href"), 'staticmock2/toc/index.html') css = t.findall("head/link[@rel='stylesheet']") self.assertRegex(css[0].get('href'), '^rsrc/css')
def test_frontpage(self): test = staticmockclass() test2 = staticmockclass2() outfile = self.tempdir+'/index.html' manager.makeresources([test,test2], self.tempdir+'/rsrc') res = manager.frontpage([test,test2], path=outfile) self.assertTrue(res) tree = ET.parse(outfile) header = tree.find(".//header/h1/a") self.assertEqual(header.get("href"), 'http://*****:*****@class='section-wrapper']") self.assertEqual(2, len(list(divs))) self.assertEqual("staticmock", divs[0].get("id")) self.assertEqual("staticmock2", divs[1].get("id")) self.assertIn("Handles foaf:Document", divs[0].find("p").text) self.assertIn("Contains 3 published documents", divs[0].find("p").text)
'items': items, 'doccount': len(list(self.store.list_basefiles_for("_postgenerate")))}) # end frontpage_content from ferenda import manager, LayeredConfig import sys manager.setup_logger("DEBUG") d = RFCs(downloadmax=5) d.download() for basefile in d.store.list_basefiles_for("parse"): d.parse(basefile) RFCs.setup("relate", LayeredConfig(d.get_default_options())) for basefile in d.store.list_basefiles_for("relate"): d.relate(basefile) RFCs.teardown("relate", LayeredConfig(d.get_default_options())) manager.makeresources([d]) for basefile in d.store.list_basefiles_for("generate"): d.generate(basefile) d.toc() d.news() manager.frontpage([d]) shutil.rmtree("data") return_value = True
# begin parse-all import logging from w3cstandards import W3CStandards # client code is responsible for setting the effective log level -- ferenda # just emits log messages, and depends on the caller to setup the logging # subsystem in an appropriate way logging.getLogger().setLevel(logging.INFO) repo = W3CStandards() for basefile in repo.store.list_basefiles_for("parse"): # You you might want to try/catch the exception # ferenda.errors.ParseError or any of it's children here repo.parse(basefile) # end parse-all # begin final-commands from ferenda import manager from w3cstandards import W3CStandards repo = W3CStandards() for basefile in repo.store.list_basefiles_for("relate"): repo.relate(basefile) manager.makeresources([repo], sitename="Standards", sitedescription="W3C standards, in a new form") for basefile in repo.store.list_basefiles_for("generate"): repo.generate(basefile) repo.toc() repo.news() manager.frontpage([repo]) # end final-commands shutil.rmtree(repo.config.datadir) return_value = True
docrepo.download() # Parse all downloaded documents for basefile in docrepo.store.list_basefiles_for("parse"): try: docrepo.parse(basefile) except ParseError as e: pass # or handle this in an appropriate way # Index the text content and metadata of all parsed documents for basefile in docrepo.store.list_basefiles_for("relate"): docrepo.relate(basefile, docrepos) # Prepare various assets for web site navigation makeresources(docrepos, resourcedir="netstandards/exampledata/rsrc", sitename="Netstandards", sitedescription="A repository of internet standard documents") # Relate for all repos must run before generate for any repo for docrepo in docrepos: # Generate static HTML files from the parsed documents, # with back- and forward links between them, etc. for basefile in docrepo.store.list_basefiles_for("generate"): docrepo.generate(basefile) # Generate a table of contents of all available documents docrepo.toc() # Generate feeds of new and updated documents, in HTML and Atom flavors docrepo.news() # Create a frontpage for the entire site
def test_makeresources(self): # Test1: No combining, resources specified by docrepos test = staticmockclass() # print("test.get_default_options %r" % test.get_default_options()) test2 = staticmockclass2() s = os.sep want = {'css':[s.join(['rsrc', 'css','test.css'])], 'js':[s.join(['rsrc', 'js','test.js'])], 'xml':[s.join(['rsrc', 'resources.xml'])] } got = manager.makeresources([test,test2],self.tempdir+os.sep+'rsrc') self.assertEqual(want, got) tree = ET.parse(self.tempdir+os.sep+got['xml'][0]) stylesheets=tree.find("stylesheets").getchildren() self.assertEqual(len(stylesheets),1) self.assertEqual(stylesheets[0].attrib['href'],'rsrc/css/test.css') javascripts=tree.find("javascripts").getchildren() self.assertEqual(len(javascripts),1) self.assertEqual(javascripts[0].attrib['src'],'rsrc/js/test.js') self.assertEqual(tree.find("sitename").text,"MySite") self.assertEqual(tree.find("sitedescription").text,"Just another Ferenda site") self.assertEqual(tree.find("url").text,"http://localhost:8000/") self.assertTrue(os.path.exists(self.tempdir+'/rsrc/css/test.css')) self.assertTrue(os.path.exists(self.tempdir+'/rsrc/js/test.js')) tabs=tree.find("tabs") self.assertTrue(tabs is not None) search=tree.find("search") self.assertTrue(search is not None) # Test2: combining, resources specified by global config # (maybe we should use smaller CSS+JS files? Test takes 2+ seconds...) want = {'css':[s.join(['rsrc', 'css','combined.css'])], 'js':[s.join(['rsrc', 'js','combined.js'])], 'xml':[s.join(['rsrc', 'resources.xml'])] } got = manager.makeresources([test,test2],self.tempdir+os.sep+'rsrc', combine=True, cssfiles=['res/css/normalize-1.1.3.css', 'res/css/main.css'], jsfiles=['res/js/jquery-1.10.2.js', 'res/js/modernizr-2.6.3.js', 'res/js/respond-1.3.0.js'], sitename="Blahonga", sitedescription="A non-default value") self.assertEqual(want,got) tree = ET.parse(self.tempdir+'/'+got['xml'][0]) stylesheets=tree.find("stylesheets").getchildren() self.assertEqual(len(stylesheets),1) self.assertEqual(stylesheets[0].attrib['href'],'rsrc/css/combined.css') javascripts=tree.find("javascripts").getchildren() self.assertEqual(len(javascripts),1) self.assertEqual(javascripts[0].attrib['src'],'rsrc/js/combined.js') self.assertEqual(tree.find("sitename").text,"Blahonga") self.assertEqual(tree.find("sitedescription").text,"A non-default value") self.assertTrue(os.path.exists(self.tempdir+'/rsrc/css/combined.css')) self.assertTrue(os.path.exists(self.tempdir+'/rsrc/js/combined.js')) # check that the combining/minifying indeed saved us some space # physical path for these: relative to the location of ferenda/manager.py. self.assertLess(os.path.getsize(self.tempdir+'/rsrc/css/combined.css'), sum([os.path.getsize(x) for x in ("ferenda/res/css/normalize-1.1.3.css", "ferenda/res/css/main.css")])) self.assertLess(os.path.getsize(self.tempdir+'/rsrc/js/combined.js'), sum([os.path.getsize(x) for x in ("ferenda/res/js/jquery-1.10.2.js", "ferenda/res/js/modernizr-2.6.3.js", "ferenda/res/js/respond-1.3.0.js")])) # Test3: No combining, make sure that a non-customized # DocumentRepository works repo = DocumentRepository() # but remove any external urls -- that's tested separately in Test5 repo.config.cssfiles = [x for x in repo.config.cssfiles if not x.startswith("http://")] got = manager.makeresources([repo],self.tempdir+os.sep+'rsrc') s = os.sep want = {'css':[s.join(['rsrc', 'css','normalize-1.1.3.css']), s.join(['rsrc', 'css','main.css']), s.join(['rsrc', 'css','ferenda.css'])], 'js':[s.join(['rsrc', 'js','jquery-1.10.2.js']), s.join(['rsrc', 'js','modernizr-2.6.3.js']), s.join(['rsrc', 'js','respond-1.3.0.js']), s.join(['rsrc', 'js','ferenda.js'])], 'xml':[s.join(['rsrc', 'resources.xml'])] } self.assertEqual(want,got) # test4: Make sure staticsite works (ie no search form in resources.xml): repo = DocumentRepository() got = manager.makeresources([repo],self.tempdir+os.sep+'rsrc', staticsite = True) tree = ET.parse(self.tempdir+os.sep+got['xml'][0]) search=tree.find("search") self.assertFalse(search) # test5: include one external resource, combine=False test = staticmockclass() test.config.cssfiles.append('http://example.org/css/main.css') want = {'css':[s.join(['rsrc', 'css','test.css']), 'http://example.org/css/main.css'], 'js':[s.join(['rsrc', 'js','test.js'])], 'xml':[s.join(['rsrc', 'resources.xml'])] } got = manager.makeresources([test],self.tempdir+os.sep+'rsrc') self.assertEqual(want,got) # test6: include one external resource but with combine=True, which is unsupported with self.assertRaises(errors.ConfigurationError): got = manager.makeresources([test],self.tempdir+os.sep+'rsrc', combine=True) # test7: test the footer() functionality test = staticmockclass3() got = manager.makeresources([test], self.tempdir+os.sep+'rsrc') tree = ET.parse(self.tempdir+os.sep+got['xml'][0]) footerlinks=tree.findall("footerlinks/nav/ul/li") self.assertTrue(footerlinks) self.assertEqual(3,len(footerlinks)) # test8: test win32 path generation on all OS:es, including one full URL test = staticmockclass() test.config.cssfiles.append('http://example.org/css/main.css') want = {'css':['rsrc\\css\\test.css', 'http://example.org/css/main.css'], 'js':['rsrc\\js\\test.js'], 'xml':['rsrc\\resources.xml']} try: realsep = os.sep os.sep = "\\" got = manager.makeresources([test], self.tempdir+os.sep+'rsrc') self.assertEqual(want,got) finally: os.sep = realsep # test9: nonexistent resources should not be included test = staticmockclass() test.config.cssfiles = ['nonexistent.css'] want = {'css':[], 'js':[s.join(['rsrc', 'js','test.js'])], 'xml':[s.join(['rsrc', 'resources.xml'])] } got = manager.makeresources([test], self.tempdir+os.sep+'rsrc') self.assertEqual(want,got)
items, 'doccount': len(list(self.store.list_basefiles_for("_postgenerate"))) }) # end frontpage_content from ferenda import manager from layeredconfig import LayeredConfig, Defaults import sys manager.setup_logger("DEBUG") d = RFCs(downloadmax=5) d.download() for basefile in d.store.list_basefiles_for("parse"): d.parse(basefile) RFCs.setup("relate", LayeredConfig(Defaults(d.get_default_options()))) for basefile in d.store.list_basefiles_for("relate"): d.relate(basefile) RFCs.teardown("relate", LayeredConfig(Defaults(d.get_default_options()))) manager.makeresources([d]) for basefile in d.store.list_basefiles_for("generate"): d.generate(basefile) d.toc() d.news() manager.frontpage([d]) shutil.rmtree("data") return_value = True