Adding basic embed
parent
0dffceb0be
commit
ae78b1da7f
|
@ -0,0 +1 @@
|
|||
document.open();document.writeln('<div onmouseover="document.getElementById(\'snipt-{{ snipt.id }}\').style.display = \'block\'; return false;" onmouseout="document.getElementById(\'snipt-{{ snipt.id }}\').style.display = \'none\'; return false;" style="position: relative;">');{% for sniptln in snipt.code_stylized %}document.writeln('{{ sniptln|safe }}');{% endfor %}document.writeln('<div style="background-color: #111; color: #D0D0D0; float: right; padding: 5px 10px; -moz-border-radius-topleft: 5px; -webkit-border-top-left-radius: 5px; border-top-left-radius: 5px; -moz-border-radius-bottomright: 5px; -webkit-border-bottom-right-radius: 5px; border-bottom-right-radius: 5px; font: 11px Arial,Sans-Serif; display: none; position: absolute; bottom: 0; right: 0;" id="snipt-{{ snipt.id }}">code hosted by <a href="http://snipt.net/{{ snipt.user }}/{{ snipt.slug }}{% if not snipt.public %}?key={{ snipt.key }}{% endif %}" style="color: #0084FF; text-decoration: none;">snipt.net</a></div>');document.writeln('</div>');document.close();
|
|
@ -7,6 +7,7 @@ urlpatterns = patterns('',
|
|||
url(r'^$', views.home, name='home'),
|
||||
url(r'^public/$', views.list_public, name='list-public'),
|
||||
url(r'^public/tag/(?P<tag_slug>[^/]+)/$', views.list_public, name='list-public-tag'),
|
||||
url(r'^embed/(?P<snipt_key>[^/]+)/$', views.embed, name='embed'),
|
||||
url(r'^(?P<username>[^/]+)/$', views.list_user, name='list-user'),
|
||||
url(r'^(?P<username>[^/]+)/tag/(?P<tag_slug>[^/]+)/$', views.list_user, name='list-user-tag'),
|
||||
url(r'^(?P<username>[^/]+)/(?P<snipt_slug>[^/]+)/$', views.detail, name='detail'),
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from pygments.formatters import HtmlFormatter
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
from django.contrib.auth.models import User
|
||||
from django.template import RequestContext
|
||||
from annoying.decorators import render_to
|
||||
from snipts.models import Favorite, Snipt
|
||||
from django.db.models import Count
|
||||
from django.db.models import Q
|
||||
from pygments import highlight
|
||||
from taggit.models import Tag
|
||||
|
||||
def home(request):
|
||||
|
@ -93,5 +97,16 @@ def detail(request, username, snipt_slug):
|
|||
}
|
||||
|
||||
def embed(request, snipt_key):
|
||||
# TODO
|
||||
return {}
|
||||
try:
|
||||
snipt = Snipt.objects.get(key=snipt_key)
|
||||
snipt.code_stylized = highlight(snipt.code.replace("\\\"","\\\\\""), get_lexer_by_name(snipt.lexer, encoding='UTF-8'), HtmlFormatter(style="native", noclasses=True, prestyles="-moz-border-radius: 5px; border-radius: 5px; -webkit-border-radius: 5px; margin: 0; display: block; font: 11px Monaco, monospace !important; padding: 15px; background-color: #1C1C1C; overflow: auto; color: #D0D0D0;"))
|
||||
snipt.code_stylized = snipt.code_stylized.split('\n')
|
||||
snipt.referer = request.META.get('HTTP_REFERER', '')
|
||||
i = 0;
|
||||
for sniptln in snipt.code_stylized:
|
||||
snipt.code_stylized[i] = snipt.code_stylized[i].replace(" font-weight: bold", " font-weight: normal").replace('\'','\\\'').replace('\\n','\\\\n').replace("\\x", "\\\\x").replace('\\'', '\\\\'').replace('\\s', '\\\\s')
|
||||
i = i + 1
|
||||
except Snipt.DoesNotExist:
|
||||
raise Http404
|
||||
|
||||
return render_to_response('snipts/embed.html', locals(), context_instance=RequestContext(request), mimetype="application/javascript")
|
||||
|
|
Loading…
Reference in New Issue