weatherhacks 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +56 -0
- data/Manifest.txt +30 -0
- data/README.txt +9 -0
- data/Rakefile +4 -0
- data/bin/lwws +58 -0
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +17 -0
- data/lib/weatherhacks/forecastmap.rb +266 -0
- data/lib/weatherhacks/lwws.rb +140 -0
- data/lib/weatherhacks/version.rb +9 -0
- data/lib/weatherhacks.rb +58 -0
- data/misc/forecastmap.xsl +45 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/lwws_spec.rb +243 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +11 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/weatherhacks.rake +20 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +119 -0
- data/website/index.txt +57 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +80 -0
data/lib/weatherhacks.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module WeatherHacks
|
2
|
+
module ForecastMap
|
3
|
+
class Area
|
4
|
+
attr_reader :name, :rss, :prefs
|
5
|
+
def initialize(name, rss)
|
6
|
+
@name = name
|
7
|
+
@rss = rss
|
8
|
+
@prefs = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def pref(name, &block)
|
12
|
+
pref = Pref.new(name)
|
13
|
+
pref.instance_eval(&block)
|
14
|
+
@prefs << pref
|
15
|
+
PREF[pref.name] = pref
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Pref
|
20
|
+
attr_reader :name, :cities
|
21
|
+
def initialize(name)
|
22
|
+
@name = name
|
23
|
+
@cities = []
|
24
|
+
end
|
25
|
+
|
26
|
+
def city(name, id, rss)
|
27
|
+
city = City.new(name, id, rss)
|
28
|
+
@cities << city
|
29
|
+
CITY[city.name] = city
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class City
|
34
|
+
attr_reader :name, :id, :rss
|
35
|
+
def initialize(name, id, rss)
|
36
|
+
@name = name
|
37
|
+
@id = id
|
38
|
+
@rss = rss
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
AREA = Hash.new
|
43
|
+
PREF = Hash.new
|
44
|
+
CITY = Hash.new
|
45
|
+
AREAS = Array.new
|
46
|
+
|
47
|
+
def self.area(title, rss, &block)
|
48
|
+
area = Area.new(title, rss)
|
49
|
+
area.instance_eval(&block)
|
50
|
+
AREA[area.name] = area
|
51
|
+
AREAS << area
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
require "weatherhacks/lwws"
|
57
|
+
require "weatherhacks/forecastmap"
|
58
|
+
require "weatherhacks/version"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
3
|
+
<xsl:output method="text" standalone="yes"/>
|
4
|
+
|
5
|
+
<xsl:template match="/">
|
6
|
+
<xsl:text>module WeatherHacks </xsl:text>
|
7
|
+
<xsl:text> module ForecastMap </xsl:text>
|
8
|
+
<xsl:apply-templates select="//*/area"/>
|
9
|
+
<xsl:text> end </xsl:text>
|
10
|
+
<xsl:text>end </xsl:text>
|
11
|
+
</xsl:template>
|
12
|
+
|
13
|
+
<xsl:template match="area">
|
14
|
+
<xsl:text> </xsl:text>
|
15
|
+
<xsl:text>area("</xsl:text>
|
16
|
+
<xsl:value-of select="@title"/>
|
17
|
+
<xsl:text>", "</xsl:text>
|
18
|
+
<xsl:value-of select="@source"/>
|
19
|
+
<xsl:text>") do </xsl:text>
|
20
|
+
<xsl:apply-templates select="pref"/>
|
21
|
+
<xsl:text> </xsl:text>
|
22
|
+
<xsl:text>end </xsl:text>
|
23
|
+
</xsl:template>
|
24
|
+
|
25
|
+
<xsl:template match="pref">
|
26
|
+
<xsl:text> </xsl:text>
|
27
|
+
<xsl:text>pref("</xsl:text>
|
28
|
+
<xsl:value-of select="@title"/>
|
29
|
+
<xsl:text>") do </xsl:text>
|
30
|
+
<xsl:apply-templates select="city"/>
|
31
|
+
<xsl:text> </xsl:text>
|
32
|
+
<xsl:text>end </xsl:text>
|
33
|
+
</xsl:template>
|
34
|
+
|
35
|
+
<xsl:template match="city">
|
36
|
+
<xsl:text> </xsl:text>
|
37
|
+
<xsl:text>city("</xsl:text>
|
38
|
+
<xsl:value-of select="@title"/>
|
39
|
+
<xsl:text>", </xsl:text>
|
40
|
+
<xsl:value-of select="@id"/>
|
41
|
+
<xsl:text>, "</xsl:text>
|
42
|
+
<xsl:value-of select="@source"/>
|
43
|
+
<xsl:text>") </xsl:text>
|
44
|
+
</xsl:template>
|
45
|
+
</xsl:stylesheet>
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
begin
|
5
|
+
require 'newgem'
|
6
|
+
rescue LoadError
|
7
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
8
|
+
puts "Install: gem install newgem\n\n"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
require 'redcloth'
|
12
|
+
require 'syntax/convertors/html'
|
13
|
+
require 'erb'
|
14
|
+
require File.dirname(__FILE__) + '/../lib/weatherhacks/version.rb'
|
15
|
+
|
16
|
+
version = WeatherHacks::VERSION::STRING
|
17
|
+
download = 'http://rubyforge.org/projects/weatherhacks'
|
18
|
+
|
19
|
+
class Fixnum
|
20
|
+
def ordinal
|
21
|
+
# teens
|
22
|
+
return 'th' if (10..19).include?(self % 100)
|
23
|
+
# others
|
24
|
+
case self % 10
|
25
|
+
when 1: return 'st'
|
26
|
+
when 2: return 'nd'
|
27
|
+
when 3: return 'rd'
|
28
|
+
else return 'th'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Time
|
34
|
+
def pretty
|
35
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_syntax(syntax, source)
|
40
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length >= 1
|
44
|
+
src, template = ARGV
|
45
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
|
46
|
+
|
47
|
+
else
|
48
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
49
|
+
exit!
|
50
|
+
end
|
51
|
+
|
52
|
+
template = ERB.new(File.open(template).read)
|
53
|
+
|
54
|
+
title = nil
|
55
|
+
body = nil
|
56
|
+
File.open(src) do |fsrc|
|
57
|
+
title_text = fsrc.readline
|
58
|
+
body_text = fsrc.read
|
59
|
+
syntax_items = []
|
60
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
61
|
+
ident = syntax_items.length
|
62
|
+
element, syntax, source = $1, $2, $3
|
63
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
64
|
+
"syntax-temp-#{ident}"
|
65
|
+
}
|
66
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
67
|
+
body = RedCloth.new(body_text).to_html
|
68
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
69
|
+
end
|
70
|
+
stat = File.stat(src)
|
71
|
+
created = stat.ctime
|
72
|
+
modified = stat.mtime
|
73
|
+
|
74
|
+
$stdout << template.result(binding)
|