jquery-ui-form 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.document +5 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +109 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +25 -0
  7. data/Rakefile +53 -0
  8. data/VERSION +1 -0
  9. data/jquery-ui-form.gemspec +149 -0
  10. data/lib/generators/jquery_ui_form/install/install_generator.rb +18 -0
  11. data/lib/generators/templates/jquery-ui-form.js +46 -0
  12. data/lib/generators/templates/jquery-ui-form.rb +5 -0
  13. data/lib/generators/templates/jquery-ui-form.sass +115 -0
  14. data/lib/jquery-ui-form.rb +1 -0
  15. data/lib/jquery_ui_form.rb +7 -0
  16. data/lib/jquery_ui_form/form_builder.rb +43 -0
  17. data/lib/jquery_ui_form/helpers.rb +17 -0
  18. data/lib/jquery_ui_form/helpers/button_helper.rb +39 -0
  19. data/lib/jquery_ui_form/helpers/error_helper.rb +39 -0
  20. data/lib/jquery_ui_form/helpers/form_helper.rb +19 -0
  21. data/lib/jquery_ui_form/helpers/input_helper.rb +145 -0
  22. data/lib/jquery_ui_form/helpers/label_helper.rb +33 -0
  23. data/lib/jquery_ui_form/helpers/wrapper_helper.rb +41 -0
  24. data/lib/jquery_ui_form/inputs.rb +20 -0
  25. data/lib/jquery_ui_form/inputs/boolean_input.rb +16 -0
  26. data/lib/jquery_ui_form/inputs/check_boxes_input.rb +75 -0
  27. data/lib/jquery_ui_form/inputs/date_input.rb +24 -0
  28. data/lib/jquery_ui_form/inputs/email_input.rb +12 -0
  29. data/lib/jquery_ui_form/inputs/file_input.rb +12 -0
  30. data/lib/jquery_ui_form/inputs/hidden_input.rb +11 -0
  31. data/lib/jquery_ui_form/inputs/number_input.rb +12 -0
  32. data/lib/jquery_ui_form/inputs/password_input.rb +11 -0
  33. data/lib/jquery_ui_form/inputs/phone_input.rb +12 -0
  34. data/lib/jquery_ui_form/inputs/radio_input.rb +33 -0
  35. data/lib/jquery_ui_form/inputs/range_input.rb +12 -0
  36. data/lib/jquery_ui_form/inputs/search_input.rb +12 -0
  37. data/lib/jquery_ui_form/inputs/select_input.rb +19 -0
  38. data/lib/jquery_ui_form/inputs/string_input.rb +11 -0
  39. data/lib/jquery_ui_form/inputs/text_input.rb +13 -0
  40. data/lib/jquery_ui_form/inputs/url_input.rb +12 -0
  41. data/lib/jquery_ui_form/railtie.rb +14 -0
  42. data/spec/form_helper_spec.rb +22 -0
  43. data/spec/helpers/button_helper_spec.rb +54 -0
  44. data/spec/helpers/error_helper_spec.rb +81 -0
  45. data/spec/helpers/input_helper_spec.rb +18 -0
  46. data/spec/helpers/label_helper_spec.rb +31 -0
  47. data/spec/helpers/wrapper_helper_spec.rb +73 -0
  48. data/spec/inputs/boolean_input_spec.rb +25 -0
  49. data/spec/inputs/check_boxes_input_spec.rb +39 -0
  50. data/spec/inputs/date_input_spec.rb +47 -0
  51. data/spec/inputs/email_input_spec.rb +24 -0
  52. data/spec/inputs/file_input_spec.rb +24 -0
  53. data/spec/inputs/hidden_input_spec.rb +24 -0
  54. data/spec/inputs/number_input_spec.rb +24 -0
  55. data/spec/inputs/password_input_spec.rb +23 -0
  56. data/spec/inputs/phone_input_spec.rb +24 -0
  57. data/spec/inputs/radio_input_spec.rb +39 -0
  58. data/spec/inputs/range_input_spec.rb +24 -0
  59. data/spec/inputs/search_input_spec.rb +24 -0
  60. data/spec/inputs/select_input_spec.rb +28 -0
  61. data/spec/inputs/string_input_spec.rb +24 -0
  62. data/spec/inputs/text_input_spec.rb +24 -0
  63. data/spec/inputs/url_input_spec.rb +24 -0
  64. data/spec/spec_helper.rb +63 -0
  65. metadata +272 -0
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ButtonHelper' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+ @object = mock({
10
+ :new_record? => true
11
+ })
12
+ end
13
+
14
+ it "should show button tag" do
15
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
16
+ builder.button("My button").should have_tag("button[type='submit'].ui-button") do |text|
17
+ text.should contain("My button")
18
+ end
19
+ end
20
+ end
21
+
22
+ it "should show button tag with options" do
23
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
24
+ builder.button("My button", :class => "kuku", :type => "reset", :icon => "plus").should have_tag("button[type='reset'][data-icon='ui-icon-plus'].kuku") do |text|
25
+ text.should contain("My button")
26
+ end
27
+ end
28
+ end
29
+
30
+ it "should show submit button" do
31
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
32
+ builder.object = @object
33
+ builder.submit.should have_tag("button[type='submit'][data-icon='ui-icon-check']") do |text|
34
+ text.should contain("Create")
35
+ end
36
+ end
37
+ end
38
+
39
+ it "should show cancel button" do
40
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
41
+ builder.cancel.should have_tag("button[type='reset'][data-icon='ui-icon-close']") do |text|
42
+ text.should contain("Cancel")
43
+ end
44
+ end
45
+ end
46
+
47
+ it "should show cancel button with options" do
48
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
49
+ builder.cancel("data-href" => "/www").should have_tag("button[type='reset'][data-icon='ui-icon-close'][data-href='/www']") do |text|
50
+ text.should contain("Cancel")
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ErrorHelper' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+ @object = mock({
10
+ :errors => {:name => "Invalid name"}
11
+ })
12
+ end
13
+
14
+ it "should not find existing errors" do
15
+ helper.has_errors?(:login).should be_false
16
+ end
17
+
18
+ it "should find existing errors" do
19
+ helper.has_errors?(:name).should be_true
20
+ end
21
+
22
+ it "should get errors for attribute" do
23
+ helper.error_message_on(:name).should == "Invalid name"
24
+ end
25
+
26
+ it "should get errors for base" do
27
+ helper.error_messages_on_base.should be_blank
28
+ end
29
+
30
+ it "should return inline error for attribute" do
31
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
32
+ builder.object = @object
33
+ builder.inline_error(:name).should have_tag("div.ui-input-error-message")
34
+ end
35
+ end
36
+
37
+ it "should not display model errors" do
38
+ helper.model_errors.should be_blank
39
+ end
40
+
41
+ it "should display default error" do
42
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
43
+ builder.object = @object
44
+ builder.model_errors("One error").should have_tag("div.ui-base-error-messages>p>strong") do |text|
45
+ text.should contain("One error")
46
+ end
47
+ end
48
+ end
49
+
50
+ it "should display default errors" do
51
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
52
+ builder.object = @object
53
+ builder.model_errors(["One", "Two"]).should have_tag("div.ui-base-error-messages>p>strong",:count => 2) do |text|
54
+ text.should contain("OneTwo")
55
+ end
56
+ end
57
+ end
58
+ it "should display model errors" do
59
+ @object = mock({
60
+ :errors => {:base => "One"}
61
+ })
62
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
63
+ builder.object = @object
64
+ builder.model_errors.should have_tag("div.ui-base-error-messages>p>strong") do |text|
65
+ text.should contain("One")
66
+ end
67
+ end
68
+ end
69
+
70
+ it "should display model errors with default" do
71
+ @object = mock({
72
+ :errors => {:base => "One"}
73
+ })
74
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
75
+ builder.object = @object
76
+ builder.model_errors(["Two", "Three"]).should have_tag("div.ui-base-error-messages>p>strong",:count => 3) do |text|
77
+ text.should contain("OneTwoThree")
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'InputHelper' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+
10
+ end
11
+
12
+ it "should show inline hint" do
13
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
14
+ builder.inline_hint("I am hint").should have_tag("div.ui-input-hint")
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'LabelHelper' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+ @object = mock({
10
+ :errors => {:name => "Invalid name"}
11
+ })
12
+ @object_name = :user
13
+ end
14
+
15
+ it "should show label tag" do
16
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
17
+ builder.label(:login).should have_tag("label") do |text|
18
+ text.should contain("Login")
19
+ end
20
+ end
21
+ end
22
+
23
+ it "should show label tag with options" do
24
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
25
+ builder.label(:login, :for => "kuku").should have_tag("label[for='kuku']") do |text|
26
+ text.should contain("Login")
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'WrapperHelper' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ %w(wrapper column row buttons).each do |mode|
9
+ describe "##{mode}" do
10
+ css = mode.gsub(/input_/,'')
11
+ it "should add #{mode} wrapper" do
12
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
13
+ builder.send(mode) do
14
+ end.should have_tag("div.ui-form-#{css}")
15
+ end
16
+ end
17
+ it "should add #{mode} tag with options" do
18
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
19
+ builder.send(mode,:class => "kuku") do
20
+ end.should have_tag("div.ui-form-#{css}.kuku")
21
+ end
22
+ end
23
+ it "should add #{mode} tag with content" do
24
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
25
+ builder.send(mode) do
26
+ "<h1>Yo</h1>".html_safe
27
+ end.should have_tag("div.ui-form-#{css}>h1") do |text|
28
+ text.should contain("Yo")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#fieldset' do
36
+
37
+ it 'should add fieldset tag ' do
38
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
39
+ builder.fieldset do
40
+ end.should have_tag("fieldset.ui-fieldset")
41
+ end
42
+ end
43
+ it 'should add fieldset tag with legend' do
44
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
45
+ builder.fieldset("Hi") do
46
+ end.should have_tag("legend") do |text|
47
+ text.should contain("Hi")
48
+ end
49
+ end
50
+ end
51
+
52
+ it 'should add fieldset tag with options and legend' do
53
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
54
+ builder.fieldset("Hi", "data-row" => "xml") do
55
+ end.should have_tag("fieldset[data-row='xml']>legend") do |text|
56
+ text.should contain("Hi")
57
+ end
58
+ end
59
+ end
60
+
61
+ it 'should add fieldset tag with content' do
62
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
63
+ builder.fieldset do
64
+ "<h1>Yo</h1>aa".html_safe
65
+ end.should have_tag("fieldset>h1") do |text|
66
+ text.should contain("Yo")
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'BooleanInput' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+ end
10
+
11
+ it "should return check box tag" do
12
+ helper.jquery_form_for(:new_post, :url => '/hello') do |builder|
13
+ builder.input(:login, :as => :boolean).should have_tag("input[type='checkbox'].ui-boolean-input")
14
+ end
15
+ end
16
+
17
+ it "should return check box tag with options" do
18
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
19
+ box = builder.input(:login, :as => :boolean, "data-name" =>"my-name", :checked_value => "One")
20
+ box.should have_tag("input[type='checkbox'][data-name='my-name'][value='One'].ui-boolean-input")
21
+ box.should have_tag("input[type='hidden'][value='0']")
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'CheckBoxesInput' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+ @object = mock({
10
+ :new_record? => true,
11
+ :login => "A"
12
+ })
13
+ end
14
+
15
+ it "should return check boxes tag" do
16
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
17
+ builder.object = @object
18
+ builder.input(:login, :as => :check_boxes, :collection => [["A","a"], ["B","b"]]).
19
+ should have_tag("input[type='checkbox'].ui-boolean-input" , :count => 2)
20
+ end
21
+ end
22
+
23
+ it "should return check boxes tag with options" do
24
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
25
+ builder.object = @object
26
+ builder.input(:login, :as => :check_boxes, :collection => [["A","a"]], "data-name" =>"my-name").
27
+ should have_tag("input[type='checkbox'][data-name='my-name'].ui-boolean-input")
28
+ end
29
+ end
30
+
31
+ it "should return check boxes tag as buttonset" do
32
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
33
+ builder.object = @object
34
+ a = builder.input(:login, :as => :check_boxes, :buttonset => true, :collection => [["A","a"], ["B","b"]])
35
+ a.should have_tag("input[type='checkbox'].ui-boolean-input" , :count => 2)
36
+ a.should have_tag("fieldset.to-buttonset")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'DateInput' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+
10
+ end
11
+
12
+ it "should return date tag" do
13
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
14
+ builder.input(:birthdate, :as => :date).should have_tag("input[type='text'].ui-date-input")
15
+ end
16
+ end
17
+
18
+ it "should return date tag with options" do
19
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
20
+ builder.input(:birthdate, :as => :date, "data-name" =>"my-name").should have_tag("input[type='text'][data-name='my-name'].ui-date-input")
21
+ end
22
+ end
23
+
24
+ it "should return datetime tag" do
25
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
26
+ builder.input(:birthdate, :as => :datetime).should have_tag("input[type='text'].ui-datetime-input")
27
+ end
28
+ end
29
+
30
+ it "should return datetime tag with options" do
31
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
32
+ builder.input(:birthdate, :as => :datetime, "data-name" =>"my-name").should have_tag("input[type='text'][data-name='my-name'].ui-datetime-input")
33
+ end
34
+ end
35
+
36
+ it "should return time tag" do
37
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
38
+ builder.input(:birthdate, :as => :time).should have_tag("input[type='text'].ui-time-input")
39
+ end
40
+ end
41
+
42
+ it "should return time tag with options" do
43
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
44
+ builder.input(:birthdate, :as => :time, "data-name" =>"my-name").should have_tag("input[type='text'][data-name='my-name'].ui-time-input")
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'EmailInput' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+
10
+ end
11
+
12
+ it "should return email tag" do
13
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
14
+ builder.input(:email).should have_tag("input[type='email'].ui-email-input")
15
+ end
16
+ end
17
+
18
+ it "should return email tag with options" do
19
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
20
+ builder.input(:email, "data-name" =>"my-name").should have_tag("input[type='email'][data-name='my-name'].ui-email-input")
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'FileInput' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+
10
+ end
11
+
12
+ it "should return file tag" do
13
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
14
+ builder.input(:attachment).should have_tag("input.ui-file-input")
15
+ end
16
+ end
17
+
18
+ it "should return textarea tag with options" do
19
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
20
+ builder.input(:attachment, "data-name" =>"my-name").should have_tag("input[data-name='my-name'].ui-file-input")
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'HiddenInput' do
4
+
5
+ include RSpec::Rails::HelperExampleGroup
6
+ include Webrat::HaveTagMatcher
7
+
8
+ before(:each) do
9
+
10
+ end
11
+
12
+ it "should return hidden tag" do
13
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
14
+ builder.input(:login, :as => :hidden).should have_tag("input[type='hidden']")
15
+ end
16
+ end
17
+
18
+ it "should return hidden tag with options" do
19
+ helper.jquery_form_for(:new_post, :as => @object, :url => '/hello') do |builder|
20
+ builder.input(:login, :as => :hidden, "data-name" =>"my-name").should have_tag("input[type='hidden'][data-name='my-name']")
21
+ end
22
+ end
23
+
24
+ end