Skip to content

Commit

Permalink
Merge pull request #50 from rightsstatements/develop
Browse files Browse the repository at this point in the history
Launch release
  • Loading branch information
anarchivist committed Apr 12, 2016
2 parents 50e0a2f + 880f4d0 commit 45acbc8
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 171 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "test/resources/data-model"]
path = test/resources/data-model
url = https://github.com/rightsstatements/data-model.git
[submodule "public/rightsstatements.github.io"]
path = public/rightsstatements.github.io
url = https://github.com/rightsstatements/rightsstatements.github.io.git
53 changes: 31 additions & 22 deletions app/controllers/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand All @@ -46,6 +47,8 @@ public class Application extends Controller {

private static Map<String, Object> sparqlQueries = Play.application().configuration().getConfig("queries").asMap();

private static Map<String, Object> languages = Play.application().configuration().getConfig("languages").asMap();

private final VocabProvider vocabProvider;

@Inject
Expand Down Expand Up @@ -96,7 +99,7 @@ public Result getVocabPage(String version, String language) throws IOException {
.absoluteURL(request())).concat(">; rel=derivedfrom"));
response().setHeader("Content-Language", locale.getLanguage());

return getPage(vocab, "vocab.hbs", locale.getLanguage(), null);
return getPage(vocab, "rightsstatements.github.io/en/statements/index.html", locale.getLanguage(), null);

}

Expand Down Expand Up @@ -151,7 +154,7 @@ public Result getStatementPage(String id, String version, String language) throw
.absoluteURL(request())).concat(">; rel=derivedfrom"));
response().setHeader("Content-Language", locale.getLanguage());

return getPage(rightsStatement, "statement.hbs", locale.getLanguage(), getParameters(request(), id));
return getPage(rightsStatement, "handlebars/statement.hbs", locale.getLanguage(), getParameters(request(), id));

}

Expand Down Expand Up @@ -187,7 +190,7 @@ public Result getCollectionData(String id, String version, String extension) {

public Result getCollectionPage(String id, String version, String language) throws IOException {

Model collection = getCollectionModel(id, version);
Model collection = getVocabModel(version);
Locale locale = getLocale(request(), language);

if (collection.isEmpty()) {
Expand All @@ -198,7 +201,8 @@ public Result getCollectionPage(String id, String version, String language) thro
.absoluteURL(request())).concat(">; rel=derivedfrom"));
response().setHeader("Content-Language", locale.getLanguage());

return getPage(collection, "collection.hbs", locale.getLanguage(), null);
return getPage(collection, "rightsstatements.github.io/en/statements/collection-".concat(id).concat(".html"),
locale.getLanguage(), null);

}

Expand Down Expand Up @@ -228,7 +232,7 @@ private Result getPage(Model model, String templateFile, String language, HashMa
scope.put("data", new ObjectMapper().readValue(boas.toString(), HashMap.class));

TemplateLoader loader = new ResourceTemplateLoader();
loader.setPrefix("public/handlebars");
loader.setPrefix("public");
loader.setSuffix("");
Handlebars handlebars = new Handlebars(loader);

Expand All @@ -239,12 +243,7 @@ private Result getPage(Model model, String templateFile, String language, HashMa
Logger.error(e.toString());
}

Template pageTemplate = handlebars.compile(templateFile);
Map<String, Object> main = new HashMap<>();
main.put("content", pageTemplate.apply(scope));
Template template = handlebars.compile("main.hbs");

return ok(template.apply(main)).as("text/html");
return ok(handlebars.compile(templateFile).apply(scope)).as("text/html");

}

