MCPcopy Create free account
hub / github.com/PageBot/PageBot / build_html

Method build_html

Lib/pagebot/elements/page.py:438–501  ·  view source on GitHub ↗

Builds the HTML/CSS code through WebBuilder (or equivalent) that is the closest representation of self. If there are any child elements, then also included their code, using the level recursive indent. Single page site, exporting to html source, with CSS inside. >>>

(self, view, path)

Source from the content-addressed store, hash-verified

436 # H T M L / C S S S U P P O R T
437
438 def build_html(self, view, path):
439 """Builds the HTML/CSS code through WebBuilder (or equivalent) that is
440 the closest representation of self. If there are any child elements,
441 then also included their code, using the level recursive indent.
442
443 Single page site, exporting to html source, with CSS inside.
444 >>> import os
445 >>> from pagebot.document import Document
446 >>> from pagebot import getContext
447 >>> context = getContext('Html')
448 >>> doc = Document(name='SinglePageSite', viewId='Site', context=context)
449 >>> page = doc[1]
450 >>> page.title = 'Home'
451 >>> page.cssCode = 'body {background-color:black}'
452 >>> # No extension for site folder if exporting to a website
453 >>> exportPath = '_export/Home'
454 >>> doc.export(exportPath)
455 >>> #result = os.system('open %s/index.html' % exportPath)
456 """
457 # Get current context and builder from this view.
458 context = view.context
459 # This is a bit more efficient than self.b once we got the context
460 # fixed.
461 b = context.b
462 b.clearHtml()
463
464 #b.clearCss()
465 #self.build_scss(view)
466
467 # In case the full HTML is here, then just output it.
468 if self.htmlCode:
469 # This is mostly used for debug and new templates.
470 b.addHtml(self.htmlCode)
471 elif self.htmlPaths is not None:
472 for htmlPath in self.htmlPaths:
473 # Add HTML content of file, if path is not None and the file exists.
474 b.importHtml(htmlPath)
475 else:
476 self.write_html(view, path)
477
478 if view.doExport:
479 # View flag to avoid writing, in case of testing. Construct the
480 # file name for this page and save the file.
481 url = self.url.lower()
482
483 if not url.endswith('.html'):
484 url += '.html'
485
486 # Make sure that the root path folder of the site is there
487 if not path.endswith('/'):
488 path += '/'
489
490 # Decide to save as folders (in which care relative image/CSS/JS
491 # paths also need to be made relative.
492 if not view.saveUrlAsDirectory:
493 url = url.replace('/', '-')
494
495 filePath = path + url

Callers 1

write_bodyMethod · 0.45

Calls 6

write_htmlMethod · 0.95
path2DirFunction · 0.90
clearHtmlMethod · 0.80
addHtmlMethod · 0.80
importHtmlMethod · 0.80
writeHtmlMethod · 0.80

Tested by

no test coverage detected