Skip to content

Commit

Permalink
Merge pull request #986 from pads/upstream
Browse files Browse the repository at this point in the history
HTML search results use site icons and time ago plugin.
  • Loading branch information
cdent committed Aug 8, 2012
2 parents 5e286d4 + 69e0ad4 commit 7ed33c2
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
14 changes: 8 additions & 6 deletions Makefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ test:
tiddlywiki: tiddlywiki:
mkdir src/externals || true mkdir src/externals || true
mkdir tiddlywebplugins/tiddlyspace/resources || true mkdir tiddlywebplugins/tiddlyspace/resources || true
wget http://tiddlywiki.com/beta/empty.html \ wget http://tiddlywiki.github.com/beta/empty.html \
-O tiddlywebplugins/tiddlyspace/resources/beta.html -O tiddlywebplugins/tiddlyspace/resources/beta.html
wget http://tiddlywiki.com/alpha/empty.html \ wget http://tiddlywiki.github.com/alpha/empty.html \
-O tiddlywebplugins/tiddlyspace/resources/alpha.html -O tiddlywebplugins/tiddlyspace/resources/alpha.html
wget http://tiddlywiki.com/alpha/tiddlywiki_externaljs_tiddlyspace.html \ wget http://tiddlywiki.github.com/alpha/tiddlywiki_externaljs_tiddlyspace.html \
-O tiddlywebplugins/tiddlyspace/resources/external_alpha.html -O tiddlywebplugins/tiddlyspace/resources/external_alpha.html
wget http://tiddlywiki.com/alpha/jquery.js \ wget http://tiddlywiki.github.com/alpha/jquery.js \
-O src/externals/alpha_jquery.js.js -O src/externals/alpha_jquery.js.js
wget http://tiddlywiki.com/alpha/jQuery.twStylesheet.js \ wget http://tiddlywiki.github.com/alpha/jQuery.twStylesheet.js \
-O src/externals/alpha_jQuery.twStylesheet.js.js -O src/externals/alpha_jQuery.twStylesheet.js.js
wget http://tiddlywiki.com/alpha/twcore.js \ wget http://tiddlywiki.github.com/alpha/twcore.js \
-O src/externals/alpha_twcore.js.js -O src/externals/alpha_twcore.js.js




Expand All @@ -46,6 +46,8 @@ jslib: qunit
http://jquery-json.googlecode.com/files/jquery.json-2.3.min.js) http://jquery-json.googlecode.com/files/jquery.json-2.3.min.js)
$(call wrap_jslib, src/lib/jquery-form.js.js, \ $(call wrap_jslib, src/lib/jquery-form.js.js, \
https://raw.github.com/malsup/form/master/jquery.form.js) https://raw.github.com/malsup/form/master/jquery.form.js)
$(call wrap_jslib, src/lib/jquery.timeago.js.js, \
http://timeago.yarp.com/jquery.timeago.js)


qunit: qunit:
mkdir -p src/test/qunit mkdir -p src/test/qunit
Expand Down
2 changes: 2 additions & 0 deletions src/common.recipe
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ tiddler: lib/chrjs.users.js
tiddler: lib/chrjs.space.js tiddler: lib/chrjs.space.js
tiddler: lib/chrjs.identities.js tiddler: lib/chrjs.identities.js
tiddler: lib/jquery-form.js.js tiddler: lib/jquery-form.js.js
tiddler: lib/jquery.timeago.js.js
tiddler: lib/run-timeago.js.js
tiddler: icons/close.png.tid tiddler: icons/close.png.tid
tiddler: icons/backstage.png.tid tiddler: icons/backstage.png.tid
tiddler: icons/shim.tid tiddler: icons/shim.tid
Expand Down
28 changes: 28 additions & 0 deletions src/lib/run-timeago.js.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
/***
Apply timeago against class annotated elements
matching the format: <el class="timeago" title="timestamp"/>.
Requires jquery,timeago - http://timeago.yarp.com/
***/
//{{{
$(function () {

function dateString(date) {
return new Date(Date.UTC(
parseInt(date.substr(0, 4), 10),
parseInt(date.substr(4, 2), 10) - 1,
parseInt(date.substr(6, 2), 10),
parseInt(date.substr(8, 2), 10),
parseInt(date.substr(10, 2), 10),
parseInt(date.substr(12, 2) || "0", 10),
parseInt(date.substr(14, 3) || "0", 10)
)).toISOString();
}

$(".timeago").each(function () {
$(this).attr('title', dateString($(this).attr('title')));
$(this).timeago();
});
});
//}}}


17 changes: 17 additions & 0 deletions src/styles/profile.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -275,6 +275,23 @@ table.twtable {
} }
} }


/**********/
/* Search */
/**********/
/* TODO: move to dedicated stylesheet. */
.search {
list-style-type: none;
line-height: 48px;
}

.search img {
width: 48px;
height: 48px;
vertical-align: middle;
padding-right: 5px;
padding-bottom: 5px;
}

