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 config/rackup.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rubygems'
require 'sinatra'

set :environment, :production

require app_file = File.dirname(__FILE__) + "/../go_get_me_some"
Expand Down
18 changes: 9 additions & 9 deletions go_get_me_some.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# GET ME SOME SOURCE CODE!
#
#
# Code by Nate Todd and Jonathan Crossman
# Built because... YES WE CAN!
# 2/6/09 is a day not unlike any other day
Expand Down Expand Up @@ -29,11 +29,11 @@ def to_pretty(topic_time)
case a
when 0 then return "just now"
when 1 then return "a second ago"
when 2..59 then return a.to_s+' seconds ago'
when 2..59 then return a.to_s+' seconds ago'
when 60..119 then return 'a minute ago' #120 = 2 minutes
when 120..3540 then return (a/60).to_i.to_s+' minutes ago'
when 3541..7100 then return 'an hour ago' # 3600 = 1 hour
when 7101..82800 then return ((a+99)/3600).to_i.to_s+' hours ago'
when 7101..82800 then return ((a+99)/3600).to_i.to_s+' hours ago'
when 82801..172000 then return 'a day ago' # 86400 = 1 day
when 172001..518400 then return ((a+800)/(60*60*24)).to_i.to_s+' days ago'
when 518400..1036800 then return 'a week ago'
Expand All @@ -42,7 +42,7 @@ def to_pretty(topic_time)
end
end

before do
before do
# kill trailing slashes for all requests except '/'
request.env['PATH_INFO'].gsub!(/\/$/, '') if request.env['PATH_INFO'] != '/'
end
Expand Down Expand Up @@ -75,22 +75,22 @@ def to_pretty(topic_time)

private
def fetch_and_display(topic_url, img_number)

# can't use CGI.escape() on deployment server, so using a gsub to catch spaces in the url
topic = topic_url.gsub(/\s+/, '%20')
doc = open("http://images.google.com/images?um=1&hl=en&client=safari&rls=en-us&btnG=Search+Images&ei=ubeLSbSgGqTUMbzxzZAL&gbv=1&ei=lLqLSYWsFaX6NJrzyIkL&q=#{topic}") { |f| Hpricot(f) }

# fetch hotlinking image source
anchor = (doc/'table[@align="center"]/tr/td/a[@href*="imgurl"]')[img_number.to_i - 1]
@thumbnail = (anchor/'img').first['src'] unless anchor.nil?

@remote_image_src = anchor['href'].match(/imgurl=(http:\/\/[^&]+(?:jpe?g|gif|png)?)/)[1] unless anchor.nil?

# Create the entry
Topic.new( :topic => topic, :timestamp => Time.now ).save unless anchor.nil?

# Find a random entry
@random_topic = Topic.first(:order => "random()", :select => "DISTINCT(topic)")

haml :view
end
2 changes: 1 addition & 1 deletion public/go_get_me_some.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.onload = function(){
var img = document.getElementsByTagName('img')[0];

if (img && img.naturalHeight + img.naturalWidth == 0)
img.src = thumbnail;
}
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ END
result = RubyProf.profile { times.times { obj.render } }
end

RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
end
rescue LoadError; end
4 changes: 2 additions & 2 deletions vendor/haml-2.0.5/lib/haml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@
# </a>
# <![endif]-->
#
# ==== \
# ==== \
#
# The backslash character escapes the first character of a line,
# allowing use of otherwise interpreted characters as plain text.
Expand Down Expand Up @@ -921,7 +921,7 @@
# ...or by setting the <tt>Merb::Plugin.config[:haml]</tt> hash in <tt>init.rb</tt> in Merb...
#
# Merb::Plugin.config[:haml][:format] = :html5
#
#
# ...or by passing an options hash to Haml::Engine.new.
# Available options are:
#
Expand Down
10 changes: 5 additions & 5 deletions vendor/haml-2.0.5/lib/haml/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def to_haml(tabs = 0)
end

private

