Skip to content

Commit

Permalink
Added (I think) all of the necessary scaffolding to handle the 24-hou…
Browse files Browse the repository at this point in the history
…r summaries.
  • Loading branch information
Jason LaPorte committed Jul 3, 2013
1 parent 31b2cf5 commit e9e2aa6
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 34 deletions.
32 changes: 22 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ <h1>Dark Sky Multilingual Text Summaries</h1>

<tr>
<td class="input"><pre>(sentence
(starting
(starting-in
very-light-snow
(minutes
35)))</pre></td>
Expand All @@ -256,7 +256,7 @@ <h1>Dark Sky Multilingual Text Summaries</h1>

<tr>
<td class="input"><pre>(sentence
(stopping
(stopping-in
light-rain
(minutes
15)))</pre></td>
Expand All @@ -266,7 +266,7 @@ <h1>Dark Sky Multilingual Text Summaries</h1>
<tr>
<td class="input"><pre>(sentence
(clauses
(starting
(starting-in
heavy-sleet
(minutes
20))
Expand All @@ -279,11 +279,11 @@ <h1>Dark Sky Multilingual Text Summaries</h1>
<tr>
<td class="input"><pre>(sentence
(clauses
(stopping
(stopping-in
medium-rain
(minutes
25))
(starting-later
(starting-again-later
(minutes
8))))</pre></td>
<td class="en">Rain stopping in 25 min., starting again 8 min. later.</td>
Expand All @@ -293,6 +293,13 @@ <h1>Dark Sky Multilingual Text Summaries</h1>
block and the "daily" data points, and represent the weather conditions
over a period of twenty-four hours. -->

<tr>
<td class="input"><pre>(sentence
(for-day
clear))</pre></td>
<td class="en">Clear throughout the day.</td>
</tr>

<!-- FIXME -->

<!-- 7-DAY SUMMARIES. These summaries are used on the "daily" data
Expand All @@ -307,7 +314,8 @@ <h1>Dark Sky Multilingual Text Summaries</h1>
(for-week
no-precipitation)
(on
(temperatures-peaking
(peaking
temperatures
(fahrenheit
85))
tomorrow)))</pre></td>
Expand All @@ -320,7 +328,8 @@ <h1>Dark Sky Multilingual Text Summaries</h1>
(over-weekend
mixed-precipitation)
(on
(temperatures-rising
(rising
temperatures
(celsius
32))
thursday)))</pre></td>
Expand All @@ -334,7 +343,8 @@ <h1>Dark Sky Multilingual Text Summaries</h1>
medium-rain
today)
(on
(temperatures-valleying
(valleying
temperatures
(fahrenheit
15))
friday)))</pre></td>
Expand All @@ -350,7 +360,8 @@ <h1>Dark Sky Multilingual Text Summaries</h1>
monday
tuesday))
(on
(temperatures-falling
(falling
temperatures
(celsius
0))
sunday)))</pre></td>
Expand All @@ -366,7 +377,8 @@ <h1>Dark Sky Multilingual Text Summaries</h1>
wednesday
saturday))
(on
(temperatures-peaking
(peaking
temperatures
(fahrenheit
100))
monday)))</pre></td>
Expand Down
26 changes: 15 additions & 11 deletions src/darksky.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ var DarkSky;
if(typeof expr === "number")
return expr.toString();

if(typeof expr === "string")
return template.hasOwnProperty(expr) ? template[expr] : expr;
else if(typeof expr === "string") {
if(template.hasOwnProperty(expr))
return template[expr];
}

