Skip to content

Commit 048481f

Browse files
committed
Initial commit using package generator.
0 parents  commit 048481f

9 files changed

+184
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
npm-debug.log
3+
node_modules

keymaps/fast-forward.cson

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Keybindings require three things to be fully defined: A selector that is
2+
# matched against the focused element, the keystroke and the command to
3+
# execute.
4+
#
5+
# Below is a basic keybinding which registers on all platforms by applying to
6+
# the root workspace element.
7+
8+
# For more detailed documentation see
9+
# https://atom.io/docs/latest/behind-atom-keymaps-in-depth
10+
'atom-workspace':
11+
'ctrl-alt-o': 'fast-forward:toggle'

lib/fast-forward-view.coffee

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports =
2+
class FastForwardView
3+
constructor: (serializedState) ->
4+
# Create root element
5+
@element = document.createElement('div')
6+
@element.classList.add('fast-forward')
7+
8+
# Create message element
9+
message = document.createElement('div')
10+
message.textContent = "The FastForward package is Alive! It's ALIVE!"
11+
message.classList.add('message')
12+
@element.appendChild(message)
13+
14+
# Returns an object that can be retrieved when package is activated
15+
serialize: ->
16+
17+
# Tear down any state and detach
18+
destroy: ->
19+
@element.remove()
20+
21+
getElement: ->
22+
@element

lib/fast-forward.coffee

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FastForwardView = require './fast-forward-view'
2+
{CompositeDisposable} = require 'atom'
3+
4+
module.exports = FastForward =
5+
fastForwardView: null
6+
modalPanel: null
7+
subscriptions: null
8+
9+
activate: (state) ->
10+
@fastForwardView = new FastForwardView(state.fastForwardViewState)
11+
@modalPanel = atom.workspace.addModalPanel(item: @fastForwardView.getElement(), visible: false)
12+
13+
# Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
14+
@subscriptions = new CompositeDisposable
15+
16+
# Register command that toggles this view
17+
@subscriptions.add atom.commands.add 'atom-workspace', 'fast-forward:toggle': => @toggle()
18+
19+
deactivate: ->
20+
@modalPanel.destroy()
21+
@subscriptions.dispose()
22+
@fastForwardView.destroy()
23+
24+
serialize: ->
25+
fastForwardViewState: @fastForwardView.serialize()
26+
27+
toggle: ->
28+
console.log 'FastForward was toggled!'
29+
30+
if @modalPanel.isVisible()
31+
@modalPanel.hide()
32+
else
33+
@modalPanel.show()

menus/fast-forward.cson

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details
2+
'context-menu':
3+
'atom-text-editor': [
4+
{
5+
'label': 'Toggle fast-forward'
6+
'command': 'fast-forward:toggle'
7+
}
8+
]
9+
'menu': [
10+
{
11+
'label': 'Packages'
12+
'submenu': [
13+
'label': 'fast-forward'
14+
'submenu': [
15+
{
16+
'label': 'Toggle'
17+
'command': 'fast-forward:toggle'
18+
}
19+
]
20+
]
21+
}
22+
]

package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "fast-forward",
3+
"main": "./lib/fast-forward",
4+
"version": "0.0.0",
5+
"description": "A short description of your package",
6+
"keywords": [
7+
],
8+
"activationCommands": {
9+
"atom-workspace": "fast-forward:toggle"
10+
},
11+
"repository": "https://github.com/atom/fast-forward",
12+
"license": "MIT",
13+
"engines": {
14+
"atom": ">=1.0.0 <2.0.0"
15+
},
16+
"dependencies": {
17+
}
18+
}

spec/fast-forward-spec.coffee

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
FastForward = require '../lib/fast-forward'
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 "FastForward", ->
9+
[workspaceElement, activationPromise] = []
10+
11+
beforeEach ->
12+
workspaceElement = atom.views.getView(atom.workspace)
13+
activationPromise = atom.packages.activatePackage('fast-forward')
14+
15+
describe "when the fast-forward:toggle event is triggered", ->
16+
it "hides and shows the modal panel", ->
17+
# Before the activation event the view is not on the DOM, and no panel
18+
# has been created
19+
expect(workspaceElement.querySelector('.fast-forward')).not.toExist()
20+
21+
# This is an activation event, triggering it will cause the package to be
22+
# activated.
23+
atom.commands.dispatch workspaceElement, 'fast-forward:toggle'
24+
25+
waitsForPromise ->
26+
activationPromise
27+
28+
runs ->
29+
expect(workspaceElement.querySelector('.fast-forward')).toExist()
30+
31+
fastForwardElement = workspaceElement.querySelector('.fast-forward')
32+
expect(fastForwardElement).toExist()
33+
34+
fastForwardPanel = atom.workspace.panelForItem(fastForwardElement)
35+
expect(fastForwardPanel.isVisible()).toBe true
36+
atom.commands.dispatch workspaceElement, 'fast-forward:toggle'
37+
expect(fastForwardPanel.isVisible()).toBe false
38+
39+
it "hides and shows the view", ->
40+
# This test shows you an integration test testing at the view level.
41+
42+
# Attaching the workspaceElement to the DOM is required to allow the
43+
# `toBeVisible()` matchers to work. Anything testing visibility or focus
44+
# requires that the workspaceElement is on the DOM. Tests that attach the
45+
# workspaceElement to the DOM are generally slower than those off DOM.
46+
jasmine.attachToDOM(workspaceElement)
47+
48+
expect(workspaceElement.querySelector('.fast-forward')).not.toExist()
49+
50+
# This is an activation event, triggering it causes the package to be
51+
# activated.
52+
atom.commands.dispatch workspaceElement, 'fast-forward:toggle'
53+
54+
waitsForPromise ->
55+
activationPromise
56+
57+
runs ->
58+
# Now we can test for view visibility
59+
fastForwardElement = workspaceElement.querySelector('.fast-forward')
60+
expect(fastForwardElement).toBeVisible()
61+
atom.commands.dispatch workspaceElement, 'fast-forward:toggle'
62+
expect(fastForwardElement).not.toBeVisible()

spec/fast-forward-view-spec.coffee

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FastForwardView = require '../lib/fast-forward-view'
2+
3+
describe "FastForwardView", ->
4+
it "has one valid test", ->
5+
expect("life").toBe "easy"

styles/fast-forward.less

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// The ui-variables file is provided by base themes provided by Atom.
2+
//
3+
// See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less
4+
// for a full listing of what's available.
5+
@import "ui-variables";
6+
7+
.fast-forward {
8+
}

0 commit comments

Comments
 (0)