예제 #1
0
파일: make.py 프로젝트: dungmv56/Xierpa3
 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)  
예제 #2
0
파일: make.py 프로젝트: dungmv56/Xierpa3
    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)
예제 #3
0
 def page(self, component):
     u"""Put the result of **self.page()** by the parent class HtmlBuilder
     in a separate result stream, that can be save into header.php.
     This method assumes that the parent method builds _div+_body+_html,
     to fit the standard footer.php file structure."""
     self.pushResult()
     HtmlBuilder.page(self, component)
     self.phpHeader = self.popResult()
     pass
예제 #4
0
 def _page(self, component):
     u"""Put the result of **self._page()** by the parent class HtmlBuilder
     in a separate result stream, that can be saved into footer.php.
     This method assumes that the parent method builds html+head+_head+body+div,
     to fit the standard header.php file structure."""
     self.pushResult()
     HtmlBuilder._page(self, component)
     self.phpFooter = self.popResult()
     pass
예제 #5
0
 def _page(self, component):
     u"""Put the result of <b>self._page()</b> by the parent class HtmlBuilder
     in a separate result stream, that can be saved into footer.php.
     This method assumes that the parent method builds html+head+_head+body+div,
     to fit the standard header.php file structure."""
     self.pushResult()
     HtmlBuilder._page(self, component)
     self.phpFooter = self.popResult()
     pass
예제 #6
0
 def page(self, component):
     u"""Put the result of <b>self.page()</b> by the parent class HtmlBuilder
     in a separate result stream, that can be save into header.php.
     This method assumes that the parent method builds _div+_body+_html,
     to fit the standard footer.php file structure."""
     self.pushResult()
     HtmlBuilder.page(self, component)
     self.phpHeader = self.popResult()
     pass
예제 #7
0
파일: make.py 프로젝트: thongnv/Xierpa3
 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)
예제 #8
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"""
     cssBuilder = CssBuilder()
     self.build(cssBuilder)
     cssBuilder.save(self, root)
     htmlBuilder = HtmlBuilder()
     self.build(htmlBuilder)
     return htmlBuilder.save(self, root)
예제 #9
0
파일: make.py 프로젝트: thongnv/Xierpa3
 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')  
예제 #10
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')  
예제 #11
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)
예제 #12
0
    def make(self):
        u"""Make the instance of this class to build CSS and HTML."""
        # Create an "instance" (=object) of type "HelloWorld". 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)  
예제 #13
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)  
예제 #14
0
파일: make.py 프로젝트: thongnv/Xierpa3
    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"""
        # 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)  
예제 #15
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))
예제 #16
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
예제 #17
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)
예제 #18
0
파일: theme.py 프로젝트: math-u/Xierpa3
        ), id='sidebar', width='38%', float='left'
    )
    main = Group(components=(
        Header(Text('Header of the page', fontsize=50, color='red')),
        Article(Text('This is a text. ' * 40)),
        Header(Text('Another header')),
        Article(Text('This is another text. ' * 20)),
        ), id='main', width='60%', float='left'
    )
    contact = Group(components=(
        Header(Text('Contact', fontsize=50), name='Contact'))
    )
    components = (
        Page(name='index', components=(main, sidebar), style=style),
        Page(name='contact', components=(contact, sidebar), style=style)
    )
    t = Theme(components)
    hb = HtmlBuilder()
    for page in t.pages:
        page.build(hb) # Clear the builder and build the HTML for page
        hb.save('/Library/WebServer/Documents/xierpa3/%s.html' % page.name)
        print hb.getResult()
        print
        print

    sb = SassBuilder()
    t.build(sb)
    sb.save('/Library/WebServer/Documents/xierpa3/style.scss')
    print sb.getResult()

예제 #19
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.
예제 #20
0
    TITLE = 'Blog Petr van Blokland + Claudia Mens'
    SUBTITLE = 'Notes on design and education.'

    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.