Giter Site home page Giter Site logo

fishbars's Introduction

Build Status Coverage Status

fishbars

Helpers for Handlebars templates used at FishBrain

Installation

npm install fishbars

Getting started

var handlebars = require("handlebars");
var fishbars = require("fishbars");

fishbars.registerHelpers(handlebars, {
  language: 'sv'
});

var template = handlebars.compile("{{translate greeting}} {{name}}");
var result = template({ name: 'jakob', greeting: { sv: 'hej', en: 'hi' } });

console.log(result); // hej jakob

Features

There is one function independent of user settings:

image

It take three arguments; a comparison operator, a size and an array of photos. It then returns the photo that satisfy the given given comparions. If more than one does, it selects the one that is closest to the requirement.

var template = handlebars.compile("{{image '>=' '64x64' photos }}");
var result = template({
    photos: photos: [{
        url: "file1.png",
        size: "140x140"
    }, {
        url: "file2.png",
        size: "600x600"
    }]
});

console.log(result); // file1.png

There are also five functions depending on user settings:

translate
weight
length
temperature
speed

Translate is used as in the "getting started"-example above. Given a string as language in registerHelpers, that key is looked up when translate is called on an object in the template. You can use any language code you want; to the function it's just a key in a lookup.

The remaining four functions are used to convert a number (given in SI-units) to a string representation in the configured unit, including the unit abbreviation. For example, getting my length in feet would go like this:

var handlebars = require("handlebars");
var fishbars = require("fishbars");

fishbars.registerHelpers(handlebars, {
  units: {
    weight: 'lb'
  }
});

var template = handlebars.compile("{{name}} is {{length myLength}} tall");
var result = template({ name: 'jakob', myLength: 1.81 }); // note that length is given in meters

console.log(result); // Jakob is 5.94 ft tall

The full configuration would look like this:

fishbars.registerHelpers(handlebars, {
  language: 'sv',
  units: {
    weight: 'kg',     // or 'lb'
    length: 'm',      // or 'ft'
    temperature: 'C', // or 'F'
    speed: 'm/s'      // or 'km/h' or 'mph' or 'kn'
  }
});

Developing

Make sure you have node installed. Running node -v should give you v0.10.29 or above.

Run npm install to install the dependencies of the project.

Run npm test to run all the tests. It will also show you the test coverage on completion.

You can run a subset of the tests using TESTS="some pattern" npm test, where the pattern is matched to the names of the tests.

In order to release a new version of the library, run make release VERSION=x.x.x. Your package file, git tags, coveralls and the global npm repository will all automatically be updated (but only if the tests pass, your working tree is clean and if you're on the right branch - master of course).

fishbars's People

Contributors

jakobmattsson avatar resadzacina avatar johanlunds avatar

Stargazers

Pete Richardson avatar  avatar Emil Bogren avatar Boris Serdiuk avatar

Watchers

Albert Hafvenström avatar  avatar Shafiq avatar Brian Underwood avatar Ben Counsell avatar Petteri Hyttinen avatar Pang Kien avatar Tim Sneed avatar James Cloos avatar Alexander Cederblad avatar Mattias Lundell avatar Hossam Ghareeb avatar Chris Nordqvist avatar Joe Elliott avatar  avatar Klas Eskilson avatar Ariel Ekgren avatar Pedro avatar Nan avatar Joakim avatar Konstantin Zyrianov avatar Piotr Bernad avatar Luke Hansford avatar Victor avatar Tudor Maxim avatar Pontus Niltoft avatar Lovis Dahl avatar Gayan Charith Witharana avatar Mateusz Zagórski avatar Robert Malmling avatar Cynthia Palma avatar Lisa Kennelly avatar Cẩm Huỳnh avatar Josef Lindman Hörnlund avatar  avatar Monika avatar Dimitris Lachanas avatar Kasia Bernad avatar Anton Westman avatar Nikita Evdokimov avatar Hassan Nazar avatar Felipe Ribeiro R. Magalhães avatar Sara Edin avatar Adrian Orłów avatar Johan Sundgren avatar  avatar Maryam Mohammadi avatar  avatar Olaf Bergmann avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.