def baseComponents(self): u"""Create the component instances""" # Import current example site, as anchor for the article files. from xierpa3.sites.examples import textilearticles # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(textilearticles) + '/files/articles/' adapter = ArticleAdapter(articleRoot) # Preferred adapter class for articles in this site. # Create navigation instance, to choose between the available articles. menu = Menu(adapter=adapter) menuContainer = Container(components=menu) # Create the article component to contain articles answered by the adapter. #article = SimplexArticle(adapter=adapter) article = Article(width=Perc(70), adapter=adapter, showPoster=True, splitChapters=False) articleSideBar = ArticleSideBar(width=Perc(22), adapter=adapter) featuredArticles = FeaturedByImage(width=Perc(22), adapter=adapter, # Example to overwrite the default BluePrint parameter titleColor titleColor=Color('red')) #featuredByImage = FeaturedByText(widht=Perc(22), adapter=adapter) # Make main page container for the article column container = Container(components=( #article, articleSideBar, #featuredArticles, #featuredByImage )) # The class is also the page name in the url. homePage = Page(class_=self.C.TEMPLATE_INDEX, name=self.C.TEMPLATE_INDEX, fonts=self.URL_FONTS, title=self.TITLE, css=self.C.URL_CSS, components=(menuContainer, container)) return [homePage]
def baseComponents(self): # Create the article adapter # Import articles from the doingbydesign site, sharing the article files. from xierpa3.sites import doingbydesign # Root path where to find the article Simplex wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' adapter = SimpleSiteAdapter(articleRoot) # Header logo = Logo() menu = Menu() header = Header(components=(logo,menu), mobileContainerDisplay=self.C.NONE, doc_mobileContainerDisplay=u'Header is not visible for mobile') mobileNavigation = MobileNavigation() # Is container by itself. Change?? # Create the component instances article = Article(width=Perc(68)) featuredByImage = FeaturedByImage(count=1, width=Perc(30)) featuredByText = FeaturedByText(start=1, count=3, width=Perc(30)) # Create the single page instance, containing the number of components mainHome = Container(components=(article, featuredByImage, featuredByText)) # Footer footer = Footer(components=(menu,), containerBackgroundColor=self.FOOTERBGCOLOR) # The class is also the page name in the url. homePage = Page(class_=self.C.TEMPLATE_INDEX, name=self.C.TEMPLATE_INDEX, adapter=adapter, #components=(mobileNavigation, header, mainHome, footer), #components=(header, mainHome, footer), components=Container(header), fonts=self.URL_FONTS, title=self.TITLE, css=self.C.URL_CSS) return [homePage]
def getSiteAdapter(self): u"""Answer the adapter for this site, including all articles of the DbD site.""" from xierpa3.sites import doingbydesign # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' return TextileFileAdapter( articleRoot) # Preferred adapter class for articles in this site.
def baseComponents(self): # Import current example site, as anchor for the article files. from xierpa3.sites import doingbydesign # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' adapter = DbDAdapter(articleRoot) # Preferred adapter class for articles in this site. logo = Logo(text='Doing by Design', fontFamily='Impact', color=Color('#888'), fontSize=Em(1.8)) menu = Menu() mobileNavigation = DbDMobileNavigation() article = Article() featuredByImage = FeaturedByImage(start=0, width=Perc(65.4), showTitle=False, showHeadline=False, showTopic=False) featuredByText = FeaturedByText(start=0, width=Perc(30.75)) # Containers top = Top(components=(logo, menu), media=Media(max=self.C.M_MOBILE_MAX, display=self.C.NONE)) featured = Featured(components=(featuredByImage, featuredByText), backgroundColor=Color('#262c37')) section = Section(components=(featuredByImage,)) mainContent = MainContent(components=article) footer = Footer(components=(menu)) homePage = Page(name=self.C.TEMPLATE_INDEX, components=(mobileNavigation, top, featured, section, mainContent, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) articlePage = Page(name=self.C.TEMPLATE_ARTICLE, comoonents=(mobileNavigation, top, article, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) return [homePage, articlePage]
class Typo2014(BaseBlog): u"""The <b>Blog</b> class implements the standard example show with content based on files.""" TITLE = 'Typo 2014' SUBTITLE = 'Roots' SRCLOGO = 'http://data.xierpa.com.s3.amazonaws.com/_images/examples/typo2014.png' # Cache the adapter, initialized automatic. ADAPTER = Typo2014Adapter(root=TX.module2Path(typo2014) + '/files/articles') def baseComponents(self): logo = Logo(logoName='Type 2014', hoverColor='#888') # logoSrc=self.SRCLOGO menu = Menu() socialmedia = SocialMedia(twitterAccount='typo2014', facebookAccount='typo2014') title = self.TITLE + ': ' + self.SUBTITLE header = Header(components=(logo, menu, socialmedia), mobileContainerDisplay=C.NONE) mobileNavigation = MobileNavigation( title=title) # Is container by itself. Change?? footer = Footer(components=(menu, )) homePage = Page(name=C.TEMPLATE_INDEX, components=(mobileNavigation, header, footer), css=self.URL_CSS, fonts=self.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.URL_FAVICON) return [homePage]
class Typo2014(BaseBlog): TITLE = 'Typo2014' SUBTITLE = 'Roots.' SRCLOGO = 'http://data.xierpa.com.s3.amazonaws.com/_images/examples/typo2014.png' # Cache the adapter, initialized automatic. ADAPTER = Typo2014Adapter(root=TX.module2Path(typo2014) + '/files/articles') def baseComponents(self): logo = Logo(logoSrc=self.SRCLOGO) menu = Menu() socialmedia = SocialMedia(twitterAccount='typo2014', facebookAccount='typo2014') header = Header(components=(logo, menu, socialmedia), mobileContainerDisplay=C.NONE) mobileNavigation = MobileNavigation( ) # Is container by itself. Change?? footer = Footer(components=(menu, )) homePage = Page(name=C.TEMPLATE_INDEX, components=(mobileNavigation, header, footer), css=self.URL_CSS, fonts=self.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.URL_FAVICON) return [homePage]
def buildResource(self, site): u"""The url refers to a xierpa3 resource, try to find it and answer the result with the appropriate mime type.""" path = TX.path2ParentDirectory(TX.module2Path(xierpa3)) + site.e.request.path if os.path.exists(path): f = open(path, 'rb') result = f.read() f.close() return result, self.C.MIMETYPE_PNG return '', self.C.MIMETYPE_HTML
def baseComponents(self): # Import current example site, as anchor for the article files. from xierpa3.sites import doingbydesign # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' adapter = DbDAdapter( articleRoot) # Preferred adapter class for articles in this site. logo = Logo(text='Doing by Design', fontFamily='Impact', color=Color('#888'), fontSize=Em(1.8)) menu = Menu() mobileNavigation = DbDMobileNavigation() article = Article() featuredByImage = FeaturedByImage(start=0, width=Perc(65.4), showTitle=False, showHeadline=False, showTopic=False) featuredByText = FeaturedByText(start=0, width=Perc(30.75)) # Containers top = Top(components=(logo, menu), media=Media(max=self.C.M_MOBILE_MAX, display=self.C.NONE)) featured = Featured(components=(featuredByImage, featuredByText), backgroundColor=Color('#262c37')) section = Section(components=(featuredByImage, )) mainContent = MainContent(components=article) footer = Footer(components=(menu)) homePage = Page(name=self.C.TEMPLATE_INDEX, components=(mobileNavigation, top, featured, section, mainContent, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) articlePage = Page(name=self.C.TEMPLATE_ARTICLE, comoonents=(mobileNavigation, top, article, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) return [homePage, articlePage]
def baseComponents(self): u"""Create a theme site with just one single template home page. Answer a list of page instances that are used as templates for this site.""" # Create an instance (=object) of components to be placed on the page. # Import current example site, as anchor for the article files. from xierpa3.sites import doingbydesign # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' adapter = TextileFileAdapter(articleRoot) # Preferred adapter class for articles in this site. column = ExampleArticle() container = Container(components=column) # Create an instance (=object) of the page, containing the navigation components. # The class is also the page name in the url. homePage = Page(class_=self.C.TEMPLATE_INDEX, components=container, adapter=adapter, title=self.TITLE, fonts=self.URL_FONTS) # Answer a list of types of pages for this site. In this case just one template. return [homePage]
def baseComponents(self): # Create the article adapter # Import articles from the doingbydesign site, sharing the article files. from xierpa3.sites import doingbydesign # Root path where to find the article Simplex wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' adapter = SimpleSiteAdapter(articleRoot) # Header logo = Logo() menu = Menu() header = Header( components=(logo, menu), mobileContainerDisplay=self.C.NONE, doc_mobileContainerDisplay=u'Header is not visible for mobile') mobileNavigation = MobileNavigation( ) # Is container by itself. Change?? # Create the component instances article = Article(width=Perc(68)) featuredByImage = FeaturedByImage(count=1, width=Perc(30)) featuredByText = FeaturedByText(start=1, count=3, width=Perc(30)) # Create the single page instance, containing the number of components mainHome = Container(components=(article, featuredByImage, featuredByText)) # Footer footer = Footer(components=(menu, ), containerBackgroundColor=self.FOOTERBGCOLOR) # The class is also the page name in the url. homePage = Page( class_=self.C.TEMPLATE_INDEX, name=self.C.TEMPLATE_INDEX, adapter=adapter, #components=(mobileNavigation, header, mainHome, footer), #components=(header, mainHome, footer), components=Container(header), fonts=self.URL_FONTS, title=self.TITLE, css=self.C.URL_CSS) return [homePage]
def baseComponents(self): u"""Create the component instances""" # Import current example site, as anchor for the article files. from xierpa3.sites.examples import textilearticles # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(textilearticles) + '/files/articles/' adapter = ArticleAdapter( articleRoot) # Preferred adapter class for articles in this site. # Create navigation instance, to choose between the available articles. menu = Menu(adapter=adapter) menuContainer = Container(components=menu) # Create the article component to contain articles answered by the adapter. #article = SimplexArticle(adapter=adapter) article = Article(width=Perc(70), adapter=adapter, showPoster=True, splitChapters=False) articleSideBar = ArticleSideBar(width=Perc(22), adapter=adapter) featuredArticles = FeaturedByImage( width=Perc(22), adapter=adapter, # Example to overwrite the default BluePrint parameter titleColor titleColor=Color('red')) #featuredByImage = FeaturedByText(widht=Perc(22), adapter=adapter) # Make main page container for the article column container = Container(components=( article, articleSideBar, featuredArticles, #featuredByImage )) # The class is also the page name in the url. homePage = Page(class_=self.C.TEMPLATE_INDEX, name=self.C.TEMPLATE_INDEX, fonts=self.URL_FONTS, title=self.TITLE, css=self.C.URL_CSS, components=(menuContainer, container)) return [homePage]
def baseComponents(self): u"""Create a theme site with just one single template home page. Answer a list of page instances that are used as templates for this site.""" # Create an instance (=object) of components to be placed on the page. # Import current example site, as anchor for the article files. from xierpa3.sites import doingbydesign # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' adapter = TextileFileAdapter( articleRoot) # Preferred adapter class for articles in this site. column = ExampleArticle() container = Container(components=column) # Create an instance (=object) of the page, containing the navigation components. # The class is also the page name in the url. homePage = Page(class_=self.C.TEMPLATE_INDEX, components=container, adapter=adapter, title=self.TITLE, fonts=self.URL_FONTS) # Answer a list of types of pages for this site. In this case just one template. return [homePage]
class Documentation(BaseDocumentation): u"""The <b>Documentation</b> class implements the standard example shop with content based on files.""" TITLE = 'Documentation' SUBTITLE = 'The End of CSS: How to implement Xierpa.' # LOGO = 'http://%s/%s/logo.png' % (HOST, IMAGES_PATH) # LOGO = 'http://data.doingbydesign.com.s3.amazonaws.com/_images/logo.png' LOGO = 'Xierpa3' SRCLOGO = 'http://data.xierpa.com.s3.amazonaws.com/_images/xierpa_x_green.png' TEMPLATE_COURSES = 'courses' TEMPLATE_CATEGORY = 'category' TEMPLATE_PRODUCTS = 'products' URL_BACKGROUNDIMAGE = 'http://data.doingbydesign.com.s3.amazonaws.com/_images/articlebackground.png' URL_FONTS = ( # Google 'http://fonts.googleapis.com/css?family=Bree+Serif', #'http://fonts.googleapis.com/css?family=Droid+Sans:400,700' # Webtype project Poynter #'http://cloud.webtype.com/css/0d2e9f93-9866-45e1-8119-9b678ba5ce23.css' # Webtype project Doing by Design (Proforma & Rocky) #'http://cloud.webtype.com/css/d5663b37-b395-4934-9f68-2f7ccd9e8c87.css', # Topaz (Benton Sans RE) 'http://cloud.webtype.com/css/7aa22aa1-1709-4b55-b95c-3413d3e5280a.css', ) URL_JAVASCRIPT = [ 'http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js', 'js/toggle.js' ] # Cache the adapter, initialized automatic. ADAPTER = DocumentationAdapter(root=TX.module2Path(documentation) + '/files/articles') CSS_BODYFONT = '"BentonSansRE"' CSS_HEADFONT = '"BentonSansCond Medium"' CSS_BODYSIZE = 13 # Fixed anchor for relative Em-based body sizes CSS_BODYLEADING = Em(1.4) CSS_BGCOLOR = '#FFFFFF' CSS_ALINKCOLOR = '#888888' CSS_AVISITEDCOLOR = '+60%' CSS_AHOVERCOLOR = '-60%' CSS_ACTIVECOLOR = '+60%' MAXWIDTH = 1140 MINWIDTH = 755 def _get_css(self): # Force building of CSS with valid set of parameters force = '' if self.e.form['force']: force = '/force' return ['%s/css/site.css' % force] def _set_css(self, urls): # Ignore for now? pass css = property(_get_css, _set_css) def baseStyle(self): s = StyleSet() # Answer root style without selector s.addStyle('body', fontfamily=self.CSS_BODYFONT, fontsize=self.CSS_BODYSIZE, backgroundcolor=self.CSS_BGCOLOR, lineheight=self.CSS_BODYLEADING) s.addStyle('h1, h2, h3, h4, h5, p.lead', fontfamily=self.CSS_HEADFONT) s.addStyle('h6', fontfamily=self.CSS_BODYFONT) s.addStyle('div', float=self.FLOAT_LEFT, width=self.C100) s.addStyle('a, a:link', color=self.CSS_ALINKCOLOR) s.addStyle('a:visited', color=self.CSS_AVISITEDCOLOR) s.addStyle('a:hover', color=self.CSS_AHOVERCOLOR) s.addStyle('a:active', color=self.CSS_AACTIVECOLOR) s.addStyle('div.' + C.CLASS_1COL, margin=Em(0.5), float=C.LEFT, width='%d%%' % (98 / 12)) s.addStyle('div.' + C.CLASS_2COL, margin=Em(0.5), float=C.LEFT, width='%d%%' % (98 * 2 / 12)) s.addStyle('div.' + C.CLASS_4COL, margin=Em(0.5), float=C.LEFT, width='%d%%' % 30) #(98 * 4 / 12)) s.addStyle('div.' + C.CLASS_8COL, margin=Em(0.5), float=C.LEFT, width='%d%%' % (98 * 8 / 12)) s.addStyle('div.' + C.CLASS_12COL, margin=Em(0.5), float=C.LEFT, width=C.C100) s.addStyle('div.' + C.CLASS_LAST, marginright=Em(0)) s.addStyle('ul', display=C.BLOCK) s.addStyle('li', display=C.BLOCK) s.addStyle('ol', liststyletype=C.DECIMAL) return s def baseComponents(self): logo = Logo(logoSrc=self.SRCLOGO, logoName=self.LOGO, color=C.WHITE, margintop=Em(0.5), fontsize=Em(2), fontfamily='AmplitudeComp Medium') menu = Menu() socialmedia = SocialMedia(twitterAccount='xierpa', facebookAccount='xierpa') header = Header(components=(logo, menu), mobileContainerDisplay=C.NONE) mobileNavigation = MobileNavigation( title=self.TITLE) # Is container by itself. Change?? # Articles featured by image featuredByImage = FeaturedByImage( ) # Featured article on a page. Main photo+link #featuredByImageList = FeaturedByImageList() # Featured article on a page. List of related links # Articles featured by summary text featuredSideText = FeaturedByDiapText(colWidth=4, itemStart=1, label='Featured course') featuredByText = FeaturedByText(itemStart=2, showPoster=False) featuredByTextList = FeaturedByTextList(itemStart=5) # Featured black container bgColor = '#323A47' featuredImages = Featured( class_='featuredImages', components=(featuredByImage, featuredSideText), #components=(featuredSideText, featuredByImage), containerBackgroundColor=bgColor) # Featured text container bgColor = '#E8E8E8' featuredTexts = Featured(class_='featuredTexts', components=(featuredByText, featuredByTextList), containerBackgroundColor=bgColor) # Footer group footer = Footer(components=(menu, ), containerBackgroundColor=FOOTERBACKGROUNDCOLOR) # Article featuredByTextList = FeaturedByTextList( ) # Default start a featured index 0 article = Container(class_=C.CLASS_ARTICLE, containerBackgroundImage=self.URL_BACKGROUNDIMAGE, containerBackgroundRepeat=C.REPEAT, components=(Article(), socialmedia, ArticleSideBar(), featuredByTextList)) homePage = Page(name=C.TEMPLATE_INDEX, components=(mobileNavigation, header, featuredImages, featuredTexts, footer), css=self.URL_CSS, fonts=self.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.URL_FAVICON) articlePage = Page(name=C.TEMPLATE_ARTICLE, components=(mobileNavigation, header, article, footer), css=self.URL_CSS, fonts=self.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.URL_FAVICON) return [homePage, articlePage]
def baseComponents(self): logo = Logo() menu = Menu() socialmedia = SocialMedia(twitterAccount='doingbydesign', facebookAccount='doingbydesign') header = Header(components=(logo,menu), mobileContainerDisplay=self.C.NONE, doc_mobileContainerDisplay=u'Header is not visible for mobile') mobileNavigation = MobileNavigation() # Is container by itself. Change?? # Articles featured by image #featuredByImage = FeaturedByImage() # Featured article on a page. Main photo+link #featuredByImage100 = FeaturedByImage(colWidth=9) # Featured article as group item #featuredByImageList = FeaturedByImageList() # Featured article on a page. List of related links # Articles featured by summary text #featuredSideText = FeaturedByDiapText(colWidth=4, itemStart=1, label='Featured course') #featuredByText = FeaturedByText(itemStart=2, showPoster=False) #featuredByTextList = FeaturedByTextList(itemStart=5) #featuredSideText = Featured(colWidth=4, itemStart=1, label='Featured course') #featuredByText = Featured(itemStart=2, showPoster=False) #featuredByTextList = Featured(itemStart=5) featuredSideText = featuredByImage = featuredByText = featuredByTextList = featuredByImage100 = FeaturedByImage() # Featured black container BGCOLOR = Color('#323A47') featuredImages = FeaturedByImage(class_='featuredImages', components=(featuredByImage, featuredSideText), containerBackgroundColor=BGCOLOR) # Featured text container BGCOLOR = Color('#E8E8E8') featuredTexts = FeaturedByImage(class_='featuredTexts', components=(featuredByText, featuredByTextList), containerBackgroundColor=BGCOLOR) # Footer group footer = Footer(components=(menu,), containerBackgroundColor=self.CSS_FOOTERBGCOLOR) # Documentation # The documentation class knows how to collect methods and their attributes # from components, adapters and builders and build them in an automated # documentation site. documentation = Documentation() # Article #featuredByTextList = FeaturedByTextList() # Default start at featured index 0 featuredByTextList = FeaturedByImage() # Default start at featured index 0 article = Container(class_=self.C.CLASS_ARTICLE, containerBackgroundImage=self.URL_BACKGROUNDIMAGE, containerBackgroundRepeat=self.C.REPEAT, components=(Article(), socialmedia, ArticleSideBar(), featuredByTextList)) # Floating items thumbnails = ItemGroup(components=(featuredByImage100,)) # Import current example site, as anchor for the article files. from xierpa3.sites import doingbydesign # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' adapter = DbDAdapter(articleRoot) # Preferred adapter class for articles in this site. #homePage = Page(name=self.C.TEMPLATE_INDEX, # components=(mobileNavigation, header, featuredImages, featuredTexts, footer), # css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, # favicon=self.C.URL_FAVICON, adapter=adapter) homePage = Page(name=self.C.TEMPLATE_INDEX, components=featuredSideText, css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) articlePage = Page(name=self.C.TEMPLATE_ARTICLE, components=(mobileNavigation, header, article, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) thumbnailPage = Page(name=self.TEMPLATE_COURSES, components=(mobileNavigation, header, featuredImages, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) productsPage = Page(name=self.TEMPLATE_PRODUCTS, components=(mobileNavigation, header, thumbnails, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) categoryPage = Page(name=self.TEMPLATE_CATEGORY, components=(mobileNavigation, header, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) # Automatic documentation about Xierpa3 documentationPage = Page(name=self.C.TEMPLATE_DOCUMENTATION, components=(mobileNavigation, header, documentation, footer), css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT, favicon=self.C.URL_FAVICON, adapter=adapter) return [homePage, articlePage, productsPage, thumbnailPage, categoryPage, documentationPage]
def getMenu(self, component, id): u"""Answer the list of menu articles in this component.""" data = Data() data.menuItems = [] article = self.getArticle(component, id) if article: for menu in article.menu: menuArticle = self.getArticle(component, menu.attrib['id']) if menuArticle is not None: data.menuItems.append(menuArticle) return data def getLogo(self, component): data = Data() data.url = '/home' data.src = 'http://data.doingbydesign.com.s3.amazonaws.com/_images/logo.png' return data if __name__ == '__main__': # Cache the adapter from xierpa3.sites import doingbydesign fa = FileAdapter(root=TX.module2Path(doingbydesign)+'/files/articles') if 0: print fa.getIdPaths() print fa.getPages(None).items if 1: featured = fa.getFeaturedArticles(None, 'home', 3).items print featured print featured[0].name print featured[0].poster
def getSiteAdapter(self): u"""Answer the adapter for this site, including all articles of the DbD site.""" from xierpa3.sites import doingbydesign # Root path where to find the article Simples wiki file for this example page. articleRoot = TX.module2Path(doingbydesign) + '/files/articles/' return TextileFileAdapter(articleRoot) # Preferred adapter class for articles in this site.
class Xierpa3App(AppC): u"""Implementation of a vanilla-based GUI for the Xierpa 3 environment.""" # Get Constants->Config as class variable, so inheriting classes can redefined values. C = Constants PORT = 8060 URL = 'http://localhost:%d' % PORT # Make sure that the PHP frameworks are downloaded from the latest version in git. GIT_ROOT = '/'.join(TX.module2Path(constants).split('/')[:-2]) + '/../' PHP_SIMPLEMVC = GIT_ROOT + 'simple-mvc-framework-v2/' if not os.path.exists(PHP_SIMPLEMVC): print 'Download //github.com/simple-mvc-framework/v2 to', PHP_SIMPLEMVC PHP_KIRBY = GIT_ROOT + 'kirby/' if not os.path.exists(PHP_KIRBY): print 'License //kirby.com and save to', PHP_KIRBY EXAMPLE_SCRIPT = """ s = CurrentSite() page = s.components[0] print page print page.name """ SITE_LABELS = [ ("Hello world", HelloWorld()), ("Hello world style", HelloWorldStyle()), ("Hello world layout", HelloWorldLayout()), ("Hello world pages", HelloWorldPages()), ("Hello world responsive", HelloWorldResponsive()), ("Hello world BluePrint", HelloWorldBluePrint()), ("Simple responsive page", SimpleResponsivePage()), ("One column", OneColumnSite()), ("One Textile Wiki article", OneArticleSite()), ("Simple type specimen", SimpleTypeSpecimenSite()), ("Simple website", SimpleWebSite()), ("Simple Textile article", TextileArticles()), ("Basis website without styles", BasicWebsite()), ("Featured column", FeaturedColumn()), ("Basic DoingByDesign", DbdWebsite()), ("DoingByDesign", DoingByDesign()), ] def __init__(self): u""" Initialize the window and open it. """ self.w = view = Window((AppC.WINDOW_WIDTH, AppC.WINDOW_HEIGHT), "Xierpa 3", closable=True, minSize=(200, 200), maxSize=(1600, 1000)) siteLabels = self.getSiteLabels() #y = len(siteLabels)*20 y = 10 bo = 25 # Button offset view.optionalSites = PopUpButton((10, y, 150, 24), siteLabels, sizeStyle='small', callback=self.selectSiteCallback) #view.optionalSites = RadioGroup((10, 10, 150, y), siteLabels, # callback=self.selectSiteCallback, sizeStyle='small') self.w.optionalSites.set(0) y = y + 32 view.openSite = Button((10, y, 150, 20), 'Open site', callback=self.openSiteCallback, sizeStyle='small') y += bo self.w.saveSite = Button((10, y, 150, 20), 'Save HTML+CSS', callback=self.saveSiteCallback, sizeStyle='small') y += bo view.openCss = Button((10, y, 150, 20), 'Open CSS', callback=self.openCssCallback, sizeStyle='small') y += bo #view.openSass = Button((10, y, 150, 20), 'Open SASS', callback=self.openSassCallback, sizeStyle='small') #y += bo view.openDocumentation = Button( (10, y, 150, 20), 'Documentation', callback=self.openDocumentationCallback, sizeStyle='small') y += bo view.openAsPhp = Button((10, y, 150, 20), 'Open as PHP', callback=self.openAsPhpCallback, sizeStyle='small') #view.makeSite = Button((10, y+95, 150, 20), 'Make site', callback=self.makeSiteCallback, sizeStyle='small') view.forceCss = CheckBox((180, 10, 150, 20), 'Force make CSS', sizeStyle='small', value=True) view.doIndent = CheckBox((180, 30, 150, 20), 'Build indents', sizeStyle='small', value=True) view.forceCopy = CheckBox((180, 50, 150, 20), 'Overwrite files', sizeStyle='small', value=True) view.isOnline = CheckBox((180, 70, 150, 20), 'Online', sizeStyle='small', value=True, callback=self.isOnlineCallback) view.console = EditText((10, -200, -10, -10), sizeStyle='small') # Path defaults y = 20 view.mampRootLabel = TextBox((300, y, 100, 20), 'MAMP folder', sizeStyle='small') view.mampRoot = EditText((400, y, -10, 20), self.C.PATH_MAMP, sizeStyle='small') y += bo view.exampleRootLabel = TextBox((300, y, 100, 20), 'Root folder', sizeStyle='small') view.exampleRoot = EditText((400, y, -10, 20), self.C.PATH_EXAMPLES, sizeStyle='small') # Scripting y += bo view.script = TextEditor((300, y, -10, -240)) view.runScript = Button((500, -230, 150, -210), 'Run script', callback=self.runScriptCallback, sizeStyle='small') view.script.set(self.EXAMPLE_SCRIPT) view.open() def getView(self): return self.w def getSiteLabels(self): siteLabels = [] for siteLabel, _ in self.SITE_LABELS: siteLabels.append(siteLabel) return siteLabels def isOnlineCallback(self, sender): u"""Set the Constants.USE_ONLINE flag.""" view = self.getView() Constants.USE_ONLINE = view.isOnline.get() def runScriptCallback(self, sender): view = self.getView() src = self.BASESCRIPT + view.script.get() cc = compile(src, 'abc', mode='exec') eval(cc, {'currentSite': self.getSite()}) #, self.getSite().__dict__) def selectSiteCallback(self, sender): pass def openSiteCallback(self, sender): self.openSiteInBrowser(self.URL) def updateBuilderRootPaths(self): view = self.getView() rootPath = view.exampleRoot.get() HtmlBuilder.ROOT_PATH = rootPath SassBuilder.ROOT_PATH = rootPath CssBuilder.ROOT_PATH = rootPath def saveSiteCallback(self, sender): self.updateBuilderRootPaths() site = self.getSite() site.make() path = self.getExampleRootPath(site) if path is not None: webbrowser.open('file:' + path) def openSiteInBrowser(self, url): self.updateBuilderRootPaths() view = self.getView() if view.forceCss.get(): url += '/' + self.C.PARAM_FORCE # Always open url with generic /index so css/style.css will inherit the /force url += '/index' webbrowser.open(url) def openCssCallback(self, sender): view = self.getView() self.updateBuilderRootPaths() url = self.URL if view.forceCss.get(): url += '/' + self.C.PARAM_FORCE webbrowser.open(url + '/css/style.css') def openSassCallback(self, sender): url = self.URL #os.open(url + '/css/style.scss') def openDocumentationCallback(self, sender): self.updateBuilderRootPaths() url = self.URL webbrowser.open(url + '/' + self.C.PARAM_DOCUMENTATION + '/' + self.C.PARAM_FORCE) def getMampRootPath(self, site): view = self.getView() root = os.path.expanduser(view.mampRoot.get()) # File root of server. if not root.endswith('/'): root += '/' if not os.path.exists(root): message(messageText='Error in MAMP path.', informativeText='The MAMP folder "%s" does not exist.' % root, alertStyle=NSInformationalAlertStyle, parentWindow=view) return None return root + site.getPythonClassName().lower() + '/' def getExampleRootPath(self, site): view = self.getView() root = os.path.expanduser( view.exampleRoot.get()) # File root of server. if not root.endswith('/'): root += '/' if not os.path.exists(root): message( messageText='Error in Examples path.', informativeText='The Examples folder "%s" does not exist.' % root, alertStyle=NSInformationalAlertStyle, parentWindow=view) return None return root + site.getPythonClassName().lower() + '/' 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()) def getSite(self): view = self.getView() _, site = self.SITE_LABELS[view.optionalSites.get()] return site def makeSiteCallback(self, sender): self.getSite().make() def handleRequest(self, httprequest, site): self.addConsole( ` httprequest ` + ' ' + ` site.e.form `) def addConsole(self, s): view = self.getView() view.console.set(view.console.get() + '\n' + s) def getDoIndent(self): u"""Answer true if building output code with indent.""" view = self.getView() return view.doIndent.get()