From 43a700b74fa738e85e8ce2cf6d4ef11f8659f6b8 Mon Sep 17 00:00:00 2001 From: Derek Schneider Date: Tue, 9 Jun 2015 19:17:33 -0400 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ CHANGELOG.md | 3 ++ LICENSE.md | 20 +++++++++++ README.md | 7 ++++ keymaps/weather.cson | 11 +++++++ lib/weather-view.coffee | 39 ++++++++++++++++++++++ lib/weather.coffee | 26 +++++++++++++++ menus/weather.cson | 10 ++++++ package.json | 22 +++++++++++++ spec/weather-spec.coffee | 62 +++++++++++++++++++++++++++++++++++ spec/weather-view-spec.coffee | 5 +++ styles/weather.less | 8 +++++ 12 files changed, 216 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 keymaps/weather.cson create mode 100644 lib/weather-view.coffee create mode 100644 lib/weather.coffee create mode 100644 menus/weather.cson create mode 100644 package.json create mode 100644 spec/weather-spec.coffee create mode 100644 spec/weather-view-spec.coffee create mode 100644 styles/weather.less diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ade14b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c3d858c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.1.0 - First Release +* Every feature added +* Every bug fixed diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..40a0eeb --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2015 + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..39fc96e --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Weather package + +Displays the temperature in the status bar of Atom. + +![Screenshot](http://imgur.com/dShmGtR) + +More features coming soon, feel free to put in requests or contribute! diff --git a/keymaps/weather.cson b/keymaps/weather.cson new file mode 100644 index 0000000..9fa4b00 --- /dev/null +++ b/keymaps/weather.cson @@ -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': + 'ctrl-alt-o': 'weather:toggle' diff --git a/lib/weather-view.coffee b/lib/weather-view.coffee new file mode 100644 index 0000000..99650b3 --- /dev/null +++ b/lib/weather-view.coffee @@ -0,0 +1,39 @@ +class WeatherView extends HTMLElement + initialize: -> + @classList.add('weather', 'inline-block') + + @content = document.createElement('div') + @content.classList.add('weather-content') + + @appendChild(@content) + + @showLoading() + @fetchWeather() + + showLoading: -> + @content.innerText = 'Getting weather for: ' + @zipcode() + + zipcode: -> + atom.config.get('weather.zipcode') + + weatherUrl: -> + 'http://api.openweathermap.org/data/2.5/weather?zip=' + @zipcode() + ',us&units=imperial' + + showWeather: (weather) -> + @content.innerText = weather.main.temp + 'F' + + fetchWeather: -> + console.info('Fetching weather') + request = new XMLHttpRequest() + request.open 'GET', @weatherUrl() + request.send() + view = @ + + request.onreadystatechange = -> + if (request.readyState == 4 && request.status == 200) + view.showWeather JSON.parse(request.responseText) + + +module.exports = document.registerElement('status-bar-weather', + prototype: WeatherView.prototype, + extends: 'div') diff --git a/lib/weather.coffee b/lib/weather.coffee new file mode 100644 index 0000000..eefc138 --- /dev/null +++ b/lib/weather.coffee @@ -0,0 +1,26 @@ +WeatherView = require './weather-view' +{CompositeDisposable} = require 'atom' + +module.exports = Weather = + weatherView: null + subscriptions: null + config: + zipcode: + type: 'string' + default: '43201' + + consumeStatusBar: (statusBar) -> + @statusBarTile = statusBar.addRightTile(item: @weatherView, priority: 100) + + activate: (state) -> + console.info('weather activated') + + @weatherView = new WeatherView() + @weatherView.initialize() + + @subscriptions = new CompositeDisposable + + deactivate: -> + @subscriptions.dispose() + @statusBarTile?.destroy() + @statusBarTile = null diff --git a/menus/weather.cson b/menus/weather.cson new file mode 100644 index 0000000..bee420e --- /dev/null +++ b/menus/weather.cson @@ -0,0 +1,10 @@ +# See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details +'menu': [ + { + 'label': 'Packages' + 'submenu': [ + 'label': 'Weather' + 'submenu': [] + ] + } +] diff --git a/package.json b/package.json new file mode 100644 index 0000000..c4466cc --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "weather", + "main": "./lib/weather", + "version": "0.1.0", + "description": "A short description of your package", + "keywords": [ + ], + "repository": "https://github.com/atom/weather", + "license": "MIT", + "engines": { + "atom": ">=0.174.0 <2.0.0" + }, + "dependencies": { + }, + "consumedServices": { + "status-bar": { + "versions": { + "^1.0.0": "consumeStatusBar" + } + } + } +} diff --git a/spec/weather-spec.coffee b/spec/weather-spec.coffee new file mode 100644 index 0000000..dbdafcf --- /dev/null +++ b/spec/weather-spec.coffee @@ -0,0 +1,62 @@ +Weather = require '../lib/weather' + +# 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 "Weather", -> + [workspaceElement, activationPromise] = [] + + beforeEach -> + workspaceElement = atom.views.getView(atom.workspace) + activationPromise = atom.packages.activatePackage('weather') + + describe "when the weather: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('.weather')).not.toExist() + + # This is an activation event, triggering it will cause the package to be + # activated. + atom.commands.dispatch workspaceElement, 'weather:toggle' + + waitsForPromise -> + activationPromise + + runs -> + expect(workspaceElement.querySelector('.weather')).toExist() + + weatherElement = workspaceElement.querySelector('.weather') + expect(weatherElement).toExist() + + weatherPanel = atom.workspace.panelForItem(weatherElement) + expect(weatherPanel.isVisible()).toBe true + atom.commands.dispatch workspaceElement, 'weather:toggle' + expect(weatherPanel.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('.weather')).not.toExist() + + # This is an activation event, triggering it causes the package to be + # activated. + atom.commands.dispatch workspaceElement, 'weather:toggle' + + waitsForPromise -> + activationPromise + + runs -> + # Now we can test for view visibility + weatherElement = workspaceElement.querySelector('.weather') + expect(weatherElement).toBeVisible() + atom.commands.dispatch workspaceElement, 'weather:toggle' + expect(weatherElement).not.toBeVisible() diff --git a/spec/weather-view-spec.coffee b/spec/weather-view-spec.coffee new file mode 100644 index 0000000..06b5654 --- /dev/null +++ b/spec/weather-view-spec.coffee @@ -0,0 +1,5 @@ +WeatherView = require '../lib/weather-view' + +describe "WeatherView", -> + it "has one valid test", -> + expect("life").toBe "easy" diff --git a/styles/weather.less b/styles/weather.less new file mode 100644 index 0000000..a09242c --- /dev/null +++ b/styles/weather.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"; + +.weather { +}