This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// note: this script depends on the jQuery browser plugin | |
// http://jquery.thewikies.com/browser/ | |
// place this at the very top of application.js | |
// outside of the document ready block to ensue | |
// it loads and initiates redirect as quickly | |
// as possible. | |
var browser_redirect = function() { | |
var os_param = $.os.name === 'mac' ? '?os=mac' : '?os=win'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helper method for asking questions in a rake task - returns true or false | |
def ask?(question) | |
puts question | |
respnose = STDIN.gets.chomp.downcase | |
%w[yes y yep true].include?(respnose) | |
end | |
# example usage | |
if ask?("Are you having a nice day?") | |
puts "Great!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# builds an href for an iframe using prettyPhoto.js plugin | |
def link_to_lightbox(*args, &block) | |
if block_given? | |
options = args.first || {} | |
html_options = args.second | |
concat(link_to(capture(&block), options, html_options)) | |
else | |
name = args.first | |
options = args.second || {} | |
html_options = args.third |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SeoHelper | |
def meta_keywords(keywords) | |
tag(:meta, { :name => "keywords", :content => keywords }) | |
end | |
def meta_description(description) | |
tag(:meta, { :name => "description", :content => description }) | |
end | |
def meta_author(author_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on http://stackoverflow.com/questions/1293573/rails-smart-text-truncation | |
def sentence_truncate(string, num_sentences, enforce_max_length=true) | |
pattern = /[\.\?\!]{1,}\s/ | |
matches = string.scan(pattern) | |
sentences = string.split(pattern) | |
num_sentences = matches.length if matches.length < num_sentences | |
truncated_sentence = sentences[0...num_sentences].map do |sentence| | |
sentence << matches[sentences.index(sentence)] | |
end.join("").chop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# removes disallowed opening and closing html tags from a passed string | |
def scrub_html(string) | |
disallowed_tags = %w[p ul li ol blockquote cite pre code dl dt dd table tr th frameset from input select option address h1 h2 h3 h4 h5 h6] | |
disallowed_tags.each do |tag| | |
opening_tag = /<\s*#{tag}[^>]*>{1}/i | |
closing_tag = /<\/\s*#{tag}\s*>/i | |
hr_tag = /<\s*hr\s*\/*>/i | |
string.gsub!(opening_tag, '') | |
string.gsub!(closing_tag, '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helper method to add html soft hyphen entities to words whose character length exceeds a given integer. | |
# Note: This is an overkill substitute for the poorly supported CSS word-break property. | |
def wordbreak(string, max_length = 12) | |
max_length = max_length < 5 ? 4 : max_length # force min max_length of 4 | |
words = string.scan(/(?:"[\w'\.\-]*"\.?)|(?:'[\w'\.\-]*'\.?)|(?:[\w'\.]+)/) | |
words.each do |word| | |
if word.length > max_length | |
index = word.include?("-") ? word.index('-')+1 : max_length-2 |
NewerOlder