0.0.6 • Published 8 years ago

ember-ipsum v0.0.6

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

Creating and Implementing a Simple Addon with ember-cli

This tutorial is designed for those of us who want a very simple introduction into the world of creating addons for Ember. It assumes you already have a basic undersanding of Ember and components, but aren't sure how addons are created. We'll focus less on creating an addon that serves much purpose and more on making your addon available, how to install it, and how to implement it into applications.

Getting started

Personally, in my development folder I've created a folder designated for Ember addons called ember-addons. Navigate to the folder you would like to create addons in. 1. ember addon ember-ipsum (creates an addon and a folder of the same name: ember-ipsum) 2. cd ember-ipsum 3. Now open the addon/director with your editor of choice (sublime, atom, webstrom, etc.) 4. Navigate to package.json and move ember-cli-htmlbars from devDependencies object into the dependencies object. If you forget to do this, you'll get an error message when you try to serve the dummy application that looks something like this:

Addon templates were detected, but there are no template compilers registered for <addon-folder-name>. Please make sure your template precompiler (commonly 'ember-cli-htmlbars') is listed in 'dependencies' (NOT 'devDependencies') in <addon-folder-name>'s 'package.json'.

Creating a Component in your Addon

Type ember g component ember-ipsum in your terminal. This is going to create 4 files:
addon\components\ember-ipsum.js
addon\templates\components\ember-ipsum.hbs
app\components\ember-ipsum.js tests\integrations\components\ember-ipsum-test.js (I'm not going to cover this, but you should be aware of it.)

  1. Open addon\components\ember-ipsum.js and overwrite it's contents with:
import Ember from 'ember';
import layout from '../templates/components/ember-ipsum';

export default Ember.Component.extend({
  layout,
  paragraph: "Data down actions up. Tomster. Routable component. Controllers are dead. No wait not yet. Ember install all the things. That's a " +
"load of HBS. I'm going to go data down and take a RESTAdapter. I have no point of view. Nested routes. Resource is no more. Controllers are " +
"singletons. What's a singleton? JSONAPIAdapter. this.set('yourComputer', 'onfire'). I think we've been setupController. Your navbar needs a " +
"hamburger-helper. Star Trek's Data vs ember-data. ember generate model role. this.store.peekRecord('aboo'). Serialize. Hash. Rinse. Repeat."
});
  1. Open addon\templates\components\ember-ipsum.hbs and overwrite it's content with:
<p>
  {{paragraph}}
</p>

{{yield}}
  1. Open app\components\ember-ipsum.js to see what it's doing. It should only contain one line of code that actually does the leg-work to get the addon to communicate whatever application it's installed into.
export { default } from 'ember-ipsum/components/ember-ipsum';

Test the Addon

Ember-cli is kind enough to generate a dummy folder for you to test your addon in. This folder acts as a separate application for you to pretend you've just installed the addon and want to use it.

  1. Open tests/dummy/app/templates/application.hbs. Add {{ember-ipsum}} to the code:
<h2 id="title">Welcome to Ember</h2>
{{ember-ipsum}}
{{outlet}}
  1. In the terminal, run ember s. Open your browser, navigate http://localhost:4200, and enjoy!

Setting up NPM

  1. If you don't already have a profile with npm, create one at https://www.npmjs.com/signup.
  2. Go to your terminal, type npm adduser and follow the prompts. It will ask you enter your username, password, and email associated with your npm profile.

Publishing to npm and github

Now you want to make your addon public. Just run the commands below in your terminal:

 npm version 0.0.1
 git push origin <branch-name>
 git push origin --tags
 npm publish

Follow the same steps everytime you make changes that you want available for the addon on npm. Just increment the version number appropriately major.minor.patch

Installing your addon to another project

Now you can open or create an Ember project and install your addon. In this example, you could run npm install ember-ipsum --save-dev. Then, you could add the ipsum text to any template you want simply by putting {{ember-ipsum}} wherever you want the text to appear.

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago