Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhnomoli committed Dec 4, 2011
0 parents commit d7443f5
Show file tree
Hide file tree
Showing 17 changed files with 1,000 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist/
mynt.egg-info/
*.pyc
*.sublime-project
*.sublime-workspace
26 changes: 26 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2011, Andrew Fricke
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* The names of its contributors may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include LICENSE README.md
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# mynt

_Another static site generator?_

With the ever growing population of static site generators, more often than not I found that they either had very simplistic support for blogs or used template engines that for one reason or another irked me.

After not finding a solution I was happy with, just as any other programmer would do, I decided to roll my own and wrote mynt with the hope that others would find it useful as well.


### Install

From PyPI:
`pip install mynt`

Latest trunk:
`pip install git+https://github.com/Anomareh/mynt.git`


### Getting Started

After installing mynt head on over and give the [docs][1] a read.


### Dependencies

+ [Jinja2][2]
+ [misaka][3]
+ [Pygments][4]
+ [PyYAML][5]


### Support

If you run into any issues or have any questions, either open an [issue][6] or hop in #mynt on irc.freenode.net.


[1]: http://mynt.mirroredwhite.com/
[2]: http://jinja.pocoo.org/
[3]: http://misaka.61924.nl/
[4]: http://pygments.org/
[5]: http://pyyaml.org/
[6]: https://github.com/Anomareh/mynt/issues
23 changes: 23 additions & 0 deletions mynt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals

import sys

from mynt.core import Mynt
from mynt.exceptions import MyntException


def main():
try:
Mynt().generate()
except MyntException as e:
print(e)

return e.code

return 0


if __name__ == '__main__':
sys.exit(main())
38 changes: 38 additions & 0 deletions mynt/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals


class Parser(object):
def __init__(self, options):
self.options = options

self.setup()


def parse(self, content):
raise NotImplementedError('A parser must implement parse.')

def setup(self):
pass

class Renderer(object):
def __init__(self, path, options, globals_ = {}):
self.path = path
self.options = options
self.globals = globals_

self.setup()


def from_string(self, source, vars_ = {}):
raise NotImplementedError('A renderer must implement from_string.')

def register(self, key, value):
raise NotImplementedError('A renderer must implement register.')

def render(self, template, vars_ = {}):
raise NotImplementedError('A renderer must implement render.')

def setup(self):
pass
86 changes: 86 additions & 0 deletions mynt/containers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from collections import OrderedDict
from datetime import datetime
import re

import yaml

from mynt.exceptions import ConfigException, PostException
from mynt.fs import File
from mynt.utils import get_logger


yaml.add_constructor('tag:yaml.org,2002:str', lambda loader, node: loader.construct_scalar(node))

logger = get_logger('mynt')


class Archives(object):
posts = OrderedDict()


def __init__(self, posts):
for post in posts:
year, month = datetime.utcfromtimestamp(post['timestamp']).strftime('%Y %B').split()

if year not in self.posts:
self.posts[year] = OrderedDict({month: [post]})
elif month not in self.posts[year]:
self.posts[year][month] = [post]
else:
self.posts[year][month].append(post)


def __iter__(self):
for year, months in self.posts.iteritems():
yield (year, months.items())

class Config(dict):
def __init__(self, string):
super(Config, self).__init__()

try:
self.update(yaml.load(string))
except yaml.YAMLError:
raise ConfigException('Config contains unsupported YAML.')
except:
raise ConfigException('Invalid config format.')

class Page(File):
pass

class Post(object):
def __init__(self, post):
self.path = post.path
self.root = post.root
self.name = post.name
self.extension = post.extension

logger.debug('.. {0}.{1}'.format(self.name, self.extension))

try:
date, self.slug = re.match(r'(\d{4}-\d{2}-\d{2})-(.+)', self.name).groups()
self.date = datetime.strptime(date, '%Y-%m-%d')
except (AttributeError, ValueError):
raise PostException('Invalid post filename.', 'src: {0}'.format(self.path), 'must be of the format \'YYYY-MM-DD-Post-title.md\'')

try:
frontmatter, self.bodymatter = re.search(r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', post.content, re.M | re.S).groups()
except AttributeError:
raise PostException('Invalid post format.', 'src: {0}'.format(self.path), 'frontmatter must not be empty')

try:
self.frontmatter = Config(frontmatter)
except ConfigException as e:
raise ConfigException('Invalid post frontmatter.', 'src: {0}'.format(self.path), e.message.lower().replace('.', ''))

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

class Tags(OrderedDict):
def __iter__(self):
for name in super(Tags, self).__iter__():
yield (name, self[name])
Loading

0 comments on commit d7443f5

Please sign in to comment.