ember-ipsum
v0.0.6
Published
The default blueprint for ember-cli addons.
Downloads
1
Readme
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.
ember addon ember-ipsum
(creates an addon and a folder of the same name: ember-ipsum)cd ember-ipsum
- Now open the addon/director with your editor of choice (sublime, atom, webstrom, etc.)
- Navigate to
package.json
and moveember-cli-htmlbars
fromdevDependencies
object into thedependencies
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.)
- 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."
});
- Open addon\templates\components\ember-ipsum.hbs and overwrite it's content with:
<p>
{{paragraph}}
</p>
{{yield}}
- 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.
- Open
tests/dummy/app/templates/application.hbs
. Add{{ember-ipsum}}
to the code:
<h2 id="title">Welcome to Ember</h2>
{{ember-ipsum}}
{{outlet}}
- In the terminal, run
ember s
. Open your browser, navigate http://localhost:4200, and enjoy!
Setting up NPM
- If you don't already have a profile with npm, create one at https://www.npmjs.com/signup.
- 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.