Пример #1
0
    def make(self, root=None):
        u"""The instance of this class builds CSS and HTML files at the optional path **root**.
        If not defined, then the default ~/Desktop/Xierpa3Examples/[component.name] is used as export path,
        as set by Builder.DEFAULT_ROOTPATH"""
        # Create an "instance" (=object) of type "HelloWorldLayout". The type (=class) defines
        # the behavior of the object that is made by calling the class.

        # C S S
        # Create the main CSS builder instance to build the SASS/CSS part of the site.
        cssBuilder = CssBuilder()
        # Compile (=build) the SCSS to CSS and save the file in "css/style.css".
        self.build(
            cssBuilder
        )  # Build from entire site theme, not just from template. Result is stream in builder.
        cssBuilder.save(self, root)

        # H T M L
        # Create the main HTML builder instance to build the HTML part of the site.
        htmlBuilder = HtmlBuilder()
        # Compile the HTML and save the resulting HTML file in "helloWorld.html".
        self.build(
            htmlBuilder
        )  # Build from entire site theme, not just from template. Result is stream in builder.
        # Answer the path, so we can directly open the file with a browser.
        return htmlBuilder.save(self, root)
Пример #2
0
 def render_GET(self, httprequest):
     u"""
     The <code>render_GET</code> method is called by Twisted to handle the GET <attr>httprequest</attr>. The
     site instance is called with <code>b.build()</code>. The result (this can be HTML, JSON or binary data) is
     answered. The application needs to have the the right MIME type in the output.
     """
     site = self.getSite(httprequest)  # Site is Theme instance
     # b.setMimeTypeEncoding(httprequest)
     try:
         # If there is a matching file in the site root/files folder, then answer this.
         filePath = self.getFilePath(site)
         result = self.resolveByFile(site, filePath)
         if site.e.form['force'] or result is None or self.INITCSS:
             if site.e.request.path.endswith('.css'):
                 builder = CssBuilder(e=site.e)
                 site.build(
                     builder
                 )  # Build from entire site theme, not just from template.
                 builder.save(site, path=filePath)  # Compile Sass to Css
                 result = builder.getResult()
                 self.INITCSS = False  # Mark that the initialize CSS on startup has been done.
             else:
                 site.reset(
                 )  # Allow the theme to reset values for every page request, depending on url parameters.
                 builder = HtmlBuilder(e=site.e)
                 template = site.getMatchingTemplate(builder)
                 template.build(builder)
                 result = builder.getResult()
         return result
     except Exception, e:
         t = traceback.format_exc()
         httprequest.setHeader('content-type', 'text/html')
         return self.renderError(e, t)
Пример #3
0
 def make(self, root=None):
     u"""The instance of this class builds CSS and HTML files at the optional path *root*.
     If not defined, then @Builder.C.DEFAULT_ROOTPATH@ is used, as in general builders 
     are associated where output should go to. 
     E.g. the default @HtmlBuilder.C.DEFAULT_ROOTPATH@ is defined as to the user extended 
     path of @~/Desktop/Xierpa3Examples/[component.name]@.
     And for @CssBuilder@ it is @~/Desktop/Xierpa3Examples/[component.name]/css/style.css@."""
     if root is None:
         root = TX.asDir(self.C.PATH_EXAMPLES) # Expand user path to full directory path.
     # C S S
     # Create the main CSS builder instance to build the CSS part of the site.
     cssBuilder = CssBuilder()
     # Compile (=build) the SCSS to CSS.
     self.build(cssBuilder) 
     # Save the file in "css/style.css".
     cssBuilder.save(self, root=root) 
 
     # H T M L
     # Create the main HTML builder instance to build the HTML part of the site.
     htmlBuilder = HtmlBuilder()
     # Compile the site instance and its components into HTML code.
     self.build(htmlBuilder) 
     # Save the resulting HTML file in "helloWorld.html"
     # Answer the file path, so we can directly open the file with a browser.
     return htmlBuilder.save(self, root=root)  
Пример #4
0
 def make(self, root=None):
     u"""The instance of this class builds CSS and HTML files at the optional path <b>root</b>.
     If not defined, then the default ~/Desktop/Xierpa3Examples/[component.name] is used as export path,
     as set by Builder.DEFAULT_ROOTPATH"""
     cssBuilder = CssBuilder()
     self.build(cssBuilder)
     cssBuilder.save(self, root)
     htmlBuilder = HtmlBuilder()
     self.build(htmlBuilder)
     return htmlBuilder.save(self, root)
Пример #5
0
 def make(self, root):
     u"""The instance of this class builds the HTML file at the optional path *root*.
     If not defined, then @Builder.C.DEFAULT_ROOTPATH@ is used, as in general builders 
     are associated where output should go to. 
     E.g. the default @HtmlBuilder.C.DEFAULT_ROOTPATH@ is defined as to the user extended 
     path of @~/Desktop/Xierpa3Examples/[component.name]@.
     And for @CssBuilder@ it is @~/Desktop/Xierpa3Examples/[component.name]/css/style.css@."""    
     # H T M L
     # Create the main HTML builder instance to build the HTML part of the site.
     htmlBuilder = HtmlBuilder()
     # Compile the site instance and its components into HTML code.
     self.build(htmlBuilder) 
     # Save the resulting HTML file in "index.html"
     # Answer the file path, so we can directly open the file with a browser.
     return htmlBuilder.save(self, path=root + 'index.html')  
