Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit 3c004e7

Browse files
committed
Added gulp for a build process and speed up pushing out a release. Automate ALL THE THINGS. Also some code cleanup and bug fixes.
Fix for 3200 (not available) condition code and related image [#77]. Fixed my assumption of query being present [#72].
1 parent 36f0f22 commit 3c004e7

6 files changed

Lines changed: 146 additions & 61 deletions

File tree

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

component.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44
"description": "A simple jQuery plugin to display current weather data for any location and doesn't get in your way.",
55
"version": "2.6.0",
66
"main": "jquery.simpleWeather.js",
7-
"scripts": ["jquery.simpleWeather.js"],
7+
"scripts": [
8+
"jquery.simpleWeather.js"
9+
],
810
"dependencies": {
911
"components/jquery": "*"
1012
},
1113
"author": "James Fleeting",
12-
"keywords": ["jquery", "javascript", "weather", "plugin", "simple", "monkeecreate"],
14+
"keywords": [
15+
"jquery",
16+
"javascript",
17+
"weather",
18+
"plugin",
19+
"simple",
20+
"monkeecreate"
21+
],
1322
"license": "MIT",
1423
"demo": "http://simpleweatherjs.com"
1524
}

gulpfile.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var gulp = require('gulp'),
2+
uglify = require('gulp-uglify'),
3+
jshint = require('gulp-jshint'),
4+
rename = require('gulp-rename'),
5+
bump = require('gulp-bump'),
6+
notify = require('gulp-notify'),
7+
git = require('gulp-git'),
8+
size = require('gulp-size'),
9+
pkg = require('./package.json');
10+
11+
var source = "jquery.simpleWeather.js",
12+
sourceMin = "jquery.simpleWeather.min.js";
13+
14+
gulp.task('lint', function () {
15+
return gulp.src(source)
16+
.pipe(jshint('.jshintrc'))
17+
.pipe(jshint.reporter('jshint-stylish'));
18+
});
19+
20+
21+
gulp.task('build', ['lint'], function () {
22+
return gulp.src(source)
23+
.pipe(rename(sourceMin))
24+
.pipe(uglify({preserveComments: 'all'}))
25+
.pipe(size())
26+
.pipe(gulp.dest('./'));
27+
});
28+
29+
gulp.task('bump', function () {
30+
return gulp.src(['./bower.json', './component.json', 'simpleweather.jquery.json'])
31+
.pipe(bump({version: pkg.version}))
32+
.pipe(gulp.dest('./'));
33+
});
34+
35+
gulp.task('tag', ['bump'], function () {
36+
return gulp.src('./')
37+
.pipe(git.commit('Version '+pkg.version))
38+
.pipe(git.tag(pkg.version, 'Version '+pkg.version))
39+
.pipe(git.push('monkee', 'master', '--tags'))
40+
.pipe(gulp.dest('./'));
41+
});

jquery.simpleWeather.js

Lines changed: 78 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Developed by James Fleeting <@fleetingftw> <http://iwasasuperhero.com>
99
* Another project from monkeeCreate <http://monkeecreate.com>
1010
*
11-
* Version 2.6.0 - Last updated: February 26 2014
11+
* Version 2.7.0 - Last updated: April 17 2014
1212
*/
1313
(function($) {
1414
"use strict";
@@ -23,7 +23,6 @@
2323
}, options);
2424

