Skip to content

Instantly share code, notes, and snippets.

@yannski
Created February 10, 2012 18:07
Show Gist options
  • Save yannski/1791339 to your computer and use it in GitHub Desktop.
Save yannski/1791339 to your computer and use it in GitHub Desktop.
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html_tag
end
class MyBuilder < ActionView::Helpers::FormBuilder
include ActionView::Helpers::TagHelper
def self.create_tagged_field(method_name)
define_method(method_name) do |label, *args|
if args.last.is_a? Hash
options = args.pop
end
options ||= {}
options[:class] ||= ""
error = @object && label.present? && @object.errors.keys.include?(label) && @object.errors[label].any?
options[:class] += " error" if error
input = super(label.to_sym, options)
input += content_tag "span", (content_tag "i", options[:help]), :class => "help-inline"
txt = self.label label.to_sym, nil, options
txt += content_tag "div", input, :class => "input"
content_tag "div", txt, :class => "clearfix"
end
end
%w(email_field phone_field password_field text_field text_area file_field check_box time_zone_select date_select).each do |name|
create_tagged_field(name)
end
def select method, choices, options = {}, html_options = {}
html_options[:class] ||= ""
html_options[:class] += " error" if @object && @object.errors.keys.include?(method.to_sym) && @object.errors[method].any?
super
end
def label method, content_or_options = nil, options = nil, &block
options ||= {}
options[:class] ||= ""
options[:class] += " error" if @object && @object.errors.keys.include?(method.to_sym) && @object.errors[method].any?
super
end
def radio_button method, tag_value, options = {}
options ||= {}
options[:class] ||= ""
options[:class] += " error" if @object && @object.errors.keys.include?(method.to_sym) && @object.errors[method].any?
super
end
end
class PlaceholderBuilder < ActionView::Helpers::FormBuilder
include ActionView::Helpers::TagHelper
def self.create_tagged_field(method_name)
define_method(method_name) do |label, *args|
if args.last.is_a? Hash
options = args.pop
end
options ||= {}
options[:placeholder] ||= @object.class.human_attribute_name(label)
if options[:inline]
super(label.to_sym, options)
else
content_tag "div", super(label.to_sym, options), :class => "clearfix"
end
end
end
%w(email_field password_field text_field text_area file_field check_box time_zone_select).each do |name|
create_tagged_field(name)
end
def date_select method, options = {}, html_options = {}
html_options[:class] ||= ""
html_options[:class] += " error" if @object && @object.errors.keys.include?(method.to_sym) && @object.errors[method].any?
super
end
end
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Plop
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :en
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.action_view.default_form_builder = MyBuilder
# Action Mailer complains if this is not set
config.action_mailer.default_url_options = {:host => "http://plop.dev"}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment