Skip to content

Commit

Permalink
Added Macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennykorsukewitz committed Jan 3, 2024
1 parent 1ad2034 commit 62ea0bd
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The following files can be created.
| | keymaps/Default (Linux).sublime-keymap | Shortcuts for Linux |
| | keymaps/Default (OSX).sublime-keymap | Shortcuts for OSX |
| | keymaps/Default (Windows).sublime-keymap | Shortcuts for Windows |
| **macro** | macros/SublimePackage.sublime-macro. | Macros are a basic automation facility comprising sequences of commands. Use them whenever you need to repeat the exact same steps to perform an operation. |
| **menu** | menus/Context.sublime-menu | Right click on main buffer. |
| | menus/Encoding.sublime-menu | Left click on "Encoding" section in statusbar. |
| | menus/Find in Files.sublime-menu | Left click on "..." button on Where field of Find_in_files. |
Expand All @@ -49,6 +50,10 @@ The following files can be created.
| | menus/Side Bar Mount Point.sublime-menu | Right click on main folders in Sidebar. |
| | menus/Tab Context.sublime-menu | Right click on Tab bar. |
| | menus/Widget Context.sublime-menu | Right click on text field of any widget (i.e: search panel or output panel). |
| **mousemap** | mousemaps/Default.sublime-mousemap | Creates a Default.sublime-mousemap file. The mousemap files (which have the extension .sublime-mousemap) control what commands are executed when a user performs an action with a mouse, e.g. clicking a mouse button, scrolling the scroll wheel, etc. |
| | mousemaps/Default (Linux).sublime-mousemap | Shortcuts for Linux |
| | mousemaps/Default (OSX).sublime-mousemap | Shortcuts for OSX |
| | mousemaps/Default (Windows).sublime-mousemap| Shortcuts for Windows |
| **plugin** | SublimePackage.py | Creates a new python plugin. |
| | SublimePackage.sublime-settings | Creates a SublimePackage.sublime-settings file to stores configuration data. |
| **project** | projects/SublimePackage.sublime-projects | Creates a SublimePackage.sublime-project file to register a collection of files and folders, which are shown in Sidebar. |
Expand Down Expand Up @@ -79,7 +84,9 @@ yo sublime-package:SUBGENERATOR --help
yo sublime-package:command
yo sublime-package:completion
yo sublime-package:keymap
yo sublime-package:macro
yo sublime-package:menu
yo sublime-package:mousemap
yo sublime-package:plugin
yo sublime-package:project
yo sublime-package:readme
Expand Down
50 changes: 50 additions & 0 deletions __tests__/generators/macro.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const path = require('path');
const helpers = require('yeoman-test');

describe('generators:macro', () => {
describe('creates files', () => {
let runResult;

const config = {
// generator_data
macro_file_name: 'SublimePackage',

// package_data
sublime_version: '4.0.x',
package_name: 'Sublime-Package',
package_description: 'My description.',
github_username: 'dennykorsukewitz',
github_fullname: 'Denny Korsukéwitz',
};

const expectedFiles = [
'macros/SublimePackage.sublime-macro',
];

const expectedContent = [
[ 'macros/SublimePackage.sublime-macro', 'hardeol' ],
];

beforeEach(async () => {
runResult = await helpers
.run(path.join(process.env.INIT_CWD, '/generators/macro'))
.withPrompts(config)
.withLocalConfig(config);
});

afterEach(() => {
if (runResult) {
runResult.restore();
}
});

it('expected files', () => {
runResult.assertFile(expectedFiles);
});

it('expected content', () => {
runResult.assertFileContent(expectedContent);
});

});
});
8 changes: 8 additions & 0 deletions generators/macro/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Description:
Creates a Default.sublime-macro file. Macros are a basic automation facility comprising sequences of commands. Use them whenever you need to repeat the exact same steps to perform an operation.

Example:
yo sublime-package:macro