def dynamic_attributes
@dynamic_attributes ||= begin
attributes.inject({}) do |dynamic, pair|
Expand All @@ -177,19 +177,19 @@ def dynamic_attributes
end
end
end

def static_attribute?(name)
attributes[name] and !dynamic_attribute?(name)
end

def dynamic_attribute?(name)
HTML.options[:rhtml] and dynamic_attributes.key?(name)
end

def static_id?
static_attribute? 'id'
end

def static_classname?
static_attribute? 'class'
end
Expand Down
6 changes: 3 additions & 3 deletions vendor/haml-2.0.5/lib/haml/precompiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def locals_code(names)

names.map do |name|
# Can't use || because someone might explicitly pass in false with a symbol
sym_local = "_haml_locals[#{name.to_sym.inspect}]"
str_local = "_haml_locals[#{name.to_s.inspect}]"
sym_local = "_haml_locals[#{name.to_sym.inspect}]"
str_local = "_haml_locals[#{name.to_s.inspect}]"
"#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local}"
end.join(';') + ';'
end
Expand Down Expand Up @@ -603,7 +603,7 @@ def render_tag(line)
else
open_tag << "\n" unless parse || nuke_inner_whitespace || (self_closing && nuke_outer_whitespace)
end

push_merged_text(open_tag, tag_closed || self_closing || nuke_inner_whitespace ? 0 : 1,
!nuke_outer_whitespace)

Expand Down
6 changes: 3 additions & 3 deletions vendor/haml-2.0.5/lib/haml/template/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def compile_template(handler, template, file_name, local_assigns)
begin
render_source = create_template_source(handler, template, render_symbol, local_assigns.keys)
line_offset = @@template_args[render_symbol].size + handler.line_offset

file_name = 'compiled-template' if file_name.blank?
CompiledTemplates.module_eval(render_source, file_name, -line_offset)
rescue Exception => e # errors from template code
Expand All @@ -60,10 +60,10 @@ def compile_template(handler, template, file_name, local_assigns)
# There's no way to tell Haml about the filename,
# so we've got to insert it ourselves.
e.backtrace[0].gsub!('(haml)', file_name) if e.is_a?(Haml::Error)

raise ActionView::TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e)
end

