示例#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 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 openAsPhpCallback(self, sender):
     u"""Save site as PHP template in MAMP area and then open it in the browser.
     This function assumes that a PHP server like MAMP is running. Otherwise the
     page will not open in the browser."""
     view = self.getView()
     forceCopy = view.forceCopy.get() # Overwrite existing framework file?
     # Get the current selected site instance.
     site = self.getSite()
     # Save the current adapter for this site in order to restore it in the end.
     # The site instance is create on startup, and we don't want to destroy
     # the original default adapter that is already there.
     saveAdapter = site.adapter 
     #site.adapter = PhpAdapter() # Create the site running with this adapter.
     rootPath = self.getMampRootPath(site)
     # Build the CSS and and PHP/HTML files in the MAMP directory.
     builder = CssBuilder()
     site.build(builder) # Build from entire site theme, not just from template. Result is stream in builder.
     # Copy the PHP framework on that position all files/directories the not yet exist.
     # Existing files will not be overwritten, unless the forceCopy flag is True.
     builder.makeDirectory(rootPath)
     builder.copyTree(self.PHP_SIMPLEMVC, rootPath, force=forceCopy)
     # Save the created output onto the framework template
     builder.save(site, root=rootPath + 'app/templates/default/')
     # Create the PhpBuilder instance that can build/modify the PHP file structure.
     builder = PhpBuilder()
     # Render the website as export file, positioned over the default PHP framework..
     site.build(builder) # Build from entire site theme, not just from template. Result is stream in builder.
     # Copy the PHP frame work and save PHP/HTML files,
     builder.save(site, root=rootPath)
     # Restore the original adapter.
     site.adapter = saveAdapter
     # Open the site in the browser
     webbrowser.open('http://localhost:8888/%s/index.php' % site.getPythonClassName().lower())
示例#3
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)  
示例#4
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)
示例#5
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)
示例#6
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)  
示例#7
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)  
示例#8
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)
示例#9
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)  
示例#10
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)
示例#11
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))
示例#12
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))
示例#13
0
 def buildCss(self, site):
     u"""Build the site to CSS."""
     doIndent = self.getDoIndent() # Boolean flag if indenting should be in output.
     builder = CssBuilder(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
     #    #builder.save(site, path=filePath) # Compile resulting Sass to Css
     #    #builder.save(site, path=filePath.replace('.css', '_doc.css')) # Compile resulting Sass to Css
     #    result = builder.css #getResult()
     if site.e.form[self.C.PARAM_FORCE] or site.e.form[self.C.PARAM_DOCUMENTATION] or result is None:
         # Forced or no cached CSS or building documentation,
         # so try to build is and save it in the cache.
         site.build(builder) # Build from entire site theme, not just from template. Result is stream in builder.
         builder.save(site, path=filePath) # Compile resulting Sass to Css
         result = builder.getResult() # Get the resulting Sass.
     return result, self.C.MIMETYPE_CSS
示例#14
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)
示例#15
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)
示例#16
0
class DemoMagazine(BaseMagazine):
    u"""The **Blog** class implements the standard example blog."""
    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.
        
        
示例#17
0
 def openAsPhpCallback(self, sender):
     u"""Save site as PHP template in MAMP area and then open it in the browser.
     This function assumes that a PHP server like MAMP is running. Otherwise the
     page will not open in the browser."""
     view = self.getView()
     forceCopy = view.forceCopy.get()  # Overwrite existing framework file?
     # Get the current selected site instance.
     site = self.getSite()
     # Save the current adapter for this site in order to restore it in the end.
     # The site instance is create on startup, and we don't want to destroy
     # the original default adapter that is already there.
     saveAdapter = site.adapter
     #site.adapter = PhpAdapter() # Create the site running with this adapter.
     rootPath = self.getMampRootPath(site)
     # Build the CSS and and PHP/HTML files in the MAMP directory.
     builder = CssBuilder()
     site.build(
         builder
     )  # Build from entire site theme, not just from template. Result is stream in builder.
     # Copy the PHP framework on that position all files/directories the not yet exist.
     # Existing files will not be overwritten, unless the forceCopy flag is True.
     builder.makeDirectory(rootPath)
     builder.copyTree(self.PHP_SIMPLEMVC, rootPath, force=forceCopy)
     # Save the created output onto the framework template
     builder.save(site, root=rootPath + 'app/templates/default/')
     # Create the PhpBuilder instance that can build/modify the PHP file structure.
     builder = PhpBuilder()
     # Render the website as export file, positioned over the default PHP framework..
     site.build(
         builder
     )  # Build from entire site theme, not just from template. Result is stream in builder.
     # Copy the PHP frame work and save PHP/HTML files,
     builder.save(site, root=rootPath)
     # Restore the original adapter.
     site.adapter = saveAdapter
     # Open the site in the browser
     webbrowser.open('http://localhost:8888/%s/index.php' %
                     site.getPythonClassName().lower())
示例#18
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