Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add before and after options to Blueprint#insertIntoFile #2122

Merged

Conversation

bantic
Copy link
Contributor

@bantic bantic commented Sep 26, 2014

Adds the ability to specify the string in a file to insert contents before or after, similar to the same method in Thor.

Example:

 // .jshintrc
 "predef": [
   "window",
   "document"
 ]

 insertIntoFile('.jshintrc', '  "newGlobal",', {after:'"predef": [\n'});

 // new .jshintrc
  "predef": [
    "newGlobal",
    "window",
    "document"
 ]

@bantic bantic changed the title Add before and after options to insertIntoFile Add before and after options to Blueprint#insertIntoFile Sep 26, 2014
var line1 = 'line1 is here';
var line2 = 'line2 here';
var line3 = 'line3';
var originalContent = [line1, line2, line3].join('\n');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to switch all instances of \n to use var EOL = os.eol;.

@rwjblue
Copy link
Member

rwjblue commented Sep 26, 2014

Looks great! We need to swap the \n's with os.eol (for running the tests in Windows).

I would also like to see a test that confirms the behavior if multiple matches are found. From the implementation it is obvious that it doesn't matter (it will always use the first one due to the usage of indexOf), but I would like to solidify this behavior by way of a unit test so future changes (like perhaps saying "insert after the second occurrence") do not change this.

"newGlobal",
"window",
"document"
]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to change this example. I've been focused on automatically adding test helpers but it's not good to encourage people to add globals

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@bantic bantic force-pushed the add-before-after-options-to-insert-into-file branch from 3dc7864 to f3983f1 Compare September 26, 2014 17:15
@bantic bantic force-pushed the add-before-after-options-to-insert-into-file branch from f3983f1 to 61b1101 Compare September 26, 2014 17:18
@bantic
Copy link
Contributor Author

bantic commented Sep 26, 2014

thanks! Added 2 more tests to ensure that it inserts before/after the first instance of the string only.

Changed \n to os.EOL throughout.

rwjblue added a commit that referenced this pull request Sep 26, 2014
…rt-into-file

Add `before` and `after` options to Blueprint#insertIntoFile
@rwjblue rwjblue merged commit aa4e696 into ember-cli:master Sep 26, 2014
@bantic bantic deleted the add-before-after-options-to-insert-into-file branch September 26, 2014 17:31
@rwjblue
Copy link
Member

rwjblue commented Sep 26, 2014

image

});

it('will insert into the file before a specified string if options.before is specified', function(){
var toInsert = 'blahzorz blammo';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inserting an EOL in the "before" statment causes formatting issues. Can we just insert "before" starting immediately before the statement? And leave it to the insertion statment to add the EOL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants