def __init__( self ): self.sitepath = self['sitepath'] if isinstance(self['siteconfig'], dict) : self.siteconfig = self['siteconfig'] else : self.siteconfig = json2dict( join( self['siteconfig'] )) self.plugins = self._plugins( self.sitepath, self.siteconfig )
def default_context( self, contentdir, page ): """Return a list of context dictionaries from default-context under each sub-directory of content-page's path.""" path = page.relpath.strip(os.sep) contexts = [] fname = self['default_context'] while path : f = join(contentdir, path, fname) contexts.insert(0, json2dict(f)) if isfile(f) else None path, _ = split( path ) return contexts
def handle( self, args ): """:meth:`pluggdapps.interfaces.ICommand.handle` interface method. Instantiate a layout plugin and apply generate() method on the instantiated plugin. ``sitepath`` and ``siteconfig`` references willbe passed as settings dictionary. """ siteconfig = join( args.sitepath, args.configfile ) siteconfig = json2dict( siteconfig ) layoutname = siteconfig.get( 'layout', args.layout ) sett = { 'sitepath' : args.sitepath, 'siteconfig' : siteconfig } layout = self.qp( ILayout, layoutname, settings=sett ) self.pa.loginfo( "Generating site at [%s] with layout [%s] ..." % (args.sitepath, layoutname)) layout.generate( abspath(args.buildtarget), regen=args.regen ) self.pa.loginfo("... complete")
def pagecontext( self, page ): """Gathers default context for page. Default context is specified by one or more JSON files by name `_context.json` that is located under every sub-directory that leads to the page-content under layout's content-directory. `_context.json` found one level deeper under content directory will override `_context.json` found in the upper levels. Also, if a pagename has a corresponding JSON file, for eg, ``<layout>/_contents/path/hello-world.rst`` file has a corresponding ``<layout>/_contents/path/hello-world.json``, it will be interepreted as the page's context. This context will override all the default context. If `_xcontext` attribute is found in a default context file, it will be interpreted as plugin name implementing :class:`IXContext` interface. The plugin will be queried, instantiated, to fetch context information from external sources like database. Finally ``last_modified`` time will be gathered from content-file's mtime statistics. """ contentdir = join( self.sitepath, *self['contentdir'].split('/') ) contexts = self.default_context(contentdir, page) # Page's context, if available. page_context_file = join(page.relpath, page.pagename) + '.json' c = json2dict(page_context_file) if isfile(page_context_file) else None contexts.append(c) if c else None context = {} # From the list of context dictionaries in `contexts` check for # `_xcontext` attribute and fetch the context from external source. for c in contexts : context.update(c) context.update( self._fetch_xc( c.get('_xcontext', ''), page )) return context