Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updates for something

  • Loading branch information...
commit 613c036f5b63f637d48aa04ef3268ea66417b6df 1 parent 3805b8c
@jschoolcraft authored
View
42 app/models/tagged_link.rb
@@ -1,38 +1,16 @@
class TaggedLink < ActiveRecord::Base
belongs_to :tag
belongs_to :link
-
+
class << self
- def fetch_log(message, indent=0)
- Rails.logger.info("#{' ' * indent}#{message}")
- end
-
def fetch_links_for_all_tags
- fetch_log("#{'-'*20}\nFetch started: #{Time.now}")
@tags = Tag.find :all
@tags.each do |tag|
fetch_and_create_tagged_links_for_tag(tag)
- # fetch_and_create_recent_links_for_tag(tag)
end
- fetch_log("Fetch completed: #{Time.now}")
end
-
- def fetch_and_create_recent_links_for_tag(tag)
- url = "http://feeds.delicious.com/v2/json/tag/#{URI.escape(tag.name)}"
- special_tags = %w[hot popular]
- unless special_tags.include?(tag.name)
- json = JSON.parse(open(url).read)
- json.each do |item|
- link = parse_json_link(item)
- unless tag.tagged_links.find_by_link_id(link.id)
- tag.links << link
- end
- end
- end
- end
-
+
def fetch_and_create_tagged_links_for_tag(tag)
- fetch_log("Fetching for tag '#{tag}'", 2)
special_tags = %w[hot popular]
if special_tags.include?(tag.name)
case tag.name
@@ -45,10 +23,9 @@ def fetch_and_create_tagged_links_for_tag(tag)
url = "http://feeds.delicious.com/v2/json/popular/#{URI.escape(tag.name)}?count=30"
end
json = JSON.parse(open(url).read)
-
- fetch_log("Found #{json.size} links for '#{tag}'", 4)
+
added_count = 0
-
+
json.each do |item|
link = parse_json_link(item)
unless tag.tagged_links.find_by_link_id(link.id)
@@ -56,7 +33,6 @@ def fetch_and_create_tagged_links_for_tag(tag)
tag.links << link
end
end
- fetch_log("Added #{added_count} new links for '#{tag}'", 4)
end
def parse_json_link(attributes)
@@ -66,7 +42,7 @@ def parse_json_link(attributes)
end
link
end
-
+
private
def map_attributes(attributes)
delicious_mapping = {
@@ -74,14 +50,14 @@ def map_attributes(attributes)
"d" => :title,
"t" => :source_tags
}
-
+
ret = {}
attributes.each do |k, v|
ret[delicious_mapping[k]] = v if delicious_mapping[k]
end
-
+
ret
end
-
+
end
-end
+end
View
5 config/application.rb
@@ -3,12 +3,11 @@
require 'rails/all'
require 'open-uri'
-Bundler.require(:default, Rails.env) if defined?(Bundler)
+Bundler.require(:default, Rails.env) if defined?(Bundler)
module Urlagg
class Application < Rails::Application
- config.time_zone = 'UTC'
+ config.time_zone = 'UTC'
end
end
-# FETCH_LOG = Logger.new(File.open(Rails.root + '/log/fetch.log', File::WRONLY | File::APPEND | File::CREAT))
View
6 lib/tasks/cron.rake
@@ -4,7 +4,7 @@ task :cron => :environment do
fetch_links_for_all_tags
# generate sitemap
# generate_xml_sitemap
-
+
# likely want to clean out database daily
if Time.now.hour == 1
# clean out the database...
@@ -12,7 +12,7 @@ task :cron => :environment do
end
def fetch_links_for_all_tags
- TaggedLink.fetch_links_for_all_tags
+ TaggedLink.fetch_links_for_all_tags
end
def generate_xml_sitemap
@@ -26,4 +26,4 @@ def generate_xml_sitemap
sitemap = BigSitemap.new({:url_options => {:host => 'urlagg.com'}}.merge(live_options))
sitemap.add(Tag, { :change_frequency => 'hourly', :priority => 0.5 })
sitemap.generate
-end
+end
View
305 public/stylesheets/sass/application.sass
@@ -2,254 +2,225 @@
@import text.sass
@import pagination.sass
-!body_bg= #A5D0EB
-!content_padding= 13px
+$body_bg: #a5d0eb
+$content_padding: 13px
-!tag_link= #105CB6
-!tag_link_visited = #86B0E1
-!tag_link_hover= #000033
+$tag_link: #105cb6
+$tag_link_visited: #86b0e1
+$tag_link_hover: #000033
-!orange= #FFC33E
+$orange: #ffc33e
html, body
- :height 100%
-
+ height: 100%
+
#not_ft
- :position relative
- :min-height 100%
- :background transparent url(../images/w980.gif) repeat-y center 0
- :background-color= !body_bg
-
+ position: relative
+ min-height: 100%
+ background: transparent url(../images/w980.gif) repeat-y center 0
+ background-color: $body_bg
+
*
html
#not_ft
- :height 100%
+ height: 100%
#content
- :padding-bottom 60px
+ padding-bottom: 60px
#ft
- :position relative
- :margin-top -60px
+ position: relative
+ margin-top: -60px
body, html
- :background-color= !body_bg
+ background-color: $body_bg
#bd
- :padding
- :top= !content_padding
- :bottom= !content_padding
+ padding:
+ top: $content_padding
+ bottom: $content_padding
.bg_space
- :height= !content_padding
- :background-color= !body_bg
+ height: $content_padding
+ background-color: $body_bg
#hd
.wrapper
- :height 1%
- :background-color= !orange
- :border-bottom 1px solid #aaa
- :padding
- :top 10px
- :bottom 10px
-
+ height: 1%
+ background-color: $orange
+ border-bottom: 1px solid #aaaaaa
+ padding:
+ top: 10px
+ bottom: 10px
a, a:visited
- :color= !tag_link
-
+ color: $tag_link
p
- :margin-bottom 5px
-
+ margin-bottom: 5px
h1
- :margin 0.5em 0 0 0
- :display inline
-
+ margin: 0.5em 0 0 0
+ display: inline
a
- :color #000
- :text-decoration none
-
+ color: black
+ text-decoration: none
&:visited
- :color #000
-
+ color: black
span
- :color #fefefe
+ color: #fefefe
#ft
- :height 50px
- :color #fefefe
-
+ height: 50px
+ color: #fefefe
.wrapper
- :background-color #333
- :padding 1em 0
- :border-top 1px solid #fefefe
-
+ background-color: #333333
+ padding: 1em 0
+ border-top: 1px solid #fefefe
p
- :margin 0
-
+ margin: 0
a, a:visited
- :color #fefefe
+ color: #fefefe
+
#bd
h1
- :font-size 20px
- :margin-left 0
- :color #333
+ font-size: 20px
+ margin-left: 0
+ color: #333333
.tags#index, .tags#top
.tag
h3
- :margin-bottom 0
-
+ margin-bottom: 0
a, a:visited
- :color= !tag_link
- :text-decoration none
-
+ color: $tag_link
+ text-decoration: none
li
- :margin-left 0
- :padding
- :top 4px
- :bottom 3px
- :border-top 1px solid silver
- :line-height 1.22em
- :list-style none
-
+ margin-left: 0
+ padding:
+ top: 4px
+ bottom: 3px
+ border-top: 1px solid silver
+ line-height: 1.22em
+ list-style: none
a
- :color= !tag_link
- :text-decoration none
-
+ color: $tag_link
+ text-decoration: none
&:hover
- :color= !tag_link_hover
- :text-decoration underline
-
+ color: $tag_link_hover
+ text-decoration: underline
&:visited
- :color= !tag_link_visited
+ color: $tag_link_visited
a
- :color= !tag_link
- :text-decoration none
-
+ color: $tag_link
+ text-decoration: none
&:hover
- :color= !tag_link_hover
- :text-decoration underline
-
+ color: $tag_link_hover
+ text-decoration: underline
&:visited
- :color= !tag_link
+ color: $tag_link
a.action, a.important
- :text-decoration none
+ text-decoration: none
a.action:hover, a.important:hover
- :text-decoration underline
-
+ text-decoration: underline
+
a.action, a.action:visited
- :color #333
+ color: #333333
a.important:hover
- :color red
+ color: red
ul.links
li
- :line-height 1.22em
- :padding
- :top 3px
- :bottom 2px
- :list-style disc
-
+ line-height: 1.22em
+ padding:
+ top: 3px
+ bottom: 2px
+ list-style: disc
a
- :color= !tag_link
- :text-decoration none
- :font-size 1.1em
+ color: $tag_link
+ text-decoration: none
+ font-size: 1.1em
&:visited
- :color= !tag_link_visited
-
+ color: $tag_link_visited
&:hover
- :color= !tag_link_hover
- :text-decoration underline
+ color: $tag_link_hover
+ text-decoration: underline
.source_tags
- :margin-left 20px
- :font-size 0.8em
-
+ margin-left: 20px
+ font-size: 0.8em
.label
- :width 10%
- :float left
- :text-align right
- :margin-right 1%
-
+ width: 10%
+ float: left
+ text-align: right
+ margin-right: 1%
.tags
- :width 88%
- :float left
+ width: 88%
+ float: left
.even
- :background-color #efefef
-
+ background-color: #efefef
+
h2.nice
- :font-size 28px
- :line-height 1em
- :letter-spacing -1px
+ font-size: 28px
+ line-height: 1em
+ letter-spacing: -1px
#flash_notice
- :padding 5px 8px
- :margin 10px 0
- :background-color #CFC
- :border solid 1px #6C6
-
+ padding: 5px 8px
+ margin: 10px 0
+ background-color: #ccffcc
+ border: solid 1px #66cc66
#flash_error
- :padding 5px 8px
- :margin 10px 0
- :background-color #FCC
- :border solid 1px #C66
-
+ padding: 5px 8px
+ margin: 10px 0
+ background-color: #ffcccc
+ border: solid 1px #cc6666
.fieldWithErrors
- :display inline
-
+ display: inline
#errorExplanation
- :width 400px
- :border 2px solid #CF0000
- :padding 0px
- :padding-bottom 12px
- :margin-bottom 20px
- :background-color #f0f0f0
-
+ width: 400px
+ border: 2px solid #cf0000
+ padding: 0px
+ padding-bottom: 12px
+ margin-bottom: 20px
+ background-color: #f0f0f0
h2
- :text-align left
- :font-weight bold
- :padding 5px 5px 5px 15px
- :font-size 12px
- :margin 0
- :background-color #c00
- :color #fff
-
+ text-align: left
+ font-weight: bold
+ padding: 5px 5px 5px 15px
+ font-size: 12px
+ margin: 0
+ background-color: #cc0000
+ color: white
p
- :color #333
- :margin-bottom 0
- :padding 8px
-
+ color: #333333
+ margin-bottom: 0
+ padding: 8px
ul
- :margin 2px 24px
-
+ margin: 2px 24px
li
- :font-size 12px
- :list-style disc
+ font-size: 12px
+ list-style: disc
table.admin
- :width 85%
- :background #fff
- :margin 45px
- :border-collapse collapse
- :text-align left
-
+ width: 85%
+ background: white
+ margin: 45px
+ border-collapse: collapse
+ text-align: left
th
- :font-size 14
- :color #039
- :padding 10px 8px
- :border-bottom 2px solid #6678b1
-
+ font-size: 14
+ color: #003399
+ padding: 10px 8px
+ border-bottom: 2px solid #6678b1
td
- :border-bottom 1px solid #ccc
- :color #669
- :padding 6px 8px
-
+ border-bottom: 1px solid #cccccc
+ color: #666699
+ padding: 6px 8px
tbody,tr:hover,td
- :color #009
+ color: #000099
View
165 public/stylesheets/sass/pagination.sass
@@ -1,125 +1,100 @@
.digg_pagination
- :margin 10px
- :background white
- :line-height 1.22em
-
+ margin: 10px
+ background: white
+ line-height: 1.22em
a
- :padding .2em .5em
- :display block
- :float left
- :margin-right 1px
- :text-decoration none
- :color #105CB6
- :border 1px solid #9AAFE5
-
+ padding: 0.2em 0.5em
+ display: block
+ float: left
+ margin-right: 1px
+ text-decoration: none
+ color: #105cb6
+ border: 1px solid #9aafe5
&:hover, &:focus
- :text-decoration none
- :color #003
- :border-color #003
-
+ text-decoration: none
+ color: #000033
+ border-color: #000033
span
- :padding .2em .5em
- :display block
- :float left
- :margin-right 1px
-
+ padding: 0.2em 0.5em
+ display: block
+ float: left
+ margin-right: 1px
&.disabled
- :color #999
- :border 1px solid #DDD
-
+ color: #999999
+ border: 1px solid #dddddd
&.current
- :font-weight bold
- :background #2E6AB1
- :color white
- :border 1px solid #2E6AB1
-
+ font-weight: bold
+ background: #2e6ab1
+ color: white
+ border: 1px solid #2e6ab1
.page_info
- :background #2E6AB1
- :color white
- :padding .4em .6em
- :width 22em
- :margin-bottom .3em
- :text-align center
-
+ background: #2e6ab1
+ color: white
+ padding: 0.4em 0.6em
+ width: 22em
+ margin-bottom: 0.3em
+ text-align: center
b
- :color #003
- :background #6aa6ed
- :padding .1em .25em
-
+ color: #000033
+ background: #6aa6ed
+ padding: 0.1em 0.25em
&:after
- :content "."
- :display block
- :height 0
- :clear both
- :visibility hidden
-
+ content: "."
+ display: block
+ height: 0
+ clear: both
+ visibility: hidden
*
html .digg_pagination
- :height 1%
-
+ height: 1%
&:first-child+html .digg_pagination
- :overflow hidden
-
+ overflow: hidden
.apple_pagination
- :background #F1F1F1
- :border 1px solid #E5E5E5
- :text-align center
- :padding 1em
-
+ background: #f1f1f1
+ border: 1px solid #e5e5e5
+ text-align: center
+ padding: 1em
a
- :padding .2em .3em
- :text-decoration none
- :color black
-
+ padding: 0.2em 0.3em
+ text-decoration: none
+ color: black
&:hover, &:focus
- :text-decoration underline
-
+ text-decoration: underline
span
- :padding .2em .3em
-
+ padding: 0.2em 0.3em
&.disabled
- :color #AAA
-
+ color: #aaaaaa
&.current
- :font-weight bold
- :background transparent url(apple-circle.gif) no-repeat 50% 50%
-
+ font-weight: bold
+ background: transparent url(apple-circle.gif) no-repeat 50% 50%
.flickr_pagination
- :text-align center
- :padding .3em
-
+ text-align: center
+ padding: 0.3em
a
- :padding .2em .5em
- :border 1px solid #DDDDDD
- :color #0063DC
- :text-decoration none
-
+ padding: 0.2em 0.5em
+ border: 1px solid #dddddd
+ color: #0063dc
+ text-decoration: none
&:hover, &:focus
- :border-color #003366
- :background #0063DC
- :color white
-
+ border-color: #003366
+ background: #0063dc
+ color: white
span
- :padding .2em .5em
-
+ padding: 0.2em 0.5em
&.disabled
- :color #AAA
-
+ color: #aaaaaa
&.current
- :font-weight bold
- :color #FF0084
-
+ font-weight: bold
+ color: #ff0084
.page_info
- :color #aaa
- :padding-top .8em
-
+ color: #aaaaaa
+ padding-top: 0.8em
.prev_page
- :border-width 2px
- :margin-right 1em
-
+ border-width: 2px
+ margin-right: 1em
.next_page
- :border-width 2px
- :margin-left 1em
+ border-width: 2px
+ margin-left: 1em
View
62 public/stylesheets/sass/text.sass
@@ -1,62 +1,50 @@
body
- :font 13px/1.5 Helvetica,Arial,'Liberation Sans',FreeSans,sans-serif
-
+ font: 13px / 1.5 Helvetica, Arial, "Liberation Sans", FreeSans, sans-serif
a:focus
- :outline 1px dotted invert
-
+ outline: 1px dotted invert
hr
- :border 0 #ccc solid
- :border-top-width 1px
- :clear both
- :height 0
- :margin-bottom 20px
-
+ border: 0 #cccccc solid
+ border-top-width: 1px
+ clear: both
+ height: 0
+ margin-bottom: 20px
h1
- :font-size 25px
- :margin-bottom 20px
-
+ font-size: 25px
+ margin-bottom: 20px
h2
- :font-size 23px
- :margin-bottom 20px
-
+ font-size: 23px
+ margin-bottom: 20px
h3
- :font-size 21px
- :margin-bottom 20px
-
+ font-size: 21px
+ margin-bottom: 20px
h4
- :font-size 19px
- :margin-bottom 20px
-
+ font-size: 19px
+ margin-bottom: 20px
h5
- :font-size 17px
- :margin-bottom 20px
-
+ font-size: 17px
+ margin-bottom: 20px
h6
- :font-size 15px
- :margin-bottom 20px
-
+ font-size: 15px
+ margin-bottom: 20px
ol
- :list-style decimal
- :margin-bottom 20px
-
+ list-style: decimal
+ margin-bottom: 20px
ul
- :list-style square
- :margin-bottom 20px
-
+ list-style: square
+ margin-bottom: 20px
li
- :margin-left 30px
-
+ margin-left: 30px
p, dl, pre, table, address, fieldset
- :margin-bottom 20px
+ margin-bottom: 20px
View
10 public/stylesheets/sass/tools.sass
@@ -1,8 +1,8 @@
.right, .r
- :text-align right
-
+ text-align: right
+
.center, .c
- :text-align center
-
+ text-align: center
+
.small, .s
- :font-size 11px
+ font-size: 11px
View
56 spec/models/tagged_link_spec.rb
@@ -5,7 +5,7 @@
before do
@tags = (1..5).map { |i| mock_model(Tag, :name => "tag-#{i}") }
end
-
+
it "should call fetch_and_create... for each tag" do
Tag.should_receive(:find).with(:all).and_return(@tags)
@tags.each do |tag|
@@ -15,7 +15,7 @@
TaggedLink.fetch_links_for_all_tags
end
end
-
+
describe "parsing a link" do
before do
@json = {"d"=>"Remember The Milk: Online to do list and task management",
@@ -23,7 +23,7 @@
"t"=>["tool", "productivity"],
"u"=>"http://www.rememberthemilk.com/"}
end
-
+
it "assigns attributes" do
@link = TaggedLink.parse_json_link(@json)
@link.class.should == Link
@@ -32,120 +32,120 @@
@link.source_tags.should == ["tool", "productivity"]
end
end
-
+
describe "#fetch_and_create_tagged_links_for_tag" do
before do
@tag = Factory.create(:tag, :name => 'gtd')
@tag.tagged_links.stub!(:find_by_link_id).and_return(nil)
-
+
@json_file = open(File.join(Rails.root, '/spec/fixtures/delicious/gtd.json'))
@json = open(File.join(Rails.root, '/spec/fixtures/delicious/gtd.json')).read
-
+
TaggedLink.stub!(:open).and_return(@json_file)
-
+
@parsed_response = (1..5).map { |i| {"u" => "http://link-#{i}-for-tag-#{@tag.name}.com", "t" => ["source-tag-#{i}-for-link-#{i}", "source-tag-#{i+1}-for-link-#{i+1}"]} }
JSON.stub!(:parse).and_return(@parsed_response)
end
-
+
it "should fetch the json feed for the tag" do
url = "http://feeds.delicious.com/v2/json/popular/gtd?count=30"
TaggedLink.should_receive(:open).with(url).and_return(@json_file)
TaggedLink.fetch_and_create_tagged_links_for_tag(@tag)
end
-
+
it "should escape the tag name to deal with special characters" do
url = "http://feeds.delicious.com/v2/json/popular/c%23?count=30"
TaggedLink.should_receive(:open).with(url).and_return(@json_file)
TaggedLink.fetch_and_create_tagged_links_for_tag(Factory.create(:tag, :name => 'c#'))
end
-
+
it "should fetch popular/ for the tag 'popular'" do
@tag = Factory.create(:tag, :name => 'popular')
url = "http://feeds.delicious.com/v2/json/popular?count=30"
TaggedLink.should_receive(:open).with(url).and_return(@json_file)
TaggedLink.fetch_and_create_tagged_links_for_tag(@tag)
end
-
+
it "should fetch json/ for tag 'hot'" do
@tag = Factory.create(:tag, :name => 'hot')
url = "http://feeds.delicious.com/v2/json/?count=30"
TaggedLink.should_receive(:open).with(url)
TaggedLink.fetch_and_create_tagged_links_for_tag(@tag)
end
-
+
it "should fetch popular/tag for tag 'hotter'" do
@tag = Factory.create(:tag, :name => 'hotter')
url = "http://feeds.delicious.com/v2/json/popular/hotter?count=30"
TaggedLink.should_receive(:open).with(url)
TaggedLink.fetch_and_create_tagged_links_for_tag(@tag)
end
-
+
it "should parse the json response" do
JSON.should_receive(:parse).with(@json).and_return(@parsed_response)
TaggedLink.fetch_and_create_tagged_links_for_tag(@tag)
end
-
+
it "should build a link for each item in the response" do
@parsed_response.each do |link|
TaggedLink.should_receive(:parse_json_link).with(link).and_return(mock_model(Link))
end
TaggedLink.fetch_and_create_tagged_links_for_tag(@tag)
end
-
+
it "should not add a duplicate link to the collection" do
JSON.stub!(:parse).and_return([{ "u" => "http://foo.com", "t" => ["foo", "bar", "baz"] }])
@tag.tagged_links.should_receive(:find_by_link_id).and_return(@link = Factory.create(:link))
lambda {
TaggedLink.fetch_and_create_tagged_links_for_tag(@tag)
- }.should_not change(@tag.tagged_links, :count)
+ }.should_not change(@tag.tagged_links, :count)
end
-
+
it "should add the fetched link to the tagged links collection if not already there" do
lambda {
TaggedLink.fetch_and_create_tagged_links_for_tag(@tag)
}.should change(@tag.tagged_links, :count).by(5)
end
-
+
end
describe "#fetch_and_create_recent_links_for_tag" do
before do
@tag = Factory.create(:tag, :name => 'gtd')
@tag.tagged_links.stub!(:find_by_link_id).and_return(nil)
-
+
@json_file = open(File.join(Rails.root, '/spec/fixtures/delicious/gtd-recent.json'))
@json = open(File.join(Rails.root, '/spec/fixtures/delicious/gtd-recent.json')).read
-
+
TaggedLink.stub!(:open).and_return(@json_file)
-
+
@parsed_response = (1..5).map { |i| {"u" => "http://link-#{i}-for-tag-#{@tag.name}.com", "t" => ["source-tag-#{i}-for-link-#{i}", "source-tag-#{i+1}-for-link-#{i+1}"]} }
JSON.stub!(:parse).and_return(@parsed_response)
end
-
+
it "should fetch the json feed for the tag" do
url = "http://feeds.delicious.com/v2/json/tag/gtd"
TaggedLink.should_receive(:open).with(url).and_return(@json_file)
TaggedLink.fetch_and_create_recent_links_for_tag(@tag)
end
-
+
it "should escape the tag name to deal with special characters" do
url = "http://feeds.delicious.com/v2/json/tag/c%23"
TaggedLink.should_receive(:open).with(url).and_return(@json_file)
TaggedLink.fetch_and_create_recent_links_for_tag(Factory.create(:tag, :name => 'c#'))
end
-
+
it "should parse the json response" do
JSON.should_receive(:parse).with(@json).and_return(@parsed_response)
TaggedLink.fetch_and_create_recent_links_for_tag(@tag)
end
-
+
it "should not add a duplicate link to the collection" do
JSON.stub!(:parse).and_return([{ "u" => "http://foo.com", "t" => ["foo", "bar", "baz"] }])
@tag.tagged_links.should_receive(:find_by_link_id).and_return(@link = Factory.create(:link))
lambda {
TaggedLink.fetch_and_create_recent_links_for_tag(@tag)
- }.should_not change(@tag.tagged_links, :count)
- end
+ }.should_not change(@tag.tagged_links, :count)
+ end
it "should build a link for each item in the response" do
@parsed_response.each do |link|
@@ -153,7 +153,7 @@
end
TaggedLink.fetch_and_create_recent_links_for_tag(@tag)
end
-
+
it "should add the fetched link to the tagged links collection if not already there" do
lambda {
TaggedLink.fetch_and_create_recent_links_for_tag(@tag)

0 comments on commit 613c036

Please sign in to comment.
Something went wrong with that request. Please try again.