Skip to content

Commit

Permalink
Updating sexy_bookmarks for rails 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbob committed Jul 9, 2011
1 parent 6b8ebd5 commit 8d10725
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
8 changes: 4 additions & 4 deletions lib/fixtures/socials.yml
Expand Up @@ -28,17 +28,17 @@ technorati:
mixx:
url: 'http://www.mixx.com/submit?page_url=PERMALINK&title=TITLE'
message: 'Share this on Mixx'
myspace:
myspace:
url: 'http://www.myspace.com/Modules/PostTo/Pages/?u=PERMALINK&t=TITLE'
message: 'Post this to MySpace'
designfloat:
url: 'http://www.designfloat.com/submit.php?url=PERMALINK&title=TITLE'
message: 'Submit this to DesignFloat'
facebook:
url: 'http://www.facebook.com/share.php?v=4&src=bm&u=PERMALINK&t=TITLE'
url: 'http://www.facebook.com/share.php?v=4&src=bm&u=PERMALINK&t=TITLE'
message: 'Share this on Facebook'
twitter:
url: 'http://twitter.com/home?status='
url: 'http://twitter.com/share?url=PERMALINK&text=POST_SUMMARY'
message: 'Tweet This!'
linkedin:
url: 'http://www.linkedin.com/shareArticle?mini=true&url=PERMALINK&title=TITLE&summary=POST_SUMMARY&source=SITE_NAME'
Expand Down Expand Up @@ -149,7 +149,7 @@ blogengage:
url: 'http://www.blogengage.com/submit.php?url=PERMALINK'
message: 'Engage this article!'
hyves:
url:'http://www.hyves.nl/profilemanage/add/tips/?name=TITLE&text=POST_SUMMARY+-+PERMALINK&rating=5'
url: 'http://www.hyves.nl/profilemanage/add/tips/?name=TITLE&text=POST_SUMMARY+-+PERMALINK&rating=5'
message: 'Share this on Hyves'
pusha:
url: 'http://www.pusha.se/posta?url=PERMALINK&title=TITLE'
Expand Down
28 changes: 14 additions & 14 deletions lib/sexy_bookmarks.rb
Expand Up @@ -4,25 +4,25 @@ module SexyBookmarks
def self.included(base)
base.extend(ClassMethods)
end

def self.initialize
return if @intialized

SexyBookmarks.install
@intialized = true
end

def self.install
require 'fileutils'
original_stylesheets = File.join(File.dirname(__FILE__), 'sexybookmarks', 'assets', 'stylesheets', 'sexybookmarks' )
original_images = File.join(File.dirname(__FILE__), 'sexybookmarks', 'assets', 'images', 'sexybookmarks' )
destination = File.join(Rails.root.to_s, 'public')
destination = File.join(Rails.root.to_s, 'app', 'assets')

stylesheet_dest = File.join(destination, 'stylesheets', 'sexybookmarks')
stylesheet = File.join(stylesheet_dest, 'style.css')
images_dest = File.join(destination, 'images', 'sexybookmarks')

images_dest = File.join(Rails.root.to_s, 'public', 'images', 'sexybookmarks')

unless File.exists?( stylesheet ) && FileUtils.identical?( File.join( original_stylesheets, 'style.css' ), stylesheet )
if !File.exists?( stylesheet )
begin
Expand Down Expand Up @@ -51,26 +51,26 @@ def self.install
puts "ERROR: Problem installing SexyBookmarks. Please manually copy the images in"
puts original_images
puts "to"
puts images_dest
puts images_dest
end
end
end

module ClassMethods
def uses_sexy_bookmarks(options = {})
proc = Proc.new do |current_class|
current_class.instance_variable_set(:@uses_sexy_bookmarks, true)
end

before_filter(proc, options)
end
end

self.initialize

end

class ActionController::Base
include SexyBookmarks
self.helper SexyBookmarksMacrosHelper
end
end
45 changes: 22 additions & 23 deletions lib/sexy_bookmarks_macros_helper.rb
@@ -1,58 +1,57 @@
module SexyBookmarksMacrosHelper

def available_social_networks
if @available_socials.nil?
socials = File.new( File.join(File.dirname(__FILE__), 'fixtures', 'socials.yml') )
@available_socials = YAML::load socials
socials.close
end

@available_socials
end

def show_sexy_bookmarks( content, socials = nil, per_row = 8 )
socials = available_social_networks.keys if socials.nil?

list_items = socials.collect do |social|

list_items = socials.collect do |social|
link_url = available_social_networks[social.to_s]['url'].to_s.gsub( /SHORT_TITLE|TITLE/, content[:title].to_s )
link_url = link_url.gsub( /FETCH_URL|PERMALINK/, content[:permalink].to_s )
link_url = link_url.gsub( /POST_SUMMARY|SEXY_TEASER/, content[:post_summary].to_s ).gsub(/SITE_NAME/, content[:site_name].to_s )
link_url = link_url.gsub( /TWITT_CAT/, content[:twitt_cat].to_s ).gsub( /DEFAULT_TAGS/, content[:default_tags].to_s )
link_url = link_url.gsub( /YAHOOTEASER/, content[:yahooteaser].to_s ).gsub( /YAHOOCATEGORY/, content[:yahoocategory].to_s )
link_url = link_url.gsub( /YAHOOMEDIATYPE/, content[:yahoomediatype].to_s )

link_options = {
:href => link_url,
:rel => :nofollow,
debugger if social == :twitter
link_options = {
:href => link_url,
:rel => :nofollow,
:title => available_social_networks[social.to_s]['message'],
:class => :external
}
}
link = content_tag( 'a', available_social_networks[social.to_s]['message'], link_options )
content_tag( 'li', link, :class => 'shr-' + social.to_s )
end
unordered_list = content_tag( 'ul', list_items, :class => 'socials' )
content_tag( 'div', unordered_list, { :class => 'shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-shr', :id => 'sexybookmarks' } ) + reveal_social_list(socials.count, per_row)
end.join('')

unordered_list = content_tag( 'ul', list_items.html_safe, :class => 'socials' )
content_tag( 'div', unordered_list.html_safe, { :class => 'shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-shr', :id => 'sexybookmarks' } ) + reveal_social_list(socials.count, per_row)
end

def include_sexy_bookmarks_if_needed
stylesheet_link_tag "sexybookmarks/style.css" if @uses_sexy_bookmarks
end
def reveal_social_list(total, per_row)

def reveal_social_list(total, per_row)
rows = ( total / Float(per_row ) % 2 == 0 ) ? total / per_row : ( total / per_row ) + 1
javascript = %{
$(document).ready(function() {
$(".socials").hover(function(){
$("#sexybookmarks").delay(500).animate({ height: "#{rows*32}px" }, 750);
$(".socials").hover(function(){
$("#sexybookmarks").delay(500).animate({ height: "#{rows*32}px" }, 750);
},
function(){
$("#sexybookmarks").animate({ height: "32px"}, 750);
function(){
$("#sexybookmarks").animate({ height: "32px"}, 750);
});
});
}
content_tag('script', javascript, :type => 'text/javascript')

content_tag('script', javascript.html_safe, :type => 'text/javascript')
end
end
end

0 comments on commit 8d10725

Please sign in to comment.