/*****************/ /*****************/
/* Media Queries */ /* Media Queries */
/*****************/ /*****************/
Expand Down
14 changes: 12 additions & 2 deletions test/test_search.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_search_no_args():
response, content = http.request('http://0.0.0.0:8080/search.json?q=_limit:999') response, content = http.request('http://0.0.0.0:8080/search.json?q=_limit:999')
assert response['status'] == '200' assert response['status'] == '200'
allinfo = simplejson.loads(content) allinfo = simplejson.loads(content)
assert len(allinfo) == 163 assert len(allinfo) == 165


response, content = http.request('http://fnd.0.0.0.0:8080/search.json') response, content = http.request('http://fnd.0.0.0.0:8080/search.json')
assert response['status'] == '200' assert response['status'] == '200'
Expand All @@ -128,7 +128,7 @@ def test_search_no_args():
response, content = http.request('http://fnd.0.0.0.0:8080/search.json?q=_limit:999') response, content = http.request('http://fnd.0.0.0.0:8080/search.json?q=_limit:999')
assert response['status'] == '200' assert response['status'] == '200'
fndinfo = simplejson.loads(content) fndinfo = simplejson.loads(content)
assert len(fndinfo) == 144 assert len(fndinfo) == 146


assert len(allinfo) > len(fndinfo) assert len(allinfo) > len(fndinfo)


Expand All @@ -155,6 +155,8 @@ def test_search_html():


assert '<a class="space" href="http://fnd.0.0.0.0:8080/">' in content assert '<a class="space" href="http://fnd.0.0.0.0:8080/">' in content


assert '<img alt="space icon" src="http://fnd.0.0.0.0:8080/SiteIcon"/>' in content

tiddler = store.get(Tiddler('One Two', 'fnd_public')) tiddler = store.get(Tiddler('One Two', 'fnd_public'))
tiddler.modifier = 'cowboy' tiddler.modifier = 'cowboy'
store.put(tiddler) store.put(tiddler)
Expand All @@ -163,3 +165,11 @@ def test_search_html():
assert response['status'] == '200', content assert response['status'] == '200', content
assert '<a class="modifier" href="http://fnd.0.0.0.0:8080/">' not in content assert '<a class="modifier" href="http://fnd.0.0.0.0:8080/">' not in content
assert '<a class="modifier" href="http://cowboy.0.0.0.0:8080/">' in content assert '<a class="modifier" href="http://cowboy.0.0.0.0:8080/">' in content
# tiddlers that do not come from a space should show the default tiddlyspace site icon.
tiddler = Tiddler('commoner', 'common')
tiddler.text = 'I want to live like common people.'
store.put(tiddler)

response, content = http.request('http://0.0.0.0:8080/search?q=title:commoner')
assert response['status'] == '200', content
assert '<img alt="space icon" src="http://0.0.0.0:8080/SiteIcon"/>' in content
17 changes: 14 additions & 3 deletions tiddlywebplugins/templates/search.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ <h1>{{ title|e }}</h1>
<div class="main section" id="tiddlers"> <div class="main section" id="tiddlers">
<ul id="tiddlers" class="listing"> <ul id="tiddlers" class="listing">
{% for tiddler in tiddlers %} {% for tiddler in tiddlers %}
<li> <li class="search">
{% if space_bag(tiddler.bag) -%}
<img alt="space icon" src="{{
'%s%s' % (space_uri(environ, tiddler.bag.split('_')[0]), 'SiteIcon')}}"/>
{% else -%}
<img alt="space icon" src="{{ '%s/%s' % (original_server_host, 'SiteIcon') }}"/>
{%- endif -%}
<a class="title" <a class="title"
href="{{ tiddler_url(environ, tiddler, href="{{ tiddler_url(environ, tiddler,
container_type, friendly=True) }}">{{ container_type, friendly=True) }}">{{
tiddler.title|e }}</a> tiddler.title|e }}</a>
modified <span modified <span class="modified timeago"
class="modified">{{tiddler.modified|format_modified}}</a> title="{{ tiddler.modified }}">{{ tiddler.modified|format_modified }}</span></a>
{% if tiddler.modifier -%} {% if tiddler.modifier -%}
by <a class="modifier" href="{{ space_uri(environ, by <a class="modifier" href="{{ space_uri(environ,
tiddler.modifier) }}">@{{tiddler.modifier}}</a> tiddler.modifier) }}">@{{tiddler.modifier}}</a>
Expand All @@ -42,3 +48,8 @@ <h1>{{ title|e }}</h1>
</ul> </ul>
</div> </div>
{% endblock %} {% endblock %}
{% block scripts %}
<script type="text/javascript" src="/bags/common/tiddlers/jquery.js"></script>
<script type="text/javascript" src="/bags/common/tiddlers/jquery.timeago.js"></script>
<script type="text/javascript" src="/bags/common/tiddlers/run-timeago.js"></script>
{% endblock %}

0 comments on commit 7ed33c2

Please sign in to comment.