Пример #6
0
 def save(self, theme, path=None, makeDirectory=True):
     u"""Create all necessery Kirby directories. Then call the CssBuilder and
     HtmlBuilder to generate the site files. Note that the special PHP syntax in
     the HTML output is entirely caused by the KirbyAdapter, generating the
     PHP code instead of fixed content."""
     if path is None:
         path = self.getRootPath() + theme.root.name.lower() + '/'
     self.makeDirectory(path)
     for directory in self.DIRECTORIES:
         self.makeDirectory(path + directory)
     # Output CSS as single .scss and convert to .css
     builder = CssBuilder()
     builder.save(theme, path + self.getStylePath(theme))
     # Output HTML pages
     builder = HtmlBuilder()
     builder.save(theme, path + self.getTemplatePath(theme))
Пример #7
0
    def make(self):
        u"""Make the instance of this class to build CSS and HTML."""
        # Create an "instance" (=object) of type "HelloWorldLayout". The type (=class) defines
        # the behavior of the object that is made by calling the class.

        # C S S
        # Create the main CSS builder instance to build the CSS part of the site.
        cssBuilder = CssBuilder()
        # Compile (=build) the SCSS to CSS and save the file in "css/style.css".
        cssBuilder.save(self) 
    
        # H T M L
        # Create the main HTML builder instance to build the HTML part of the site.
        htmlBuilder = HtmlBuilder()
        # Compile the HTML and save the resulting HTML file in "helloWorld.html".
        # Answer the path, so we can open the file with a browser.
        return htmlBuilder.save(self)  
Пример #8
0
 def buildHtml(self, site):
     u"""Build the site for HTML."""
     doIndent = self.getDoIndent() # Boolean flag if indenting should be in output.
     site.reset() # Allow the theme to reset values for every page request, depending on url parameters.
     builder = HtmlBuilder(e=site.e, doIndent=doIndent)
     filePath = builder.getFilePath(site)
     result = self.resolveByFile(site, filePath)
     if site.e.form[self.C.PARAM_DOCUMENTATION]: # /documentation
         site.buildDocumentation(builder) # Build the live documentation page from the site
         result = builder.popResult()
     elif site.e.form[self.C.PARAM_FORCE] or result is None:
         # Find the matching template for the current site and build from there.
         template = site.getMatchingTemplate(builder)
         builder.pushResult()
         template.build(builder)
         result = builder.popResult()
     return result, self.C.MIMETYPE_HTML
Пример #9
0
    def render_POST(self, httprequest):
        u"""
        The <code>render_POST</code> method is called by Twisted to handle the POST <attr>httprequest</attr>. The
        site instance is called with <code>b.build()</code>. The result (this can be HTML, JSON or binary data) is
        answered. The application is supposed to have the the right MIME type in the output. The data of the post is
        located in the file object <code>httprequest.content</code>. The data can be read by <code>
        httprequest.content.read()</code>.
        
        """
        site = self.getSite(httprequest)  # Site is Theme instance
        site.handlePost()
        # b.setMimeTypeEncoding(httprequest)

        if isinstance(httprequest.content, StringIO.OutputType):
            # Probably JSON.
            json = httprequest.content.getvalue()
            # print json
            # b.buildJSON(json)
        try:
            # If there is a matching file in the site root folder, then answer this.
            result = self.resolveByFile(site, self.getFilePath(site))
            if result is None:
                if site.e.request.path.endswith('.css'):
                    builder = CssBuilder(e=site.e)
                    site.build(
                        builder
                    )  # Build from entire site theme, not just from template.
                    builder.save()  # Compile Sass to Css
                    result = builder.getResult()
                else:
                    builder = HtmlBuilder(e=site.e)
                    template = site.getMatchingTemplate(builder)
                    template.build(builder)
                    result = builder.getResult()
            return result
        except Exception, e:
            t = traceback.format_exc()
            return self.renderError(e, t)
Пример #10
0
    def baseComponents(self):
        logo = Logo()
        socialmedia = SocialMedia(twitterAccount='mymagazine',
                                  facebookAccount='mymagazine')

        homePage = Page(components=(logo, socialmedia))
        return [homePage]


if __name__ == '__main__':
    magazine = DemoMagazine()
    # Create the main CSS builder
    cssBuilder = CssBuilder()
    # Create the main HTML builder
    htmlBuilder = HtmlBuilder()
    #bluePrintBuilder = BluePrintBuilder()
    for template in magazine.getTemplates():
        # Build the SCSS/CSS of this theme template
        template.build(cssBuilder)
        cssPath = template.getStylePath()
        cssBuilder.save(
            cssPath,
            makeDirectory=True)  # Compile the SCSS to CSS and save the file.
        # Build the HTML of this theme template
        template.build(
            htmlBuilder)  # Build the code for every page template in the theme
        exportPath = htmlBuilder.getTemplatePath(magazine)
        print 'Saving', exportPath
        htmlBuilder.save(exportPath, makeDirectory=True
                         )  # Save the exported template code into its file.