Skip to content

Commit ed3ad22

Browse files
committed
Add JavaScript integration page.
1 parent 06cdfb4 commit ed3ad22

File tree

5 files changed

+92
-3
lines changed

5 files changed

+92
-3
lines changed

example/static/css/styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
div {
2-
margin-top: 40px;
2+
margin-top: 40px;
33
}
44

55
label {
6-
font-weight: bold;
6+
font-weight: bold;
77
}

example/unicorn/components/js.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from django_unicorn.components import UnicornView
2+
3+
4+
class JsView(UnicornView):
5+
states = (
6+
"Alabama",
7+
"Alaska",
8+
"Arizona",
9+
"Arkansas",
10+
"California",
11+
"Colorado",
12+
"Connecticut",
13+
"Delaware",
14+
"Florida",
15+
"Georgia",
16+
"Hawaii",
17+
"Idaho",
18+
"Illinois",
19+
"Indiana",
20+
"Iowa",
21+
"Kansas",
22+
"Kentucky",
23+
"Louisiana",
24+
"Maine",
25+
"Maryland",
26+
"Massachusetts",
27+
"Michigan",
28+
"Minnesota",
29+
"Mississippi",
30+
"Missouri",
31+
"Montana",
32+
"Nebraska",
33+
"Nevada",
34+
"New Hampshire",
35+
"New Jersey",
36+
"New Mexico",
37+
"New York",
38+
"North Carolina",
39+
"North Dakota",
40+
"Ohio",
41+
"Oklahoma",
42+
"Oregon",
43+
"Pennsylvania",
44+
"Rhode Island",
45+
"South Carolina",
46+
"South Dakota",
47+
"Tennessee",
48+
"Texas",
49+
"Utah",
50+
"Vermont",
51+
"Virginia",
52+
"Washington",
53+
"West Virginia",
54+
"Wisconsin",
55+
"Wyoming",
56+
)
57+
58+
class Meta:
59+
javascript_excludes = ("states",)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
{% for state in states %}
3+
{{ state }}
4+
{% endfor %}
5+
</div>

example/www/templates/www/base.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
<title>django-unicorn examples</title>
66
<link rel="stylesheet" href="{% static 'css/marx.min.css' %}">
77
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
8+
<style>
9+
#menu {
10+
list-style: none;
11+
}
12+
#menu li {
13+
display: inline;
14+
padding: 0 10px;
15+
border-left: solid 1px black;
16+
}
17+
#menu li:first-child {
18+
border-left: none !important;
19+
}
20+
</style>
21+
822
{% unicorn_scripts %}
923
</head>
1024

@@ -14,7 +28,7 @@
1428

1529
<h1>django-unicorn</h1>
1630

17-
<ul>
31+
<ul id="menu">
1832
<li><a href="{% url 'www:index' %}">Index</a></li>
1933
<li><a href="{% url 'www:template' 'text-inputs' %}">Text inputs</a></li>
2034
<li><a href="{% url 'www:template' 'html-inputs' %}">Other inputs</a></li>
@@ -23,6 +37,7 @@ <h1>django-unicorn</h1>
2337
<li><a href="{% url 'www:template' 'polling' %}">Polling</a></li>
2438
<li><a href="{% url 'www:template' 'models' %}">Models</a></li>
2539
<li><a href="{% url 'www:template' 'nested' %}">Nested components (table)</a></li>
40+
<li><a href="{% url 'www:template' 'js' %}">JavaScript integration</a></li>
2641
</ul>
2742

2843
{% block content %}{% endblock content %}

example/www/templates/www/js.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "www/base.html" %}
2+
{% load static unicorn %}
3+
4+
{% block content %}
5+
6+
<h2>JavaScript integration</h2>
7+
8+
{% unicorn 'js' %}
9+
10+
{% endblock content %}

0 commit comments

Comments
 (0)