Skip to content

Commit

Permalink
0.3.3: Add Twitter Bootstrap.
Browse files Browse the repository at this point in the history
Summary:
Also adds static files via `django.contrib.staticfiles` (preferred) or
serving static media via `django.views.static.serve`.

Test Plan: Visual.

Reviewers: jeff, dcramer

Reviewed By: jeff

CC: vincelane

Differential Revision: http://phabricator.local.disqus.net/D4329
  • Loading branch information
tkaemming committed Dec 10, 2012
1 parent f47477d commit 849df95
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 50 deletions.
1 change: 0 additions & 1 deletion .arcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"copyright_holder": "Disqus, Inc.",
"immutable_history": false,
"differential.field-selector": "DisqusDifferentialFieldSelector",
"unit_engine": "DisqusUnitTestEngine",
"lint_engine": "ComprehensiveLintEngine",
"lint.pep8.options": "--ignore=W391,W292,W293,E501,E225",
"lint.jshint.prefix": "node_modules/jshint/bin",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.tox/
dist/
docs/_build/
node_modules/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/bootstrap"]
path = vendor/bootstrap
url = git://github.com/twitter/bootstrap.git
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
recursive-include mailviews/static *
recursive-include mailviews/templates *
32 changes: 28 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
develop:
STATIC_DIRECTORY = mailviews/static/mailviews

LESSC = ./node_modules/.bin/lessc
JQUERY = $(STATIC_DIRECTORY)/javascript/jquery.js


$(LESSC):
npm install .

bootstrap: $(LESSC)
git submodule update --init
$(LESSC) vendor/bootstrap/less/bootstrap.less > $(STATIC_DIRECTORY)/css/bootstrap.css
cp vendor/bootstrap/js/bootstrap-*.js $(STATIC_DIRECTORY)/javascript

$(JQUERY):
curl http://code.jquery.com/jquery-1.8.3.js > $(JQUERY)

static: bootstrap $(JQUERY)


develop: static
python setup.py develop

lint:
Expand All @@ -18,9 +38,13 @@ test-matrix: clean
test-server: develop
python mailviews/tests/manage.py runserver

publish: lint test-matrix
sdist: static
python setup.py sdist

publish: lint test-matrix sdist
git tag $$(python setup.py --version)
git push --tags
python setup.py sdist upload -r disqus
python setup.py upload -r disqus


.PHONY: clean lint test test-matrix test-server publish
.PHONY: bootstrap static develop lint clean test test-matrix test-server sdist publish
2 changes: 1 addition & 1 deletion mailviews/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = (0, 3, 2)
__version__ = (0, 3, 3)
5 changes: 5 additions & 0 deletions mailviews/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.conf import settings


def should_use_staticfiles():
return 'django.contrib.staticfiles' in settings.INSTALLED_APPS
3 changes: 3 additions & 0 deletions mailviews/static/mailviews/css/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!mailviews.css
26 changes: 26 additions & 0 deletions mailviews/static/mailviews/css/mailviews.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
body {
padding-top: 60px;
}

#html iframe,
#html textarea {
border: 0;
height: 700px;
width: 100%;
}

#html textarea {
font-family: monospace;
padding: 0;
}

section {
border-bottom: 1px solid #ddd;
padding-bottom: 20px;
margin-bottom: 20px;
}

section.last {
border-bottom: 0;
padding-bottom: 0;
}
2 changes: 2 additions & 0 deletions mailviews/static/mailviews/javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
110 changes: 69 additions & 41 deletions mailviews/templates/mailviews/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,105 @@
<html lang="en">
<head>

<style type="text/css">
{% load mailviews %}

iframe {
height: 700px;
width: 100%;
}
<link rel="stylesheet" type="text/css" href="{% mailviews_static 'mailviews/css/bootstrap.css' %}" />
<link rel="stylesheet" type="text/css" href="{% mailviews_static 'mailviews/css/mailviews.css' %}" />

textarea {
min-height: 250px;
width: 100%;
}

</style>
<script type="text/javascript" src="{% mailviews_static 'mailviews/javascript/jquery.js' %}"></script>
<script type="text/javascript" src="{% mailviews_static 'mailviews/javascript/bootstrap-tab.js' %}"></script>

</head>
<body>

<header>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">Preview</a>
<div class="nav-collapse collapse">
<ul class="nav">
{% if html %}
<li><a href="#html">HTML</a></li>
{% endif %}
<li><a href="#body-plain">Text</a></li>
<li><a href="#raw">Raw</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>

<h1>{{ subject }}</h1>
<div class="container">