Expand Down Expand Up @@ -326,31 +325,41 @@ private static MimeType getMimeTypeByExtension(@Nonnull String extension) {

private Locale getLocale(Http.Request request, String language) {

Locale[] requestedLocales;

if (language != null) {
return getLocaleByCode(language);
requestedLocales = getLocalesByCode(language);
} else {
return getLocaleFromRequest(request);
requestedLocales = getLocalesFromRequest(request);
}

}
String[] availableLocales = languages.get("available").toString().split(" +");

if (requestedLocales != null) {
for (Locale requestedLocale : requestedLocales) {
if (Arrays.asList(availableLocales).contains(requestedLocale.getLanguage())) {
return requestedLocale;
}
}
}

private Locale getLocaleFromRequest(Http.Request request) {
return new Locale(availableLocales[0]);

String code;
}

private Locale[] getLocalesFromRequest(Http.Request request) {

if (!request.acceptLanguages().isEmpty()) {
code = request.acceptLanguages().get(0).language();
} else {
code = defaults.get("language").toString();
return request.acceptLanguages().stream().map(lang -> new Locale(lang.language())).toArray(Locale[]::new);
}

return new Locale(code);
return null;

}

private Locale getLocaleByCode(String code) {
private Locale[] getLocalesByCode(String code) {

return new Locale(code);
return new Locale[]{new Locale(code)};

}

Expand Down
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ play.modules.enabled += "modules.VocabProviderModule"
vocab.provider = "services.GitVocabProvider"
source.git.remote = "https://github.com/rightsstatements/data-model.git"
source.git.local = "data-model"
default.language = "en"
default.mime = "application/json"
default.parser = "JSON-LD"
params.InC-OW-EU = "relatedURL"
Expand All @@ -21,3 +20,4 @@ queries.vocab = "CONSTRUCT WHERE {?s <http://www.w3.org/2002/07/owl#versionInfo>
queries.statement = "CONSTRUCT WHERE {?s <http://www.w3.org/2002/07/owl#versionInfo> \"%1$s\" . ?s <http://purl.org/dc/elements/1.1/identifier> \"%2$s\" . ?s ?p ?o}"
queries.collection = "CONSTRUCT WHERE {<http://rightsstatements.org/vocab/collection-%1$s/%2$s/> <http://www.w3.org/2002/07/owl#versionInfo> \"%2$s\" . <http://rightsstatements.org/vocab/collection-%1$s/%2$s/> ?p ?o }"
queries.localize = "CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o . FILTER(!isLiteral(?o) || lang(?o) = \"\" || langMatches(lang(?o), \"%1$s\" ))}"
languages.available = "en"
4 changes: 3 additions & 1 deletion conf/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ InC-OW-EU = More information about the Work may be found in the following entry
NoC-NC = The limitations on commercial use of this item will expire on {0}
NoC-CR = More information about the contractual restrictions can be found here: <a href="{0}" target="_blank">{0}</a>
NoC-OKLR = More information about the legal restrictions can be found here: <a href="{0}" target="_blank">{0}</a>
Disclaimer = The purpose of this statement is to help the public understand how this Item may be used. When there is a (non-standard) License or contract that governs re-use of the associated Item, this statement only summarizes the effects of some of its terms. It is not a License, and should not be used to license your Work. To license your own Work, use a License offered at <a href="http://creativecommons.org/">http://creativecommons.org/</a>
Disclaimer = DISCLAIMER The purpose of this statement is to help the public understand how this Item may be used. When there is a (non-standard) License or contract that governs re-use of the associated Item, this statement only summarizes the effects of some of its terms. It is not a License, and should not be used to license your Work. To license your own Work, use a License offered at <a href="http://creativecommons.org/">http://creativecommons.org/</a>
notices = Notices
provider = This statement is provided by <a href="http://rightsstatements.org">rightsstatements.org</a>
4 changes: 4 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ GET /data/:id/:version.:ext controllers.Application.getStatementDa
GET /page/:version/ controllers.Application.getVocabPage(version: String, language: String ?= null)
GET /page/collection-:id/:version/ controllers.Application.getCollectionPage(id: String, version: String, language: String ?= null)
GET /page/:id/:version/ controllers.Application.getStatementPage(id: String, version: String, language: String ?= null)

GET /css/*file controllers.Assets.at(path="/public/rightsstatements.github.io/css", file)
GET /js/*file controllers.Assets.at(path="/public/rightsstatements.github.io/js", file)
GET /files/*file controllers.Assets.at(path="/public/rightsstatements.github.io/files", file)
5 changes: 0 additions & 5 deletions public/handlebars/collection.hbs

This file was deleted.

19 changes: 0 additions & 19 deletions public/handlebars/main.hbs

This file was deleted.

76 changes: 65 additions & 11 deletions public/handlebars/statement.hbs
Original file line number Diff line number Diff line change
@@ -1,15 +1,69 @@
<script type="application/ld+json">
{{json data}}
</script>
<!doctype html>

{{> table.hbs data}}
<html class="no-js" lang="{{ language }}">

{{#parameters.date}}
<p>{{i18n data.identifier . locale=language}}</p>
{{/parameters.date}}
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rights Statements</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/foundation/6.2.0/foundation.min.css" />
<link rel="stylesheet" href="/css/stmt.css" />
<link rel="stylesheet" type="text/css" href="//cloud.typography.com/7018914/6677352/css/fonts.css" />
</head>

{{#parameters.relatedURL}}
<p>{{{i18n data.identifier . locale=language}}}</p>
{{/parameters.relatedURL}}
<body>

<p>{{{i18n "Disclaimer" locale=language}}}</p>
<script type="application/ld+json">
{{json data}}
</script>

<div class="row columns statement-container">
<div class="row statement-main">
<div class="large-4 columns">
<div class="statement-iconcolumn">
<img src="/files/icons/{{ data.identifier }}.white.svg" title="{{ data.prefLabel.[@value] }}" />
</div>
</div>
<div class="large-8 columns">
<div class="statement-textcolumn">
<h1>{{ data.prefLabel.[@value] }}</h1>
<p>{{ data.definition.[@value] }}</p>
<h2>{{i18n "notices" locale=language}}</h2>
<ul>
{{#data.note}}
<li><span>{{ [@value] }}</span></li>
{{/data.note}}
</ul>
<p class="disclaimer">{{{i18n "Disclaimer" locale=language}}}</p>
{{#parameters.date}}
<p>{{i18n data.identifier . locale=language}}</p>
{{/parameters.date}}

{{#parameters.relatedURL}}
<p>{{{i18n data.identifier . locale=language}}}</p>
{{/parameters.relatedURL}}
</div>
</div>
</div>

<div class="row footer">
<div class="large-9 columns">
{{{ i18n "provider" locale=language }}}
</div>
<div class="large-3 columns">
<img src="/files/images/logo.svg" />
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/what-input/2.0.1/what-input.min.js"></script>
<script src="https://cdn.jsdelivr.net/foundation/6.2.0/foundation.min.js"></script>
<script>
$(document).foundation();
</script>

</body>

</html>
102 changes: 0 additions & 102 deletions public/handlebars/table.hbs

This file was deleted.

7 changes: 0 additions & 7 deletions public/handlebars/vocab.hbs

This file was deleted.

10 changes: 10 additions & 0 deletions public/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ Handlebars.registerHelper('json', function (obj, options) {
Handlebars.registerHelper('a', function (href, options) {
return new Handlebars.SafeString("<a href=\"" + href + "\">" + href + "</a>");
});

Handlebars.registerHelper('id', function(id, graph, options) {

for (var i = 0; i < graph.length; i++) {
if (graph[i]['@id'].trim() == id.trim()) {
return options.fn(graph[i]);
}
}

});
1 change: 1 addition & 0 deletions public/rightsstatements.github.io
Loading

0 comments on commit 45acbc8

Please sign in to comment.