def __init__(self, template_path): self.html_template = settings.JINJA_ENV.get_template( str(settings.TEMPLATE_DIR.relpathto(template_path)).replace('\\', '/')) namebase = template_path.namebase name_components = settings.TEMPLATE_PAGE_DIR.relpathto(template_path).splitall()[1:] name_components[-1] = namebase self.name = '/'.join(name_components) self.absolute_url = urljoin(settings.HOME_URL, self.name) self.output_path = path(settings.OUTPUT_CACHE_DIR / self.name) self.output_file_name = 'index.html' settings.URLS[self.name] = self.absolute_url
def tag(name): page_path = urljoin('tag', slugify(name)) page_path = urljoin(self.HOME_URL, page_path) return page_path
def page(num): page_path = urljoin('page', str(num)) return urljoin(self.HOME_URL, page_path)
def _initialize(self, config): self._check_deprecated_settings(config) self.ENGINEER = EngineerConfiguration._EngineerConstants() # CONTENT DIRECTORIES self.SETTINGS_DIR = path(config.pop('SETTINGS_DIR', self.SETTINGS_FILE.dirname().abspath() if self.SETTINGS_FILE is not None else path.getcwd())) self.CONTENT_DIR = self.normalize(config.pop('CONTENT_DIR', 'content')) self.POST_DIR = self.normalize_list(config.pop('POST_DIR', 'posts')) self.OUTPUT_DIR = self.normalize(config.pop('OUTPUT_DIR', 'output')) self.OUTPUT_DIR_IGNORE = wrap_list(config.pop('OUTPUT_DIR_IGNORE', ['.git', '.gitignore'])) self.TEMPLATE_DIR = self.normalize(config.pop('TEMPLATE_DIR', 'templates')) self.TEMPLATE_PAGE_DIR = self.normalize( config.pop('TEMPLATE_PAGE_DIR', (self.TEMPLATE_DIR / 'pages').abspath()) ) self.LOG_DIR = self.normalize(config.pop('LOG_DIR', 'logs')) if self.SETTINGS_FILE is None: self.LOG_FILE = self.normalize(config.pop('LOG_FILE', (self.LOG_DIR / 'build.log').abspath())) else: self.LOG_FILE = self.normalize( config.pop( 'LOG_FILE', (self.LOG_DIR / ('%s-%s.log' % (datetime.now().strftime('%m.%d_%H.%M.%S'), self.SETTINGS_FILE.name))).abspath()) ) self.CACHE_DIR = self.normalize(config.pop('CACHE_DIR', None)) if self.CACHE_DIR is None: if self.SETTINGS_FILE is not None: self.CACHE_DIR = self.normalize('_cache/%s' % self.SETTINGS_FILE.name) else: self.CACHE_DIR = self.normalize('_cache/None') else: self.CACHE_DIR = self.normalize(self.CACHE_DIR) self.CACHE_FILE = self.normalize( config.pop('CACHE_FILE', (self.CACHE_DIR / 'engineer.cache').abspath()) ) self.OUTPUT_CACHE_DIR = self.normalize( config.pop('OUTPUT_CACHE_DIR', (self.CACHE_DIR / 'output_cache').abspath()) ) self.JINJA_CACHE_DIR = self.normalize( config.pop('JINJA_CACHE_DIR', (self.CACHE_DIR / 'jinja_cache').abspath()) ) self.BUILD_STATS_FILE = self.normalize( config.pop('BUILD_STATS_FILE', (self.CACHE_DIR / 'build_stats.cache').abspath()) ) # PLUGINS self.PLUGINS = self.normalize_list(config.pop('PLUGINS', None)) if self.PLUGINS is not None: for plugin in self.PLUGINS: __import__(plugin) # THEMES self.THEME_DIRS = self.normalize_list(config.pop('THEME_DIRS', None)) self.THEME_FINDERS = [ 'engineer.finders.ThemeDirsFinder', 'engineer.finders.SiteFinder', 'engineer.finders.PluginFinder', 'engineer.finders.DefaultFinder' ] self.THEME_SETTINGS = config.pop('THEME_SETTINGS', {}) self.THEME = config.pop('THEME', 'dark_rainbow') # PREPROCESSOR / COMPRESSOR SETTINGS self.COMPRESSOR_ENABLED = config.pop('COMPRESSOR_ENABLED', True) self.COMPRESSOR_FILE_EXTENSIONS = config.pop('COMPRESSOR_FILE_EXTENSIONS', ['js', 'css']) self.PREPROCESS_LESS = config.pop('PREPROCESS_LESS', True) if not 'LESS_PREPROCESSOR' in config: if platform.system() == 'Windows': self.LESS_PREPROCESSOR = str(self.ENGINEER.ROOT_DIR / 'lib/less.js-windows/lessc.cmd') + ' {infile} {outfile}' else: self.LESS_PREPROCESSOR = 'lessc {infile} {outfile}' else: self.LESS_PREPROCESSOR = path(config.pop('LESS_PREPROCESSOR')) # SITE SETTINGS self.SITE_TITLE = config.pop('SITE_TITLE', 'SITE_TITLE') self.SITE_URL = config.pop('SITE_URL', 'SITE_URL') self.SITE_AUTHOR = config.pop('SITE_AUTHOR', None) self.HOME_URL = config.pop('HOME_URL', '/') # HOME_URL must end with a slash if not self.HOME_URL.endswith('/'): self.HOME_URL += '/' self.STATIC_URL = config.pop('STATIC_URL', urljoin(self.HOME_URL, 'static')) # starting in version 0.5, the default permalink style will change to 'pretty' permalink_setting = config.pop('PERMALINK_STYLE', None) if permalink_setting is None: self.PERMALINK_STYLE = permalink_styles['pretty'] else: self.PERMALINK_STYLE = permalink_styles.get(permalink_setting, permalink_setting) self.ROLLUP_PAGE_SIZE = int(config.pop('ROLLUP_PAGE_SIZE', 5)) # RSS FEED SETTINGS self.FEED_TITLE = config.pop('FEED_TITLE', self.SITE_TITLE + ' Feed') self.FEED_ITEM_LIMIT = config.pop('FEED_ITEM_LIMIT', self.ROLLUP_PAGE_SIZE) self.FEED_DESCRIPTION = config.pop('FEED_DESCRIPTION', 'The %s most recent posts from %s.' % (self.FEED_ITEM_LIMIT, self.SITE_URL)) self.FEED_URL = config.pop('FEED_URL', urljoin(self.HOME_URL, 'feeds/atom.xml')) # These 'constants' are updated here so they're relative to the STATIC_URL value lib_path = urljoin(self.STATIC_URL, 'engineer/lib') self.ENGINEER.FOUNDATION_CSS_URL = urljoin(lib_path, 'foundation/') self.ENGINEER.JQUERY_URL = urljoin(lib_path, self.ENGINEER.JQUERY) self.ENGINEER.LESS_JS_URL = urljoin(lib_path, self.ENGINEER.LESS_JS) self.ENGINEER.MODERNIZR_URL = urljoin(lib_path, self.ENGINEER.MODERNIZR) self.ENGINEER.NORMALIZE_CSS_URL = urljoin(lib_path, self.ENGINEER.NORMALIZE_CSS) # URL helper functions def page(num): page_path = urljoin('page', str(num)) return urljoin(self.HOME_URL, page_path) def tag(name): page_path = urljoin('tag', slugify(name)) page_path = urljoin(self.HOME_URL, page_path) return page_path self.URLS = { 'home': self.HOME_URL, 'archives': urljoin(self.HOME_URL, 'archives'), 'feed': self.FEED_URL, 'listpage': page, 'tag': tag, } # Update URLs from the config setting if they're present self.URLS.update(config.pop('URLS', {})) # MISCELLANEOUS SETTINGS self.ACTIVE_NAV_CLASS = config.pop('ACTIVE_NAV_CLASS', 'current') self.DEBUG = config.pop('DEBUG', False) #self.DISABLE_CACHE = config.pop('DISABLE_CACHE', False) self.PLUGIN_PERMISSIONS = { 'MODIFY_RAW_POST': [] } provided_permissions = config.pop('PLUGIN_PERMISSIONS', {}) update_additive(self.PLUGIN_PERMISSIONS, provided_permissions) self.PUBLISH_DRAFTS = config.pop('PUBLISH_DRAFTS', False) self.PUBLISH_PENDING = config.pop('PUBLISH_PENDING', False) self.PUBLISH_REVIEW = config.pop('PUBLISH_REVIEW', False) self.POST_TIMEZONE = pytz.timezone(config.pop('POST_TIMEZONE', 'UTC')) self.SERVER_TIMEZONE = self.POST_TIMEZONE if config.get('SERVER_TIMEZONE', None) is None else config.pop('SERVER_TIMEZONE') self.TIME_FORMAT = config.pop('TIME_FORMAT', '%I:%M %p %A, %B %d, %Y %Z') # '%Y-%m-%d %H:%M:%S %Z%z' # Let plugins deal with their settings in their own way if needed for plugin_type in get_all_plugin_types(): for plugin in plugin_type.plugins: logger.debug("Calling handle_settings on plugin: %s. config dict is: %s" % (plugin, config)) config = plugin.handle_settings(config, self) # Pull any remaining settings in the config and set them as attributes on the settings object for k, v in config.iteritems(): setattr(self, k, v)
def _initialize(self, config): self._check_deprecated_settings(config) self.ENGINEER = EngineerConfiguration._EngineerConstants() # CONTENT DIRECTORIES self.SETTINGS_DIR = path( config.pop( 'SETTINGS_DIR', self.SETTINGS_FILE.dirname().abspath() if self.SETTINGS_FILE is not None else path.getcwd())) self.CONTENT_DIR = self.normalize(config.pop('CONTENT_DIR', 'content')) self.POST_DIR = self.normalize_list(config.pop('POST_DIR', 'posts')) self.OUTPUT_DIR = self.normalize(config.pop('OUTPUT_DIR', 'output')) self.TEMPLATE_DIR = self.normalize( config.pop('TEMPLATE_DIR', 'templates')) self.TEMPLATE_PAGE_DIR = config.pop( 'TEMPLATE_PAGE_DIR', (self.TEMPLATE_DIR / 'pages').abspath()) self.LOG_DIR = self.normalize(config.pop('LOG_DIR', 'logs')) if self.SETTINGS_FILE is None: self.LOG_FILE = config.pop('LOG_FILE', (self.LOG_DIR / 'build.log').abspath()) else: self.LOG_FILE = config.pop( 'LOG_FILE', (self.LOG_DIR / ('%s-%s.log' % (datetime.now().strftime('%m.%d_%H.%M.%S'), self.SETTINGS_FILE.name))).abspath()) self.CACHE_DIR = config.pop('CACHE_DIR', None) if self.CACHE_DIR is None: if self.SETTINGS_FILE is not None: self.CACHE_DIR = self.normalize('_cache/%s' % self.SETTINGS_FILE.name) else: self.CACHE_DIR = self.normalize('_cache/None') else: self.CACHE_DIR = self.normalize(self.CACHE_DIR) self.CACHE_FILE = config.pop( 'CACHE_FILE', (self.CACHE_DIR / 'engineer.cache').abspath()) self.OUTPUT_CACHE_DIR = config.pop( 'OUTPUT_CACHE_DIR', (self.CACHE_DIR / 'output_cache').abspath()) self.JINJA_CACHE_DIR = config.pop( 'JINJA_CACHE_DIR', (self.CACHE_DIR / 'jinja_cache').abspath()) self.BUILD_STATS_FILE = config.pop('BUILD_STATS_FILE', (self.CACHE_DIR / 'build_stats.cache').abspath()) # PLUGINS self.PLUGINS = self.normalize_list(config.pop('PLUGINS', None)) if self.PLUGINS is not None: for plugin in self.PLUGINS: __import__(plugin) # THEMES self.THEME_DIRS = self.normalize_list(config.pop('THEME_DIRS', None)) self.THEME_FINDERS = [ 'engineer.finders.ThemeDirsFinder', 'engineer.finders.SiteFinder', 'engineer.finders.PluginFinder', 'engineer.finders.DefaultFinder' ] self.THEME_SETTINGS = config.pop('THEME_SETTINGS', {}) self.THEME = config.pop('THEME', 'dark_rainbow') # PREPROCESSOR / COMPRESSOR SETTINGS self.COMPRESSOR_ENABLED = config.pop('COMPRESSOR_ENABLED', True) self.COMPRESSOR_FILE_EXTENSIONS = config.pop( 'COMPRESSOR_FILE_EXTENSIONS', ['js', 'css']) self.PREPROCESS_LESS = config.pop('PREPROCESS_LESS', True) if not 'LESS_PREPROCESSOR' in config: if platform.system() == 'Windows': self.LESS_PREPROCESSOR = str( self.ENGINEER.ROOT_DIR / 'lib/dotless/dotless.Compiler.exe') + ' {infile} {outfile}' else: self.LESS_PREPROCESSOR = 'lessc {infile} {outfile}' else: self.LESS_PREPROCESSOR = path(config.pop('LESS_PREPROCESSOR')) # SITE SETTINGS self.SITE_TITLE = config.pop('SITE_TITLE', 'SITE_TITLE') self.SITE_URL = config.pop('SITE_URL', 'SITE_URL') self.SITE_AUTHOR = config.pop('SITE_AUTHOR', None) self.HOME_URL = config.pop('HOME_URL', '/') # HOME_URL must end with a slash if not self.HOME_URL.endswith('/'): self.HOME_URL += '/' self.STATIC_URL = config.pop('STATIC_URL', urljoin(self.HOME_URL, 'static')) # starting in version 0.5, the default permalink style will change to 'pretty' permalink_setting = config.pop('PERMALINK_STYLE', None) if permalink_setting is None: self.PERMALINK_STYLE = permalink_styles['fulldate'] else: self.PERMALINK_STYLE = permalink_styles.get( permalink_setting, permalink_setting) self.ROLLUP_PAGE_SIZE = int(config.pop('ROLLUP_PAGE_SIZE', 5)) # RSS FEED SETTINGS self.FEED_TITLE = config.pop('FEED_TITLE', self.SITE_TITLE + ' Feed') self.FEED_ITEM_LIMIT = config.pop('FEED_ITEM_LIMIT', self.ROLLUP_PAGE_SIZE) self.FEED_DESCRIPTION = config.pop( 'FEED_DESCRIPTION', 'The %s most recent posts from %s.' % (self.FEED_ITEM_LIMIT, self.SITE_URL)) self.FEED_URL = config.pop('FEED_URL', urljoin(self.HOME_URL, 'feeds/rss.xml')) # These 'constants' are updated here so they're relative to the STATIC_URL value self.ENGINEER.FOUNDATION_CSS_URL = urljoin(self.STATIC_URL, 'engineer/lib/foundation/') self.ENGINEER.JQUERY_URL = urljoin(self.STATIC_URL, 'engineer/lib/jquery-1.7.1.min.js') self.ENGINEER.MODERNIZR_URL = urljoin( self.STATIC_URL, 'engineer/lib/modernizr-2.5.3.min.js') self.ENGINEER.LESS_JS_URL = urljoin(self.STATIC_URL, 'engineer/lib/less-1.3.1.min.js') self.ENGINEER.TWEET_URL = urljoin( self.STATIC_URL, 'engineer/lib/tweet/tweet/jquery.tweet.js') # URL helper functions def page(num): page_path = urljoin('page', str(num)) return urljoin(self.HOME_URL, page_path) def tag(name): page_path = urljoin('tag', slugify(name)) page_path = urljoin(self.HOME_URL, page_path) return page_path self.URLS = { 'home': self.HOME_URL, 'archives': urljoin(self.HOME_URL, 'archives'), 'feed': self.FEED_URL, 'listpage': page, 'tag': tag, } # Update URLs from the config setting if they're present self.URLS.update(config.pop('URLS', {})) # MISCELLANEOUS SETTINGS self.ACTIVE_NAV_CLASS = config.pop('ACTIVE_NAV_CLASS', 'current') self.DEBUG = config.pop('DEBUG', False) #self.DISABLE_CACHE = config.pop('DISABLE_CACHE', False) self.PUBLISH_DRAFTS = config.pop('PUBLISH_DRAFTS', False) self.PUBLISH_PENDING = config.pop('PUBLISH_PENDING', False) self.PUBLISH_REVIEW = config.pop('PUBLISH_REVIEW', False) self.POST_TIMEZONE = pytz.timezone(config.pop('POST_TIMEZONE', 'UTC')) self.SERVER_TIMEZONE = self.POST_TIMEZONE if config.get( 'SERVER_TIMEZONE', None) is None else config.pop('SERVER_TIMEZONE') self.TIME_FORMAT = config.pop( 'TIME_FORMAT', '%I:%M %p %A, %B %d, %Y %Z') # '%Y-%m-%d %H:%M:%S %Z%z' # Let plugins deal with their settings in their own way if needed for plugin_type in get_all_plugin_types(): for plugin in plugin_type.plugins: logger.debug( "Calling handle_settings on plugin: %s. config dict is: %s" % (plugin, config)) config = plugin.handle_settings(config, self) # Pull any remaining settings in the config and set them as attributes on the settings object for k, v in config.iteritems(): setattr(self, k, v)