Permalink
Browse files

Remove form helper (formtastic provides all of these)

  • Loading branch information...
joshuaclayton committed Mar 31, 2010
1 parent 518f041 commit f2e301a1163b0b586112938c22bc1bc46f3056f7
Showing with 13 additions and 326 deletions.
  1. +0 −2 lib/viewaide/helpers.rb
  2. +0 −165 lib/viewaide/helpers/form_helper.rb
  3. +0 −135 test/form_helper_test.rb
  4. +13 −24 test/grid_helper_test.rb
View
@@ -1,5 +1,4 @@
require "viewaide/helpers/date_helper"
-require "viewaide/helpers/form_helper"
require "viewaide/helpers/link_helper"
require "viewaide/helpers/structure_helper"
require "viewaide/helpers/table_helper"
@@ -11,7 +10,6 @@
module Viewaide
module Helpers
include DateHelper
- include FormHelper
include LinkHelper
include StructureHelper
include TableHelper
@@ -1,165 +0,0 @@
-module Viewaide
- module Helpers
- module FormHelper
-
- # Generates a submit button for forms
- #
- # @param [String] value the text for the button
- # @param [*Args]
- # @return [String]
- # @example
- # <%= submit_button "Create" %>
- # generates
- # <button class="btn" type="submit" value="Create">
- # <span>Create</span>
- # </button>
- #
- # @example
- # <%= submit_button "Create", :class1, :class2, "another-class" %>
- # generates
- # <button class="btn class1 class2 another-class" type="submit" value="Create">
- # <span>Create</span>
- # </button>
- #
- # @example
- # <%= submit_button "Create", :class1, :id => "custom", :type => "image" %>
- # generates
- # <button class="btn class1" type="image" id="custom" value="Create">
- # <span>Create</span>
- # </button>
- #
- # @example
- # <%= submit_button "Create", :class1, :value => "override" %>
- # generates
- # <button class="btn class1" type="submit" value="override">
- # <span>Create</span>
- # </button>
- def submit_button(value, *args)
- options = args.extract_options!
- css_classes = ["btn"] << options.delete(:class) << args
- css_classes = clean_css_classes(css_classes, {"last" => last_column})
-
- content_tag :button,
- "<span>#{value}</span>",
- { :value => value,
- :type => "submit",
- :class => css_classes
- }.merge(options)
- end
-
- # Generates a wrapper set for form inputs and labels
- #
- # @param [*Args]
- # @return [String]
- # @example
- # <% set do %>words<% end %>
- # generates
- # <div class="text">words</div>
- #
- # @example
- # <% set :checkbox do %>words<% end %>
- # generates
- # <div class="checkbox">words</div>
- #
- # @example
- # <% set :id => "custom-id" do %>words<% end %>
- # generates
- # <div class="text" id="custom-id">words</div>
- #
- # @example
- # <% set :half do %>words<% end %>
- # generates
- # <div class="text span-12">words</div>
- def set(*args, &block)
- options = args.extract_options!
- css_classes = [] << options.delete(:class) << args
-
- if !other_than_grid?(args.map(&:to_s) - ["error", "last", last_column.to_s])
- css_classes << "text"
- end
-
- if standardize_css_classes(css_classes).include?("textarea")
- css_classes << "text"
- end
-
- css_classes = clean_css_classes(css_classes, {"last" => last_column})
-
- html = clean_column(css_classes) do
- content_tag :div,
- capture(&block),
- options.merge(:class => css_classes)
- end
-
- concat(html)
- end
-
- # Generates a fieldset with legend
- #
- # @param [*Args]
- # @return [String]
- # @example
- # <% fieldset do %>words<% end %>
- # generates
- # <fieldset>words</fieldset>
- #
- # @example
- # <% fieldset "User Information" do %>words<% end %>
- # generates
- # <fieldset>
- # <h3 class="legend">User Information</h3>
- # </fieldset>
- #
- # @example
- # <% fieldset "User Information", :hform do %>words<% end %>
- # generates
- # <fieldset class="hform">
- # <h3 class="legend">User Information</h3>
- # </fieldset>
- #
- # @example
- # <% fieldset "User Information", :hform, :legend => {:class => "lgnd", :id => "legend-id"} do %>
- # words
- # <% end %>
- # generates
- # <fieldset class="hform">
- # <h3 class="legend lgnd" id="legend-id">User Information</h3>
- # words
- # </fieldset>
- #
- # @example
- # <% fieldset "User Information", :hform, :id => "user-info" do %>
- # words
- # <% end %>
- # generates
- # <fieldset class="hform" id="user-info">
- # <h3 class="legend">User Information</h3>
- # words
- # </fieldset>
- def fieldset(*args, &block)
- options = args.extract_options!
- css_classes = [] << options.delete(:class) << args
- title = args.shift if args.first.is_a?(String)
- legend = if title.blank?
- ""
- else
- legend_opts = options.delete(:legend) || {}
- legend_classes = clean_css_classes([legend_opts.delete(:class)] << "legend")
- content_tag :h3,
- title,
- {:class => legend_classes}.merge(legend_opts)
- end
-
- css_classes = clean_css_classes(css_classes, {"last" => last_column})
-
- html = clean_column(css_classes) do
- content_tag :fieldset,
- legend + capture(&block),
- options.merge(:class => css_classes)
- end
-
- concat(html)
- end
-
- end
- end
-end
View
@@ -1,135 +0,0 @@
-require "test_helper"
-
-class FormHelperTest < Viewaide::ViewTestCase
-
- context "submit_button" do
-
- should "default with the correct structure" do
- show_view "<%= submit_button 'Create' %>" do
- assert_select "button.btn[type=submit][value=Create]" do
- assert_select "span", "Create"
- end
- end
- end
-
- should "allow adding additional classes" do
- show_view "<%= submit_button 'Create', 'adtl-class', :dumb %>" do
- assert_select "button.btn.adtl-class.dumb[type=submit][value=Create]" do
- assert_select "span", "Create"
- end
- end
- end
-
- should "handle additional attributes set" do
- show_view "<%= submit_button 'Create', :kls, :id => 'my-id', :type => 'image' %>" do
- assert_select "button.btn.kls#my-id[type=image][value=Create]" do
- assert_select "span", "Create"
- end
- end
- end
-
- should "allow overriding of value" do
- show_view "<%= submit_button 'Create', :value => 'override' %>" do
- assert_select "button.btn[type=submit][value=override]" do
- assert_select "span", "Create"
- end
- end
- end
-
- end
-
- context "set" do
-
- should "default with the correct structure" do
- show_view "<% set do %>words<% end %>" do
- assert_select "div.text", "words"
- end
- end
-
- should "allow adding/overriding classes" do
- show_view "<% set :checkbox do %>words<% end %>" do
- assert_select "div.checkbox", "words"
- end
- end
-
- should "handle additional attributes set" do
- show_view "<% set :id => 'custom-id' do %>words<% end %>" do
- assert_select "div.text#custom-id", "words"
- end
- end
-
- should "assign default class if width class is passed as the only class" do
- show_view "<% set :half do %>words<% end %>" do
- assert_select "div.text.span-12", "words"
- end
- end
-
- should "assign default class if last class is passed as the only class" do
- show_view "<% set :half, :last do %>words<% end %>" do
- assert_select "div.span-12.text.last", "words"
- end
- end
-
- should "assign default class if error class is passed" do
- show_view "<% set :half, :last, :error do %>words<% end %>" do
- assert_select "div.span-12.text.last.error", "words"
- end
- end
-
- should "assign default class if the class textarea is present" do
- show_view "<% set :textarea do %>words<% end %>" do
- assert_select "div.textarea.text", "words"
- end
- end
-
- end
-
- context "fieldset" do
-
- should "default with the correct structure" do
- show_view "<% fieldset do %>words<% end %>" do
- assert_select "fieldset", "words"
- end
- end
-
- should "assign the first argument as the legend if it is a string" do
- show_view "<% fieldset 'User Information' do %>words<% end %>" do
- assert_select "fieldset", /words/ do
- assert_select "h3.legend", "User Information"
- end
- end
- end
-
- should "allow adding fieldset classes" do
- show_view "<% fieldset :hform, :last do %>words<% end %>" do
- assert_select "fieldset.hform.last", "words"
- end
- end
-
- should "allow adding fieldset classes and a legend" do
- show_view "<% fieldset 'User Information', :hform, :last do %>words<% end %>" do
- assert_select "fieldset.hform.last", /words/ do
- assert_select "h3.legend", "User Information"
- end
- end
- end
-
- should "allow assignment of legend attributes" do
- show_view "<% fieldset 'User Information', :hform, :legend => {:class => 'lgnd', :id => 'legend-id'} do %>words<% end %>" do
- assert_select "fieldset.hform", /words/ do
- assert_select "h3.legend.lgnd#legend-id", "User Information"
- end
- end
- end
-
- should "allow assignment of fieldset attributes" do
- show_view "<% fieldset 'User Information', :hform, :id => 'my-fieldset' do %>words<% end %>" do
- assert_select "fieldset.hform#my-fieldset", /words/ do
- assert_select "h3.legend", "User Information"
- end
- end
- end
-
- end
-
-end
Oops, something went wrong.

0 comments on commit f2e301a

Please sign in to comment.