Skip to content
This repository has been archived by the owner on Nov 25, 2018. It is now read-only.

Commit

Permalink
Import blueprints from ember.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Mar 9, 2016
1 parent daaa0e5 commit ef4ce31
Show file tree
Hide file tree
Showing 48 changed files with 4,210 additions and 65 deletions.
54 changes: 54 additions & 0 deletions blueprints/-addon-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*jshint node:true*/

var stringUtil = require('ember-cli-string-utils');
var path = require('path');
var inflector = require('inflection');

module.exports = {
description: 'Generates an import wrapper.',

fileMapTokens: function() {
return {
__name__: function(options) {
if (options.pod && options.hasPathToken) {
return options.locals.blueprintName;
}
return options.dasherizedModuleName;
},
__path__: function(options) {
if (options.pod && options.hasPathToken) {
return path.join(options.podPath, options.dasherizedModuleName);
}
return inflector.pluralize(options.locals.blueprintName);
},
__root__: function(options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'app');
}
return 'app';
}
};
},

locals: function(options) {
var addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name();
var addonName = stringUtil.dasherize(addonRawName);
var fileName = stringUtil.dasherize(options.entity.name);
var blueprintName = options.originBlueprintName;
var modulePathSegments = [addonName, inflector.pluralize(options.originBlueprintName), fileName];

if (blueprintName.match(/-addon/)) {
blueprintName = blueprintName.substr(0,blueprintName.indexOf('-addon'));
modulePathSegments = [addonName, inflector.pluralize(blueprintName), fileName];
}

if (options.pod) {
modulePathSegments = [addonName, fileName, blueprintName];
}

return {
modulePath: modulePathSegments.join('/'),
blueprintName: blueprintName
};
}
};
15 changes: 3 additions & 12 deletions blueprints/acceptance-test/files/tests/acceptance/__name__-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { module, test } from 'qunit';
import startApp from '<%= testFolderRoot %>/tests/helpers/start-app';
import destroyApp from '<%= testFolderRoot %>/tests/helpers/destroy-app';
import { test } from 'qunit';
import moduleForAcceptance from '<%= testFolderRoot %>/tests/helpers/module-for-acceptance';

module('<%= friendlyTestName %>', {
beforeEach: function() {
this.application = startApp();
},

afterEach: function() {
destroyApp(this.application);
}
});
moduleForAcceptance('<%= friendlyTestName %>');

test('visiting /<%= dasherizedModuleName %>', function(assert) {
visit('/<%= dasherizedModuleName %>');
Expand Down
2 changes: 1 addition & 1 deletion blueprints/acceptance-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
}
return {
testFolderRoot: testFolderRoot,
friendlyTestName: testInfo.name(options.entity.name, "Acceptance", null)
friendlyTestName: testInfo.name(options.entity.name, 'Acceptance', null)
};
}
};
4 changes: 2 additions & 2 deletions blueprints/component-addon/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*jshint node:true*/

var stringUtil = require('ember-cli-string-utils');
var validComponentName = require('ember-cli/lib/utilities/valid-component-name');
var getPathOption = require('ember-cli/lib/utilities/get-component-path-option');
var validComponentName = require('ember-cli-valid-component-name');
var getPathOption = require('ember-cli-get-component-path-option');
var path = require('path');
var normalizeEntityName = require('ember-cli-normalize-entity-name');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ moduleForComponent('<%= componentPathName %>', '<%= friendlyTestDescription %>',
});

