def parse_catsup_meta(lines, path=None): meta = ObjectDict() title_line = lines.pop(0) if title_line[0] != "#": not_valid(path) meta.title = escape_html(title_line[1:].strip()) for line in lines: if not line: continue if ":" not in line: not_valid(path) name, value = line.split(':', 1) name = name.strip().lstrip('-').strip().lower() meta[name] = value.strip() return meta
def html_reader(path): meta, content = split_content(path) if not meta: meta = ObjectDict() else: meta = parse_yaml_meta(meta, path) return Post(path=path, meta=meta, content=to_unicode(content))
def read_base_meta(path): meta = ObjectDict( type="post" ) if path: pass return meta
def parse_yaml_meta(lines, path=None): title_line = lines.pop(0) if not title_line.startswith("---"): not_valid(path) meta = read_base_meta(path) meta.update(yaml.load("\n".join(lines))) return update_nested_dict(ObjectDict(), meta)
def markdown_reader(path): meta, content = split_content(path) content = content.replace("\n", " \n") if not meta: meta = ObjectDict() else: meta = parse_meta(meta, path) return Post(path=path, meta=meta, content=md.render(content))
def parse(path): """ Parser json configuration file """ try: f = open(path, 'r') except IOError: logger.error("Can't find config file." "Run `catsup init` to generate a new config file.") exit(1) return update_nested_dict(ObjectDict(), ujson.load(f))
def read_theme(path): """ :param path: path for the theme. :return: Theme theme read in path. """ if not os.path.exists(path): return theme_file = os.path.join(path, 'theme.py') if not os.path.exists(theme_file): logger.warn("%s is not a catsup theme." % path) return theme = ObjectDict( name='', author='', homepage='', path=path, post_per_page=5, vars={}, ) exec(open(theme_file).read(), {}, theme) theme.name = theme.name.lower() return theme
def read_theme(path): """ :param path: path for the theme. :return: Theme theme read in path. """ if not os.path.exists(path): return theme_file = os.path.join(path, 'theme.py') if not os.path.exists(theme_file): logger.warn("%s is not a catsup theme." % path) return theme = ObjectDict( name='', author='', homepage='', path=path, post_per_page=5, vars={}, ) exec(open(theme_file).read(), {}, theme) theme.name = theme.name.lower() return theme
def test_config_parser(): from catsup.parser.config import parse from catsup.utils import ObjectDict config = parse(os.path.join(BASE_DIR, "config.json")) assert config == ObjectDict({ u'site': { u'url': u'http://blog.com/', u'name': u'blogname', u'description': u'Just another catsup blog' }, u'author': { u'twitter': u'twitter', u'name': u'nickname', u'email': u'*****@*****.**' } })
from catsup.utils import ObjectDict g = ObjectDict()
import os from catsup.utils import ObjectDict g = ObjectDict() g.catsup_path = os.path.abspath(os.path.dirname(__file__)) g.public_templates_path = os.path.join(g.catsup_path, 'templates') g.cwdpath = os.path.abspath('.')