@@compile_time[render_symbol] = Time.now
# logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger
end
Expand Down
4 changes: 2 additions & 2 deletions vendor/haml-2.0.5/lib/sass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# sass input.sass output.css
#
# Use <tt>sass --help</tt> for full documentation.
#
#
# Using Sass in Ruby code is very simple.
# After installing the Haml gem,
# you can use it by running <tt>require "sass"</tt>
Expand Down Expand Up @@ -791,7 +791,7 @@
# ...or by setting the <tt>Merb::Plugin.config[:sass]</tt> hash in <tt>init.rb</tt> in Merb...
#
# Merb::Plugin.config[:sass][:style] = :compact
#
#
# ...or by passing an options hash to Sass::Engine.new.
# Available options are:
#
Expand Down
14 changes: 7 additions & 7 deletions vendor/haml-2.0.5/test/haml/markaby/standard.mab
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ html(:xmlns=>'http://www.w3.org/1999/xhtml', 'xml:lang'=>'en-US') do
end
self << "Wow.|"
p do
self << "Holy cow " +
"multiline " +
"tags! " +
"A pipe (|) even!"
self << "Holy cow " +
"multiline " +
"tags! " +
"A pipe (|) even!"
self << [1, 2, 3].collect { |n| "PipesIgnored|" }
self << [1, 2, 3].collect { |n|
n.to_s
}.join("|")
self << [1, 2, 3].collect { |n|
n.to_s
}.join("|")
end
div(:class => "silent") do
foo = String.new
Expand Down
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/test/haml/results/filters.xhtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<style>
p { border-style: dotted; border-width: 22px; border-color: #ff00ff; }

h1 { font-weight: normal; }
</style>
TESTING HAHAHAHA!
Expand Down
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/test/haml/results/standard.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
hello
<div class='footer'>
<strong class='shout'>
This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.
This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.
So, I'm just making it *really* long. God, I hope this works
</strong>
</div>
Expand Down
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/test/haml/rhtml/action_view.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
end %>
<div class='footer'>
<strong class='shout'>
<%= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.\n" +
<%= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.\n" +
" So, I'm just making it *really* long. God, I hope this works" %>
</strong>
</div>
Expand Down
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/test/haml/rhtml/standard.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
end %>
<div class='footer'>
<strong class='shout'>
<%= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.\n" +
<%= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.\n" +
" So, I'm just making it *really* long. God, I hope this works" %>
</strong>
</div>
Expand Down
4 changes: 2 additions & 2 deletions vendor/haml-2.0.5/test/haml/templates/_partial.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%p
@foo =
@foo =
= @foo
- @foo = 'value three'
== Toplevel? #{haml_buffer.toplevel?}
%p
@foo =
@foo =
= @foo
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/test/haml/templates/action_view.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Wow.|
%p
= "Holy cow " + |
"multiline " + |
"multiline " + |
"tags! " + |
"A pipe (|) even!" |
= [1, 2, 3].collect { |n| "PipesIgnored|" }
Expand Down
4 changes: 2 additions & 2 deletions vendor/haml-2.0.5/test/haml/templates/just_stuff.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
%p== Embedded? #{"twice! #{true}"}!
%p== Embedded? #{"one"} af"t"er #{"another"}!
= "stuff followed by whitespace"

- if true

%strong block with whitespace
Expand Down Expand Up @@ -51,7 +51,7 @@
= "test" |
"test" |
-# Hard tabs shouldn't throw errors.

- case :foo
- when :bar
%br Blah
Expand Down
6 changes: 3 additions & 3 deletions vendor/haml-2.0.5/test/haml/templates/partials.haml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
- @foo = 'value one'
%p
@foo =
@foo =
= @foo
- @foo = 'value two'
%p
@foo =
@foo =
= @foo
= test_partial "partial"
%p
@foo =
@foo =
= @foo
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/test/haml/templates/silent_script.haml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
- "foo |
bar |
baz" |

%p boom
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/test/haml/templates/standard.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Wow.|
%p
= "Holy cow " + |
"multiline " + |
"multiline " + |
"tags! " + |
"A pipe (|) even!" |
= [1, 2, 3].collect { |n| "PipesIgnored|" }
Expand Down
16 changes: 8 additions & 8 deletions vendor/haml-2.0.5/test/haml/templates/whitespace_handling.haml
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@
%strong This should!
%textarea
:preserve
___ ___ ___ ___
___ ___ ___ ___
/\__\ /\ \ /\__\ /\__\
/:/ / /::\ \ /::| | /:/ /
/:/__/ /:/\:\ \ /:|:| | /:/ /
/::\ \ ___ /::\~\:\ \ /:/|:|__|__ /:/ /
/:/\:\ /\__\ /:/\:\ \:\__\ /:/ |::::\__\ /:/__/
\/__\:\/:/ / \/__\:\/:/ / \/__/~~/:/ / \:\ \
\::/ / \::/ / /:/ / \:\ \
/:/ / /:/ / /:/ / \:\ \
/:/__/ /:/\:\ \ /:|:| | /:/ /
/::\ \ ___ /::\~\:\ \ /:/|:|__|__ /:/ /
/:/\:\ /\__\ /:/\:\ \:\__\ /:/ |::::\__\ /:/__/
\/__\:\/:/ / \/__\:\/:/ / \/__/~~/:/ / \:\ \
\::/ / \::/ / /:/ / \:\ \
/:/ / /:/ / /:/ / \:\ \
/:/ / /:/ / /:/ / \:\__\
\/__/ \/__/ \/__/ \/__/

Many
thanks
to
Expand Down
2 changes: 1 addition & 1 deletion vendor/haml-2.0.5/test/sass/templates/basic.sass
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


body
body
:font Arial
:background blue

Expand Down
Loading