Ejemplo n.º 1
0
    def render(self, context):
        filepath = "%s/%s.markdown" % (settings.COPYBLOCK_ROOT, self.filepath)
        nocache = self.nocache
        nomarkdown = self.nomarkdown
        
#        if nocache \
#           or not settings.COPYBLOCK_CACHE \
#           or filepath not in CACHE:
#            try:
#                content = get_file_contents(filepath)
#
#                if nomarkdown:
#                    output = content
#                else:
#                    output = markdown(content)
#                CACHE[self.filepath] = output
#            except IOError:
#                import sys
#                exc_type, exc_value, exc_traceback = sys.exc_info()
#                output = '<!-- file %s not found -->' % filepath
#        else:
#            output = CACHE[self.filepath]

        output = copydown(filepath, nocache=nocache, nomarkdown=nomarkdown)

        return output
Ejemplo n.º 2
0
from django.shortcuts import render_to_response
from django.template.context import RequestContext

from copyblock.utils import copydown

def serve(request, path):
    # files should be here
    root = settings.COPYBLOCK_ROOT
    template = ''
    try:
        template = settings.COPYBLOCK_TEMPLATE
    except AttributeError, ae:
        HttpResponseServerError('Template not defined.')

    print template
    
    filepath = "%s/%s.markdown" % (root, path)
    print filepath

    # check file path
    if not os.path.exists(filepath):
        return HttpResponseNotFound()

    # run through markdown?
    output = copydown(filepath, nocache=True)
    print output

    # run as template? which first?
    return render_to_response(template, {
        'output': output,
    }, context_instance=RequestContext(request))