# Path: daimaduan/models/syntax.py
# class Syntax(BaseDocument):
#     key = db.StringField(required=True, unique=True)
#     name = db.StringField(required=True, unique=True)
# 
#     @property
#     def pastes(self):
#         return Paste.objects(codes__syntax=self.key)


import json
from operator import itemgetter
from fabric.decorators import task
from daimaduan.models.syntax import Syntax
    ('swift', 'Swift'),
    ('tex', 'Tex'),
    ('text', 'Text'),
    ('vbscript', 'VBScript'),
    ('vim', 'Vim'),
    ('xml', 'XML'),
    ('yaml', 'Yaml')
)


def lexer_parser(lexer):
    return {"name": lexer[1], "value": lexer[0]}


def get_lexers():
    lexers = map(lexer_parser, ALL_SUPPORTED_SYNTAX)
    return sorted(lexers, key=itemgetter("name"))


def lexer_dumps(lexer):
    return json.dumps(lexer)


@task
def seed():
    """Seed syntax data in MongoDB"""
    def find_or_create_syntax(key, name):
        syn = Syntax.objects(key=key).first()
        if syn is None:
            print "Seeding syntax: %s, %s" % (key, name)

# Path: daimaduan/models/syntax.py
# class Syntax(BaseDocument):
#     key = db.StringField(required=True, unique=True)
#     name = db.StringField(required=True, unique=True)
# 
#     @property
#     def pastes(self):
#         return Paste.objects(codes__syntax=self.key)


# Path: daimaduan/tasks/seed_data.py
import json
from operator import itemgetter
from fabric.decorators import task
from daimaduan.models.syntax import Syntax

    ('swift', 'Swift'),
    ('tex', 'Tex'),
    ('text', 'Text'),
    ('vbscript', 'VBScript'),
    ('vim', 'Vim'),
    ('xml', 'XML'),
    ('yaml', 'Yaml')
)


def lexer_parser(lexer):
    return {"name": lexer[1], "value": lexer[0]}


def get_lexers():
    lexers = map(lexer_parser, ALL_SUPPORTED_SYNTAX)
    return sorted(lexers, key=itemgetter("name"))


def lexer_dumps(lexer):
    return json.dumps(lexer)


@task
def seed():
    """Seed syntax data in MongoDB"""
    def find_or_create_syntax(key, name):
        syn = Syntax.objects(key=key).first()
        if syn is None:
            print "Seeding syntax: %s, %s" % (key, name)

            Syntax(key=key, name=name).save()