Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 ####

Expand Down
12 changes: 6 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/config_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
6 changes: 3 additions & 3 deletions lib/site_skel/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions tweetscope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('<link type="image/png"','<image')
headers 'Cache-Control' => "public, max-age=#{@site['cache_max_age'] || config['_global']['cache_max_age']}"
Expand All @@ -31,15 +31,15 @@
def decode_html(string)
HTMLEntities.new.decode(string.gsub('&#8217;','&apos;'))
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
Expand Down
2 changes: 1 addition & 1 deletion vendor/htmlentities-4.0.0/History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions vendor/htmlentities-4.0.0/lib/htmlentities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -100,7 +100,7 @@ def encode(source, *instructions)
encode_extended(extended_entity_encoders, $&)
}
end

return string
end

Expand All @@ -120,7 +120,7 @@ def basic_entity_regexp
end
)
end

def extended_entity_regexp
@extended_entity_regexp ||= (
regexp = '[\x00-\x1f]|[\xc0-\xfd][\x80-\xbf]+'
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions vendor/htmlentities-4.0.0/lib/htmlentities/legacy.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
class HTMLEntities
class << self

#
# Legacy compatibility class method allowing direct encoding of XHTML1 entities.
# See HTMLEntities#encode for description of parameters.
#
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.
#
def decode_entities(*args)
xhtml1_entities.decode(*args)
end

private

def xhtml1_entities
@xhtml1_entities ||= new('xhtml1')
end

end
end
2 changes: 1 addition & 1 deletion vendor/htmlentities-4.0.0/lib/htmlentities/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vendor/htmlentities-4.0.0/test/entities_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_should_encode_basic_entities
assert_encode('&lt;', '<', :basic)
assert_encode('&lt;', '<')
end

def test_should_encode_basic_entities_to_decimal
assert_encode('&#38;', '&', :decimal)
assert_encode('&#34;', '"', :decimal)
Expand Down
6 changes: 3 additions & 3 deletions vendor/htmlentities-4.0.0/test/legacy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('&', '&amp;')
assert_decode('±', '&plusmn;')
Expand All @@ -22,13 +22,13 @@ def test_should_encode_via_legacy_interface
assert_encode('&#8230;', '…', :decimal)
assert_encode('&#x2212;', '−', :hexadecimal)
end

def assert_encode(expected, *encode_args)
assert_equal expected, HTMLEntities.encode_entities(*encode_args)
end

def assert_decode(expected, *decode_args)
assert_equal expected, HTMLEntities.decode_entities(*decode_args)
end

end
36 changes: 18 additions & 18 deletions vendor/htmlentities-4.0.0/test/roundtrip_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion vendor/htmlentities-4.0.0/test/string_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$KCODE = 'u'

class TestHTMLEntities < Test::Unit::TestCase

def test_string_responds_correctly_to_decode_entities
assert_equal('±', '&plusmn;'.decode_entities)
end
Expand Down
2 changes: 1 addition & 1 deletion vendor/simple-rss-1.2/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading