All pastes #1799026 Raw Edit

Site

public diff v1 · immutable
#1799026 ·published 2010-02-16 21:50 UTC
rendered paste body
Index: apps/markdownext/utils.py===================================================================--- apps/markdownext/utils.py	(rvision 223)+++ apps/markdownext/utils.py	(copie de travail)@@ -8,7 +8,7 @@         self.images = images      def to_html(self):-        md = markdown.Markdown(['video'])+        md = markdown.Markdown(['video', 'gallery'])         for image in self.images:             md.references[image.name] = (image.image.url, '')         html = md.convert(self.text)Index: external_apps/mdx_gallery.py===================================================================--- external_apps/mdx_gallery.py	(rvision 0)+++ external_apps/mdx_gallery.py	(rvision 0)@@ -0,0 +1,76 @@+#!/usr/bin/env python++"""+Embeds web videos using URLs.  For instance, if a URL to an youtube video is+found in the text submitted to markdown and it isn't enclosed in parenthesis+like a normal link in markdown, then the URL will be swapped with a embedded+youtube video.++All resulting HTML is XHTML Strict compatible.++"""++import markdown+import xml+from django.template.loader import render_to_string+from xml.etree import ElementTree++version = "0.1.0"++class Gallery(markdown.Extension):+    def __init__(self, configs):+        self.config = {+        }++        # Override defaults with user settings+        for key, value in configs:+            self.setConfig(key, value)++    def add_inline(self, md, name, klass, re):+        pattern = klass(re)+        pattern.md = md+        pattern.ext = self+        md.inlinePatterns.add(name, pattern, "<reference")++    def extendMarkdown(self, md, md_globals):+        self.add_inline(md, 'galleryimpl', GalleryImpl,+            r'^gallery\[(?P<params>.*)\]$')++class GalleryImpl(markdown.inlinepatterns.Pattern):+    def handleMatch(self, m):+        params=eval("["+m.group('params')+"]", {}, {})+        images=[]+        for param in params:+            image={}+            image["url"]=param+            image["caption"]="captionnnnneeee"+            images+=image+        +        gallery={}+        gallery["name"]="Gallery name"+        gallery["images"]=images+        +        data={}+        data["gallery"]=gallery+        +        html=render_to_string("gallery/show_gallery.html", data)+        print "\""+html+"\""+        return markdown.etree.ElementTree.fromstring(html)++"""ret="(gallery("+str(len(images))+"):"+            for image in images:+                try:+                    ret+=MarkdownContent(image)+" "+                    #ret+=image+" "+                except Exception as detail:+                    ret+="(error: "+detail+")"+            ret+=")"+        except Exception:+            ret="{Gallery: Invalid Syntax}"""++def makeExtension(configs=None) :+    return Gallery(configs=configs)++if __name__ == "__main__":+    import doctest+    doctest.testmod()Index: templates/gallery/show_gallery.html===================================================================--- templates/gallery/show_gallery.html	(rvision 0)+++ templates/gallery/show_gallery.html	(rvision 0)@@ -0,0 +1,28 @@+{% load i18n %}+  <script type="text/javascript">+	<!--//+	   $('#screenshots-link-{{ project.slug|escapejs }}').removeAttr('href').click(function() {+	   var box = $("#gallery");+	   box.data('gallery_img_index', 0);+	   box.data('title', '{{ gallery.name|escapejs }}');++	   var images = new Array();+	   var captions = new Array();+	   var widths = new Array();+	   var heights = new Array();+	   {% for img in gallery.images %}+	   images.push('{{ img.image.url|escapejs }}');+	   captions.push('{{ img.caption|escapejs }}');+	   widths.push({{ screenshot.image.width }});+	   heights.push({{ screenshot.image.height }});+	   {% endfor %}++	   box.data('images', images);+	   box.data('captions', captions);+	   box.data('widths', widths);+	   box.data('heights', heights);++	   view_image(box);+	   });+	   //-->+  </script>\ No newline at end of fileIndex: templates/gallery/gallery.html===================================================================--- templates/gallery/gallery.html	(rvision 0)+++ templates/gallery/gallery.html	(rvision 0)@@ -0,0 +1,35 @@+{% extends "base.html" %}++{% load i18n %}++{% block content %}+<h2>+  <img alt="{% trans "Screenshots" %}" src="{{ MEDIA_URL }}images/screenshots-32.png" />+  {% trans "Screenshots" %}: {{ project.name }}+</h2>++<div class="content-text">++<div id="project-screenshots-header">+  {% if prev_screenshot %}+  <a href="{% url project_screenshot prev_screenshot.id %}">+	<img id="project-screenshots-prev" alt="{% trans "Previous" %}" src="{{ MEDIA_URL }}images/back-16.png" />+  </a>+  {% endif %}++  {% if next_screenshot %}+  <a href="{% url project_screenshot next_screenshot.id %}">+	<img id="project-screenshots-next" alt="{% trans "Next" %}" src="{{ MEDIA_URL }}images/next-16.png" />+  </a>+  {% endif %}+  <span id="project-screenshots-caption">{{ current_screenshot.caption }} ({{ screenshot_index }}/{{ screenshot_count }})</span>+</div>++<a href="{% url project project.slug %}">{% trans "Go back to the project page" %}</a>++<div id="project-screenshots-image">+  <img alt="{% trans "Screenshot" %}" src="{{ current_screenshot.image.url }}" />+</div>++</div>+{% endblock %}Index: templates/gallery/no_pictures.html===================================================================--- templates/gallery/no_pictures.html	(rvision 0)+++ templates/gallery/no_pictures.html	(rvision 0)@@ -0,0 +1,16 @@+{% extends "base.html" %}++{% load i18n %}++{% block content %}+<h2>+  <img alt="{% trans "Screenshots" %}" src="{{ MEDIA_URL }}images/screenshots-32.png" />+  {% trans "Screenshots" %}: {{ project.name }}+</h2>++<div class="content-text">+<p>{% trans "No screenshots are available for this project." %}</p>++<a href="{% url project project.slug %}">{% trans "Go back to the project page" %}</a>+</div>+{% endblock %}Index: templates/gallery/gallery_js.html===================================================================--- templates/gallery/gallery_js.html	(rvision 0)+++ templates/gallery/gallery_js.html	(rvision 0)@@ -0,0 +1,79 @@+{% load i18n %}++<div id="gallery"> {# jquery dialog contents #}+  <div id="gallery-header">+	<img id="gallery-prev" alt="{% trans "Previous" %}" src="{{ MEDIA_URL }}images/back-16.png" />+	<img id="gallery-next" alt="{% trans "Next" %}" src="{{ MEDIA_URL }}images/next-16.png" />+	<span id="gallery-caption"></span>+  </div>+  <div id="gallery-image"></div>+</div>++<script type="text/javascript">+<!--//+	  function view_image(box)+	  {+	  var gallery_img_index = box.data('gallery_img_index');+	  var title = box.data('title');+	  var images = box.data('images');+	  var captions = box.data('captions');+      var widths = box.data('widths');+      var heights = box.data('heights');++	  /* opens the dialog with the div inside */+      box.dialog();+	  box.dialog('option', 'title', title);+	  box.dialog('open');++	  /* replace the previous content */+	  var caption = $("#gallery-caption");+	  var image = $("#gallery-image");++	  var prev = $('#gallery-prev');+	  var next = $('#gallery-next');++	  var len = images.length;+	  if (len == 0)+	  {+      box.dialog('option', 'width', 400);+      box.dialog('option', 'height', 80);+	  box.dialog('option', 'position', 'center');++	  caption.text('{% trans "No screenshots are available for this project." %}');+	  image.children().remove();+	  prev.hide();+	  next.hide();+	  } else {+      newWidth = widths[gallery_img_index] + 64;+      if (newWidth < 400) { newWidth = 400; }+      box.dialog('option', 'width', newWidth);+      box.dialog('option', 'height', heights[gallery_img_index] + 96);+	  box.dialog('option', 'position', 'center');+	  +	  if (gallery_img_index > 0) prev.show(); else prev.hide();+	  if (gallery_img_index < len - 1) next.show(); else next.hide();++      caption.text(captions[gallery_img_index] ++		' (' + (gallery_img_index + 1) + '/' + len + ')');++	  /* replace the contents of the image element */+	  image.children().remove();+	  image.append('<img alt="{% trans "Screenshot" %}" src="' + images[gallery_img_index] + '" />');+	  }+	  };++	  $('#gallery-prev').click(function() {+	  var box = $("#gallery");+	  var idx = box.data('gallery_img_index');+	  box.data('gallery_img_index', idx - 1);+	  view_image(box);+	  });++	  $('#gallery-next').click(function() {+	  var box = $("#gallery");+	  var idx = box.data('gallery_img_index');+	  box.data('gallery_img_index', idx + 1);+	  view_image(box);+	  });+//-->+</script>Index: templates/contact/contact_portfolio.html===================================================================--- templates/contact/contact_portfolio.html	(rvision 229)+++ templates/contact/contact_portfolio.html	(copie de travail)@@ -12,6 +12,8 @@ 		<img class="icon" alt="{% trans "Contacts" %}" src="{{ MEDIA_URL }}images/about-32.png" />{% trans "Contact" %} 	</h2> +	{% include "gallery/gallery_js.html" %}+ 	{% with user.userprofile as profile%} 	<div class="content-text"> 		<div class="contact-user">