# Path: dju_common/constants.py
# DJU_EMAIL_BLOCK_MARKERS = {
#     'subject': ('<!--__DJU_EMAIL_SUBJECT_BEGIN__-->', '<!--__DJU_EMAIL_SUBJECT_END__-->'),
#     'plain_body': ('<!--__DJU_EMAIL_PLAIN_BODY_BEGIN__-->', '<!--__DJU_EMAIL_PLAIN_BODY_END__-->'),
#     'html_body': ('<!--__DJU_EMAIL_HTML_BODY_BEGIN__-->', '<!--__DJU_EMAIL_HTML_BODY_END__-->'),
# }


from django import template
from ..constants import DJU_EMAIL_BLOCK_MARKERS


register = template.Library()


class EmailBlockNode(template.Node):
    def __init__(self, nodelist, markers):
        self.nodelist = nodelist
        self.markers = markers

    def render(self, context):
        return u'{1}{0}{2}'.format(self.nodelist.render(context), *self.markers)


@register.tag
def dju_email_subject(parser, token):
    nodelist = parser.parse(('enddju_email_subject', 'end_dju_email_subject'))
    parser.delete_first_token()
    return EmailBlockNode(nodelist, DJU_EMAIL_BLOCK_MARKERS['subject'])


@register.tag
def dju_email_plain_body(parser, token):
    nodelist = parser.parse(('enddju_email_plain_body', 'end_dju_email_plain_body'))
    parser.delete_first_token()

# Path: dju_common/constants.py
# DJU_EMAIL_BLOCK_MARKERS = {
#     'subject': ('<!--__DJU_EMAIL_SUBJECT_BEGIN__-->', '<!--__DJU_EMAIL_SUBJECT_END__-->'),
#     'plain_body': ('<!--__DJU_EMAIL_PLAIN_BODY_BEGIN__-->', '<!--__DJU_EMAIL_PLAIN_BODY_END__-->'),
#     'html_body': ('<!--__DJU_EMAIL_HTML_BODY_BEGIN__-->', '<!--__DJU_EMAIL_HTML_BODY_END__-->'),
# }


# Path: dju_common/templatetags/dju_email.py
from django import template
from ..constants import DJU_EMAIL_BLOCK_MARKERS



register = template.Library()


class EmailBlockNode(template.Node):
    def __init__(self, nodelist, markers):
        self.nodelist = nodelist
        self.markers = markers

    def render(self, context):
        return u'{1}{0}{2}'.format(self.nodelist.render(context), *self.markers)


@register.tag
def dju_email_subject(parser, token):
    nodelist = parser.parse(('enddju_email_subject', 'end_dju_email_subject'))
    parser.delete_first_token()
    return EmailBlockNode(nodelist, DJU_EMAIL_BLOCK_MARKERS['subject'])


@register.tag
def dju_email_plain_body(parser, token):
    nodelist = parser.parse(('enddju_email_plain_body', 'end_dju_email_plain_body'))
    parser.delete_first_token()

    return EmailBlockNode(nodelist, DJU_EMAIL_BLOCK_MARKERS['plain_body'])