Skip to content

Instantly share code, notes, and snippets.

# image_uploader.rb
version :small_3x do process resize_to_limit: [900, 900] end
version :small_2x, from_version: :small_3x do process resize_to_limit: [600, 600] end
version :small, from_version: :small_2x do process resize_to_limit: [300, 300] end
version :thumb_3x, from_version: :small do process resize_to_limit: [150, 150] end
version :thumb_2x, from_version: :thumb_3x do process resize_to_limit: [100, 100] end
version :thumb, from_version: :thumb_2x do process resize_to_limit: [50, 50] end
# application_helper.rb
def default_content_for(name, content = nil, options = {}, &block)
if name.is_a? Hash
name.each { |k, v| content_for(k, v) unless content_for?(k) }
elsif content || block_given?
content_for(name, content, options, &block) unless content_for?(name)
else
raise(ArgumentError, 'expected a second argument or block for the default content')
end
end
def titled_time_tag(time, *args, &block)
options = args.extract_options!
format = options.delete(:format) || :mon_d_12hr
content = args.first || time.to_s(format)
time_tag time, content, options.reverse_merge(title: time.to_s(:long)), &block
end
def bool_label(toggle)
if toggle
content_tag(:span, defined?(icon) ? icon('check') : 'Yes', class: 'label label-success')
else
content_tag(:span, defined?(icon) ? icon('times') : 'No', class: 'label label-default')
end
end
class CocoonLimit
constructor: (@$cocoon) ->
@limit = parseInt(@$cocoon.data("cocoon-limit"))
@$cocoon.on "cocoon:after-insert", @toggleAddButton
@$cocoon.on "cocoon:after-remove", @toggleAddButton
@toggleAddButton()
toggleAddButton: =>
hide = @$cocoon.find(".nested-fields:visible").length >= @limit
@$cocoon.find(".add_fields").toggleClass("hidden", hide)
.valign-outer {
&::before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.3em; //adjusts for spacing
}
.valign-inner {
class Tableless
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :new_record
def initialize(attributes={})
self.new_record = attributes.blank?
attributes && attributes.each do |name, value|
def bootstrap_nav_dropdown(text, url="#", active=nil, &block)
toggle_content = "#{text} #{content_tag(:b, '', class: 'caret')}"
toggle = link_to toggle_content.html_safe, url, class: "dropdown-toggle", "data-toggle" => "dropdown"
list = content_tag(:ul, class: "dropdown-menu", &block)
active = list.include?('li class="active"') if active.nil?
content_tag(:li, toggle + list, class: "dropdown#{' active' if active}")
end
def bootstrap_btn_dropdown(text, style="default", &block)
on trim(theseCharacters, someText)
-- default values (all whitespace)
if theseCharacters is true then set theseCharacters to {" ", tab, ASCII character 10, return, ASCII character 0}
repeat until first character of someText is not in theseCharacters
set someText to text 2 thru -1 of someText
end repeat
repeat until last character of someText is not in theseCharacters
set someText to text 1 thru -2 of someText
class FluidVideos
@init: (container=null, $videos=null) ->
$videos ||= $("iframe[src*='vimeo.com'], iframe[src*='youtube.com']")
$videos.each ->
$(this)
.data('aspectRatio', this.height/this.width)
.removeAttr('height')
.removeAttr('width')