2525
var now = new Date();
26-
2726
var weatherUrl = '//query.yahooapis.com/v1/public/yql?format=json&rnd='+now.getFullYear()+now.getMonth()+now.getDay()+now.getHours()+'&diagnostics=true&callback=?&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=';
2827
if(options.location !== '') {
2928
weatherUrl += 'select * from weather.forecast where woeid in (select woeid from geo.placefinder where text="'+options.location+'" and gflags="R") and u="'+options.unit+'"';
@@ -37,71 +36,96 @@
3736
$.getJSON(
3837
encodeURI(weatherUrl),
3938
function(data) {
40-
if(data !== null && data.query.results !== null && data.query.results.channel.description !== 'Yahoo! Weather Error') {
39+
if(data !== null && data.query !== null && data.query.results !== null && data.query.results.channel.description !== 'Yahoo! Weather Error') {
4140
$.each(data.query.results, function(i, result) {
4241
if (result.constructor.toString().indexOf("Array") !== -1) {
4342
result = result[0];
4443
}
4544

45+
var altTemps = [], heatIndex, images = [];
4646
var compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'];
4747
var windDirection = compass[Math.round(result.wind.direction / 22.5)];
4848

4949
if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40) {
50-
var heatIndex = -42.379+2.04901523*result.item.condition.temp+10.14333127*result.atmosphere.humidity-0.22475541*result.item.condition.temp*result.atmosphere.humidity-6.83783*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(result.atmosphere.humidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))*result.atmosphere.humidity+8.5282*(Math.pow(10, -4))*result.item.condition.temp*(Math.pow(result.atmosphere.humidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow(result.item.condition.temp, 2))*(Math.pow(result.atmosphere.humidity,2));
50+
heatIndex = -42.379+2.04901523*result.item.condition.temp+10.14333127*result.atmosphere.humidity-0.22475541*result.item.condition.temp*result.atmosphere.humidity-6.83783*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(result.atmosphere.humidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))*result.atmosphere.humidity+8.5282*(Math.pow(10, -4))*result.item.condition.temp*(Math.pow(result.atmosphere.humidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow(result.item.condition.temp, 2))*(Math.pow(result.atmosphere.humidity,2));
5151
} else {
52-
var heatIndex = result.item.condition.temp;
52+
heatIndex = result.item.condition.temp;
5353
}
5454

5555
if(options.unit === "f") {
56-
var unitAlt = "c";
57-
var tempAlt = Math.round((5.0/9.0)*(result.item.condition.temp-32.0));
58-
var highAlt = Math.round((5.0/9.0)*(result.item.forecast[0].high-32.0));
59-
var lowAlt = Math.round((5.0/9.0)*(result.item.forecast[0].low-32.0));
60-
var tomorrowHighAlt = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0));
61-
var tomorrowLowAlt = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0));
62-
var forecastOneHighAlt = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0));
63-
var forecastOneLowAlt = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0));
64-
var forecastTwoHighAlt = Math.round((5.0/9.0)*(result.item.forecast[2].high-32.0));
65-
var forecastTwoLowAlt = Math.round((5.0/9.0)*(result.item.forecast[2].low-32.0));
66-
var forecastThreeHighAlt = Math.round((5.0/9.0)*(result.item.forecast[3].high-32.0));
67-
var forecastThreeLowAlt = Math.round((5.0/9.0)*(result.item.forecast[3].low-32.0));
68-
var forecastFourHighAlt = Math.round((5.0/9.0)*(result.item.forecast[4].high-32.0));
69-
var forecastFourLowAlt = Math.round((5.0/9.0)*(result.item.forecast[4].low-32.0));
56+
altTemps.unit = "c";
57+
altTemps.temp = Math.round((5.0/9.0)*(result.item.condition.temp-32.0));
58+
altTemps.high = Math.round((5.0/9.0)*(result.item.forecast[0].high-32.0));
59+
altTemps.low = Math.round((5.0/9.0)*(result.item.forecast[0].low-32.0));
60+
altTemps.forecastOneHigh = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0));
61+
altTemps.forecastOneLow = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0));
62+
altTemps.forecastTwoHigh = Math.round((5.0/9.0)*(result.item.forecast[2].high-32.0));
63+
altTemps.forecastTwoLow = Math.round((5.0/9.0)*(result.item.forecast[2].low-32.0));
64+
altTemps.forecastThreeHigh = Math.round((5.0/9.0)*(result.item.forecast[3].high-32.0));
65+
altTemps.forecastThreeLow = Math.round((5.0/9.0)*(result.item.forecast[3].low-32.0));
66+
altTemps.forecastFourHigh = Math.round((5.0/9.0)*(result.item.forecast[4].high-32.0));
67+
altTemps.forecastFourLow = Math.round((5.0/9.0)*(result.item.forecast[4].low-32.0));
68+
} else {
69+
altTemps.unit = "f";
70+
altTemps.temp = Math.round((9.0/5.0)*result.item.condition.temp+32.0);
71+
altTemps.high = Math.round((9.0/5.0)*result.item.forecast[0].high+32.0);
72+
altTemps.low = Math.round((9.0/5.0)*result.item.forecast[0].low+32.0);
73+
altTemps.forecastOneHigh = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0));
74+
altTemps.forecastOneLow = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0));
75+
altTemps.forecastTwoHigh = Math.round((9.0/5.0)*(result.item.forecast[2].high+32.0));
76+
altTemps.forecastTwoLow = Math.round((9.0/5.0)*(result.item.forecast[2].low+32.0));
77+
altTemps.forecastThreeHigh = Math.round((9.0/5.0)*(result.item.forecast[3].high+32.0));
78+
altTemps.forecastThreeLow = Math.round((9.0/5.0)*(result.item.forecast[3].low+32.0));
79+
altTemps.forecastFourHigh = Math.round((9.0/5.0)*(result.item.forecast[4].high+32.0));
80+
altTemps.forecastFourLow = Math.round((9.0/5.0)*(result.item.forecast[4].low+32.0));
81+
}
82+
83+
if(result.item.condition.code == "3200") {
84+
images.thumbnail = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
85+
images.image = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
7086
} else {
71-
var unitAlt = "f";
72-
var tempAlt = Math.round((9.0/5.0)*result.item.condition.temp+32.0);
73-
var highAlt = Math.round((9.0/5.0)*result.item.forecast[0].high+32.0);
74-
var lowAlt = Math.round((9.0/5.0)*result.item.forecast[0].low+32.0);
75-
var tomorrowHighAlt = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0));
76-
var tomorrowLowAlt = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0));
77-
var forecastOneHighAlt = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0));
78-
var forecastOneLowAlt = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0));
79-
var forecastTwoHighAlt = Math.round((9.0/5.0)*(result.item.forecast[2].high+32.0));
80-
var forecastTwoLowAlt = Math.round((9.0/5.0)*(result.item.forecast[2].low+32.0));
81-
var forecastThreeHighAlt = Math.round((9.0/5.0)*(result.item.forecast[3].high+32.0));
82-
var forecastThreeLowAlt = Math.round((9.0/5.0)*(result.item.forecast[3].low+32.0));
83-
var forecastFourHighAlt = Math.round((9.0/5.0)*(result.item.forecast[4].high+32.0));
84-
var forecastFourLowAlt = Math.round((9.0/5.0)*(result.item.forecast[4].low+32.0));
87+
images.thumbnail = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"ds.png";
88+
images.image = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"d.png";
8589
}
8690

