Skip to content

Commit

Permalink
[framework] add ember support
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcsapo committed Oct 1, 2018
1 parent 621a4ed commit afea517
Show file tree
Hide file tree
Showing 79 changed files with 3,140 additions and 2,908 deletions.
13 changes: 12 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ aliases:
- &defaults
working_directory: /tmp/storybook
docker:
- image: circleci/node:8
- image: circleci/node:8.12.0

dependencies:
pre:
Expand Down Expand Up @@ -37,6 +37,7 @@ jobs:
paths:
- node_modules
- examples/angular-cli/node_modules
- examples/ember-cli/node_modules
- examples/cra-kitchen-sink/node_modules
- examples/mithril-kitchen-sink/node_modules
- examples/official-storybook/node_modules
Expand Down Expand Up @@ -78,6 +79,11 @@ jobs:
command: |
cd examples/angular-cli
yarn build-storybook
- run:
name: Build ember-cli
command: |
cd examples/ember-cli
yarn build-storybook
- run:
name: Build polymer-cli
command: |
Expand Down Expand Up @@ -140,6 +146,11 @@ jobs:
command: |
cd examples/angular-cli
yarn storybook --smoke-test
- run:
name: Run ember-cli (smoke test)
command: |
cd examples/ember-cli
yarn storybook --smoke-test
- run:
name: Run polymer-cli (smoke test)
command: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum class StorybookApp(val appName: String, val exampleDir: String, val merged:
SVELTE("Svelte", "svelte-kitchen-sink"),
RIOT("Riot", "riot-kitchen-sink"),
HYPERAPP("Hyperapp", "hyperapp-kitchen-sink", false),
EMBER("Ember", "ember-cli", false);
EMBER("Ember", "ember-cli");

val lowerName = appName.toLowerCase()

Expand Down
34 changes: 17 additions & 17 deletions ADDONS_SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
## Addon / Framework Support Table

| | [React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [HTML](app/html)| [Marko](app/marko)| [Svelte](app/svelte)| [Riot](app/riot)|
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|
|[a11y](addons/a11y) |+| |+|+|+|+|+|+| | |
|[actions](addons/actions) |+|+|+|+|+|+|+|+|+|+|
|[backgrounds](addons/backgrounds) |+| |+|+|+|+|+|+|+|+|
|[centered](addons/centered) |+| |+|+| |+|+| |+| |
|[events](addons/events) |+| |+|+|+|+|+|+| | |
|[graphql](addons/graphql) |+| | | | | | | | | |
|[info](addons/info) |+| | | | | | | | | |
|[jest](addons/jest) |+| | |+| | |+| | | |
|[knobs](addons/knobs) |+|+|+|+|+|+|+|+|+|+|
|[links](addons/links) |+|+|+|+|+|+|+| |+|+|
|[notes](addons/notes) |+| |+|+|+|+|+| |+|+|
|[options](addons/options) |+|+|+|+|+|+|+| |+|+|
|[storyshots](addons/storyshots) |+|+|+|+| | |+| |+|+|
|[storysource](addons/storysource)|+| |+|+|+|+|+|+|+|+|
|[viewport](addons/viewport) |+| |+|+|+|+|+|+|+|+|
| | [React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [HTML](app/html)| [Marko](app/marko)| [Svelte](app/svelte)| [Riot](app/riot)| [Ember](app/ember)|
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|
|[a11y](addons/a11y) |+| |+|+|+|+|+|+| | |+|
|[actions](addons/actions) |+|+|+|+|+|+|+|+|+|+|+|
|[backgrounds](addons/backgrounds)|+| |+|+|+|+|+|+|+|+|+|
|[centered](addons/centered) |+| |+|+| |+|+| |+| |+|
|[events](addons/events) |+| |+|+|+|+|+|+| | |+|
|[graphql](addons/graphql) |+| | | | | | | | | | |
|[info](addons/info) |+| | | | | | | | | | |
|[jest](addons/jest) |+| | |+| | |+| | | | |
|[knobs](addons/knobs) |+|+|+|+|+|+|+|+|+|+|+|
|[links](addons/links) |+|+|+|+|+|+|+| |+|+|+|
|[notes](addons/notes) |+| |+|+|+|+|+| |+|+|+|
|[options](addons/options) |+|+|+|+|+|+|+| |+|+|+|
|[storyshots](addons/storyshots) |+|+|+|+| | |+| |+|+| |
|[storysource](addons/storysource)|+| |+|+|+|+|+|+|+|+|+|
|[viewport](addons/viewport) |+| |+|+|+|+|+|+|+|+|+|
1 change: 1 addition & 0 deletions addons/centered/ember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/ember');
25 changes: 25 additions & 0 deletions addons/centered/src/ember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { document } from 'global';
import styles from './styles';

export default function(storyFn) {
const { template, context } = storyFn();

const element = document.createElement('div');
Object.assign(element.style, styles.style);

const innerElement = document.createElement('div');
Object.assign(innerElement.style, styles.innerStyle);

element.appendChild(innerElement);

// the inner element should append the parent
innerElement.appendTo = function appendTo(el) {
el.appendChild(element);
};

return {
template,
context,
element: innerElement,
};
}
30 changes: 30 additions & 0 deletions app/ember/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Storybook for Ember

Storybook for Ember is a UI development environment for your Ember components.
With it, you can visualize different states of your UI components and develop them interactively.

![Storybook Screenshot](https://github.com/storybooks/storybook/blob/master/media/storybook-intro.gif)

Storybook runs outside of your app.
So you can develop UI components in isolation without worrying about app specific dependencies and requirements.

## Getting Started

```sh
npm i -g @storybook/cli
cd my-ember-app
storybook init
```

For more information visit: [storybook.js.org](https://storybook.js.org)

* * *

Storybook also comes with a lot of [addons](https://storybook.js.org/addons/introduction) and a great API to customize as you wish.
You can also build a [static version](https://storybook.js.org/basics/exporting-storybook) of your storybook and deploy it anywhere you want.

## Docs

- [Basics](https://storybook.js.org/basics/introduction)
- [Configurations](https://storybook.js.org/configurations/default-config)
- [Addons](https://storybook.js.org/addons/introduction)
4 changes: 4 additions & 0 deletions app/ember/bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

process.env.NODE_ENV = process.env.NODE_ENV || 'production';
require('../dist/server/build');
3 changes: 3 additions & 0 deletions app/ember/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/server');
37 changes: 37 additions & 0 deletions app/ember/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@storybook/ember",
"version": "4.0.0-alpha.23",
"description": "Storybook for Ember: Develop Ember Component in isolation with Hot Reloading.",
"homepage": "https://github.com/storybooks/storybook/tree/master/app/ember",
"bugs": {
"url": "https://github.com/storybooks/storybook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybooks/storybook.git"
},
"license": "MIT",
"main": "dist/client/index.js",
"jsnext:main": "src/client/index.js",
"bin": {
"build-storybook": "./bin/build.js",
"start-storybook": "./bin/index.js",
"storybook-server": "./bin/index.js"
},
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"@ember/test-helpers": "^0.7.25",
"@storybook/core": "4.0.0-alpha.23",
"global": "^4.3.2"
},
"peerDependencies": {
"babel-plugin-ember-modules-api-polyfill": "^2.4.0",
"babel-loader": "^7.0.0 || ^8.0.0",
"common-tags": "^1.8.0",
"ember-cli-htmlbars-inline-precompile": "^1.0.3",
"ember-source": "^3.4.0"
}
}
9 changes: 9 additions & 0 deletions app/ember/src/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export {
storiesOf,
setAddon,
addDecorator,
addParameters,
configure,
getStorybook,
forceReRender,
} from './preview';
4 changes: 4 additions & 0 deletions app/ember/src/client/preview/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { window } from 'global';

window.STORYBOOK_NAME = process.env.STORYBOOK_NAME;
window.STORYBOOK_ENV = 'ember';
18 changes: 18 additions & 0 deletions app/ember/src/client/preview/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { start } from '@storybook/core/client';

import './globals';
import render from './render';

const { clientApi, configApi, forceReRender } = start(render);

export const {
storiesOf,
setAddon,
addDecorator,
addParameters,
clearDecorators,
getStorybook,
} = clientApi;

export const { configure } = configApi;
export { forceReRender };
71 changes: 71 additions & 0 deletions app/ember/src/client/preview/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* eslint-disable no-undef */
import { window, document } from 'global';
import { stripIndents } from 'common-tags';

const rootEl = document.getElementById('root');

const config = window.require(`${window.STORYBOOK_NAME}/config/environment`);
const app = window.require(`${window.STORYBOOK_NAME}/app`).default.create({
autoboot: false,
rootElement: rootEl,
...config.APP,
});

let lastPromise = app.boot();
let hasRendered = false;

function render(options, el) {
const { template, context = {}, element } = options;

if (hasRendered) {
lastPromise = lastPromise.then(instance => instance.destroy());
}

lastPromise = lastPromise
.then(() => {
const appInstancePrivate = app.buildInstance();
return appInstancePrivate.boot().then(() => appInstancePrivate);
})
.then(instance => {
instance.register(
'component:story-mode',
Ember.Component.extend({
layout: template || options,
...context,
})
);

const component = instance.lookup('component:story-mode');

if (element) {
component.appendTo(element);

element.appendTo(el);
} else {
component.appendTo(el);
}
hasRendered = true;

return instance;
});
}

export default function renderMain({ story, selectedKind, selectedStory, showMain, showError }) {
const element = story();

if (!element) {
showError({
title: `Expecting a Ember element from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Did you forget to return the Ember element from the story?
Use "() => hbs('{{component}}')" or "() => { return {
template: hbs\`{{component}}\`
} }" when defining the story.
`,
});
return;
}

showMain();
render(element, rootEl);
}
4 changes: 4 additions & 0 deletions app/ember/src/server/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { buildStatic } from '@storybook/core/server';
import options from './options';

buildStatic(options);
15 changes: 15 additions & 0 deletions app/ember/src/server/framework-preset-babel-ember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { precompile } from 'ember-source/dist/ember-template-compiler';

export function babel(config) {
const babelConfigPlugins = config.plugins || [];

const extraPlugins = [
[require.resolve('babel-plugin-htmlbars-inline-precompile'), { precompile }],
[require.resolve('babel-plugin-ember-modules-api-polyfill')],
];

return {
...config,
plugins: [].concat(babelConfigPlugins, extraPlugins),
};
}
5 changes: 5 additions & 0 deletions app/ember/src/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { buildDev } from '@storybook/core/server';

import options from './options';

buildDev(options);
7 changes: 7 additions & 0 deletions app/ember/src/server/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import packageJson from '../../package.json';

export default {
packageJson,
defaultConfigName: 'ember-cli',
frameworkPresets: [require.resolve('./framework-preset-babel-ember.js')],
};
6 changes: 3 additions & 3 deletions docs/src/pages/testing/automated-visual-testing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ Here's a sample Storybook we'd like to visually test:

The Storybook UI has a bunch of elements you wouldn't want to include in your visual test. Besides being extraneous, your tests could incorrectly fail when you add a new, unrelated story or state because it would show up in the side menu.

Instead, we'll want to render a component's story by itself. Let's assume the above Storybook runs on port 9009 and we can access it via http://localhost:9009/.
Instead, we'll want to render a component's story by itself. Let's assume the above Storybook runs on port 9009 and we can access it via [http://localhost:9009/](http://localhost:9009/).

Now let's pick a single story: the "with text" story of the Button.

The URL for that story contains a number of query parameters, but the first two are the most important: http://localhost:9009/?selectedKind=Button&selectedStory=with+text
The URL for that story contains a number of query parameters, but the first two are the most important: [http://localhost:9009/?selectedKind=Button&selectedStory=with+text](http://localhost:9009/?selectedKind=Button&selectedStory=with+text)

- selectedKind=Button
- selectedStory=with+text

Using these two parameters we can generate the URL to render the story by itself. Instead of the URL's path being the homepage/index we use `/iframe.html`:

http://localhost:9009/iframe.html?selectedKind=Button&selectedStory=with+text
[http://localhost:9009/iframe.html?selectedKind=Button&selectedStory=with+text](http://localhost:9009/iframe.html?selectedKind=Button&selectedStory=with+text)

![Storybook iframe Screenshot](../static/storybook-iframe-screenshot.png)

Expand Down
9 changes: 9 additions & 0 deletions examples/ember-cli/.ember-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
}
2 changes: 2 additions & 0 deletions examples/ember-cli/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
STORYBOOK_EXAMPLE_APP=true
STORYBOOK_NAME=ember-example
14 changes: 14 additions & 0 deletions examples/ember-cli/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
rules: {
'import/extensions': 0,
},
settings: {
'import/core-modules': [
'@ember/component',
'@ember/routing/router',
'@ember/application',
'./config/environment',
'htmlbars-inline-precompile',
],
},
};
15 changes: 15 additions & 0 deletions examples/ember-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
build

# misc
.DS_Store
npm-debug.log
tmp

0 comments on commit afea517

Please sign in to comment.