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 selection replacement #400

Merged
merged 1 commit into from
Apr 22, 2016
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ values of `env`. They should all be enclosed in curly brackets `{}`
* `{FILE_ACTIVE_NAME}` - Full name and extension of active file. E.g., `build.js`
* `{FILE_ACTIVE_NAME_BASE}` - Name of active file WITHOUT extension. E.g., `build`
* `{PROJECT_PATH}` - Full path to the root of the project. This is normally the path Atom has as root. E.g `/home/noseglid/github/atom-build`
* `{REPO_BRANCH_SHORT}` - Short name of the current active branch (if project is backed by git). E.g `master` or `v0.9.1`.
* `{REPO_BRANCH_SHORT}` - Short name of the current active branch (if project is backed by git). E.g `master` or `v0.9.1`
* `{SELECTION}` - Selected text.

### Creating a build provider
Creating a build provider require very little code in the easiest case, and can
Expand Down
1 change: 1 addition & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const replace = (value = '', targetEnv) => {
value = value.replace(/{FILE_ACTIVE_PATH}/g, activeFilePath);
value = value.replace(/{FILE_ACTIVE_NAME}/g, path.basename(activeFile));
value = value.replace(/{FILE_ACTIVE_NAME_BASE}/g, path.basename(activeFile, path.extname(activeFile)));
value = value.replace(/{SELECTION}/g, editor.getSelectedText());
}
value = value.replace(/{PROJECT_PATH}/g, projectPath);
if (atom.project.getRepositories[0]) {
Expand Down
3 changes: 3 additions & 0 deletions spec/build-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ describe('Build', () => {
]);
});

runs(() => atom.workspace.getActiveTextEditor().setSelectedBufferRange([[1, 3], [1, 6]]));

runs(() => atom.commands.dispatch(workspaceElement, 'build:trigger'));

waitsFor(() => {
Expand All @@ -389,6 +391,7 @@ describe('Build', () => {
expect(output.indexOf('FROM_PROCESS_ENV=' + directory + '.atom-build.json')).not.toBe(-1);
expect(output.indexOf('FILE_ACTIVE_NAME=.atom-build.json')).not.toBe(-1);
expect(output.indexOf('FILE_ACTIVE_NAME_BASE=.atom-build')).not.toBe(-1);
expect(output.indexOf('SELECTION=cmd')).not.toBe(-1);
});
});
});
Expand Down
1 change: 1 addition & 0 deletions spec/fixture/.atom-build.replace.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"REPO_BRANCH_SHORT={REPO_BRANCH_SHORT}",
"FILE_ACTIVE_NAME={FILE_ACTIVE_NAME}",
"FILE_ACTIVE_NAME_BASE={FILE_ACTIVE_NAME_BASE}",
"SELECTION={SELECTION}",
"FROM_ENV=$FROM_ENV",
"FROM_PROCESS_ENV=$FROM_PROCESS_ENV"
],
Expand Down