Skip to content

Commit

Permalink
initial iplementation
Browse files Browse the repository at this point in the history
  • Loading branch information
buschtoens committed Sep 13, 2019
1 parent 3c9596e commit 8bd6b36
Show file tree
Hide file tree
Showing 33 changed files with 689 additions and 233 deletions.
13 changes: 13 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 1
update_configs:
- package_manager: 'javascript'
directory: '/'
update_schedule: 'live'
version_requirement_updates: increase_versions
automerged_updates:
- match:
dependency_type: 'development'
update_type: 'all'
- match:
dependency_type: 'production'
update_type: 'all'
49 changes: 1 addition & 48 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,4 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
env: {
browser: true
},
rules: {
},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'index.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script'
},
env: {
browser: false,
node: true
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
extends: '@clark/node'
};
47 changes: 21 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
ember-service-helper
==============================================================================
# ember-service-helper

[Short description of the addon.]
[![Build Status](https://travis-ci.org/buschtoens/ember-service-helper.svg)](https://travis-ci.org/buschtoens/ember-service-helper)
[![npm version](https://badge.fury.io/js/ember-service-helper.svg)](http://badge.fury.io/js/ember-service-helper)
[![Download Total](https://img.shields.io/npm/dt/ember-service-helper.svg)](http://badge.fury.io/js/ember-service-helper)
[![Ember Observer Score](https://emberobserver.com/badges/ember-service-helper.svg)](https://emberobserver.com/addons/ember-service-helper)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![dependencies](https://img.shields.io/david/buschtoens/ember-service-helper.svg)](https://david-dm.org/buschtoens/ember-service-helper)
[![devDependencies](https://img.shields.io/david/dev/buschtoens/ember-service-helper.svg)](https://david-dm.org/buschtoens/ember-service-helper)

Simple template helper to inject services into templates.

Compatibility
------------------------------------------------------------------------------

* Ember.js v3.4 or above
* Ember CLI v2.13 or above
* Node.js v8 or above


Installation
------------------------------------------------------------------------------
## Installation

```
ember install ember-service-helper
```

## Usage

Usage
------------------------------------------------------------------------------

[Longer description of how to use the addon in apps.]


Contributing
------------------------------------------------------------------------------

See the [Contributing](CONTRIBUTING.md) guide for details.
Example using [`ember-responsive`](https://github.com/freshbooks/ember-responsive).

```hbs
{{#if (get (service "breakpoints") "isDesktop")}}
Desktop breakpoint
{{else}}
Mobile breakpoint
{{/if}}
```

License
------------------------------------------------------------------------------
## Related

This project is licensed under the [MIT License](LICENSE.md).
- [Pre-RFC 543: Ability to inject service into Template Only component](https://github.com/emberjs/rfcs/issues/543)
4 changes: 4 additions & 0 deletions addon/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@clark/ember'
};
12 changes: 12 additions & 0 deletions addon/helpers/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getOwner } from '@ember/application';
import Helper from '@ember/component/helper';
import { assert } from '@ember/debug';

export default class ServiceHelper extends Helper {
compute([serviceName]) {
const service = getOwner(this).lookup(`service:${serviceName}`);
assert(`The service '${serviceName}' does not exist`, service);

return service;
}
}
4 changes: 4 additions & 0 deletions app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@clark/ember'
};
Empty file removed app/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions app/helpers/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, service } from 'ember-service-helper/helpers/service';
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = function(/* environment, appConfig */) {
return { };
return {};
};
2 changes: 1 addition & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
const app = new EmberAddon(defaults, {
// Add options here
});

Expand Down
22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"name": "ember-service-helper",
"version": "0.0.0",
"description": "The default blueprint for ember-cli addons.",
"description": "Simple template helper to inject services into templates.",
"keywords": [
"ember-addon"
"ember-addon",
"helper",
"inject",
"service",
"template",
"only",
"component"
],
"repository": "",
"repository": "buschtoens/ember-service-helper",
"license": "MIT",
"author": "",
"author": "Jan Buschtöns <[email protected]> (https://jan.buschtoens.me)",
"directories": {
"doc": "doc",
"test": "tests"
Expand All @@ -24,16 +30,16 @@
"ember-cli-babel": "^7.7.3"
},
"devDependencies": {
"@clark/eslint-config-ember": "^1.14.1",
"@clark/eslint-config-node": "^1.14.1",
"@ember/optional-features": "^0.7.0",
"broccoli-asset-rev": "^3.0.0",
"ember-cli": "~3.12.0",
"ember-cli-dependency-checker": "^3.1.0",
"ember-cli-eslint": "^5.1.0",
"ember-cli-htmlbars": "^3.0.1",
"ember-cli-htmlbars-inline-precompile": "^2.1.0",
"ember-cli-inject-live-reload": "^1.8.2",
"ember-cli-sri": "^2.1.1",
"ember-cli-template-lint": "^1.0.0-beta.1",
"ember-cli-uglify": "^2.1.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.0",
Expand All @@ -43,9 +49,9 @@
"ember-resolver": "^5.0.1",
"ember-source": "~3.12.0",
"ember-source-channel-url": "^1.1.0",
"ember-template-lint": "^1.5.3",
"ember-try": "^1.0.0",
"eslint-plugin-ember": "^6.2.0",
"eslint-plugin-node": "^9.0.1",
"eslint": "^6.3.0",
"loader.js": "^4.7.0",
"qunit-dom": "^0.8.4"
},
Expand Down
8 changes: 2 additions & 6 deletions testem.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
launch_in_ci: [
'Chrome'
],
launch_in_dev: [
'Chrome'
],
launch_in_ci: ['Chrome'],
launch_in_dev: ['Chrome'],
browser_args: {
Chrome: {
ci: [
Expand Down
4 changes: 4 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@clark/ember'
};
4 changes: 3 additions & 1 deletion tests/dummy/app/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Application from '@ember/application';
import Resolver from './resolver';

import loadInitializers from 'ember-load-initializers';

import config from './config/environment';
import Resolver from './resolver';

const App = Application.extend({
modulePrefix: config.modulePrefix,
Expand Down
Empty file.
Empty file.
Empty file removed tests/dummy/app/helpers/.gitkeep
Empty file.
Empty file removed tests/dummy/app/models/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import EmberRouter from '@ember/routing/router';

import config from './config/environment';

const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
});
Router.map(function() {});

export default Router;
Empty file removed tests/dummy/app/routes/.gitkeep
Empty file.
File renamed without changes.
Empty file removed tests/dummy/app/styles/app.css
Empty file.
3 changes: 0 additions & 3 deletions tests/dummy/app/templates/application.hbs

This file was deleted.

Empty file.
4 changes: 4 additions & 0 deletions tests/dummy/config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@clark/node'
};
2 changes: 1 addition & 1 deletion tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = function(environment) {
let ENV = {
const ENV = {
modulePrefix: 'dummy',
environment,
rootURL: '/',
Expand Down
Empty file removed tests/helpers/.gitkeep
Empty file.
Empty file removed tests/integration/.gitkeep
Empty file.
59 changes: 59 additions & 0 deletions tests/integration/helpers/service-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { render } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

import { set } from '@ember/object';
import { run } from '@ember/runloop';
import Service from '@ember/service';
import Ember from 'ember';

import hbs from 'htmlbars-inline-precompile';

module('Integration | Helpers | Service', function(hooks) {
setupRenderingTest(hooks);

const { onerror } = Ember;
hooks.afterEach(() => {
Ember.onerror = onerror;
});

hooks.beforeEach(function() {
this.owner.register(
'service:some-service',
class SomeService extends Service {
init() {
super.init();

this.isTrue = true;
this.fruitType = 'Banana';
}
}
);
});

test('it allows you to access a property on a service if it exists', async function(assert) {
await render(hbs`{{get (service "some-service") "fruitType"}}`);
assert.dom().includesText('Banana');

await render(
hbs`{{if (get (service "some-service") "isTrue") "I am here"}}`
);
assert.dom().includesText('I am here');

const service = this.owner.lookup('service:some-service');
run(() => set(service, 'isTrue', false));
assert.dom().doesNotIncludeText('I am here');
});

test('it throws an error when trying to access a service that does not exist', async function(assert) {
assert.expect(1);

Ember.onerror = error =>
assert.equal(
error.message,
"Assertion Failed: The service 'not-a-service' does not exist"
);

await render(hbs`{{service "not-a-service"}}`);
});
});
5 changes: 3 additions & 2 deletions tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';

import Application from '../app';
import config from '../config/environment';

setApplication(Application.create(config.APP));

start();
Empty file removed tests/unit/.gitkeep
Empty file.
Empty file removed vendor/.gitkeep
Empty file.
Loading

0 comments on commit 8bd6b36

Please sign in to comment.