Skip to content

Commit

Permalink
moved getLabel and getDefaultLabel to ManifestResource
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Sep 20, 2018
1 parent 67da0d4 commit d8dc48e
Show file tree
Hide file tree
Showing 10 changed files with 645 additions and 54 deletions.
19 changes: 8 additions & 11 deletions dist/client/manifesto.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,14 @@ var Manifesto;
return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type')));
};
ManifestResource.prototype.getLabel = function () {
return Manifesto.LanguageMap.parse(this.getProperty('label'), this.options.locale);
var label = this.getProperty('label');
if (label) {
return Manifesto.LanguageMap.parse(label, this.options.locale);
}
return [];
};
ManifestResource.prototype.getDefaultLabel = function () {
return Manifesto.LanguageMap.getValue(this.getLabel());
};
ManifestResource.prototype.getMetadata = function () {
var _metadata = this.getProperty('metadata');
Expand Down Expand Up @@ -1199,16 +1206,6 @@ var Manifesto;
IIIFResource.prototype.getSeeAlso = function () {
return this.getProperty('seeAlso');
};
IIIFResource.prototype.getLabel = function () {
var label = this.getProperty('label');
if (label) {
return Manifesto.LanguageMap.parse(label, this.options.locale);
}
return [];
};
IIIFResource.prototype.getDefaultLabel = function () {
return Manifesto.LanguageMap.getValue(this.getLabel());
};
IIIFResource.prototype.getDefaultTree = function () {
this.defaultTree = new Manifesto.TreeNode('root');
this.defaultTree.data = this;
Expand Down
21 changes: 9 additions & 12 deletions dist/client/manifesto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// manifesto v3.0.4 https://github.com/iiif-commons/manifesto
// manifesto v3.0.5 https://github.com/iiif-commons/manifesto
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.manifesto = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function (global){

Expand Down Expand Up @@ -693,7 +693,14 @@ var Manifesto;
return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type')));
};
ManifestResource.prototype.getLabel = function () {
return Manifesto.LanguageMap.parse(this.getProperty('label'), this.options.locale);
var label = this.getProperty('label');
if (label) {
return Manifesto.LanguageMap.parse(label, this.options.locale);
}
return [];
};
ManifestResource.prototype.getDefaultLabel = function () {
return Manifesto.LanguageMap.getValue(this.getLabel());
};
ManifestResource.prototype.getMetadata = function () {
var _metadata = this.getProperty('metadata');
Expand Down Expand Up @@ -1127,16 +1134,6 @@ var Manifesto;
IIIFResource.prototype.getSeeAlso = function () {
return this.getProperty('seeAlso');
};
IIIFResource.prototype.getLabel = function () {
var label = this.getProperty('label');
if (label) {
return Manifesto.LanguageMap.parse(label, this.options.locale);
}
return [];
};
IIIFResource.prototype.getDefaultLabel = function () {
return Manifesto.LanguageMap.getValue(this.getLabel());
};
IIIFResource.prototype.getDefaultTree = function () {
this.defaultTree = new Manifesto.TreeNode('root');
this.defaultTree.data = this;
Expand Down
5 changes: 2 additions & 3 deletions dist/manifesto.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// manifesto v3.0.4 https://github.com/iiif-commons/manifesto
// manifesto v3.0.5 https://github.com/iiif-commons/manifesto

declare namespace Manifesto {
class StringValue {
Expand Down Expand Up @@ -262,6 +262,7 @@ declare namespace Manifesto {
constructor(jsonld: any, options?: IManifestoOptions);
getIIIFResourceType(): IIIFResourceType;
getLabel(): LanguageMap;
getDefaultLabel(): string | null;
getMetadata(): LabelValuePair[];
getRendering(format: RenderingFormat | string): IRendering | null;
getRenderings(): IRendering[];
Expand Down Expand Up @@ -323,8 +324,6 @@ declare namespace Manifesto {
getNavDate(): Date;
getRelated(): any;
getSeeAlso(): any;
getLabel(): LanguageMap;
getDefaultLabel(): string | null;
getDefaultTree(): ITreeNode;
getRequiredStatement(): LabelValuePair | null;
isCollection(): boolean;
Expand Down
21 changes: 9 additions & 12 deletions dist/server/manifesto.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "manifesto.js",
"version": "3.0.4",
"version": "3.0.5",
"description": "IIIF Presentation API utility library for client and server",
"main": "./dist/server/manifesto.js",
"types": "./dist/manifesto.d.ts",
Expand Down
14 changes: 0 additions & 14 deletions src/IIIFResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ namespace Manifesto {
return this.getProperty('seeAlso');
}

getLabel(): LanguageMap {
const label: any = this.getProperty('label');

if (label) {
return LanguageMap.parse(label, this.options.locale);
}

return [];
}

getDefaultLabel(): string | null {
return Manifesto.LanguageMap.getValue(this.getLabel());
}

getDefaultTree(): ITreeNode{
this.defaultTree = new TreeNode('root');
this.defaultTree.data = this;
Expand Down
12 changes: 11 additions & 1 deletion src/ManifestResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ namespace Manifesto {
}

getLabel(): LanguageMap {
return LanguageMap.parse(this.getProperty('label'), this.options.locale);
const label: any = this.getProperty('label');

if (label) {
return LanguageMap.parse(label, this.options.locale);
}

return [];
}

getDefaultLabel(): string | null {
return Manifesto.LanguageMap.getValue(this.getLabel());
}

getMetadata(): LabelValuePair[] {
Expand Down
58 changes: 58 additions & 0 deletions test/default-label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var expect = require('chai').expect;
var manifesto = require('../dist/server/manifesto');
var should = require('chai').should();
var manifests = require('./fixtures/manifests');
require('./shared');

var manifest, sequence, canvas, content, annotation, body, label;

describe('#getDefaultLabel', function() {

it('loads successfully', function (done) {
manifesto.loadManifest(manifests.defaultlabel).then(function(data) {
manifest = manifesto.create(data);
done();
});
});

it('has a sequence', function() {
sequence = manifest.getSequenceByIndex(0);
expect(sequence).to.exist;
});

it('has a canvas', function() {
canvas = sequence.getCanvases()[0];
expect(canvas).to.exist;
});

it('has a canvas label', function() {
label = canvas.getLabel();
var labelValue = Manifesto.LanguageMap.getValue(label);
expect(labelValue).to.equal('Abyssinian');
});

it('has a canvas default label', function() {
label = canvas.getDefaultLabel();
expect(label).to.equal('Abyssinian');
});

it('has an annotation body', function() {
content = canvas.getContent();
annotation = content[0];
expect(annotation).to.exist;
body = annotation.getBody()[0];
expect(body).to.exist;
});

it('has an annotation label', function() {
label = body.getLabel();
var labelValue = Manifesto.LanguageMap.getValue(label);
expect(labelValue).to.equal('Abyssinian');
});

it('has a annotation default label', function() {
label = body.getDefaultLabel();
expect(label).to.equal('Abyssinian');
});

});
Loading

0 comments on commit d8dc48e

Please sign in to comment.