Skip to content

Commit

Permalink
new DOM management with vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Jul 28, 2015
0 parents commit 7ee1314
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 0 deletions.
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) 2015 <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 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# header-42 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)
11 changes: 11 additions & 0 deletions keymaps/header-42.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Keybindings require three things to be fully defined: A selector that is
# matched against the focused element, the keystroke and the command to
# execute.
#
# Below is a basic keybinding which registers on all platforms by applying to
# the root workspace element.

# For more detailed documentation see
# https://atom.io/docs/latest/behind-atom-keymaps-in-depth
'atom-workspace':
'cmd-alt-h': 'header-42:insert'
Empty file added lib/header-42-view.coffee
Empty file.
33 changes: 33 additions & 0 deletions lib/header-42.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{CompositeDisposable} = require 'atom'

module.exports = Header42 =
subscriptions: null
insertTemplateStr: null

activate: (state) ->
atom.workspace.observeTextEditors (editor) =>
editor.getBuffer().onWillSave => @update(editor.getBuffer())

#
# regex: %-(\d*)s

# Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
@subscriptions = new CompositeDisposable

# Register command that toggles this view
@subscriptions.add atom.commands.add 'atom-workspace', 'header-42:insert': => @insert()

deactivate: ->
@subscriptions.dispose()

serialize: ->
header42ViewState: @header42View.serialize()

update: ->
#

insert: ->
console.log 'Header42 was toggled!'
textEditor = atom.workspace.getActiveTextEditor()
textEditorElement = atom.views.getView(textEditor)
textEditorElement.setAttribute("hasheader", true)
12 changes: 12 additions & 0 deletions lib/headers/ASM.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; **************************************************************************** ;
; ;
; ::: :::::::: ;
; %-51s:+: :+: :+: ;
; +:+ +:+ +:+ ;
; By: %-43s+#+ +:+ +#+ ;
; +#+#+#+#+#+ +#+ ;
; Created: %-41s#+# #+# ;
; Updated: %-40s### ########.fr ;
; ;
; **************************************************************************** ;

12 changes: 12 additions & 0 deletions lib/headers/C.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* %-51s:+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: %-43s+#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: %-41s#+# #+# */
/* Updated: %-40s### ########.fr */
/* */
/* ************************************************************************** */

11 changes: 11 additions & 0 deletions lib/headers/Haskell.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{- ************************************************************************** -}
{- -}
{- ::: :::::::: -}
{- %-51s:+: :+: :+: -}
{- +:+ +:+ +:+ -}
{- By: %-43s+#+ +:+ +#+ -}
{- +#+#+#+#+#+ +#+ -}
{- Created: %-41s#+# #+# -}
{- Updated: %-40s### ########.fr -}
{- -}
{- ************************************************************************** -}
9 changes: 9 additions & 0 deletions lib/headers/Html.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
::: ::::::::
%-51s:+: :+: :+:
+:+ +:+ +:+
By: %-43s+#+ +:+ +#+
+#+#+#+#+#+ +#+
Created: %-41s#+# #+#
Updated: %-40s### ########.fr
-->
11 changes: 11 additions & 0 deletions lib/headers/Lua.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[ ########################################################################## ]]
[[ ]]
[[ ::: :::::::: ]]
[[ %-51s:+: :+: :+: ]]
[[ +:+ +:+ +:+ ]]
[[ By: %-43s+#+ +:+ +#+ ]]
[[ +#+#+#+#+#+ +#+ ]]
[[ Created: %-41s#+# #+# ]]
[[ Updated: %-40s### ########.fr ]]
[[ ]]
[[ ########################################################################## ]]
11 changes: 11 additions & 0 deletions lib/headers/Makefile.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# %-51s:+: :+: :+: #
# +:+ +:+ +:+ #
# By: %-43s+#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: %-41s#+# #+# #
# Updated: %-40s### ########.fr #
# #
# **************************************************************************** #
11 changes: 11 additions & 0 deletions lib/headers/OCaml.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(* ************************************************************************** *)
(* *)
(* ::: :::::::: *)
(* %-51s:+: :+: :+: *)
(* +:+ +:+ +:+ *)
(* By: %-43s+#+ +:+ +#+ *)
(* +#+#+#+#+#+ +#+ *)
(* Created: %-41s#+# #+# *)
(* Updated: %-40s### ########.fr *)
(* *)
(* ************************************************************************** *)
13 changes: 13 additions & 0 deletions lib/headers/Php.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* %-51s:+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: %-43s+#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: %-41s#+# #+# */
/* Updated: %-40s### ########.fr */
/* */
/* ************************************************************************** */

1 change: 1 addition & 0 deletions menus/header-42.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "header-42",
"main": "./lib/header-42",
"version": "0.0.0",
"description": "A short description of your package",
"keywords": [
],
"activationCommands": {
"atom-workspace": "header-42:insert"
},
"repository": "https://github.com/atom/header-42",
"license": "MIT",
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {
}
}
62 changes: 62 additions & 0 deletions spec/header-42-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Header42 = require '../lib/header-42'

# 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 "Header42", ->
[workspaceElement, activationPromise] = []

beforeEach ->
workspaceElement = atom.views.getView(atom.workspace)
activationPromise = atom.packages.activatePackage('header-42')

describe "when the header-42:insert 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('.header-42')).not.toExist()

# This is an activation event, triggering it will cause the package to be
# activated.
atom.commands.dispatch workspaceElement, 'header-42:insert'

waitsForPromise ->
activationPromise

runs ->
expect(workspaceElement.querySelector('.header-42')).toExist()

# header42Element = workspaceElement.querySelector('.header-42')
# expect(header42Element).toExist()
#
# header42Panel = atom.workspace.panelForItem(header42Element)
# expect(header42Panel.isVisible()).toBe true
# atom.commands.dispatch workspaceElement, 'header-42:insert'
# expect(header42Panel.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('.header-42')).not.toExist()

# This is an activation event, triggering it causes the package to be
# activated.
atom.commands.dispatch workspaceElement, 'header-42:insert'

waitsForPromise ->
activationPromise

runs ->
# Now we can test for view visibility
header42Element = workspaceElement.querySelector('.header-42')
expect(header42Element).toBeVisible()
atom.commands.dispatch workspaceElement, 'header-42:insert'
expect(header42Element).not.toBeVisible()
8 changes: 8 additions & 0 deletions styles/header-42.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";

.header-42 {
}

0 comments on commit 7ee1314

Please sign in to comment.