Coder Social home page Coder Social logo

swr / ember-cli-server-variables Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blimmer/ember-cli-server-variables

0.0 1.0 0.0 97 KB

Insert meta tag server variables into ember-cli built Ember applications

License: MIT License

JavaScript 83.48% HTML 16.08% Handlebars 0.44%

ember-cli-server-variables's Introduction

ember-cli-server-variables Build Status Ember Observer Score Code Climate

An Ember CLI add-on to support adding variables to the generated index.html file's head tag.

<html>
  <head>
    <meta name='your-app-token' content='example:app:token'>
    <meta name='your-app-user-location' content='Denver'>
  </head>
</html>

This is handy when you need to dynamically insert variables from your application server, such as a session application token to communicate with your API or a user's location based on their request IP address.

You can modify the blank content tags on your generated index.html file using a library like Cheerio. Eventually, with "configuration-only" deployments and ember-cli-deploy, Cheerio will be unnecessary because you can construct the entire index.html file on your application server.

Usage

You need to install and configure this add-on for it to work properly.

Installation

In your CLI project, run

ember install ember-cli-server-variables

Configuration

First, you need to modify your index.html file to have a {{content-for 'server-variables'}} block. Here's an example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Dummy</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {{content-for 'head'}}

    <link rel="stylesheet" href="assets/vendor.css">
    <link rel="stylesheet" href="assets/dummy.css">

    {{content-for 'server-variables'}}

    {{content-for 'head-footer'}}
  </head>
  <body>
    {{content-for 'body'}}

    <script src="assets/vendor.js"></script>
    <script src="assets/dummy.js"></script>

    {{content-for 'body-footer'}}
  </body>
</html>

Next, modify your environment.js file. Convention is to use dasherized names.

Configuration Variables:

  • vars (required): An array of your server variables.
  • tagPrefix: a prefix to append to every meta tag to avoid collision. Defaults to ENV.modulePrefix.
  • defaults: a POJO of default values for your server variables.

an array that describes the variables you want inserted. If you don't provide defaults, the fallback is a blank string. Most of the time you'll probably want to only provide defaults in development mode.

module.exports = function(environment) {
  var ENV = {
    serverVariables: {
      tagPrefix: 'your-app',
      vars: ['app-token', 'user-location', 'key']
    }
  }

  ...

  if (environment === 'development') {
    ENV.serverVariables.defaults = {
      'app-token': 'dev-app-token',
      'user-location': 'Denver'
    }
  }
}

Usage

This plugin provides a service to retrieve the server variables in your Ember app. You can use it like this:

MyController = Ember.Controller.extend({
  serverVariablesService: Ember.inject.service('serverVariables'),

  userLocation: Ember.computed.reads('serverVariablesService.userLocation')
});

Development

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

ember-cli-server-variables's People

Contributors

blimmer avatar zeppelin avatar

Watchers

 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.