Skip to content

Instantly share code, notes, and snippets.

View seyhunak's full-sized avatar
🏆
Winning The Life

Seyhun Akyürek seyhunak

🏆
Winning The Life
View GitHub Profile
@seyhunak
seyhunak / bootstrap_form_builder.rb
Created January 28, 2012 17:58
Makes building forms that follow Twitter Bootstrap 2.0's conventions easier
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
def control_group(method, *args, &block)
options = args.extract_options!
error_class = object.errors[method].present? ? 'error' : ''
@template.field_set_tag(nil, class: ['control-group', error_class].join(' ')) do
label(method, options[:label], class: 'control-label') +
@template.content_tag(:div, class: 'controls') do
doc = Nokogiri::HTML::DocumentFragment.parse(@template.capture(&block))
if help_block = doc.at_css('.help-block')
help_block.before inline_errors(method)
@seyhunak
seyhunak / erb2haml.sh
Created February 6, 2012 16:06
Erb2Haml (requires ruby_parser)
find . -name '*erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \
bash
@seyhunak
seyhunak / haml2slim
Created February 6, 2012 16:12
Haml2Slim
Install:
gem install haml2slim
Usage:
# haml2slim -h
Usage: haml2slim INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY] [options]
--trace Show a full traceback on error
-d, --delete Delete HAML files
-h, --help Show this message
@seyhunak
seyhunak / database.yml.example mysql2
Created February 8, 2012 11:39 — forked from erichurst/database.yml.example mysql2
Rails 3 database.yml examples
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@seyhunak
seyhunak / on_update.task.rb
Created February 15, 2012 12:51 — forked from peterc/on_update.task.rb
Rake task to automatically run something (i.e. specs) when code files are changed
# Rake task to automatically run something (i.e. specs) when code files are changed
# By Peter Çoopér
#
# Motivation: I couldn't get autotest to run on my Sinatra project for some reason but realized
# it didn't require overengineering. Just detect when a file is changed and then re-run the specs!
#
# Examples:
# # rake on_update "rake"
# # rake on_update "spec spec/user_spec.rb"
#
@seyhunak
seyhunak / edit.html.erb
Created February 22, 2012 20:34 — forked from daz/edit.html.erb
twitter-bootstrap-rails ERB template
<%= render :partial => 'form' %>
@seyhunak
seyhunak / Gemfile
Created March 2, 2012 11:59
Rails TDD environment setup
group :test do
# rspec goodies
gem 'rspec-rails'
# DRb server for testing frameworks
gem 'spork'
# command line tool to easily handle events on file system modifications
gem 'guard'
gem 'guard-bundler'
@seyhunak
seyhunak / Guardfile
Created March 2, 2012 12:08
Rails TDD environment setup (observe changes on the file system)
# /
guard 'bundler' do
watch('Gemfile')
end
guard 'spork', wait: 60, cucumber: false, rspec: true, test_unit: false do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
@seyhunak
seyhunak / spec_helper.rb
Created March 2, 2012 12:14
Rails TDD environment setup (Spec)
# spec/spec_helper.rb
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# This file is copied to spec/ when you run 'rails generate rspec:install'
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private