Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / gist:139987
Created July 3, 2009 07:23
A ruby snippet for Parsing and cleaning Word HTML
#
# This function takes messy Word HTML pasted into a WYSIWYG and cleans it up
# It leaves the tags and attributes specified in the params
# Copyright (c) 2009, Radio New Zealand
# Released under the MIT license
require 'rubygems'
require 'sanitize'
def clean_up_word_html(html, elements = ['p', 'b', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], attributes={})
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@kaievns
kaievns / gist:1200232
Created September 7, 2011 10:28
RJS substitute for right-rails
#
# RJS handler was kicked out of Rails 3.1 along with Prototype
# so, here is a little substitute coz we use it here and there
#
# Just save it in some file in the `config/initializers`
#
module ActionView
module Template::Handlers
class RJS
# Default format used by RJS.
@kaievns
kaievns / gist:1497611
Created December 19, 2011 15:11
Gradient Buttons The Right Way
// This way you can change the buttons color with a simple `background-color` setting
// without need to regenerate the whole gradient
input[type=button], input[type=submit], button
font-family: Arial, Helvetica
color: #333
border: 1px solid #ccc
border-radius: .25em
text-shadow: 0 1px 1px rgba(0,0,0,.3)
@kaievns
kaievns / gist:1509909
Created December 22, 2011 10:54
CSS3 Links without icons
a.add, a.edit, a.delete
&:before
margin-right: .25em
a.add:before
content: "\271A"
a.edit:before
content: "\270E"
@clyfe
clyfe / cancan.rb
Last active September 29, 2015 01:07
Monkey patch for CanCan 1.6.7, replaces MetaWhere with Squeel and more
# Setup
# =====
#
# Put this gist in Rails.root/config/initializers/cancan.rb
# Add Squeel to Gemfile, see https://github.com/ernie/squeel
#
# gem "squeel", "~> 0.9.3"
#
# Load Squeel hash and symbol extensions in squeel config initializer
#
@simi
simi / Gemfile
Created February 7, 2012 14:32
Refinery + Twitter Bootstrap WIP
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
Order.class_eval do
checkout_flow do
go_to_state :address
go_to_state :delivery
go_to_state :payment, :if => lambda { payment_required? }
go_to_state :confirm, :if => lambda { confirmation_required? }
go_to_state :complete
remove_transition :from => :delivery, :to => :confirm
end
end
@troy
troy / oneline_detailed_logging.rb
Created August 10, 2012 02:13
One-line detailed logging for Rails 3 (ActiveSupport::Notifications) and later
# Outputs this at warn log level:
# 1.2.3.4 GET /path 200 OK BlahController#action HTML 938.2 (DB 11.8, View 719.7) {params} {optional params from flash[:log]}
#
# Save as config/initializers/oneline_detailed_logging.rb. Consider
# decreasing the log level from "info" to "warn" (in production.rb) so
# the one-line log message replaces the standard request logs.
# override process_action to add 2 things to the payload:
# - remote IP
@jrochkind
jrochkind / Explanation.md
Created October 15, 2012 17:19
Truncating html with nokogiri, with/without Rails

Rails has a handy truncate helper (which is actually mostly a method added to String ), but it warns you it's not safe to use on html source, it'll cut off end tags and such.

What if you want an HTML safe one? There are a variety of suggested solutions you can google, none of which were quite robust/powerful enough for me.

So I started with my favorite, by Andrea Singh, using nokogiri.

But:

  • I modified it to not monkey-patch Nokogiri, but be a static method instead (sadly making already confusing code yet more confusing, but I didn't want to monkey patch nokogiri)