예제 #1
0
파일: core.py 프로젝트: willingc/mynt
    def init(self):
        Timer.start()

        self.src = Directory(self._get_theme(self.opts['theme']))
        self.dest = Directory(self.opts['dest'])

        if not self.src.exists:
            raise OptionException('Theme not found.')
        elif self.dest.exists and not self.opts['force']:
            raise OptionException(
                'Destination already exists.',
                'the -f flag must be passed to force initialization by deleting the destination'
            )

        logger.info('>> Initializing')

        if self.opts['bare']:
            self.dest.rm()

            for d in ('_assets/css', '_assets/images', '_assets/js',
                      '_templates', '_posts'):
                Directory(normpath(self.dest.path, d)).mk()

            File(normpath(self.dest.path, 'config.yml')).mk()
        else:
            self.src.cp(self.dest.path, False)

        logger.info('Completed in %.3fs', Timer.stop())
예제 #2
0
파일: core.py 프로젝트: shamansir/mynt
    def init(self):
        Timer.start()

        self.src = Directory(self._get_theme(self.opts['theme']))
        self.dest = Directory(self.opts['dest'])

        if not self.src.exists:
            raise OptionException('Theme not found.')
        elif self.dest.exists and not self.opts['force']:
            raise OptionException('Destination already exists.',
                'the -f flag must be passed to force initialization by deleting the destination')

        logger.info('>> Initializing')

        if self.opts['bare']:
            self.dest.rm()

            for d in ('_assets/css', '_assets/images', '_assets/js', '_templates', '_posts'):
                Directory(normpath(self.dest.path, d)).mk()

            File(normpath(self.dest.path, 'config.yml')).mk()
        else:
            self.src.cp(self.dest.path, False)

        logger.info('Completed in %.3fs', Timer.stop())
예제 #3
0
    def initialize(self):
        Timer.start()

        self.source = Directory(self._get_theme(self.options['theme']))
        self.destination = Directory(self.options['destination'])

        if not self.source.exists:
            raise OptionException('Theme not found')
        elif self.destination.exists and not self.options['delete']:
            raise OptionException(
                'Destination already exists',
                'to force initialization, use the following flag',
                '  `-d` to DELETE the destination')

        logger.info('>> Initializing')

        if self.options['bare']:
            self.destination.rm()

            directories = ('_assets/css', '_assets/images', '_assets/js',
                           '_templates', '_posts')

            for d in directories:
                Directory(normpath(self.destination.path, d)).mk()

            File(normpath(self.destination.path, 'mynt.yml')).mk()
        else:
            self.source.cp(self.destination.path, False)

        logger.info('Completed in %.3fs', Timer.stop())
예제 #4
0
    def _parse_item(self, configuration, f, simple=False):
        Timer.start()

        item = Item(f.path)

        try:
            matches = re.search(r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', f.content,
                                re.M | re.S)
            frontmatter, bodymatter = matches.groups()
            frontmatter = Configuration(frontmatter)
        except AttributeError:
            raise ContentException('Invalid frontmatter',
                                   'src: {0}'.format(f.path),
                                   'frontmatter must not be empty')
        except ConfigurationException:
            raise ConfigurationException('Invalid frontmatter',
                                         'src: {0}'.format(f.path),
                                         'fontmatter contains invalid YAML')

        if 'layout' not in frontmatter:
            raise ContentException('Invalid frontmatter',
                                   'src: {0}'.format(f.path),
                                   'layout must be set')

        frontmatter.pop('url', None)

        parser = configuration.get('parser', None)
        parser = frontmatter.get('parser', parser)
        parser = self._get_parser(f, parser)

        text, date = self._parse_filename(f)
        content = self._writer.from_string(bodymatter, frontmatter)
        content = parser.parse(content)

        item['content'] = content
        item['date'] = date.strftime(self.site['date_format'])
        item['timestamp'] = timegm(date.utctimetuple())

        if simple:
            url = f.root.path.replace(self.source.path, '')

            item['url'] = URL.from_path(url, text)
        else:
            excerpt = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content,
                                re.M | re.S).group(1)
            url = URL.from_format(configuration['url'], text, date,
                                  frontmatter)

            item['excerpt'] = excerpt
            item['tags'] = []
            item['url'] = url

        item.update(frontmatter)

        logger.debug('..  (%.3fs) %s', Timer.stop(),
                     f.path.replace(self.source.path, ''))

        return item
