Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/gist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default Ember.Controller.extend({
},

addComponent() {
let path = prompt('Component path (without file extension)', 'components/my-component');
let path = prompt('Component path (without file extension)', 'my-component');
if (Ember.isBlank(path)){
return;
}
Expand All @@ -256,7 +256,13 @@ export default Ember.Controller.extend({
}
['js', 'hbs'].forEach((fileExt, i)=>{
let fileProperties = this.get('emberCli').buildProperties(`component-${fileExt}`);
let filePath = `${fileExt === 'hbs' ? 'templates/' : ''}${path}.${fileExt}`;
let notPodPrefix = "components/";
let filePath;
if (path.substr(0, notPodPrefix.length) === notPodPrefix) {
filePath = `${fileExt === 'hbs' ? 'templates/' : ''}${path}.${fileExt}`;
} else {
filePath = path + "/" + (fileExt === 'hbs' ? 'template.hbs' : 'component.js');
}
let fileColumn = i+1;
this.createFile(filePath, fileProperties, fileColumn);
});
Expand Down
8 changes: 4 additions & 4 deletions app/services/ember-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const requiredFiles = [
const availableBlueprints = {
'templates/application': {
blueprint: 'templates/application',
filePath: 'templates/application.hbs',
filePath: 'application/template.hbs',
},
'controllers/application': {
blueprint: 'controllers/application',
filePath: 'controllers/application.js',
filePath: 'application/controller.js',
},
'app': {
blueprint: 'app',
Expand All @@ -37,11 +37,11 @@ const availableBlueprints = {
},
'component-hbs': {
blueprint: 'component-hbs',
filePath: 'templates/components/my-component.hbs',
filePath: 'my-component/template.hbs',
},
'component-js': {
blueprint: 'component-js',
filePath: 'components/my-component.js',
filePath: 'my-component/component.js',
},
'controller': {
blueprint: 'controller',
Expand Down
26 changes: 26 additions & 0 deletions tests/acceptance/gist-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ test('can add component (js and hbs)', function(assert){
});
});

test('can add component (js and hbs) using pod format', function(assert){

let origFileCount;
promptValue = "my-comp";
visit('/');
andThen(function(){
origFileCount = find(firstFilePickerFiles).length;
});

click(fileMenu);
click('.add-component-link');
click(firstFilePicker);
andThen(function() {
let numFiles = find(firstFilePickerFiles).length;
assert.equal(numFiles, origFileCount + 2, 'Added component files');
let fileNames = findMapText(`${firstFilePickerFiles} a`);
let jsFile = `${promptValue}/component.js`;
let hbsFile = `${promptValue}/template.hbs`;
assert.equal(fileNames[3], jsFile);
assert.equal(fileNames[4], hbsFile);
let columnFiles = findMapText(displayedFiles);
assert.deepEqual(columnFiles, [jsFile, hbsFile], 'Added files are displayed');

});
});

test('component without hyphen fails', function(assert){

let alertFn = window.alert;
Expand Down