├── .gitignore ├── keymaps └── ascii-art.json ├── README.md ├── package.json ├── lib └── ascii-art.js ├── LICENSE.md └── spec └── ascii-art-spec.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /keymaps/ascii-art.json: -------------------------------------------------------------------------------- 1 | { 2 | "atom-text-editor": { 3 | "ctrl-alt-a": "ascii-art:convert" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##### Atom and all repositories under Atom will be archived on December 15, 2022. Learn more in our [official announcement](https://github.blog/2022-06-08-sunsetting-atom/) 2 | # ascii-art package 3 | 4 | Convert selected text to ascii art banner 5 | 6 | This is the source code for the [create your own package](https://atom.io/docs/latest/hacking-atom-package-modifying-text) tutorial. 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ascii-art", 3 | "main": "./lib/ascii-art", 4 | "version": "0.0.0", 5 | "description": "A short description of your package", 6 | "activationCommands": { 7 | "atom-workspace": "ascii-art:convert" 8 | }, 9 | "repository": "https://github.com/atom/ascii-art", 10 | "license": "MIT", 11 | "engines": { 12 | "atom": ">=0.174.0 <2.0.0" 13 | }, 14 | "dependencies": { 15 | "figlet": "1.0.8" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/ascii-art.js: -------------------------------------------------------------------------------- 1 | const {CompositeDisposable} = require('atom') 2 | 3 | module.exports = { 4 | subscriptions: null, 5 | 6 | activate () { 7 | this.subscriptions = new CompositeDisposable() 8 | this.subscriptions.add(atom.commands.add('atom-workspace', 9 | {'ascii-art:convert': () => this.convert()}) 10 | ) 11 | }, 12 | 13 | deactivate () { 14 | this.subscriptions.dispose() 15 | }, 16 | 17 | convert () { 18 | const editor = atom.workspace.getActiveTextEditor() 19 | if (editor) { 20 | const selection = editor.getSelectedText() 21 | 22 | const figlet = require('figlet') 23 | const font = 'o8' 24 | figlet(selection, {font}, function (error, art) { 25 | if (error) { 26 | console.error(error) 27 | } else { 28 | editor.insertText(`\n${art}\n`) 29 | } 30 | }) 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 GitHub Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /spec/ascii-art-spec.js: -------------------------------------------------------------------------------- 1 | const AsciiArt = require('../lib/ascii-art') 2 | 3 | // Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. 4 | // 5 | // To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` 6 | // or `fdescribe`). Remove the `f` to unfocus the block. 7 | 8 | describe('AsciiArt', function () { 9 | let workspaceElement, activationPromise 10 | 11 | beforeEach(function () { 12 | workspaceElement = atom.views.getView(atom.workspace) 13 | activationPromise = atom.packages.activatePackage('ascii-art') 14 | 15 | waitsForPromise(() => atom.workspace.open()) 16 | }) 17 | 18 | it('converts', function () { 19 | const editor = atom.workspace.getActiveTextEditor() 20 | editor.insertText('cool') 21 | editor.selectAll() 22 | const changeHandler = jasmine.createSpy('changeHandler') 23 | editor.onDidChange(changeHandler) 24 | 25 | atom.commands.dispatch(workspaceElement, 'ascii-art:convert') 26 | 27 | waitsForPromise(() => activationPromise) 28 | 29 | waitsFor(() => changeHandler.callCount > 0) 30 | 31 | runs(() => 32 | expect(editor.getText()).toEqual(`\ 33 | 34 | o888 35 | ooooooo ooooooo ooooooo 888 36 | 888 888 888 888 888 888 888 37 | 888 888 888 888 888 888 38 | 88ooo888 88ooo88 88ooo88 o888o 39 | 40 | \ 41 | ` 42 | ) 43 | ) 44 | }) 45 | }) 46 | --------------------------------------------------------------------------------