Browse Source

Initial version.

Frederic G. MARAND 6 years ago
commit
55e8031738

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.DS_Store
+npm-debug.log
+node_modules

+ 3 - 0
CHANGELOG.md

@@ -0,0 +1,3 @@
+## 0.1.0 - First Release
+* Every feature added
+* Every bug fixed

+ 20 - 0
LICENSE.md

@@ -0,0 +1,20 @@
+Copyright (c) 2016 <Your name here>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 5 - 0
README.md

@@ -0,0 +1,5 @@
+# orderthings package
+
+A short description of your package.
+
+![A screenshot of your package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif)

+ 5 - 0
keymaps/orderthings.json

@@ -0,0 +1,5 @@
+{
+  "atom-workspace": {
+    "ctrl-alt-o": "orderthings:toggle"
+  }
+}

+ 29 - 0
lib/orderthings-view.js

@@ -0,0 +1,29 @@
+'use babel';
+
+export default class OrderthingsView {
+
+  constructor(serializedState) {
+    // Create root element
+    this.element = document.createElement('div');
+    this.element.classList.add('orderthings');
+
+    // Create message element
+    const message = document.createElement('div');
+    message.textContent = 'The Orderthings package is Alive! It\'s ALIVE!';
+    message.classList.add('message');
+    this.element.appendChild(message);
+  }
+
+  // Returns an object that can be retrieved when package is activated
+  serialize() {}
+
+  // Tear down any state and detach
+  destroy() {
+    this.element.remove();
+  }
+
+  getElement() {
+    return this.element;
+  }
+
+}

+ 57 - 0
lib/orderthings.js

@@ -0,0 +1,57 @@
+'use babel';
+
+import OrderthingsView from './orderthings-view';
+import { CompositeDisposable } from 'atom';
+
+export default {
+
+  orderthingsView: null,
+  modalPanel: null,
+  subscriptions: null,
+
+  activate(state) {
+    this.orderthingsView = new OrderthingsView(state.orderthingsViewState);
+    this.modalPanel = atom.workspace.addModalPanel({
+      item: this.orderthingsView.getElement(),
+      visible: false
+    });
+
+    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
+    this.subscriptions = new CompositeDisposable();
+
+    // Register command that toggles this view
+    this.subscriptions.add(atom.commands.add('atom-workspace', {
+      'orderthings:toggle': () => this.toggle()
+    }));
+  },
+
+  deactivate() {
+    this.modalPanel.destroy();
+    this.subscriptions.dispose();
+    this.orderthingsView.destroy();
+  },
+
+  serialize() {
+    return {
+      orderthingsViewState: this.orderthingsView.serialize()
+    };
+  },
+
+  toggle1() {
+    console.log('Orderthings was toggled!');
+    return (
+      this.modalPanel.isVisible()
+        ? this.modalPanel.hide()
+        : this.modalPanel.show()
+    );
+  },
+
+  toggle() {
+    let editor;
+    if (editor = atom.workspace.getActiveTextEditor()) {
+      let selection = editor.getSelectedText();
+      let reversed = selection.split('').reverse().join('');
+      editor.insertText(reversed);
+    }
+  }
+};

+ 26 - 0
menus/orderthings.json

@@ -0,0 +1,26 @@
+{
+  "context-menu": {
+    "atom-text-editor": [
+      {
+        "label": "Toggle orderthings",
+        "command": "orderthings:toggle"
+      }
+    ]
+  },
+  "menu": [
+    {
+      "label": "Packages",
+      "submenu": [
+        {
+          "label": "Order all the things!",
+          "submenu": [
+            {
+              "label": "Toggle",
+              "command": "orderthings:toggle"
+            }
+          ]
+        }
+      ]
+    }
+  ]
+}

+ 18 - 0
package.json

@@ -0,0 +1,18 @@
+{
+  "name": "orderthings",
+  "main": "./lib/orderthings",
+  "version": "0.0.0",
+  "description": "A short description of your package",
+  "keywords": [
+  ],
+  "activationCommands": {
+    "atom-workspace": "orderthings:toggle"
+  },
+  "repository": "https://github.com/atom/orderthings",
+  "license": "MIT",
+  "engines": {
+    "atom": ">=1.0.0 <2.0.0"
+  },
+  "dependencies": {
+  }
+}

+ 73 - 0
spec/orderthings-spec.js

@@ -0,0 +1,73 @@
+'use babel';
+
+import Orderthings from '../lib/orderthings';
+
+// Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
+//
+// To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
+// or `fdescribe`). Remove the `f` to unfocus the block.
+
+describe('Orderthings', () => {
+  let workspaceElement, activationPromise;
+
+  beforeEach(() => {
+    workspaceElement = atom.views.getView(atom.workspace);
+    activationPromise = atom.packages.activatePackage('orderthings');
+  });
+
+  describe('when the orderthings:toggle event is triggered', () => {
+    it('hides and shows the modal panel', () => {
+      // Before the activation event the view is not on the DOM, and no panel
+      // has been created
+      expect(workspaceElement.querySelector('.orderthings')).not.toExist();
+
+      // This is an activation event, triggering it will cause the package to be
+      // activated.
+      atom.commands.dispatch(workspaceElement, 'orderthings:toggle');
+
+      waitsForPromise(() => {
+        return activationPromise;
+      });
+
+      runs(() => {
+        expect(workspaceElement.querySelector('.orderthings')).toExist();
+
+        let orderthingsElement = workspaceElement.querySelector('.orderthings');
+        expect(orderthingsElement).toExist();
+
+        let orderthingsPanel = atom.workspace.panelForItem(orderthingsElement);
+        expect(orderthingsPanel.isVisible()).toBe(true);
+        atom.commands.dispatch(workspaceElement, 'orderthings:toggle');
+        expect(orderthingsPanel.isVisible()).toBe(false);
+      });
+    });
+
+    it('hides and shows the view', () => {
+      // This test shows you an integration test testing at the view level.
+
+      // Attaching the workspaceElement to the DOM is required to allow the
+      // `toBeVisible()` matchers to work. Anything testing visibility or focus
+      // requires that the workspaceElement is on the DOM. Tests that attach the
+      // workspaceElement to the DOM are generally slower than those off DOM.
+      jasmine.attachToDOM(workspaceElement);
+
+      expect(workspaceElement.querySelector('.orderthings')).not.toExist();
+
+      // This is an activation event, triggering it causes the package to be
+      // activated.
+      atom.commands.dispatch(workspaceElement, 'orderthings:toggle');
+
+      waitsForPromise(() => {
+        return activationPromise;
+      });
+
+      runs(() => {
+        // Now we can test for view visibility
+        let orderthingsElement = workspaceElement.querySelector('.orderthings');
+        expect(orderthingsElement).toBeVisible();
+        atom.commands.dispatch(workspaceElement, 'orderthings:toggle');
+        expect(orderthingsElement).not.toBeVisible();
+      });
+    });
+  });
+});

+ 9 - 0
spec/orderthings-view-spec.js

@@ -0,0 +1,9 @@
+'use babel';
+
+import OrderthingsView from '../lib/orderthings-view';
+
+describe('OrderthingsView', () => {
+  it('has one valid test', () => {
+    expect('life').toBe('easy');
+  });
+});

+ 8 - 0
styles/orderthings.less

@@ -0,0 +1,8 @@
+// The ui-variables file is provided by base themes provided by Atom.
+//
+// See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less
+// for a full listing of what's available.
+@import "ui-variables";
+
+.orderthings {
+}