def build_node_tree(parent_node, source_path, target_path): # scan the folder files = os.listdir(source_path) files.sort() for file_name in files: nodes = build_node(parent_node.config_copy(), source_path, target_path, file_name) if nodes: parent_node.extend(nodes) def root_processor(config, deploy_path, target_path): node = RootFolderNode(config, deploy_path, target_path) build_node_tree(node, deploy_path, target_path) return (node, ) Registry.register('root', root_processor) def folder_processor(config, source_path, target_path): node = FolderNode(config, source_path, target_path) target_path = os.path.join(target_path, node.target_name) if source_path and os.path.isdir(source_path): build_node_tree(node, source_path, target_path) return (node, ) Registry.register('folder', folder_processor) def asset_processor(config, source_path, target_path): node = AssetNode(config, source_path, target_path) return (node, )
if 'thumbnails' not in config: return (image_node,) thumbs = [] thumb_index = 0 for thumbnail in config['thumbnails']: if isinstance(config['thumbnails'], list): thumb_index += 1 size = thumbnail thumbnail = thumb_index = 1 and 'thumbnail' or 'thumbnail_' + thumb_index else: size = config['thumbnails'][thumbnail] target_name, ext = os.path.splitext(image_node.target_name) target_name += '_' + thumbnail target_name += ext thumb_config = image_node.config_copy(name=thumbnail, target_name=target_name) thumb_config['size'] = size thumb_config['iterable'] = False thumb_config['is_thumbnail'] = True thumb_config['skip'] = config['skip'] configurate(os.path.join(source_path, target_name), thumb_config) thumbnail_node = ImageNode(thumb_config, source_path, target_path) image_node.config[thumbnail] = thumbnail_node thumbs.append(thumbnail_node) return (image_node, ) + tuple(thumbs) Registry.register('image', processor) Registry.associate('image', ['*.png', '*.jpg', '*.jpeg', '*.gif'])
def root_processor(config, deploy_path, target_path): node = RootFolderNode(config, deploy_path, target_path) build_node_tree(node, deploy_path, target_path) return (node, ) def folder_processor(config, source_path, target_path): node = FolderNode(config, source_path, target_path) target_path = os.path.join(target_path, node.target_name) if source_path and os.path.isdir(source_path): build_node_tree(node, source_path, target_path) return (node, ) def asset_processor(config, source_path, target_path): node = AssetNode(config, source_path, target_path) return (node, ) def page_processor(config, source_path, target_path): node = JinjaNode(config, source_path, target_path) return (node, ) Registry.register('root', root_processor) Registry.register('folder', folder_processor) Registry.register('asset', asset_processor) Registry.register('page', page_processor)
files = os.listdir(source_path) files.sort() for file_name in files: nodes = build_node(parent_node.config_copy(), source_path, target_path, file_name) if nodes: parent_node.extend(nodes) def root_processor(config, deploy_path, target_path): node = RootFolderNode(config, deploy_path, target_path) build_node_tree(node, deploy_path, target_path) return (node,) Registry.register("root", root_processor) def folder_processor(config, source_path, target_path): node = FolderNode(config, source_path, target_path) target_path = os.path.join(target_path, node.target_name) if source_path and os.path.isdir(source_path): build_node_tree(node, source_path, target_path) return (node,) Registry.register("folder", folder_processor) def asset_processor(config, source_path, target_path):
[], body).set_lineno(lineno) def _scss_support(self, caller): return scss_compiler(caller()).strip() class ScssNode(AssetNode): """ Converts a .scss file into css """ def generate_file(self, site, source_path, target_path): if not self['skip']: scss_content = open(source_path, 'r').read() css_content = scss_compiler(scss_content) with open(target_path, 'w') as f: f.write(css_content) self.files_tracked.append(source_path) self.files_written.append(target_path) def processor(config, source_path, target_path): if config['target_name'].endswith('.scss'): config['target_name'] = config['target_name'][:-4] + 'css' scss_node = ScssNode(config, source_path, target_path) return (scss_node, ) Registry.register('scss', processor) Registry.associate('scss', ['*.scss'])
from strange_case.nodes import CategoryFolderProcesser, FolderNode, JinjaNode, CategoryDetail from copy import deepcopy def category_index_processor(config, source_path, target_path): categories_name = 'categories' folder_config = deepcopy(config) folder_config['target_name'] = categories_name folder_config['name'] = categories_name folder = FolderNode(folder_config, None, target_path) index_config = deepcopy(config) index_config['target_name'] = config['index'] index_config['name'] = 'index' categories_target_path = os.path.join(target_path, categories_name) index = JinjaNode(index_config, source_path, categories_target_path) folder.append(index) folder.append(CategoryFolderProcesser(config, categories_target_path)) return (folder, ) def category_detail_processer(config, source_path, target_path): CategoryDetail.source_path = source_path return () Registry.register('category_index', category_index_processor) Registry.register('category_detail', category_detail_processer)
body ).set_lineno(lineno) def _scss_support(self, caller): return scss_compiler(caller()).strip() class ScssNode(AssetNode): """ Converts a .scss file into css """ def generate_file(self, site, source_path, target_path): if not self['skip']: scss_content = open(source_path, 'r').read() css_content = scss_compiler(scss_content) with open(target_path, 'w') as f: f.write(css_content) self.files_tracked.append(source_path) self.files_written.append(target_path) def processor(config, source_path, target_path): if config['target_name'].endswith('.scss'): config['target_name'] = config['target_name'][:-4] + 'css' scss_node = ScssNode(config, source_path, target_path) return (scss_node,) Registry.register('scss', processor) Registry.associate('scss', ['*.scss'])
if 'thumbnails' not in config: return (image_node,) thumbs = [] thumb_index = 0 for thumbnail in config['thumbnails']: if isinstance(config['thumbnails'], list): thumb_index += 1 size = thumbnail thumbnail = thumb_index = 1 and 'thumbnail' or 'thumbnail_' + thumb_index else: size = config['thumbnails'][thumbnail] target_name, ext = os.path.splitext(image_node.target_name) target_name += '_' + thumbnail target_name += ext thumb_config = image_node.config_copy(name=thumbnail, target_name=target_name) thumb_config['size'] = size thumb_config['iterable'] = False thumb_config['is_thumbnail'] = True thumb_config['skip'] = config['skip'] configurate(os.path.join(source_path, target_name), thumb_config) thumbnail_node = ImageNode(thumb_config, source_path, target_path) image_node.config[thumbnail] = thumbnail_node thumbs.append(thumbnail_node) return (image_node, ) + tuple(thumbs) Registry.register('image', processor) Registry.associate('image', ['*.png', '*.jpg', '*.jpeg', '*.gif', '*.PNG', '*.JPG', '*.JPEG', '*.GIF'])
class CleverCssNode(AssetNode): """ Converts a .ccss file into css """ def generate_file(self, site, source_path, target_path): if not self['skip']: ccss_content = open(source_path, 'r').read() css_content = clevercss_compiler(ccss_content) with open(target_path, 'w') as f: f.write(css_content) elif self['__verbose']: sys.stderr.write("Skipping %s\n" % target_path) self.files_tracked.append(source_path) self.files_written.append(target_path) def processor(config, source_path, target_path): if config['target_name'].endswith('ccss'): config['target_name'] = config['target_name'][:-4] + 'css' if config['target_name'].endswith('clevercss'): config['target_name'] = config['target_name'][:-9] + 'css' ccss_node = CleverCssNode(config, source_path, target_path) return (ccss_node,) Registry.register('clevercss', processor) Registry.associate('clevercss', ['*.ccss', '*.clevercss'])
# page configuration can be further customized by creating a # pages: {} dictionary. The key names should be the page index page_index = 1 + len(ret) page_config.setdefault('title', "%s %i" % (page_title, page_index)) page_config.setdefault('page', page) page_config.setdefault('iterable', False) configurate(source_path, page_config) more_page_config = self.config.get('pages', {}).get(page_index) if more_page_config: page_config.update(more_page_config) node = JinjaNode(page_config, source_path, target_path) # now that we have node objects we can assign prev and next properties onto # the page object. page.prev = last_page page.next = None if last_page: last_page.page.next = node ret.append(node) last_page = node for node in ret: node.page.first = first_page node.page.last = last_page return ret return (paginated_processor, ) Registry.register('paginated', paginated_processor)
# page configuration can be further customized by creating a # pages: {} dictionary. The key names should be the page index page_index = 1 + len(ret) page_config.setdefault('title', "%s %i" % (page_title, page_index)) page_config.setdefault('page', page) page_config.setdefault('iterable', False) configurate(source_path, page_config) more_page_config = self.config.get('pages', {}).get(page_index) if more_page_config: page_config.update(more_page_config) node = JinjaNode(page_config, source_path, target_path) # now that we have node objects we can assign prev and next properties onto # the page object. page.prev = last_page page.next = None if last_page: last_page.page.next = node ret.append(node) last_page = node for node in ret: node.page.first = first_page node.page.last = last_page return ret return (paginated_processor, ) Registry.register('paginated', paginated_processor)
class CleverCssNode(AssetNode): """ Converts a .ccss file into css """ def generate_file(self, site, source_path, target_path): if self['skip']: print 'Skipping %s' % target_path if not self['skip']: ccss_content = open(source_path, 'r').read() css_content = clevercss_compiler(ccss_content) with open(target_path, 'w') as f: f.write(css_content) self.files_tracked.append(source_path) self.files_written.append(target_path) def processor(config, source_path, target_path): if config['target_name'].endswith('ccss'): config['target_name'] = config['target_name'][:-4] + 'css' if config['target_name'].endswith('clevercss'): config['target_name'] = config['target_name'][:-9] + 'css' ccss_node = CleverCssNode(config, source_path, target_path) return (ccss_node,) Registry.register('clevercss', processor) Registry.associate('clevercss', ['*.ccss', '*.clevercss'])
def dec(function): my_name = name or function.__name__ setattr(object, my_name, types.MethodType(function, object)) return dec def toc_processor(config, source_path, target_path): toc_processor = Processor(config) options = { 'entries': int(config.get('toc', {}).get('entries', [])), 'maxdepth': int(config.get('toc', {}).get('maxdepth', 3)), 'numbered': int(config.get('toc', {}).get('numbered', False)), 'titlesonly': int(config.get('toc', {}).get('titlesonly', False)), 'glob': int(config.get('toc', {}).get('glob', False)), 'hidden': int(config.get('toc', {}).get('hidden', [])), } @bind(toc_processor) def populate(self, site): ret = [] page_config = self.config_copy(True) # copy *all* config, even name and title. node = JinjaNode(page_config, source_path, target_path) ret.append(node) return ret return (toc_processor, ) Registry.register('toc', toc_processor)
def register_category_page(category, source_path): if category in CategoryDetail.source_paths: raise TypeError('Duplicate CategoryDetail page registered for "%s"' % (category or '(default category page)')) CategoryDetail.source_paths[category] = source_path def detail_processor(config, source_path, target_path): # just store the source path - when the detail pages get created, they # will use this path. config = configurate(source_path, config) if 'category' in config: register_category_page(config['category'], source_path) elif 'categories' in config: for category in config['categories']: register_category_page(category, source_path) else: register_category_page(None, source_path) return () def reset_category_detail(config): CategoryDetail.source_paths = {} Registry.listen('on_start', reset_category_detail) Registry.register('category_index', index_processor) Registry.register('category_detail', detail_processor)