This file contains hidden or 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 Monkeys | |
# Here there be monkeys! This is for english langauge. | |
# essentially the regex doesn't titleize 1, 2, & 3 letter words | |
# needs improvement IMO. Maybe an array of black list words. | |
# eg. of an a the | |
module ActiveSupport::Inflector | |
def titleize(word) | |
humanize(underscore(word)).gsub(/\b('?[a-z]{3})/) { $1.capitalize } |
This file contains hidden or 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
def active_site_links | |
# Possible memcache candidate | |
c = %w{editions forms questions question_answers} | |
h = c.inject({}) {|a,x| a[x.to_sym] = {:name => x}; a } | |
if h.has_key? controller.controller_name.to_sym | |
h[controller.controller_name.to_sym][:active] = true | |
end | |
h | |
end |
This file contains hidden or 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
# model code | |
property :paths_mask, Integer | |
NODE_PATH = %w(path_1 path_2 path_3 path_4) | |
def paths=(paths) | |
self.paths_mask = (paths & NODE_PATH).map { |r| 2**NODE_PATH.index(r) }.sum | |
end | |
def paths |
This file contains hidden or 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
set :rvm_ruby_string, '<interpreter>@<gemset>' | |
# Load RVM's capistrano plugin. | |
require "rvm/capistrano" | |
set :rvm_path, "$HOME/.rvm" |
This file contains hidden or 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
# create this in helpers/feedback_helper.rb | |
# use version 1 for haml (buggy) or version 2 for erb | |
# version 1 via haml | |
require 'haml' | |
module FeedbackHelper | |
def self.included(base) | |
base.class_eval do | |
include Haml::Helpers |
This file contains hidden or 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
# needed to fix prepared statements error in Rails 3.1 | |
after_fork do | server, worker | | |
ActiveRecord:: Base.connection.reconnect! | |
end |
This file contains hidden or 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 ApplicationHelper | |
include FeedbackHelper | |
# Your methods here | |
end |
This file contains hidden or 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
def markdown(text) | |
options = {hard_wrap: true, filter_html: true, autolink: true, no_intraemphasis: true, fenced_code: true, gh_blockcode: true} | |
md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = options) | |
syntax_highlighter( md.render(text) ).html_safe | |
end | |
def syntax_highlighter(html) | |
doc = Nokogiri::HTML(html) | |
doc.search("//pre[@lang]").each do |pre| | |
pre.replace Albino.colorize(pre.text.rstrip, pre[:lang]) |
This file contains hidden or 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
# Authored by Braulio Carreno on railscasts site. Put here mostly as a reference for me. | |
# also remember to replace albino gem with pygments.rb gem | |
module ApplicationHelper | |
class HTMLwithPygments < Redcarpet::Render::HTML | |
def block_code(code, language) | |
Pygments.highlight(code, :lexer => language) | |
end | |
end | |
def markdown(text) |
This file contains hidden or 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
= form.input :your_checkbox_variable, :label => false, :require => false do | |
= form.check_box :your_checkbox_variable | |
My Awesome Checkbox |
OlderNewer