weatherhacks 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ module WeatherHacks #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -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&#10;</xsl:text>
7
+ <xsl:text> module ForecastMap&#10;</xsl:text>
8
+ <xsl:apply-templates select="//*/area"/>
9
+ <xsl:text> end&#10;</xsl:text>
10
+ <xsl:text>end&#10;</xsl:text>
11
+ </xsl:template>
12
+
13
+ <xsl:template match="area">
14
+ <xsl:text> </xsl:text>
15
+ <xsl:text>area(&quot;</xsl:text>
16
+ <xsl:value-of select="@title"/>
17
+ <xsl:text>&quot;, &quot;</xsl:text>
18
+ <xsl:value-of select="@source"/>
19
+ <xsl:text>&quot;) do&#10;</xsl:text>
20
+ <xsl:apply-templates select="pref"/>
21
+ <xsl:text> </xsl:text>
22
+ <xsl:text>end&#10;</xsl:text>
23
+ </xsl:template>
24
+
25
+ <xsl:template match="pref">
26
+ <xsl:text> </xsl:text>
27
+ <xsl:text>pref(&quot;</xsl:text>
28
+ <xsl:value-of select="@title"/>
29
+ <xsl:text>&quot;) do&#10;</xsl:text>
30
+ <xsl:apply-templates select="city"/>
31
+ <xsl:text> </xsl:text>
32
+ <xsl:text>end&#10;</xsl:text>
33
+ </xsl:template>
34
+
35
+ <xsl:template match="city">
36
+ <xsl:text> </xsl:text>
37
+ <xsl:text>city(&quot;</xsl:text>
38
+ <xsl:value-of select="@title"/>
39
+ <xsl:text>&quot;, </xsl:text>
40
+ <xsl:value-of select="@id"/>
41
+ <xsl:text>, &quot;</xsl:text>
42
+ <xsl:value-of select="@source"/>
43
+ <xsl:text>&quot;)&#10;</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)