npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-metis

v0.10.0

Published

Default subject pages for your Linked Data resources.

Downloads

64

Readme

ember-metis

Ember addon providing default subject pages for your Linked Data resources. The default subject page lists all incoming and outgoing relations of a resource. The addon allows to override subject pagess per resource types with a custom template.

Getting started

Adding ember-metis to your application

Setup the backend

ember-metis assumes a mu.semte.ch stack is used in the backend. The addon requires the following services to be available:

  • uri-info: Microservice listing all incoming and outgoing relations for a given subject URI
  • resource-labels: Microservice providing a human-readable label for a URI
  • resource-labels-cache: Cache for the resource-labels service

Add the following snippet to the docker-compose.yml file of your backend stack:

services:
  uri-info:
    image: redpencil/mu-uri-info-service:0.2.1
  resource-labels-cache:
    image: semtech/mu-cache:2.0.2
    links:
      - resource-labels:backend
  resource-labels:
    image: lblod/resource-label-service:0.3.2

The uri-info and resource-labels services assume the triplestore is available as database in your stack. If not, provide the appropriate docker alias to the service in the docker-compose.yml.

Next, make the service endpoints available in ./config/dispatcher/dispatcher.ex:

  define_accept_types [
    json: [ "application/json", "application/vnd.api+json" ]
  ]

  get "/uri-info/*path", %{ accept: %{ json: true } } do
    forward conn, path, "http://uri-info/"
  end

  get "/resource-labels/*path", %{ accept: %{ json: true } } do
    forward conn, path, "http://resource-labels-cache/"
  end

Setup the frontend

ember-metis requires Ember FastBoot. Install the addon in your application if it's not yet available:

ember install ember-cli-fastboot

For local development using ember serve ember-metis requires BACKEND_URL as a sandbox global when running in fastboot mode. The value of BACKEND_URL must be the same URL you pass as proxy URL in ember serve --proxy. Typically http://localhost/ (or http://host when serving the frontend from a Docker container using eds).

To define the sandbox global, add the follow content to ./config/fastboot.js in your frontend application:

module.exports = function(environment) {
  return {
    buildSandboxGlobals(defaultGlobals) {
      return Object.assign({}, defaultGlobals, {
        BACKEND_URL: 'http://localhost',
      });
    },
  };
};

Setup Appuniversum

ember-metis depends on components from the ember-appuniversum addon. Follow the getting started guide to set that up first.

Install ember-metis

Install the ember-metis addon in your application.

npm install -D ember-metis

Add the following configuration to ./config/environment.js:

let ENV = {
  metis: {
    baseUrl: "http://data.lblod.info/"
  },
  ...

The baseUrl specifies the domain you want to serve subject pages for. I.e. the base URL of your production environment.

Finally, import and add the fallbackRoute util to your router.js

import { fallbackRoute, externalRoute } from 'ember-metis';

Router.map(function() {
  // ... other routes here

  externalRoute(this);
  fallbackRoute(this);
});

Since fallbackRoute matches all paths, it's best to put the route at the bottom of your routes list.

How-to guides

Upgrade from 0.9.0

Since 0.10.0 there is a externalRoute which must also be exposed in your router.js.

import { fallbackRoute, externalRoute } from 'ember-metis'; // <-- Add externalRoute import

Router.map(function() {
  // ... other routes here

  externalRoute(this); // <-- Add this line before fallbackRoute
  fallbackRoute(this);
});

Change the locale to nl-be

ember-metis uses ember-intl for internationalization. By default the locale is set to en-us unless otherwise configured in the host app. To configure the locale in your host app, add the following application instance initializer:

// app/instance-initializers/locale.js

export function initialize(appInstance) {
  // Set default locale for intl
  const intl = appInstance.lookup('service:intl');
  intl.setLocale(['nl-be']);
}

export default {
  initialize,
};

Provide human-readable labels for URIs on the subject page

Check the README of the resource label service how to insert human-readable labels in the triplestore. Once the labels are available, they will be automatically picked up by ember-metis.

Setup a custom template for a specific resource type

For some resources you may want to display a custom template instead of the default one provided by ember-metis. The addon supports custom templates per resource type. E.g. you can provide a custom template for all resources of type http://xmlns.com/foaf/0.1/Person.

Before you generate your first custom route/template, import the classRoute util in router.js and define a view route at the root level:

import EmberRouter from '@ember/routing/router';
import config from './config/environment';
import { classRoute, fallbackRoute, externalRoute } from 'ember-metis';   // <---- Edit this line

export default class Router extends EmberRouter {
  location = config.locationType;
  rootURL = config.rootURL;
}

Router.map(function() {
  // other routes
  this.route('view', function() { });  // <---- Add this line

  externalRoute(this);
  fallbackRoute(this);
});

Next, generate your custom route using the following generate command

ember generate rdf-route <route-name> --voc <rdf-type>

E.g. to generate a person route for all resources of type foaf:Person

ember generate rdf-route person --voc http://xmlns.com/foaf/0.1/Person

A person route, controller and template will be generated as subroute of view which you can implement as regular Ember routes to your needs. A new routing rule will also automatically be added to router.js.

Whenever the user navigates to a subject page of a resource of type foaf:Person, he will be redirected to the custom template instead of the default one.

Reference

Addon configuration

ember-metis can be configured in ./config/environment.js via the metis key:

let ENV = {
  metis: {
    // ember-metis configuration here
  },
  ...

The available options are described below.

Base URL (required)

The baseUrl specifies the domain you want to serve subject pages for. I.e. the base URL of your production environment. Based on this configuration, ember-metis ensures navigation through subject pages also works on other environments and on localhost during development.

E.g.

  metis: {
    baseUrl: "http://data.lblod.info/"
  }

Fallback template (optional)

Handlebars template to render the fallback page. Defaults to fallback as provided by the addon. Useful to customize the fallback page. The route and controller for the fallback page are provided by the addon, also when using a custom template.

E.g.

  metis: {
    fallbackTemplate: "my-custom/fallback"
  }

Pagination (optional)

By default ember-metis only shows the first 50 directed and inverse relations for a subject URI. The default page size for both directions can be configured via pageSize.

E.g.

  metis: {
    ...
    pageSize: {
      directed: 100,
      inverse: 50
    }
  }

Generators

rdf-route

Generate a custom route/controller/template per rdf:type using

ember generate rdf-route <route-name> --voc <rdf-type>

Similarly, remove the custom route/controller/template using

ember delete rdf-route <route-name>

Discussion

Why using a classRoute util for custom templates?

On generation of a custom rdf-route, a routing rule will be added to the router.js which makes use of the classRoute util.

E.g.

  this.route('view', function() {
    classRoute(this, 'person', {
      class: 'http://xmlns.com/foaf/0.1/Person'
    });
  });

The classRoute util is a wrapper around the regular this.route functionality used for regular routes. In addition to the regular behaviour, the classRoute util also ensures the route-name and rdf:Class combination gets registered. This registration is used to redirect the user to the appropriate custom route when navigating through the subject pages based on the subject's rdf:Class.