예제 #5
0
파일: processors.py 프로젝트: levonter/mynt
    def _parse(self, container):
        for f in container.path:
            Timer.start()

            item = Item(f.path)

            try:
                frontmatter, bodymatter = re.search(
                    r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', f.content,
                    re.M | re.S).groups()
                frontmatter = Config(frontmatter)
            except AttributeError:
                raise ContentException('Invalid frontmatter.',
                                       'src: {0}'.format(f.path),
                                       'frontmatter must not be empty')
            except ConfigException:
                raise ConfigException('Invalid frontmatter.',
                                      'src: {0}'.format(f.path),
                                      'fontmatter contains invalid YAML')

            if 'layout' not in frontmatter:
                raise ContentException('Invalid frontmatter.',
                                       'src: {0}'.format(f.path),
                                       'layout must be set')

            parser = self._get_parser(
                f,
                frontmatter.get('parser', container.config.get('parser',
                                                               None)))

            slug, date = self._parse_filename(f)
            content = parser.parse(
                self._writer.from_string(bodymatter, frontmatter))

            item['content'] = content
            item['date'] = date.strftime(
                self.site['date_format']).decode('utf-8')
            item['excerpt'] = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content,
                                        re.M | re.S).group(1)
            item['tags'] = []
            item['timestamp'] = timegm(date.utctimetuple())

            item.update(frontmatter)

            item['url'] = self._get_content_url(container.config['url'], slug,
                                                date, frontmatter)

            container.add(item)

            logger.debug('..  (%.3fs) %s', Timer.stop(),
                         f.path.replace(self.src.path, ''))

        container.sort()
        container.tag()
        container.archive()

        return container
예제 #6
0
    def _parse_item(self, config, f, simple = False):
        Timer.start()

        item = Item(f.path)

        try:
            frontmatter, bodymatter = re.search(r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', f.content, re.M | re.S).groups()
            frontmatter = Config(frontmatter)
        except AttributeError:
            raise ContentException('Invalid frontmatter.',
                'src: {0}'.format(f.path),
                'frontmatter must not be empty')
        except ConfigException:
            raise ConfigException('Invalid frontmatter.',
                'src: {0}'.format(f.path),
                'fontmatter contains invalid YAML')

        if 'layout' not in frontmatter:
            raise ContentException('Invalid frontmatter.',
                'src: {0}'.format(f.path),
                'layout must be set')

        parser = self._get_parser(f, frontmatter.get('parser', config.get('parser', None)))

        text, date = self._parse_filename(f)

        frontmatter.pop('url', None)
        frontmatter['slug'] = text

        result = parser.parse(self._writer.from_string(bodymatter, frontmatter))

        content, toc = result if isinstance(result, tuple) else (result, None)

        item['content'] = content
        item['date'] = date.strftime(self.site['date_format']).decode('utf-8')
        item['timestamp'] = timegm(date.utctimetuple())

        if toc is not None:
            item['toc'] = toc

        if simple:
            item['url'] = Url.from_path(f.root.path.replace(self.src.path, ''), text)
        else:
            item['excerpt'] = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content, re.M | re.S).group(1)
            item['tags'] = []
            item['url'] = Url.from_format(config['url'], text, date, frontmatter)

        item.update(frontmatter)

        logger.debug('..  (%.3fs) %s', Timer.stop(), f.path.replace(self.src.path, ''))

        return item
예제 #7
0
파일: core.py 프로젝트: NaPs/mynt
 def generate(self):
     Timer.start()
     
     self.src = Directory(self.opts['src'])
     self.dest = Directory(self.opts['dest'])
     
     if not self.src.exists:
         raise OptionException('Source must exist.')
     elif self.src == self.dest:
         raise OptionException('Source and destination must differ.')
     elif self.dest.exists and not (self.opts['force'] or self.opts['clean']):
         raise OptionException('Destination already exists.', 'the -c or -f flag must be passed to force generation by deleting or emptying the destination')
     
     self._generate()
     
     logger.info('Completed in %.3fs', Timer.stop())
예제 #8
0
파일: processors.py 프로젝트: belebulu/mynt
 def _parse(self, container):
     for f in container.path:
         Timer.start()
         
         item = Item(f.path)
         
         try:
             frontmatter, bodymatter = re.search(r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', f.content, re.M | re.S).groups()
             frontmatter = Config(frontmatter)
         except AttributeError:
             raise ContentException('Invalid frontmatter.',
                 'src: {0}'.format(f.path),
                 'frontmatter must not be empty')
         except ConfigException:
             raise ConfigException('Invalid frontmatter.',
                 'src: {0}'.format(f.path),
                 'fontmatter contains invalid YAML')
         
         if 'layout' not in frontmatter:
             raise ContentException('Invalid frontmatter.',
                 'src: {0}'.format(f.path),
                 'layout must be set')
         
         parser = self._get_parser(f, frontmatter.get('parser', container.config.get('parser', None)))
         
         slug, date = self._parse_filename(f)
         content = parser.parse(self._writer.from_string(bodymatter, frontmatter))
         
         item['content'] = content
         item['date'] = date.strftime(self.site['date_format']).decode('utf-8')
         item['excerpt'] = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content, re.M | re.S).group(1)
         item['tags'] = []
         item['timestamp'] = timegm(date.utctimetuple())
         
         item.update(frontmatter)
         
         item['url'] = self._get_content_url(container.config['url'], slug, date, frontmatter)
         
         container.add(item)
         
         logger.debug('..  (%.3fs) %s', Timer.stop(), f.path.replace(self.src.path, ''))
     
     container.sort()
     container.tag()
     container.archive()
     
     return container
