Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
dperetti committed May 16, 2017
0 parents commit 3cce93c
Show file tree
Hide file tree
Showing 16 changed files with 799 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/npm-debug.log
3 changes: 3 additions & 0 deletions Atom Code Story plug-in.codestory/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This README file is located in a .codestory documentation package.
You should not attempt to modify anything here.
Get free Code Story Reader at http://codestoryapp.com.
519 changes: 519 additions & 0 deletions Atom Code Story plug-in.codestory/data.codestory

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 0.1.0 - First Release
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.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This Atom plug-in provides [Code Story](http://codestoryapp.com) integration:

- Token highlighting,
- Command-click on tokens to view in Code Story.


![A screenshot](https://raw.githubusercontent.com/dperetti/atom-codestory/master/Atom%20Code%20Story%20plug-in.codestory/data/fb020250-0715-11e7-94be-f9b7f5eb273a.png)
5 changes: 5 additions & 0 deletions keymaps/atom-codestory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"atom-workspace": {
"ctrl-alt-o": "atom-codestory:toggle"
}
}
97 changes: 97 additions & 0 deletions lib/atom-codestory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
'use babel';

import path from 'path'
import { CompositeDisposable } from 'atom'
import { spawn } from 'child_process'
import packageConfig from './config-schema.json'
import fs from 'fs'

// this is what a token should look like
const re = /#[a-zA-Z0-9]{5}#/g

const findDocumentationUpInHierarchy = (file) => {
let folder = file
let documentationPath = null
while (documentationPath === null && folder !== '/') {
folder = path.dirname(folder)
const files = fs.readdirSync(folder)
files.some(file => {
if (file.match(/.+\.codestory$/)) {
documentationPath = path.join(folder, file)
return true
}
})
}
return documentationPath
}

export default {
config: packageConfig,
subscriptions: new CompositeDisposable(),
markers: [],
activate() {
this.subscriptions.add(atom.workspace.observeTextEditors(editor => {
this.subscriptions.add(editor.onDidChange(event => {
this.highlightTokens(editor) // #9Debv#
}))
}))
this.subscriptions.add(
atom.workspace.onDidChangeActivePaneItem(() => this.highlightTokens(atom.workspace.getActiveTextEditor())) // #Hqjn6#
)
},
deactivate() {
this.subscriptions.dispose();
},
highlightTokens(editor) { // #khGD4#
if (!editor) return
this.markers.forEach(m => m.destroy())
this.markers = []
editor.scan(re, (obj) => {
const marker = editor.markBufferRange(obj.range)
// https://atom.io/docs/api/v1.10.2/TextEditor#instance-decorateMarker
const decoration = editor.decorateMarker(marker, { type: 'highlight', class: 'codestory-token' })
this.markers.push(decoration)
})
},
// https://github.com/facebooknuclide/hyperclick#provider-api
getProvider() { // #P4S7v#
return {
providerName: 'hyperclick-codestory',
wordRegExp: re,
getSuggestionForWord(textEditor, text, range) {
if (!re.exec(text)) return null // #x8U8m#
return {
// The range(s) to underline as a visual cue for clicking.
range,
textEditor,
// The function to call when the underlined text is clicked.
callback: () => {
const cmd = atom.config.get('codestory.codeStoryAppPath') // #MsTbt#
const currentFilePath = path.join(textEditor.getDirectoryPath(), textEditor.getFileName())
const documentationPath = findDocumentationUpInHierarchy(currentFilePath)

if (documentationPath) {
const args = ['-p', documentationPath, '-s', text.slice(1, 6)]

console.log('args', cmd, args)

const p = spawn(cmd, args, { detached: true })
p.stderr.on('data', (data) => {
atom.notifications.addError('Code Story', { detail: data });
})
// p.stdout.on('data', (data) => {
// console.log('stdout: ' + data) // eslint-disable-line
// })
// p.on('close', (code) => {
// console.log('child process exited with code ' + code) // eslint-disable-line
// })
p.unref()
} else {
atom.notifications.addError('Code Story launch error', { detail: 'No Code Story documentation could be found.' });
}
},
}
},
}
},
}
7 changes: 7 additions & 0 deletions lib/config-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"codeStoryAppPath": {
"description": "Path to Code Story binary",
"type": "string",
"default": "/Applications/Code Story.app/Contents/MacOS/Code Story"
}
}
26 changes: 26 additions & 0 deletions menus/atom-codestory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"context-menu": {
"atom-text-editor": [
{
"label": "Toggle atom-codestory",
"command": "atom-codestory:toggle"
}
]
},
"menu": [
{
"label": "Packages",
"submenu": [
{
"label": "Code Story",
"submenu": [
{
"label": "Toggle",
"command": "atom-codestory:toggle"
}
]
}
]
}
]
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "codestory",
"main": "./lib/atom-codestory",
"version": "0.2.0",
"description": "This Atom plug-in provides Code Story integration",
"keywords": [],
"repository": "https://github.com/dperetti/atom-codestory",
"license": "MIT",
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {},
"providedServices": {
"hyperclick.provider": {
"versions": {
"0.0.0": "getProvider"
}
}
}
}
73 changes: 73 additions & 0 deletions spec/atom-codestory-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use babel';

import AtomCodestory from '../lib/atom-codestory';

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

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

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

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

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

runs(() => {
expect(workspaceElement.querySelector('.atom-codestory')).toExist();

let atomCodestoryElement = workspaceElement.querySelector('.atom-codestory');
expect(atomCodestoryElement).toExist();

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

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

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

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

import AtomCodestoryView from '../lib/atom-codestory-view';

describe('AtomCodestoryView', () => {
it('has one valid test', () => {
expect('life').toBe('easy');
});
});
11 changes: 11 additions & 0 deletions styles/atom-codestory.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@import "ui-variables";

atom-text-editor.editor {
.codestory-token {
color: red !important;
}
.codestory-token .region { // #kFSgH#
border-radius: 5px;
background-color: #ccc;
}
}

0 comments on commit 3cce93c

Please sign in to comment.