mbleigh-uberkit 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + "/forms/builder"
2
+ require File.dirname(__FILE__) + "/forms/helper"
3
+
4
+ ActionView::Base.send(:include, Uberkit::Forms::Helper)
@@ -0,0 +1,61 @@
1
+ class Uberkit::Forms::Builder < ActionView::Helpers::FormBuilder
2
+ include ActionView::Helpers::CaptureHelper
3
+ include ActionView::Helpers::TextHelper
4
+ include ActionView::Helpers::UrlHelper
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ helpers = field_helpers + %w(date_select datetime_select time_select select html_area state_select country_select) - %w(hidden_field label fields_for)
8
+
9
+ helpers.each do |name|
10
+ define_method(name) do |field, *args|
11
+ options = args.extract_options!
12
+ class_names = array_from_classes(options[:class])
13
+ class_names << name
14
+ options[:class] = class_names.join(" ")
15
+ args << options
16
+ generic_field(options[:label],field,super(field,*args),{:description => options.delete(:description), :help => options.delete(:help), :required => options.delete(:required)})
17
+ end
18
+ end
19
+
20
+ def generic_field(label_text,field,content,options = {})
21
+ required = options.delete(:required)
22
+ content_tag(:div, :class => "field_row#{' required' if required}#{' labelless' if label_text == ""}") do
23
+ ret = label(field, (label_text || field.to_s.titleize).to_s + ":") unless label_text == ""
24
+ ret << content
25
+ ret << content_tag(:span, options.delete(:help), :class => "help") if options[:help]
26
+ ret << content_tag(:span, options.delete(:description), :class => "description") if options[:description]
27
+ ret << "<br/>"
28
+ ret
29
+ end
30
+ end
31
+
32
+ def submit(text)
33
+ content_tag(:button, text, :type => "submit")
34
+ end
35
+
36
+ def custom(options = {}, &block)
37
+ 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)
38
+ yield
39
+ concat("</div> <br/></div>",block.binding)
40
+ end
41
+
42
+ def array_from_classes(html_classes)
43
+ html_classes ? html_classes.split(" ") : []
44
+ end
45
+
46
+ def fieldset(legend=nil,&block)
47
+ concat("<fieldset>#{"<legend>#{legend}</legend>" if legend}",block.binding)
48
+ yield
49
+ concat("</fieldset>",block.binding)
50
+ end
51
+
52
+ def output_buffer
53
+ @template.output_buffer
54
+ end
55
+
56
+ def output_buffer=(buf)
57
+ @template.output_buffer = buf
58
+ end
59
+
60
+ def is_haml?; false end
61
+ end
@@ -0,0 +1,22 @@
1
+ module Uberkit::Forms::Helper
2
+ def parse_options(*args)
3
+ options = args.extract_options!
4
+ options.merge!(:builder => Uberkit::Forms::Builder)
5
+ options[:html] ||= {}
6
+ class_names = options[:html][:class] ? options[:html][:class].split(" ") : []
7
+ class_names << "uberform"
8
+ class_names << options.delete(:kind).to_s
9
+ options[:html][:class] = class_names.join(" ")
10
+ args << options
11
+ end
12
+
13
+ def uberform_for(name_or_object_or_array, *args, &proc)
14
+ args = parse_options(*args)
15
+ form_for(name_or_object_or_array, *args, &proc)
16
+ end
17
+
18
+ def remote_uberform_for(name_or_object_or_array, *args, &proc)
19
+ args = parse_options(*args)
20
+ remote_form_for(name_or_object_or_array, *args, &proc)
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbleigh-uberkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -26,6 +26,9 @@ files:
26
26
  - README
27
27
  - lib/uberkit/displayer.rb
28
28
  - lib/uberkit/menu.rb
29
+ - lib/uberkit/form.rb
30
+ - lib/uberkit/forms/builder.rb
31
+ - lib/uberkit/forms/helper.rb
29
32
  - lib/uberkit.rb
30
33
  - rails/init.rb
31
34
  has_rdoc: false