test('it renders', function(assert) {
<% if (testType === 'integration' ) { %>assert.expect(2);

// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });" + EOL + EOL +
<% if (testType === 'integration' ) { %>// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`{{<%= componentPathName %>}}`);

assert.equal(this.$().text().trim(), '');

// Template block usage:" + EOL +
// Template block usage:
this.render(hbs`
{{#<%= componentPathName %>}}
template block text
{{/<%= componentPathName %>}}
`);

assert.equal(this.$().text().trim(), 'template block text');<% } else if(testType === 'unit') { %>assert.expect(1);

assert.equal(this.$().text().trim(), 'template block text');<% } else if(testType === 'unit') { %>
// Creates the component instance
/*var component =*/ this.subject();
/*let component =*/ this.subject();
// Renders the component to the page
this.render();
assert.equal(this.$().text().trim(), '');<% } %>
Expand Down
16 changes: 12 additions & 4 deletions blueprints/component-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var path = require('path');
var testInfo = require('ember-cli-test-info');
var stringUtil = require('ember-cli-string-utils');
var getPathOption = require('ember-cli/lib/utilities/get-component-path-option');
var isPackageMissing = require('ember-cli-is-package-missing');
var getPathOption = require('ember-cli-get-component-path-option');

module.exports = {
description: 'Generates a component integration or unit test.',
Expand Down Expand Up @@ -38,15 +39,15 @@ module.exports = {
locals: function(options) {
var dasherizedModuleName = stringUtil.dasherize(options.entity.name);
var componentPathName = dasherizedModuleName;
var testType = options.testType || "integration";
var friendlyTestDescription = testInfo.description(options.entity.name, "Integration", "Component");
var testType = options.testType || 'integration';
var friendlyTestDescription = testInfo.description(options.entity.name, 'Integration', 'Component');

if (options.pod && options.path !== 'components' && options.path !== '') {
componentPathName = [options.path, dasherizedModuleName].join('/');
}

if (options.testType === 'unit') {
friendlyTestDescription = testInfo.description(options.entity.name, "Unit", "Component");
friendlyTestDescription = testInfo.description(options.entity.name, 'Unit', 'Component');
}

return {
Expand All @@ -55,5 +56,12 @@ module.exports = {
componentPathName: componentPathName,
friendlyTestDescription: friendlyTestDescription
};
},
afterInstall: function(options) {
if (!options.dryRun && options.testType === 'integration' && isPackageMissing(this, 'ember-cli-htmlbars-inline-precompile')) {
return this.addPackagesToProject([
{ name: 'ember-cli-htmlbars-inline-precompile', target: '^0.3.1' }
]);
}
}
};
6 changes: 3 additions & 3 deletions blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

var stringUtil = require('ember-cli-string-utils');
var pathUtil = require('ember-cli-path-utils');
var validComponentName = require('ember-cli/lib/utilities/valid-component-name');
var getPathOption = require('ember-cli/lib/utilities/get-component-path-option');
var validComponentName = require('ember-cli-valid-component-name');
var getPathOption = require('ember-cli-get-component-path-option');
var path = require('path');

var normalizeEntityName = require('ember-cli-normalize-entity-name');
Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = {
'templates/components/' + stringUtil.dasherize(options.entity.name);
}
importTemplate = 'import layout from \'' + templatePath + '\';\n';
contents = '\n layout: layout';
contents = '\n layout';
}

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { moduleFor, test } from 'ember-qunit';

moduleFor('controller:<%= dasherizedModuleName %>', {
moduleFor('controller:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});

// Replace this with your real tests.
test('it exists', function(assert) {
var controller = this.subject();
let controller = this.subject();
assert.ok(controller);
});
9 changes: 8 additions & 1 deletion blueprints/controller-test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/*jshint node:true*/

var testInfo = require('ember-cli-test-info');

module.exports = {
description: 'Generates a controller unit test.'
description: 'Generates a controller unit test.',
locals: function(options) {
return {
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Controller')
};
}
};
2 changes: 1 addition & 1 deletion blueprints/helper-addon/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*jshint node:true*/

module.exports = require('ember-cli/blueprints/addon-import');
module.exports = require('../-addon-import');
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { <%= camelizedModuleName %> } from '<%= dependencyDepth %>/helpers/<%= dasherizedModuleName %>';
import { <%= camelizedModuleName %> } from '<%= dasherizedModulePrefix %>/helpers/<%= dasherizedModuleName %>';
import { module, test } from 'qunit';

module('<%= friendlyTestName %>');

// Replace this with your real tests.
test('it works', function(assert) {
var result = <%= camelizedModuleName %>(42);
let result = <%= camelizedModuleName %>([42]);
assert.ok(result);
});
6 changes: 3 additions & 3 deletions blueprints/helper-test/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*jshint node:true*/

var getDependencyDepth = require('ember-cli-get-dependency-depth');
var testInfo = require('ember-cli-test-info');
var stringUtils = require('ember-cli-string-utils');

module.exports = {
description: 'Generates a helper unit test.',
locals: function(options) {
return {
friendlyTestName: testInfo.name(options.entity.name, "Unit", "Helper"),
dependencyDepth: getDependencyDepth(options.entity.name)
friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Helper'),
dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix)
};
}
};
2 changes: 1 addition & 1 deletion blueprints/initializer-addon/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*jshint node:true*/

module.exports = require('ember-cli/blueprints/addon-import');
module.exports = require('../-addon-import');
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import Ember from 'ember';
import { initialize } from '<%= dependencyDepth %>/initializers/<%= dasherizedModuleName %>';
import <%= classifiedModuleName %>Initializer from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>';
import { module, test } from 'qunit';

var registry, application;
let application;

module('<%= friendlyTestName %>', {
beforeEach: function() {
beforeEach() {
Ember.run(function() {
application = Ember.Application.create();
registry = application.registry;
application.deferReadiness();
});
}
});

// Replace this with your real tests.
test('it works', function(assert) {
initialize(registry, application);
<%= classifiedModuleName %>Initializer.initialize(application);

// you would normally confirm the results of the initializer here
assert.ok(true);
Expand Down
6 changes: 3 additions & 3 deletions blueprints/initializer-test/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*jshint node:true*/

var getDependencyDepth = require('ember-cli-get-dependency-depth');
var testInfo = require('ember-cli-test-info');
var stringUtils = require('ember-cli-string-utils');

module.exports = {
description: 'Generates an initializer unit test.',
locals: function(options) {
return {
friendlyTestName: testInfo.name(options.entity.name, "Unit", "Initializer"),
dependencyDepth: getDependencyDepth(options.entity.name)
friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Initializer'),
dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix)
};
}
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export function initialize(/* container, application */) {
export function initialize(/* application */) {
// application.inject('route', 'foo', 'service:foo');
}

export default {
name: '<%= dasherizedModuleName %>',
initialize: initialize
initialize
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, initialize } from '<%= modulePath %>';
3 changes: 3 additions & 0 deletions blueprints/instance-initializer-addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*jshint node:true*/

module.exports = require('../-addon-import');
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Ember from 'ember';
import { initialize } from '<%= dasherizedModulePrefix %>/instance-initializers/<%= dasherizedModuleName %>';
import { module, test } from 'qunit';
import destroyApp from '../../helpers/destroy-app';

module('<%= friendlyTestName %>', {
beforeEach: function() {
Ember.run(() => {
this.application = Ember.Application.create();
this.appInstance = this.application.buildInstance();
});
},
afterEach: function() {
Ember.run(this.appInstance, 'destroy');
destroyApp(this.application);
}
});

// Replace this with your real tests.
test('it works', function(assert) {
initialize(this.appInstance);

// you would normally confirm the results of the initializer here
assert.ok(true);
});
14 changes: 14 additions & 0 deletions blueprints/instance-initializer-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*jshint node:true*/

var testInfo = require('ember-cli-test-info');
var stringUtils = require('ember-cli-string-utils');

module.exports = {
description: 'Generates an instance initializer unit test.',
locals: function(options) {
return {
friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Instance Initializer'),
dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix)
};
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function initialize(/* appInstance */) {
// appInstance.inject('route', 'foo', 'service:foo');
}

export default {
name: '<%= dasherizedModuleName %>',
initialize
};
5 changes: 5 additions & 0 deletions blueprints/instance-initializer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*jshint node:true*/

module.exports = {
description: 'Generates an instance initializer.'
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Ember from 'ember';
import <%= classifiedModuleName %>Mixin from '../../../mixins/<%= dasherizedModuleName %>';
import <%= classifiedModuleName %>Mixin from '<%= projectName %>/mixins/<%= dasherizedModuleName %>';
import { module, test } from 'qunit';

module('<%= friendlyTestName %>');

// Replace this with your real tests.
test('it works', function(assert) {
var <%= classifiedModuleName %>Object = Ember.Object.extend(<%= classifiedModuleName %>Mixin);
var subject = <%= classifiedModuleName %>Object.create();
let <%= classifiedModuleName %>Object = Ember.Object.extend(<%= classifiedModuleName %>Mixin);
let subject = <%= classifiedModuleName %>Object.create();
assert.ok(subject);
});
Loading

0 comments on commit ef4ce31

Please sign in to comment.