diff --git a/README.markdown b/README.markdown index a9f8cfa..e20fffc 100644 --- a/README.markdown +++ b/README.markdown @@ -18,7 +18,7 @@ The global\_config.yml file holds application-level settings. * __cache\_max\_age__: cache expiry time, in seconds. No caching is performed by TweetScope itself, this simply sets the value of the Cache-Control header for use with an external caching system. ### Site Configuration ### -Each site's config.yml file holds site-specific settings. +Each site's config.yml file holds site-specific settings. #### Query Settings #### diff --git a/Rakefile b/Rakefile index db6801c..99c9349 100644 --- a/Rakefile +++ b/Rakefile @@ -13,20 +13,20 @@ namespace :site do else site_name = STDIN.readline.chomp end - + site_dir = "sites/#{site_name}" public_dir = "public/#{site_name}" - + raise "Site already exists" if File.exists?(site_dir) - + puts "Creating directories: #{site_dir}, #{public_dir}" FileUtils.mkdir_p([site_dir, public_dir]) - + puts "Copying site files." File.open("#{site_dir}/config.yml",'w') {|f| f.write( open('lib/site_skel/config.yml').read.gsub("%%_SITENAME_%%",site_name) ) } - + File.open("#{site_dir}/index.haml",'w') {|f| f.write( open('lib/site_skel/index.haml').read.gsub("%%_SITENAME_%%",site_name) ) } - + puts "Copying public files." FileUtils.cp('lib/site_skel/public/style.css',public_dir) end diff --git a/lib/config_reader.rb b/lib/config_reader.rb index 2416c0a..6d1bd0d 100644 --- a/lib/config_reader.rb +++ b/lib/config_reader.rb @@ -7,18 +7,18 @@ def self.read config[site] = read_config_file("sites/#{site}/config.yml") end raise "No sites were found. Create a site using 'rake site:create' before running TweetScope." if config.keys.size == 1 - + config['_domains'] = build_domain_map(config) - + config end - + private - + def self.read_config_file(file) (File.exists?(file) && YAML::load_file(file)) || {} end - + def self.build_domain_map(config) domain_map = {} config.reject{|k,v| !v.has_key?('domain') && !v.has_key?('domains')}.each do |k,v| diff --git a/lib/site_skel/index.haml b/lib/site_skel/index.haml index 3de50bc..50d59ff 100644 --- a/lib/site_skel/index.haml +++ b/lib/site_skel/index.haml @@ -23,15 +23,15 @@ %span.minute>= ':'+item.published.localtime.strftime('%M') %span.meridian= item.published.localtime.strftime('%p') %p.content= prepare_content(item.content) - + #footer / - %p + %p We're searching twitter for “ %span.query>= @site['query'] \” %p - Powered by + Powered by %a{ :href => 'http://github.com/reidab/tweetscope' } TweetScope | %a{ :href => @feed_url } Atom Feed \ No newline at end of file diff --git a/tweetscope.rb b/tweetscope.rb index 5b66361..dc393a0 100644 --- a/tweetscope.rb +++ b/tweetscope.rb @@ -8,19 +8,19 @@ config = ConfigReader.read -get '/:site?/?' do |site| +get '/:site?/?' do |site| site ||= config['_domains'][request.env['SERVER_NAME']] || config['_global']['default_site'] || config.keys.reject{|k| k[0]==95 }.first - + raise Sinatra::NotFound unless config.has_key?(site) set :views, File.dirname(__FILE__) + "/sites/#{site}" @site = config[site] - + querystring = '' querystring += "q=#{CGI::escape(@site['query'])}" if @site['query'] querystring += "&lang=#{@site['language']}" if @site['language'] querystring += "&rpp=#{@site['count']}" if @site['count'] querystring += "&geocode=#{@site['geocode']}" if @site['geocode'] - + @feed_url = "http://search.twitter.com/search.atom?#{querystring}" @feed = SimpleRSS.parse open(@feed_url).read.gsub(' "public, max-age=#{@site['cache_max_age'] || config['_global']['cache_max_age']}" @@ -31,15 +31,15 @@ def decode_html(string) HTMLEntities.new.decode(string.gsub('’',''')) end - + def fix_search_links(string) string.gsub('href="/search?','href="http://search.twitter.com/search?') end - + def prepare_content(string) fix_search_links(decode_html(string)) end - + def extract_author_name(string) string.split(/\n/)[0].split(/ /)[0] end diff --git a/vendor/htmlentities-4.0.0/History.txt b/vendor/htmlentities-4.0.0/History.txt index eb01a43..4186a26 100644 --- a/vendor/htmlentities-4.0.0/History.txt +++ b/vendor/htmlentities-4.0.0/History.txt @@ -8,7 +8,7 @@ should be more efficient on long strings. == 3.1.0 (2007-01-19) -* Now understands all the entities referred to in the XHTML 1.0 DTD (253 +* Now understands all the entities referred to in the XHTML 1.0 DTD (253 entities compared with 131 in version 3.0.1). * Calls to_s on parameters to play nicely with Rails 1.2.1. * Entity mapping data is now lazily loaded. diff --git a/vendor/htmlentities-4.0.0/lib/htmlentities.rb b/vendor/htmlentities-4.0.0/lib/htmlentities.rb index 15d9b92..c114515 100644 --- a/vendor/htmlentities-4.0.0/lib/htmlentities.rb +++ b/vendor/htmlentities-4.0.0/lib/htmlentities.rb @@ -75,7 +75,7 @@ def encode(source, *instructions) raise InstructionError, "unknown encode_entities command(s): #{unknown_instructions.inspect}" end - + basic_entity_encoder = if instructions.include?(:basic) || instructions.include?(:named) :encode_named @@ -85,7 +85,7 @@ def encode(source, *instructions) :encode_hexadecimal end string.gsub!(basic_entity_regexp){ __send__(basic_entity_encoder, $&) } - + extended_entity_encoders = [] if instructions.include?(:named) extended_entity_encoders << :encode_named @@ -100,7 +100,7 @@ def encode(source, *instructions) encode_extended(extended_entity_encoders, $&) } end - + return string end @@ -120,7 +120,7 @@ def basic_entity_regexp end ) end - + def extended_entity_regexp @extended_entity_regexp ||= ( regexp = '[\x00-\x1f]|[\xc0-\xfd][\x80-\xbf]+' @@ -153,7 +153,7 @@ def encode_decimal(char) def encode_hexadecimal(char) "&#x#{char.unpack('U')[0].to_s(16)};" end - + def encode_extended(encoders, char) encoders.each do |encoder| encoded = __send__(encoder, char) diff --git a/vendor/htmlentities-4.0.0/lib/htmlentities/legacy.rb b/vendor/htmlentities-4.0.0/lib/htmlentities/legacy.rb index c9631a9..b554cf0 100644 --- a/vendor/htmlentities-4.0.0/lib/htmlentities/legacy.rb +++ b/vendor/htmlentities-4.0.0/lib/htmlentities/legacy.rb @@ -1,6 +1,6 @@ class HTMLEntities class << self - + # # Legacy compatibility class method allowing direct encoding of XHTML1 entities. # See HTMLEntities#encode for description of parameters. @@ -8,7 +8,7 @@ class << self def encode_entities(*args) xhtml1_entities.encode(*args) end - + # # Legacy compatibility class method allowing direct decoding of XHTML1 entities. # See HTMLEntities#decode for description of parameters. @@ -16,12 +16,12 @@ def encode_entities(*args) def decode_entities(*args) xhtml1_entities.decode(*args) end - + private - + def xhtml1_entities @xhtml1_entities ||= new('xhtml1') end - + end end \ No newline at end of file diff --git a/vendor/htmlentities-4.0.0/lib/htmlentities/string.rb b/vendor/htmlentities-4.0.0/lib/htmlentities/string.rb index 5cd497a..886342f 100644 --- a/vendor/htmlentities-4.0.0/lib/htmlentities/string.rb +++ b/vendor/htmlentities-4.0.0/lib/htmlentities/string.rb @@ -13,7 +13,7 @@ class String def decode_entities return HTMLEntities.decode_entities(self) end - + # # Encode codepoints in a string into their corresponding entities. See # the documentation of HTMLEntities.encode_entities for a list of possible diff --git a/vendor/htmlentities-4.0.0/test/entities_test.rb b/vendor/htmlentities-4.0.0/test/entities_test.rb index e5fba82..d7bfc84 100644 --- a/vendor/htmlentities-4.0.0/test/entities_test.rb +++ b/vendor/htmlentities-4.0.0/test/entities_test.rb @@ -21,7 +21,7 @@ def to_s @string end end - + def test_should_raise_exception_when_unknown_flavor_specified assert_raises(HTMLEntities::UnknownFlavor) do HTMLEntities.new('foo') @@ -52,7 +52,7 @@ def test_should_encode_basic_entities assert_encode('<', '<', :basic) assert_encode('<', '<') end - + def test_should_encode_basic_entities_to_decimal assert_encode('&', '&', :decimal) assert_encode('"', '"', :decimal) diff --git a/vendor/htmlentities-4.0.0/test/legacy_test.rb b/vendor/htmlentities-4.0.0/test/legacy_test.rb index da24f90..c4f4388 100644 --- a/vendor/htmlentities-4.0.0/test/legacy_test.rb +++ b/vendor/htmlentities-4.0.0/test/legacy_test.rb @@ -8,7 +8,7 @@ # Test that version 3.x functionality still works # class HTMLEntities::LegacyTest < Test::Unit::TestCase - + def test_should_decode_via_legacy_interface assert_decode('&', '&') assert_decode('±', '±') @@ -22,7 +22,7 @@ def test_should_encode_via_legacy_interface assert_encode('…', '…', :decimal) assert_encode('−', '−', :hexadecimal) end - + def assert_encode(expected, *encode_args) assert_equal expected, HTMLEntities.encode_entities(*encode_args) end @@ -30,5 +30,5 @@ def assert_encode(expected, *encode_args) def assert_decode(expected, *decode_args) assert_equal expected, HTMLEntities.decode_entities(*decode_args) end - + end \ No newline at end of file diff --git a/vendor/htmlentities-4.0.0/test/roundtrip_test.rb b/vendor/htmlentities-4.0.0/test/roundtrip_test.rb index 74a99af..98fc8f4 100644 --- a/vendor/htmlentities-4.0.0/test/roundtrip_test.rb +++ b/vendor/htmlentities-4.0.0/test/roundtrip_test.rb @@ -5,18 +5,18 @@ require 'htmlentities/html4' class HTMLEntities::RoundtripTest < Test::Unit::TestCase - + attr_reader :xhtml1_entities, :html4_entities - + def setup @xhtml1_entities = HTMLEntities.new('xhtml1') @html4_entities = HTMLEntities.new('html4') end - + def test_should_roundtrip_xhtml1_entities_via_named_encoding each_mapping('xhtml1') do |name, string| assert_equal( - string, + string, xhtml1_entities.decode(xhtml1_entities.encode(string, :named)) ) end @@ -25,34 +25,34 @@ def test_should_roundtrip_xhtml1_entities_via_named_encoding def test_should_roundtrip_xhtml1_entities_via_basic_and_named_encoding each_mapping('xhtml1') do |name, string| assert_equal( - string, + string, xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named)) ) end end - + def test_should_roundtrip_xhtml1_entities_via_basic_named_and_decimal_encoding each_mapping('xhtml1') do |name, string| assert_equal( - string, + string, xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named, :decimal)) ) end end - + def test_should_roundtrip_xhtml1_entities_via_hexadecimal_encoding each_mapping('xhtml1') do |name, string| assert_equal( - string, + string, xhtml1_entities.decode(xhtml1_entities.encode(string, :hexadecimal)) ) end end - + def test_should_roundtrip_html4_entities_via_named_encoding each_mapping('html4') do |name, string| assert_equal( - string, + string, html4_entities.decode(html4_entities.encode(string, :named)) ) end @@ -61,34 +61,34 @@ def test_should_roundtrip_html4_entities_via_named_encoding def test_should_roundtrip_html4_entities_via_basic_and_named_encoding each_mapping('html4') do |name, string| assert_equal( - string, + string, html4_entities.decode(html4_entities.encode(string, :basic, :named)) ) end end - + def test_should_roundtrip_html4_entities_via_basic_named_and_decimal_encoding each_mapping('html4') do |name, string| assert_equal( - string, + string, html4_entities.decode(html4_entities.encode(string, :basic, :named, :decimal)) ) end end - + def test_should_roundtrip_html4_entities_via_hexadecimal_encoding each_mapping('html4') do |name, string| assert_equal( - string, + string, html4_entities.decode(html4_entities.encode(string, :hexadecimal)) ) end end - + def each_mapping(flavor) HTMLEntities::MAPPINGS[flavor].each do |name, codepoint| yield name, [codepoint].pack('U') end end - + end \ No newline at end of file diff --git a/vendor/htmlentities-4.0.0/test/string_test.rb b/vendor/htmlentities-4.0.0/test/string_test.rb index 9e062ed..df13608 100644 --- a/vendor/htmlentities-4.0.0/test/string_test.rb +++ b/vendor/htmlentities-4.0.0/test/string_test.rb @@ -5,7 +5,7 @@ $KCODE = 'u' class TestHTMLEntities < Test::Unit::TestCase - + def test_string_responds_correctly_to_decode_entities assert_equal('±', '±'.decode_entities) end diff --git a/vendor/simple-rss-1.2/LICENSE b/vendor/simple-rss-1.2/LICENSE index cf14acc..4199dd4 100644 --- a/vendor/simple-rss-1.2/LICENSE +++ b/vendor/simple-rss-1.2/LICENSE @@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. - + 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an diff --git a/vendor/simple-rss-1.2/lib/simple-rss.rb b/vendor/simple-rss-1.2/lib/simple-rss.rb index 65327b1..47ad86a 100644 --- a/vendor/simple-rss-1.2/lib/simple-rss.rb +++ b/vendor/simple-rss-1.2/lib/simple-rss.rb @@ -3,14 +3,14 @@ class SimpleRSS VERSION = "1.2" - + attr_reader :items, :source alias :entries :items @@feed_tags = [ :id, :title, :subtitle, :link, - :description, + :description, :author, :webMaster, :managingEditor, :contributor, :pubDate, :lastBuildDate, :updated, :'dc:date', :generator, :language, :docs, :cloud, @@ -68,10 +68,10 @@ def parse(source, do_validate=true, ignore_unknown_element=true, parser_class=fa def parse raise SimpleRSSError, "Poorly formatted feed" unless @source =~ %r{<(channel|feed).*?>.*?}mi - + # Feed's title and link feed_content = $1 if @source =~ %r{(.*?)<(rss:|atom:)?(item|entry).*?>.*?}mi - + @@feed_tags.each do |tag| if feed_content && feed_content =~ %r{<(rss:|atom:)?#{tag}(.*?)>(.*?)}mi nil @@ -82,7 +82,7 @@ def parse elsif @source =~ %r{<(rss:|atom:)?#{tag}(.*?)\/\s*>}mi nil end - + if $2 || $3 tag_cleaned = clean_tag(tag) eval %{ @#{ tag_cleaned } = clean_content(tag, $2, $3) } @@ -98,7 +98,7 @@ def parse tag_data = tag.to_s.split("+") tag = tag_data[0] rel = tag_data[1] - + if match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)rel=['"]#{rel}['"](.*?)>(.*?)}mi nil elsif match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)rel=['"]#{rel}['"](.*?)/\s*>}mi @@ -135,7 +135,7 @@ def clean_content(tag, attrs, content) def clean_tag(tag) tag.to_s.gsub(':','_').intern end - + def unescape(content) if content =~ /([^-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]%)/n then CGI.unescape(content).gsub(/()/,'').strip diff --git a/vendor/simple-rss-1.2/test/base/base_test.rb b/vendor/simple-rss-1.2/test/base/base_test.rb index 66f8fbe..c8392f0 100644 --- a/vendor/simple-rss-1.2/test/base/base_test.rb +++ b/vendor/simple-rss-1.2/test/base/base_test.rb @@ -5,19 +5,19 @@ def setup @rss20 = SimpleRSS.parse open(File.dirname(__FILE__) + '/../data/rss20.xml'), false @atom = SimpleRSS.parse open(File.dirname(__FILE__) + '/../data/atom.xml') end - + def test_channel assert_equal @rss09, @rss09.channel assert_equal @rss20, @rss20.channel assert_equal @atom, @atom.feed end - + def test_items assert_kind_of Array, @rss09.items assert_kind_of Array, @rss20.items assert_kind_of Array, @atom.entries end - + def test_rss09 assert_equal 10, @rss09.items.size assert_equal "Slashdot", @rss09.title @@ -36,7 +36,7 @@ def test_rss20 assert_equal "http://feeds.feedburner.com/rufytech?m=68", @rss20.items.first[:link] assert_equal "This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site.", @rss20.channel.feedburner_browserFriendly end - + def test_atom assert_equal 1, @atom.entries.size assert_equal "dive into mark", @atom.title @@ -44,7 +44,7 @@ def test_atom assert_equal "http://example.org/2005/04/02/atom", @atom.entries.first.link assert_equal "http://example.org/2005/04/02/atom", @atom.entries.first[:link] end - + def test_bad_feed assert_raise(SimpleRSSError) { SimpleRSS.parse(open(File.dirname(__FILE__) + '/../data/not-rss.xml')) } end