forked from mbleigh/uberkit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Bleigh
committed
Jul 14, 2008
1 parent
7894d8a
commit c219287
Showing
6 changed files
with
156 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require 'uberkit/displayer' | ||
require 'uberkit/menu' | ||
require 'uberkit/menu' | ||
require 'uberkit/form' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require File.dirname(__FILE__) + "/forms/builder" | ||
require File.dirname(__FILE__) + "/forms/helper" | ||
|
||
ActionView::Base.send(:include, Uberkit::Forms::Helper) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class Uberkit::Forms::Builder < ActionView::Helpers::FormBuilder | ||
include ActionView::Helpers::CaptureHelper | ||
include ActionView::Helpers::TextHelper | ||
include ActionView::Helpers::UrlHelper | ||
include ActionView::Helpers::TagHelper | ||
|
||
helpers = field_helpers + %w(date_select datetime_select time_select select html_area state_select country_select) - %w(hidden_field label fields_for) | ||
|
||
helpers.each do |name| | ||
define_method(name) do |field, *args| | ||
options = args.extract_options! | ||
class_names = array_from_classes(options[:class]) | ||
class_names << name | ||
options[:class] = class_names.join(" ") | ||
args << options | ||
generic_field(options[:label],field,super(field,*args),{:description => options.delete(:description), :help => options.delete(:help), :required => options.delete(:required)}) | ||
end | ||
end | ||
|
||
def generic_field(label_text,field,content,options = {}) | ||
required = options.delete(:required) | ||
content_tag(:div, :class => "field_row#{' required' if required}#{' labelless' if label_text == ""}") do | ||
ret = label(field, (label_text || field.to_s.titleize).to_s + ":") unless label_text == "" | ||
ret << content | ||
ret << content_tag(:span, options.delete(:help), :class => "help") if options[:help] | ||
ret << content_tag(:span, options.delete(:description), :class => "description") if options[:description] | ||
ret << "<br/>" | ||
ret | ||
end | ||
end | ||
|
||
def submit(text) | ||
content_tag(:button, text, :type => "submit") | ||
end | ||
|
||
def custom(options = {}, &block) | ||
concat("<div class='field_row#{' labelless' unless options[:label]}'>#{"<label#{" for='#{options[:for]}'" if options[:for]}>#{options[:label] + ":" if options[:label]}</label>" if options[:label]}<div class='pseudo_field'>",block.binding) | ||
yield | ||
concat("</div> <br/></div>",block.binding) | ||
end | ||
|
||
def array_from_classes(html_classes) | ||
html_classes ? html_classes.split(" ") : [] | ||
end | ||
|
||
def fieldset(legend=nil,&block) | ||
concat("<fieldset>#{"<legend>#{legend}</legend>" if legend}",block.binding) | ||
yield | ||
concat("</fieldset>",block.binding) | ||
end | ||
|
||
def is_haml?; false 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Uberkit::Forms::Helper | ||
def parse_options(*args) | ||
options = args.extract_options! | ||
options.merge!(:builder => Uberkit::Forms::Builder) | ||
options[:html] ||= {} | ||
class_names = options[:html][:class] ? options[:html][:class].split(" ") : [] | ||
class_names << "uberform" | ||
class_names << options.delete(:kind).to_s | ||
options[:html][:class] = class_names.join(" ") | ||
args << options | ||
end | ||
|
||
def uberform_for(name_or_object_or_array, *args, &proc) | ||
args = parse_options(*args) | ||
form_for(name_or_object_or_array, *args, &proc) | ||
end | ||
|
||
def remote_uberform_for(name_or_object_or_array, *args, &proc) | ||
args = parse_options(*args) | ||
remote_form_for(name_or_object_or_array, *args, &proc) | ||
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