if(Array.isArray(expr) && template.hasOwnProperty(expr[0])) {
if(typeof template[expr[0]] === "string")
return template[expr[0]].replace(/\$\d+/g, function(n) {
return parse(template, expr[n.slice(1)|0]);
});
else if(Array.isArray(expr)) {
if(template.hasOwnProperty(expr[0])) {
if(typeof template[expr[0]] === "string")
return template[expr[0]].replace(/\$\d+/g, function(n) {
return parse(template, expr[n.slice(1)|0]);
});

if(typeof template[expr[0]] === "function")
return template[expr[0]].apply(null, expr.slice(1).map(function(arg) {
return parse(template, arg);
}));
if(typeof template[expr[0]] === "function")
return template[expr[0]].apply(null, expr.slice(1).map(function(arg) {
return parse(template, arg);
}));
}
}

throw new Error("Invalid expression.");
Expand Down
74 changes: 61 additions & 13 deletions src/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ var DarkSkyEnglish = {
"light-clouds": "partly cloudy",
"medium-clouds": "mostly cloudy",
"heavy-clouds": "overcast",
"temperatures": "temperatures",
"today-morning": "this morning",
"later-today-morning": "later this morning",
"today-afternoon": "this afternoon",
"later-today-afternoon": "later this afternoon",
"today-evening": "this evening",
"later-today-evening": "later this evening",
"today-night": "tonight",
"later-today-night": "later tonight",
"tomorrow-morning": "tomorrow morning",
"tomorrow-afternoon": "tomorrow afternoon",
"tomorrow-evening": "tomorrow evening",
"tomorrow-night": "tomorrow night",
"morning": "morning",
"afternoon": "afternoon",
"evening": "evening",
"night": "night",
"today": "today",
"tomorrow": "tomorrow",
"sunday": "Sunday",
Expand All @@ -40,29 +57,60 @@ var DarkSkyEnglish = {
"minutes": "$1 min.",
"fahrenheit": "$1\u00B0F",
"celsius": "$1\u00B0C",
"and": "$1 and $2",
"and": function(/* ... */) {
switch(arguments.length) {
case 1:
return arguments[0];

case 2:
return arguments[0] + " and " + arguments[1];

default:
return Array.prototype.slice.call(arguments, 0, -1).join(", ") +
", and " + arguments[arguments.length - 1];
}
},
"range": "$1 through $2",
"clauses": function(one, two) {
return one +
(one.indexOf(",") === -1 && two.indexOf(",") === -1 ? ", " : "; ") +
two;
},
"range": "$1 through $2",
"for-hour": "$1 for the hour",
"starting": "$1 starting in $2",
"stopping": "$1 stopping in $2",
"starting-later": "starting again $1 later",
"stopping-later": "stopping $1 later",
"for-week": "$1 throughout the week",
"over-weekend": "$1 over the weekend",
"temperatures-peaking": "temperatures peaking at $1",
"temperatures-rising": "temperatures rising to $1",
"temperatures-valleying": "temperatures bottoming out at $1",
"temperatures-falling": "temperatures falling to $1",
"during": function(period) {
switch(period) {
case "morning":
case "afternoon":
case "evening":
return "in the " + period;

case "night":
return "overnight";

default:
return period;
}
},
"on": function(condition, day) {
return condition +
(day === "today" || day === "tomorrow" ? " " : " on ") +
day;
},
"for-hour": "$1 for the hour",
"for-day": "$1 throughout the day",
"for-week": "$1 throughout the week",
"over-weekend": "$1 over the weekend",
"starting": "$1 starting $2",
"starting-in": "$1 starting in $2",
"stopping-in": "$1 stopping in $2",
"until": "$1 until $2",
"continuing-until": "$1 continuing until $2",
"peaking": "$1 peaking at $2",
"rising": "$1 rising to $2",
"valleying": "$1 bottoming out at $2",
"falling": "$1 falling to $2",
"starting-again": "starting again $1",
"starting-again-later": "starting again $1 later",
"stopping-later": "stopping $1 later",
/* Capitalize the first letter of every word, except if that word is
* "and". (This is a very crude bastardization of proper English titling
* rules, but it is adequate for the purposes of this module.) */
Expand Down

0 comments on commit e9e2aa6

Please sign in to comment.