following button on site

This commit is contained in:
Kyle Drake 2014-05-05 15:25:25 -07:00
parent 51a85a0b03
commit 0a29a496d7
5 changed files with 62 additions and 18 deletions

View file

@ -2,7 +2,7 @@ require 'tilt'
class Site < Sequel::Model
include Sequel::ParanoidDelete
VALID_MIME_TYPES = %w{
text/plain
text/html
@ -65,7 +65,10 @@ class Site < Sequel::Model
one_to_many :profile_comments
one_to_many :profile_commentings, key: :actioning_site_id, class: :ProfileComment
# Who is following this site
one_to_many :follows
# Who this site is following
one_to_many :followings, key: :actioning_site_id, class: :Follow
one_to_many :tips
@ -96,6 +99,20 @@ class Site < Sequel::Model
end
end
def is_following?(site)
followings_dataset.select(:id).filter(site_id: site.id).first ? true : false
end
def toggle_follow(site)
if is_following? site
followings_dataset.filter(site_id: site.id).delete
false
else
add_following site_id: site.id
true
end
end
def tip_amount
return '0.00' if tips_dataset.count == 0
'31.337'
@ -390,7 +407,7 @@ class Site < Sequel::Model
def title
values[:title] || values[:username]
end
def hits_english
values[:hits].to_s.reverse.gsub(/...(?=.)/,'\&,').reverse
end
@ -403,7 +420,7 @@ class Site < Sequel::Model
end
end
end
def thumbnails_delete(filename)
THUMBNAIL_RESOLUTIONS.each do |res|
begin
@ -424,22 +441,22 @@ class Site < Sequel::Model
def screenshot_url(filename, resolution)
"#{SCREENSHOTS_URL_ROOT}/#{values[:username]}/#{filename}.#{resolution}.jpg"
end
def thumbnail_path(filename, resolution)
ext = File.extname(filename).gsub('.', '').match(LOSSY_IMAGE_REGEX) ? 'jpg' : 'png'
File.join THUMBNAILS_ROOT, values[:username], "#{filename}.#{resolution}.#{ext}"
end
def thumbnail_exists?(filename, resolution)
File.exist? thumbnail_path(filename, resolution)
end
def thumbnail_delete(filename, resolution)
File.rm thumbnail_path(filename, resolution)
end
def thumbnail_url(filename, resolution)
ext = File.extname(filename).gsub('.', '').match(LOSSY_IMAGE_REGEX) ? 'jpg' : 'png'
"#{THUMBNAILS_URL_ROOT}/#{values[:username]}/#{filename}.#{resolution}.#{ext}"
end
end
end