This will create:
macros/SublimePackage.sublime-macro: Macro files are JSON files with the extension .sublime-macro.
17 changes: 17 additions & 0 deletions generators/macro/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const config = {
name: 'Macro',
description: 'Creates a Default.sublime-macro file. Macros are a basic automation facility comprising sequences of commands. Use them whenever you need to repeat the exact same steps to perform an operation.',
priority: 60,
versions: {
'4.0.x': '',
},
prompts: [
{
name: 'macro_file_name',
message: 'What is the name of your new macro file (macro file name)?',
type: 'input',
default: '${config.package_name_pascal_case}',
},
],
};
module.exports = config;
73 changes: 73 additions & 0 deletions generators/macro/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';
/* eslint no-empty-function: ["error", { "allow": ["methods"] }] */

const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');
const path = require('path');
const helper = require('./../../src/helper.js');
const generator = path.basename(__dirname);
const generator_config = require('./config.js');

let config = {};
let answers = {};

module.exports = class extends Generator {
// initializing - Your initialization methods (checking current project state, getting configs, etc)
async initializing() {

// create or update config
await helper.InitConfig(this, generator_config);

// get current config
config = this.config.getAll();
config.generator_name = generator_config.name || generator;
config.generator_description = '\n' + generator_config.description || '';
}

// prompting - Where you prompt users for options (where you’d call this.prompt())
async prompting() {
this.log(
yosay(
`${chalk.green(config.generator_name)} ${config.generator_description}`,
),
);

generator_config.prompts = helper.InterpolatePrompts(this, config, generator_config.prompts);
answers = await this.prompt(generator_config.prompts);
}

// configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files)
configuring() {}

// default - If the method name doesn’t match a priority, it will be pushed to this group.
default() {}

// writing - Where you write the generator specific files (routes, controllers, etc)
writing() {

// merge data
const data = {
...config,
...answers,
};

this.renderTemplate(
this.templatePath('macro.sublime-macro'),
this.destinationPath(`macros/${data.macro_file_name}.sublime-macro`),
data,
);
}

// conflicts - Where conflicts are handled (used internally)
conflicts() { }

// install - Where installations are run (npm, bower)
install() {}

// end - Called last, cleanup, say good bye, etc
end() {
helper.End(this, config);
}
};

4 changes: 4 additions & 0 deletions generators/macro/templates/macro.sublime-macro
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{"command": "move_to", "args": {"to": "hardeol"}},
{"command": "insert", "args": {"characters": "\n"}}
]
2 changes: 1 addition & 1 deletion generators/menu/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {
name: 'Menu',
description: 'Creates a *.sublime-menu file. Define Menubar and various right-click menus. Creates a *.sublime-menu file.',
priority: 60,
priority: 70,
versions: {
'4.0.x': '',
},
Expand Down
4 changes: 2 additions & 2 deletions generators/mousemap/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {
name: 'Mousemap',
description: 'Creates a Default.sublime-mousemap file. Default.sublime-mousemap files contain the key bindings (shortcuts) for a command.',
priority: 70,
description: 'Creates a Default.sublime-mousemap file. The mousemap files (which have the extension .sublime-mousemap) control what commands are executed when a user performs an action with a mouse, e.g. clicking a mouse button, scrolling the scroll wheel, etc.',
priority: 80,
versions: {
'4.0.x': '',
},
Expand Down
2 changes: 1 addition & 1 deletion generators/project/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {
name: 'Project',
description: 'Creates a SublimePackage.sublime-project file to register a collection of files and folders, which are shown in Sidebar.',
priority: 80,
priority: 90,
versions: {
'4.0.x': '',
},
Expand Down
2 changes: 1 addition & 1 deletion generators/setting/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {
name: 'Setting',
description: 'Creates a SublimePackage.sublime-settings file to stores configuration data.',
priority: 90,
priority: 100,
versions: {
'4.0.x': '',
},
Expand Down
2 changes: 1 addition & 1 deletion generators/snippet/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {
name: 'Snippet',
description: 'Creates a Snippet file. Snippets are smart templates that will insert text for you, adapting it to their context.',
priority: 90,
priority: 110,
versions: {
'4.0.x': '',
},
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"sublime-command",
"sublime-completion",
"sublime-keymap",
"sublime-macro",
"sublime-menu",
"sublime-mousemap",
"sublime-plugin",
"sublime-project",
"sublime-readme",
Expand Down

0 comments on commit 62ea0bd

Please sign in to comment.