Skip to content

Instantly share code, notes, and snippets.

@chriseppstein
chriseppstein / general.sass
Created July 22, 2008 22:01
Sass Mixin Examples
// Clearing floats without extra markup
// Based on How To Clear Floats Without Structural Markup by PiE
// [http://www.positioniseverything.net/easyclearing.html]
// From the official sass documentation.
=clearfix
display: inline-block
&:after
content: "."
display: block
height: 0
= spans(!columns)
- for !column from 1 through !columns by 2 // though = .., to = ..., by = incrementor
+span(!column,!columns)
= span(!column, !columns)
.span-#{!column}
:width= 45px * !column + 15px
- if !column != !columns
:margin-right 15px
require 'ignoring_diff'
Hash.send(:include, IgnoringDiff)
h = {:foo => :bar}
h.diff({})
# => {:foo => :bar}
h.ignore_difference_for(:foo)
h.diff({})
# => {}
@chriseppstein
chriseppstein / tracer.rb
Created August 21, 2008 22:44
Trace method entrances and exists. Requires ActiveSupport.
module Tracer
def trace(method)
method, ending = split_method_name(method)
define_method "#{method}_with_trace#{ending}" do |*arguments|
puts "called #{self.class}##{method}#{ending}(#{arguments.map(&:inspect).join(', ')})"
returning(send("#{method}_without_trace#{ending}", *arguments)) do |v|
puts "#{self.class}##{method}#{ending} => #{v.inspect}"
end
end
alias_method_chain "#{method}#{ending}", :trace
.compass { margin: 1em auto; position: relative; width: 16em; height: 16em; font-size: 24px; font-family: "Academy Engraved LET", "Papyrus"; }
.compass .n, .compass .s, .compass .e, .compass .w { position: absolute; width: 4em; height: 4em; text-align: center; vertical-align: middle; }
.compass .w { left: 0px; }
.compass .n.w, .compass .s.w { left: 2em; }
.compass .n, .compass .s { left: 6em; }
.compass .n.e, .compass .s.e { left: 10em; }
.compass .e { left: 12em; }
.compass .n { top: 0px; }
.compass .n.w, .compass .n.e { top: 2em; }
.compass .w, .compass .e { top: 6em; }
module Anonymizer
def anonymize_attribute(attribute)
self.send(:include, Module.new do
define_method attribute do
a = @attributes[attribute.to_s]
a && attribute.to_s.ends_with?("_id") ? a.to_i : a
end
define_method "#{attribute}_with_anonymous" do
send("#{attribute}_without_anonymous") unless anonymous?
end
module ContentForHelpers
def content_for?(name, options = {}, &block)
has_content = (!instance_variable_get("@content_for_#{name}").strip.blank? rescue nil)
should_process = options[:negate] ? !has_content : has_content
if should_process && block_given?
concat(capture(&block), block.binding)
end
return should_process
end
.field
Display Name:
= h @user.name
= link_to "edit", edit_user_url(@user, :field => "name")
.field
Your Email:
= h @user.email
= link_to "edit", edit_user_url(@user, :field => "email")
.field
Password:
From e2a475f33f822d0f5810f26fcc9e562997358326 Mon Sep 17 00:00:00 2001
From: Chris Eppstein <chris@eppsteins.net>
Date: Fri, 3 Oct 2008 14:23:25 -0700
Subject: [PATCH] Fixed bug in compass initializer.
---
config/initializers/compass.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/config/initializers/compass.rb b/config/initializers/compass.rb
//
This file is well documented with a silent comment that describes what it does.
In this comment we are testing mutli-line silent comments at the start of a document.
body
:margin 0
:font 0.85em "Lucida Grande", "Trebuchet MS", Verdana, sans-serif
:color #fff
:background url(/images/global_bg.gif)