<div id="headers">
<div class="page-header">
<h1>{{ subject }}</h1>
</div>

<h2>Headers</h2>
<header>

<dl>
{% for name, value in headers %}
<dt>{{ name }}</dt>
<dd>{{ value }}</dd>
{% endfor %}
</dl>
<div id="headers">

</div>
<table class="table table-striped table-condensed">
{% for name, value in headers %}
<tr>
<th>{{ name }}</th>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>

</header>
</div>

{% if html %}
</header>

<section id="body-html">
{% if html %}

<h2>HTML Body (Preview)</h2>
<div id="html">

<iframe src="data:text/html;base64,{{ escaped_html }}"></iframe>
<h2>HTML</h2>

</section>
<ul class="nav nav-tabs">
<li class="active"><a href="#body-html" data-toggle="tab">Preview</a></li>
<li><a href="#html-raw" data-toggle="tab">Source</a></li>
</ul>

<section id="html-raw">
<div class="tab-content">

<h2>HTML Body (Raw)</h2>
<section id="body-html" class="tab-pane active">
<iframe src="data:text/html;base64,{{ escaped_html }}" frameborder="0" allowtransparency="true"></iframe>
</section>

<textarea>{{ html|escape }}</textarea>
<section id="html-raw" class="tab-pane">
<textarea>{{ html|escape }}</textarea>
</section>

</section>
</div>

{% endif %}
</div>

{% endif %}

<section id="body-plain">
<section id="body-plain">

<h2>Body (Text)</h2>
<h2>Text</h2>

{{ body|linebreaks }}
{% if body %}
{{ body|linebreaks }}
{% else %}
<p class="alert">This message doesn't contain any text content.</p>
{% endif %}

</section>
</section>

<section id="raw">
<section id="raw" class="last">

<h2>Raw Message</h2>
<h2>Raw</h2>

<pre>{{ raw }}</pre>
<pre>{{ raw }}</pre>

</section>

</section>
</div>

</body>
</html>
Empty file.
22 changes: 22 additions & 0 deletions mailviews/templatetags/mailviews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import absolute_import

from django import template

from mailviews.helpers import should_use_staticfiles


register = template.Library()


def mailviews_static(path):
if should_use_staticfiles():
from django.contrib.staticfiles.templatetags import staticfiles
return staticfiles.static(path)
else:
from django.core.urlresolvers import reverse
return reverse('mailviews-static', kwargs={
'path': path,
})


register.simple_tag(mailviews_static)
1 change: 1 addition & 0 deletions mailviews/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
},
ROOT_URLCONF='mailviews.tests.urls',
STATIC_URL='/static/',
)


Expand Down
3 changes: 2 additions & 1 deletion mailviews/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.conf.urls.defaults import patterns, url
from django.conf.urls.defaults import include, patterns, url

from mailviews.tests.views import preview


urlpatterns = patterns('',
url(regex=r'^$', view=preview),
url(regex=r'^mailviews/', view=include('mailviews.urls')),
)
4 changes: 2 additions & 2 deletions mailviews/tests/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random

from django.contrib.webdesign.lorem_ipsum import paragraphs, sentence
from django.contrib.webdesign.lorem_ipsum import paragraphs, words
from django.template import Template

from mailviews.messages import (TemplatedEmailMessageView,
Expand All @@ -23,7 +23,7 @@ def preview(request):
message_view.html_body_template = Template('{{ content|linebreaks }}')

message = message_view.render_to_message(extra_context={
'subject': sentence(),
'subject': words(random.randint(5, 20), common=False),
'content': '\n'.join(paragraphs(random.randint(3, 6))),
})
return render_message_to_response(request, message)
19 changes: 19 additions & 0 deletions mailviews/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from django.conf.urls.defaults import patterns, url

from mailviews.helpers import should_use_staticfiles


urlpatterns = patterns('')


if not should_use_staticfiles():
urlpatterns += patterns('',
url(regex=r'^static/(?P<path>.*)$',
view='django.views.static.serve',
kwargs={
'document_root': os.path.join(os.path.dirname(__file__), 'static'),
},
name='mailviews-static'),
)
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "django-mailviews",
"version": "0.0.0",
"description": "",
"repository": {
"type": "git",
"url": "git://github.com/disqus/django-mailviews.git"
},
"author": "disqus",
"license": "apache license 2.0",
"readmeFilename": "README.rst",
"dependencies": {
"less": "1.3.1",
"jshint": "0.8.0"
}
}
1 change: 1 addition & 0 deletions vendor/bootstrap
Submodule bootstrap added at 3b3dd3

0 comments on commit 849df95

Please sign in to comment.