예제 #9
0
파일: processors.py 프로젝트: NaPs/mynt
 def render(self, template, data = None, url = None):
     url = url if url is not None else template
     path = self._get_path(url)
     
     try:
         Timer.start()
         
         content = self._renderer.render(template, data)
         
         if self.site['pygmentize']:
             content = self._pygmentize(content)
         
         logger.debug('..  (%.3fs) %s', Timer.stop(), path.replace(self.dest.path, ''))
     except RendererException as e:
         raise RendererException(e.message, '{0} in container item {1}'.format(template, data.get('item', url)))
     
     return File(path, content)
예제 #10
0
파일: processors.py 프로젝트: willingc/mynt
 def render(self, template, data = None, url = None):
     url = url if url is not None else template
     path = self._get_path(url)
     
     try:
         Timer.start()
         
         content = self._renderer.render(template, data)
         
         if self.site['pygmentize']:
             content = self._pygmentize(content)
         
         logger.debug('..  (%.3fs) %s', Timer.stop(), path.replace(self.dest.path, ''))
     except RendererException as e:
         raise RendererException(e.message,
             '{0} in container item {1}'.format(template, data.get('item', url)))
     
     return File(path, content)
예제 #11
0
파일: core.py 프로젝트: willingc/mynt
    def generate(self):
        Timer.start()

        self.src = Directory(self.opts['src'])
        self.dest = Directory(self.opts['dest'])

        if not self.src.exists:
            raise OptionException('Source must exist.')
        elif self.src == self.dest:
            raise OptionException('Source and destination must differ.')
        elif self.dest.exists and not (self.opts['force']
                                       or self.opts['clean']):
            raise OptionException(
                'Destination already exists.',
                'the -c or -f flag must be passed to force generation by deleting or emptying the destination'
            )

        self._generate()

        logger.info('Completed in %.3fs', Timer.stop())
예제 #12
0
파일: fs.py 프로젝트: NaPs/mynt
 def _regenerate(self, path):
     path = path.replace(self._src, '')
     
     if search(r'/[._](?!assets|posts|templates)', path):
         logger.debug('>> Skipping: %s', path)
     else:
         logger.info('>> Change detected in: %s', path)
         
         try:
             Timer.start()
             
             self._callback()
             
             logger.info('Regenerated in %.3fs', Timer.stop())
         except:
             t, v, tb = exc_info()
             lc = traceback.extract_tb(tb)[-1:][0]
             
             logger.error('!! %s\n..  file: %s\n..  line: %s\n..    in: %s\n..    at: %s', v, *lc)
             
             pass
예제 #13
0
    def generate(self):
        Timer.start()

        self.source = Directory(self.options['source'])
        self.destination = Directory(self.options['destination'])

        if not self.source.exists:
            raise OptionException('Source must exist')
        elif self.source == self.destination:
            raise OptionException(
                'Source and destination must be different locations')
        elif self.destination.exists:
            if not (self.options['delete'] or self.options['force']):
                raise OptionException(
                    'Destination already exists',
                    'to force generation, use one of the following flags',
                    '  `-d` to DELETE the destination',
                    '  `-f` to EMPTY the destination')

        self._generate()

        logger.info('Completed in %.3fs', Timer.stop())
예제 #14
0
파일: fs.py 프로젝트: willingc/mynt
    def _regenerate(self, path):
        path = path.replace(self._src, '')

        if search(r'/[._](?!assets|containers|posts|templates)', path):
            logger.debug('>> Skipping: %s', path)
        else:
            logger.info('>> Change detected in: %s', path)

            try:
                Timer.start()

                self._callback()

                logger.info('Regenerated in %.3fs', Timer.stop())
            except:
                t, v, tb = exc_info()
                lc = traceback.extract_tb(tb)[-1:][0]

                logger.error(
                    '!! %s\n..  file: %s\n..  line: %s\n..    in: %s\n..    at: %s',
                    v, *lc)

                pass