91+
if(result.item.forecast[1].code == "3200")
92+
images.forecastOne = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
93+
else
94+
images.forecastOne = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png";
95+
96+
if(result.item.forecast[2].code == "3200")
97+
images.forecastTwo = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
98+
else
99+
images.forecastTwo = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[2].code+"d.png";
100+
101+
if(result.item.forecast[3].code == "3200")
102+
images.forecastThree = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
103+
else
104+
images.forecastThree = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[3].code+"d.png";
105+
106+
if(result.item.forecast[4].code == "3200")
107+
images.forecastFour = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
108+
else
109+
images.forecastFour = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[4].code+"d.png";
110+
87111
var weather = {
88112
title: result.item.title,
89113
temp: result.item.condition.temp,
90-
tempAlt: tempAlt,
114+
tempAlt: altTemps.temp,
91115
code: result.item.condition.code,
92116
todayCode: result.item.forecast[0].code,
93117
units:{
94118
temp: result.units.temperature,
95119
distance: result.units.distance,
96120
pressure: result.units.pressure,
97121
speed: result.units.speed,
98-
tempAlt: unitAlt
122+
tempAlt: altTemps.unit
99123
},
100124
currently: result.item.condition.text,
101125
high: result.item.forecast[0].high,
102-
highAlt: highAlt,
126+
highAlt: altTemps.high,
103127
low: result.item.forecast[0].low,
104-
lowAlt: lowAlt,
128+
lowAlt: altTemps.low,
105129
forecast: result.item.forecast[0].text,
106130
wind:{
107131
chill: result.wind.chill,
@@ -116,63 +140,63 @@
116140
sunrise: result.astronomy.sunrise,
117141
sunset: result.astronomy.sunset,
118142
description: result.item.description,
119-
thumbnail: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"ds.png",
120-
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"d.png",
143+
thumbnail: images.thumbnail,
144+
image: images.image,
121145
tomorrow:{
122146
high: result.item.forecast[1].high,
123-
highAlt: tomorrowHighAlt,
147+
highAlt: altTemps.forecastOneHigh,
124148
low: result.item.forecast[1].low,
125-
lowAlt: tomorrowLowAlt,
149+
lowAlt: altTemps.forecastOneLow,
126150
forecast: result.item.forecast[1].text,
127151
code: result.item.forecast[1].code,
128152
date: result.item.forecast[1].date,
129153
day: result.item.forecast[1].day,
130-
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png"
154+
image: images.forecastOne
131155
},
132156
forecasts:{
133157
one:{
134158
high: result.item.forecast[1].high,
135-
highAlt: forecastOneHighAlt,
159+
highAlt: altTemps.forecastOneHigh,
136160
low: result.item.forecast[1].low,
137-
lowAlt: forecastOneLowAlt,
161+
lowAlt: altTemps.forecastOneLow,
138162
forecast: result.item.forecast[1].text,
139163
code: result.item.forecast[1].code,
140164
date: result.item.forecast[1].date,
141165
day: result.item.forecast[1].day,
142-
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png"
166+
image: images.forecastOne
143167
},
144168
two:{
145169
high: result.item.forecast[2].high,
146-
highAlt: forecastTwoHighAlt,
170+
highAlt: altTemps.forecastTwoHigh,
147171
low: result.item.forecast[2].low,
148-
lowAlt: forecastTwoLowAlt,
172+
lowAlt: altTemps.forecastTwoLow,
149173
forecast: result.item.forecast[2].text,
150174
code: result.item.forecast[2].code,
151175
date: result.item.forecast[2].date,
152176
day: result.item.forecast[2].day,
153-
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[2].code+"d.png"
177+
image: images.forecastTwo
154178
},
155179
three:{
156180
high: result.item.forecast[3].high,
157-
highAlt: forecastThreeHighAlt,
181+
highAlt: altTemps.forecastThreeHigh,
158182
low: result.item.forecast[3].low,
159-
lowAlt: forecastThreeLowAlt,
183+
lowAlt: altTemps.forecastThreeLow,
160184
forecast: result.item.forecast[3].text,
161185
code: result.item.forecast[3].code,
162186
date: result.item.forecast[3].date,
163187
day: result.item.forecast[3].day,
164-
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[3].code+"d.png"
188+
image: images.forecastThree
165189
},
166190
four:{
167191
high: result.item.forecast[4].high,
168-
highAlt: forecastFourHighAlt,
192+
highAlt: altTemps.forecastFourHigh,
169193
low: result.item.forecast[4].low,
170-
lowAlt: forecastFourLowAlt,
194+
lowAlt: altTemps.forecastFourLow,
171195
forecast: result.item.forecast[4].text,
172196
code: result.item.forecast[4].code,
173197
date: result.item.forecast[4].date,
174198
day: result.item.forecast[4].day,
175-
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[4].code+"d.png"
199+
image: images.forecastFour
176200
},
177201
},
178202
city: result.location.city,

0 commit comments

Comments
 (0)