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 Jammit | |
class Compressor | |
# Compiles a single JST file by writing out a javascript that adds | |
# template properties to a top-level template namespace object. Adds a | |
# JST-compilation function to the top of the package, unless you've | |
# specified your own preferred function, or turned it off. | |
# JST templates are named with the basename of their file. | |
# We are monkey-patching it so that we get Haml compilation *before* it hits the client. | |
def compile_jst(paths) |
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
// It's more advisable to store the compiled version of the jQuery template in JST, | |
// And then use a separate function that renders on a per-use basis from that pre-compiled template. | |
function jqueryCacheTemplate(templateString){ | |
return $.template(null, templateString); | |
} | |
function jqueryTemplate(name){ | |
return $.tmpl(JST[name], arguments[0], arguments[1]); | |
} |
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
def update_amount(amt, change_type) | |
if change_type == 'Withdraw' | |
self.amount -= amt | |
elsif change_type == 'Deposit' | |
self.amount += amt | |
else | |
raise ArgumentError.new("Unknown type #{change_type} when altering account funds.") | |
end | |
end |
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
acts_as_event_logger( | |
:attributes => [:active, :contact, :company_name, [:primary_address, :address_change], [:primary_address, :phone_change], [:primary_address, :phone2_change], | |
[:primary_address, :fax_change], :url, :description, :services, :coverage, :memberships, :business_since, :license_number, [:owners, :email], content_x_log_array ], | |
:cache_values => [:owners], | |
:event_type => "Profile Update" | |
) | |
#return an array of arrays for the act event logger track changes in content_ui fields | |
# [ profile content real name, "displayed field name: displayed field value"] |
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
class Array | |
def find_duplicates(other_array) | |
hsh = {} | |
other_array.each{|val| hsh[val] = true} | |
# Ya, could be done easier using Array.select{}, but that feels like cheating | |
# return test_array.select{|val| hsh[val] == true} | |
result_array = [] | |
self.each{ |val| result_array << val if hsh[val] } | |
result_array |
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
# Somewhere in heaven... | |
rainy_regions = Region.find(:all, :conditions => ["name IN (?)", [:denver, :loveland, :fort_collins]]) | |
rainy_regions.each{ |rain_here| rain_here.saturate_clouds! } | |
# Meanwhile, in the stratosphere... | |
if (saturated_regions = Cloud.find_all_by_density(MAX_CLOUD_SATURATION_DENSITY).map{|cloud| cloud.region}).any? | |
current_weather = Rain.new( :regions => saturated_regions ) | |
current_weather.quantity = :downpour | |
current_weather.duration = 6.hours |
NewerOlder