Skip to content

Commit

Permalink
Add files (day 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
azwreith committed Sep 7, 2016
1 parent 8ef39b6 commit 1dc6464
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0 - First Release
* Every feature added
* Every bug fixed
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# sourcefetch
# sourcefetch 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 changes: 5 additions & 0 deletions keymaps/sourcefetch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"atom-workspace": {
"ctrl-alt-o": "sourcefetch:fetch"
}
}
29 changes: 29 additions & 0 deletions lib/sourcefetch-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use babel';

export default class SourcefetchView {

constructor(serializedState) {
// Create root element
this.element = document.createElement('div');
this.element.classList.add('sourcefetch');

// Create message element
const message = document.createElement('div');
message.textContent = 'The Sourcefetch 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;
}

}
42 changes: 42 additions & 0 deletions lib/sourcefetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use babel';

import { CompositeDisposable } from 'atom';
import request from 'request'

export default {

subscriptions: null,

activate(state) {

// 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', {
'sourcefetch:fetch': () => this.fetch()
}));

},

deactivate() {
this.subscriptions.dispose();
},

fetch() {
let editor
if (editor = atom.workspace.getActiveTextEditor()) {
let selection = editor.getSelectedText()
this.download(selection)
}
},

download(url) {
request(url,(error,response,body) => {
if (!error && response.statusCode == 200) {
console.log(body)
}
})
}

};
26 changes: 26 additions & 0 deletions menus/sourcefetch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"context-menu": {
"atom-text-editor": [
{
"label": "Fetch Code",
"command": "sourcefetch:fetch"
}
]
},
"menu": [
{
"label": "Packages",
"submenu": [
{
"label": "sourcefetch",
"submenu": [
{
"label": "Fetch Code",
"command": "sourcefetch:fetch"
}
]
}
]
}
]
}
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "sourcefetch",
"main": "./lib/sourcefetch",
"version": "0.0.0",
"description": "Fetch code directly from stackoverflow!",
"keywords": [],
"activationCommands": {
"atom-workspace": "sourcefetch:fetch"
},
"repository": "https://github.com/atom/sourcefetch",
"license": "MIT",
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {
"request": "^2.73.0"
}
}
73 changes: 73 additions & 0 deletions spec/sourcefetch-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use babel';

import Sourcefetch from '../lib/sourcefetch';

// 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('Sourcefetch', () => {
let workspaceElement, activationPromise;

beforeEach(() => {
workspaceElement = atom.views.getView(atom.workspace);
activationPromise = atom.packages.activatePackage('sourcefetch');
});

describe('when the sourcefetch: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('.sourcefetch')).not.toExist();

// This is an activation event, triggering it will cause the package to be
// activated.
atom.commands.dispatch(workspaceElement, 'sourcefetch:toggle');

waitsForPromise(() => {
return activationPromise;
});

runs(() => {
expect(workspaceElement.querySelector('.sourcefetch')).toExist();

let sourcefetchElement = workspaceElement.querySelector('.sourcefetch');
expect(sourcefetchElement).toExist();

let sourcefetchPanel = atom.workspace.panelForItem(sourcefetchElement);
expect(sourcefetchPanel.isVisible()).toBe(true);
atom.commands.dispatch(workspaceElement, 'sourcefetch:toggle');
expect(sourcefetchPanel.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('.sourcefetch')).not.toExist();

// This is an activation event, triggering it causes the package to be
// activated.
atom.commands.dispatch(workspaceElement, 'sourcefetch:toggle');

waitsForPromise(() => {
return activationPromise;
});

runs(() => {
// Now we can test for view visibility
let sourcefetchElement = workspaceElement.querySelector('.sourcefetch');
expect(sourcefetchElement).toBeVisible();
atom.commands.dispatch(workspaceElement, 'sourcefetch:toggle');
expect(sourcefetchElement).not.toBeVisible();
});
});
});
});
9 changes: 9 additions & 0 deletions spec/sourcefetch-view-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use babel';

import SourcefetchView from '../lib/sourcefetch-view';

describe('SourcefetchView', () => {
it('has one valid test', () => {
expect('life').toBe('easy');
});
});
8 changes: 8 additions & 0 deletions styles/sourcefetch.less
Original file line number Diff line number Diff line change
@@ -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";

.sourcefetch {
}

0 comments on commit 1dc6464

Please sign in to comment.