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

Method build

Lib/pagebot/elements/views/mampview.py:46–106  ·  view source on GitHub ↗

>>> from pagebot.contributions.filibuster.blurb import Blurb >>> article = Blurb().getBlurb('da_text') # Answer random text of design article >>> from pagebot.toolbox.color import color >>> from pagebot.elements import newText >>> from pagebot.document impor

(self, path=None, pageSelection=None, multiPage=True, **kwargs)

Source from the content-addressed store, hash-verified

44 # B U I L D H T M L / C S S
45
46 def build(self, path=None, pageSelection=None, multiPage=True, **kwargs):
47 """
48
49 >>> from pagebot.contributions.filibuster.blurb import Blurb
50 >>> article = Blurb().getBlurb('da_text') # Answer random text of design article
51 >>> from pagebot.toolbox.color import color
52 >>> from pagebot.elements import newText
53 >>> from pagebot.document import Document
54 >>> siteName = 'TestDoc'
55 >>> sitePath = '_export/' + siteName
56 >>> from pagebot import getContext
57 >>> context = getContext('Html')
58 >>> doc = Document(name=siteName, w=300, h=400, padding=(30, 40, 50, 60), viewId='Mamp', context=context)
59 >>> view = doc.view
60 """
61 doInit = True
62 rootPath = getMampPath() # Get the root path in this context where Mamp stores files.
63 siteName = (self.doc.name or self.doc.title or 'UntitledSite').replace(' ','_') # Make safe site name
64
65 if path is None:
66 path = rootPath + siteName + '/'
67 if os.path.exists(path): # In case of using default path, it's safe to delete.
68 if self.verbose:
69 print('[MampView.build] Deleting %s' % path)
70 shutil.rmtree(path)
71 else: # Make sure it is not there. Remove manually otherwise.
72 assert path and not os.path.exists(path), '[MampView.build] Export site path "%s" exists. For safety, delete manually' % (path)
73 if not path.endswith('/'):
74 path += '/'
75
76 b = self.context.b
77 pageItems = self.doc.pages.items()
78
79 # Recursively let all elements prepare for the upcoming build_html, e.g. by saving scaled images
80 # into cache if that file does not already exists. Note that this is done on a page-by-page
81 # level, not a preparation of all
82 for pn, pages in pageItems:
83 for page in pages:
84 hook = 'prepare_' + b.PB_ID # E.g. page.prepare_html()
85 getattr(page, hook)(self) # Typically calling page.prepare_html. Pass self as view.
86
87 for pn, pages in pageItems:
88 for page in pages:
89 b.clearJs()
90 # Building for HTML, try the hook. Otherwise call by main page.build.
91 hook = 'build_' + b.PB_ID # E.g. page.build_html()
92 getattr(page, hook)(self, path) # Typically calling page.build_html. Pass self as view
93
94 # Deprecated
95 # TODO: Change this, so it will recognize the type of css file, and then decide on conversion
96 # TODO: That also applies for th cssPy % theme.mood conversion.
97 #if self.useXXXXScss:
98 # # Write all collected SCSS vatiables into one file
99 # if os.path.exists(self.SCSS_PATH):
100 # # Write all collected SCSS variables into one file
101 # b.writeScss(self.SCSS_VARIABLES_PATH)
102 # # Compile SCSS to CSS if it exists.
103 # b.compileScss(self.SCSS_PATH)

Callers

nothing calls this directly

Calls 3

getMampPathFunction · 0.90
clearJsMethod · 0.80
copyResourcesMethod · 0.80

Tested by

no test coverage detected