This repository has been archived by the owner on Jan 15, 2022. It is now read-only.
forked from toolness/openbadges.org
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 214678e
Showing
511 changed files
with
20,803 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
locale | ||
dist | ||
*.pyc | ||
settings_local.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
This is the content for the website at [openbadges.org][]. | ||
|
||
[openbadges.org]: http://openbadges.org | ||
|
||
## Prerequisites | ||
|
||
You need Python version 2.6 or higher. All other dependencies are | ||
self-contained within the project's code repository. | ||
|
||
## Setup | ||
|
||
Just run this at the terminal prompt: | ||
|
||
cd openbadges.org | ||
python manage.py runserver | ||
|
||
Then, point your browser to http://localhost:8000/. | ||
|
||
## Development | ||
|
||
All static, unlocalized files are in the `static` directory, which are | ||
placed at the root of the web site. The `templates` directory | ||
contains localized [Jinja2][] templates that are located at `/<locale>/` on | ||
the web site, where `<locale>` is the name of a locale like `en-US`. The | ||
single exception to this is the file `templates/locale-redirector.html`, | ||
which is used to redirect a non-localized pathname to a localized one (e.g., | ||
redirecting `/goggles/` to `/en-US/goggles`). | ||
|
||
Whenever you need to link to a localized template, you can do so either via | ||
a relative URL or an absolute one that begins with the template variable | ||
`{{ LOCALE_ROOT }}`. | ||
|
||
[Jinja2]: http://jinja.pocoo.org/ | ||
|
||
## Testing | ||
|
||
When writing JavaScript code, please try to make it testable and add | ||
a unit test for it in the `static/test` directory. These [QUnit][] | ||
tests can be run from the development server at [localhost:8000/test][]. | ||
|
||
[QUnit]: http://docs.jquery.com/Qunit | ||
[localhost:8000/test]: http://localhost:8000/test/ | ||
|
||
## Localization | ||
|
||
The site uses GNU gettext for localization via [Babel][] and Jinja2's | ||
[i18n extension][]. Soon we'll get the site listed on | ||
[localize.mozilla.org][] so that anyone can easily help localize | ||
the website. | ||
|
||
[Babel]: http://babel.edgewall.org/ | ||
[i18n extension]: http://jinja.pocoo.org/docs/templates/#extensions | ||
[localize.mozilla.org]: https://localize.mozilla.org | ||
|
||
## Deployment | ||
|
||
Run this at the terminal prompt: | ||
|
||
python manage.py build | ||
|
||
This will create a static version of the site, for all supported locales, in | ||
the `dist` directory. You can copy this directory to any web server that | ||
serves static files, such as Apache or Amazon S3. | ||
|
||
## Technical Design Philosophy | ||
|
||
The Open Badges website is almost entirely static content, so we didn't see | ||
much of a need to use a massive server-side framework like [Playdoh][]. | ||
Instead, we took an approach more akin to that of [Jekyll][], whereby | ||
a script can be run to generate a fully static site capable of being | ||
deployed to any static web server. | ||
|
||
However, we pick from Playdoh's toolkit when we need to solve a problem, which | ||
results in a code repository that looks more familiar to Mozilla developers as | ||
the site's requirements become more complex. | ||
|
||
[Playdoh]: https://github.com/mozilla/playdoh | ||
[Jekyll]: https://github.com/mojombo/jekyll/wiki |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[extractors] | ||
jinja2 = jinja2.ext:babel_extract | ||
|
||
[jinja2: **.html] | ||
encoding = utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import sys | ||
import os | ||
import settings | ||
|
||
ROOT = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
def path(*a): | ||
return os.path.join(ROOT, *a) | ||
|
||
sys.path.insert(0, path('vendor')) | ||
|
||
from hackasaurus.management import execute_manager | ||
|
||
if __name__ == '__main__': | ||
execute_manager( | ||
build_dir=path('dist'), | ||
static_files_dir=path('static'), | ||
template_dir=path('templates'), | ||
locale_dir=path('locale'), | ||
locale_domain='openbadges', | ||
babel_ini_file=path('babel.ini'), | ||
template_vars={'settings': settings} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
try: | ||
from settings_local import * | ||
except ImportError: | ||
pass |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
(function(jQuery) { | ||
"use strict"; | ||
|
||
var $ = jQuery; | ||
|
||
function normalizeLanguage(language) { | ||
var match = language.match(/([A-Za-z]+)-([A-Za-z]+)/); | ||
if (match) | ||
return match[1].toLowerCase() + "-" + match[2].toUpperCase(); | ||
return language.toLowerCase(); | ||
} | ||
|
||
function indexOfNearMatch(locale, available) { | ||
var match; | ||
if (locale.indexOf('-') != -1) { | ||
var localeParts = locale.split('-'); | ||
match = jQuery.inArray(localeParts[0], available); | ||
} | ||
else { | ||
match = jQuery.inArray(locale, jQuery.map(available, function(locale){ | ||
var localeParts = locale.split('-'); | ||
return localeParts[0]; | ||
})); | ||
} | ||
return match; | ||
} | ||
|
||
|
||
jQuery.extend({ | ||
localization: { | ||
DEFAULT: "en-US", | ||
activateBestLocale: function(path) { | ||
var div = $("<div></div>"); | ||
div.load("/" + this.DEFAULT + "/language-selector.html", function() { | ||
var available = []; | ||
$(this).find("option").each(function() { | ||
available.push(this.value); | ||
}); | ||
var language = navigator.language || navigator.userLanguage; | ||
var bestMatch = jQuery.localization.findBestMatch(language, | ||
available); | ||
jQuery.localization.activate(bestMatch, true, path); | ||
}); | ||
}, | ||
findBestMatch: function(locale, available) { | ||
locale = normalizeLanguage(locale); | ||
if (jQuery.inArray(locale, available) != -1){ | ||
return locale; | ||
} | ||
else { | ||
var nearMatch = indexOfNearMatch(locale, available); | ||
if (nearMatch == -1) { | ||
return this.DEFAULT; | ||
} | ||
return available[nearMatch]; | ||
} | ||
}, | ||
activate: function(locale, replaceState, path) { | ||
var newURL = '/' + locale + (path || '/'); | ||
if (replaceState && window.history && window.history.replaceState) { | ||
window.history.replaceState({}, "", newURL); | ||
window.location.reload(); | ||
} else | ||
window.location = newURL; | ||
} | ||
} | ||
}); | ||
|
||
$("select.language-selector").live("change", function() { | ||
jQuery.localization.activate(this.options[this.selectedIndex].value); | ||
}); | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: insert content here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{# Note that this template is both embedded into the footer and fetched by | ||
# the site's locale redirector pages to determine what localizations are | ||
# available for client-side content negotiation. | ||
#} | ||
<form autocomplete="off"> | ||
<select class="language-selector"> | ||
{% for locale in locales %} | ||
{% if locale is sameas current_locale %} | ||
<option value="{{ locale }}" selected>{{ locale.display_name }}</option> | ||
{% else %} | ||
<option value="{{ locale }}">{{ locale.display_name }}</option> | ||
{% endif %} | ||
{% endfor %} | ||
</select> | ||
<noscript> | ||
<ul class="noscript-language-selector"> | ||
{% for locale in locales %} | ||
<li><a href="/{{ locale }}/">{{ locale.display_name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
</noscript> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<noscript> | ||
<meta http-equiv="refresh" content="0; url=/en-US{{ PATH_INFO }}"> | ||
</noscript> | ||
<title>Open Badges</title> | ||
</head> | ||
<body> | ||
<noscript> | ||
Please click <a href="/en-US{{ PATH_INFO }}">here</a> if you are not | ||
redirected automatically. | ||
</noscript> | ||
<script src="/scripts/jquery.min.js"></script> | ||
<script src="/scripts/localize.js"></script> | ||
<script> | ||
$(window).ready(function() { | ||
jQuery.localization.activateBestLocale("{{ PATH_INFO }}"); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.