formula 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +6 -6
  3. data/lib/formula.rb +143 -143
  4. data/lib/formula/railtie.rb +1 -1
  5. data/lib/formula/version.rb +1 -1
  6. data/lib/generators/attached/templates/_form.html.haml +6 -0
  7. data/test/dummy/app/assets/javascripts/application.js +2 -1
  8. data/test/dummy/app/assets/javascripts/{contacts.js → main.js.coffee} +0 -0
  9. data/test/dummy/app/assets/stylesheets/application.css +4 -168
  10. data/test/dummy/app/assets/stylesheets/main.css.scss +6 -0
  11. data/test/dummy/app/controllers/application_controller.rb +56 -0
  12. data/test/dummy/app/controllers/contacts_controller.rb +15 -8
  13. data/test/dummy/app/controllers/main_controller.rb +2 -2
  14. data/test/dummy/app/controllers/sessions_controller.rb +37 -0
  15. data/test/dummy/app/controllers/users_controller.rb +46 -0
  16. data/test/dummy/app/helpers/sessions_helper.rb +2 -0
  17. data/test/dummy/app/helpers/users_helper.rb +2 -0
  18. data/test/dummy/app/models/contact.rb +6 -6
  19. data/test/dummy/app/models/group.rb +3 -3
  20. data/test/dummy/app/models/session.rb +39 -0
  21. data/test/dummy/app/models/user.rb +19 -0
  22. data/test/dummy/app/views/contacts/_form.html.haml +12 -0
  23. data/test/dummy/app/views/contacts/edit.html.haml +6 -0
  24. data/test/dummy/app/views/contacts/index.html.haml +21 -0
  25. data/test/dummy/app/views/contacts/new.html.haml +6 -0
  26. data/test/dummy/app/views/layouts/application.html.haml +23 -0
  27. data/test/dummy/app/views/main/index.html.haml +7 -0
  28. data/test/dummy/app/views/sessions/_fields.html.haml +3 -0
  29. data/test/dummy/app/views/sessions/_form.html.haml +5 -0
  30. data/test/dummy/app/views/sessions/_modal.html.haml +12 -0
  31. data/test/dummy/app/views/sessions/new.html.haml +5 -0
  32. data/test/dummy/app/views/sessions/new.js.haml +2 -0
  33. data/test/dummy/app/views/users/_fields.html.haml +4 -0
  34. data/test/dummy/app/views/users/_form.html.haml +5 -0
  35. data/test/dummy/app/views/users/_modal.html.haml +12 -0
  36. data/test/dummy/app/views/users/edit.html.haml +6 -0
  37. data/test/dummy/app/views/users/edit.js.haml +2 -0
  38. data/test/dummy/app/views/users/new.html.haml +6 -0
  39. data/test/dummy/app/views/users/new.js.haml +2 -0
  40. data/test/dummy/config/initializers/formula.rb +9 -0
  41. data/test/dummy/config/routes.rb +5 -3
  42. data/test/dummy/db/development.sqlite3 +0 -0
  43. data/test/dummy/db/migrate/20110109175811_create_contacts.rb +3 -3
  44. data/test/dummy/db/migrate/20120226213733_create_users.rb +11 -0
  45. data/test/dummy/db/schema.rb +9 -1
  46. data/test/dummy/db/test.sqlite3 +0 -0
  47. data/test/dummy/log/development.log +517 -8877
  48. data/test/dummy/log/test.log +125 -1276
  49. data/test/dummy/test/fixtures/users.yml +11 -0
  50. data/test/dummy/test/functional/sessions_controller_test.rb +7 -0
  51. data/test/dummy/test/functional/users_controller_test.rb +7 -0
  52. data/test/dummy/test/unit/helpers/sessions_helper_test.rb +4 -0
  53. data/test/dummy/test/unit/helpers/users_helper_test.rb +4 -0
  54. data/test/dummy/test/unit/user_test.rb +4 -0
  55. data/test/dummy/tmp/cache/assets/C78/B50/sprockets%2F50c7787472c6f1d292b210d9089ab021 +0 -0
  56. data/test/dummy/tmp/cache/assets/CA7/750/sprockets%2F26520da197942c10bb08b879dd27a335 +0 -0
  57. data/test/dummy/tmp/cache/assets/CB7/2E0/sprockets%2F122b94d05b802dec569597f372446e3e +0 -0
  58. data/test/dummy/tmp/cache/assets/CB9/500/sprockets%2Ff73079569d09e1dbf3d2610999b612d0 +0 -0
  59. data/test/dummy/tmp/cache/assets/{CFB/150/sprockets%2Ff5209763c82e66ecdff0f9583166f557 → CB9/B60/sprockets%2Fe7b839a0806e5c20e5018197f56cd656} +0 -0
  60. data/test/dummy/tmp/cache/assets/CBB/9B0/sprockets%2Fb718278187c3db586a420ec889c2950b +0 -0
  61. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  62. data/test/dummy/tmp/cache/assets/CDA/AB0/sprockets%2F4c7fc412b88cba24c365e12622902d79 +0 -0
  63. data/test/dummy/tmp/cache/assets/CDE/810/sprockets%2Fe9a718cd714105529e1126df281d5b9b +0 -0
  64. data/test/dummy/tmp/cache/assets/CDF/F20/sprockets%2Fafb369756d4161e56d25623705a1e4cf +0 -0
  65. data/test/dummy/tmp/cache/assets/D02/B20/sprockets%2F8424bdf2fc431411608e3a8ad4b12d77 +0 -0
  66. data/test/dummy/tmp/cache/assets/D07/020/sprockets%2F48a47b7a23025cf73408c7eb161fac38 +0 -0
  67. data/test/dummy/tmp/cache/assets/D11/7D0/sprockets%2F3eb85317d2ba89b1dd70fa28790a5943 +0 -0
  68. data/test/dummy/tmp/cache/assets/D1E/300/sprockets%2Fccb7b47689ba77b4d03c884f375b9154 +0 -0
  69. data/test/dummy/tmp/cache/assets/D2B/FC0/sprockets%2F90966edb48c329529d676f9a992db3da +0 -0
  70. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  71. data/test/dummy/tmp/cache/assets/D3E/520/sprockets%2F0c368fc7951f5ee15b407bf530a5df25 +0 -0
  72. data/test/dummy/tmp/cache/assets/D48/6E0/sprockets%2Fee6b9dc867c5bc23c4c70f38549b2371 +0 -0
  73. data/test/dummy/tmp/cache/assets/D4A/E30/sprockets%2F058c4112a2f16c6d9a8499fffa24e6f7 +0 -0
  74. data/test/dummy/tmp/cache/assets/D4E/110/sprockets%2Fd604658b4f6b260ccdc967ed53b9926e +0 -0
  75. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  76. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  77. data/test/dummy/tmp/cache/assets/D62/170/sprockets%2F75a5cc23ce1b2511be2ff95407e62d1e +0 -0
  78. data/test/dummy/tmp/cache/assets/D6C/090/sprockets%2F51b52949eefd109c700dc0ad8bd96d42 +0 -0
  79. data/test/dummy/tmp/cache/assets/D6C/210/sprockets%2Fc38fd401489a552f8716adf4aedaa325 +0 -0
  80. data/test/dummy/tmp/cache/assets/D6E/060/sprockets%2Fc0f3f19ea49926baf1623d4e12bc8f64 +0 -0
  81. data/test/dummy/tmp/cache/assets/{D2F/290/sprockets%2Fd5c244ec777cb5719f86d085df9f8816 → D76/4D0/sprockets%2F8a096b6dd59bfda3e461617a95524eaf} +0 -0
  82. data/test/dummy/tmp/cache/assets/D7B/CF0/sprockets%2Fd500cd67c78fa2fc96993e6cdd3050f6 +0 -0
  83. data/test/dummy/tmp/cache/assets/D93/910/sprockets%2Fb3f07cff0c2b5450dff46b72d29ec320 +0 -0
  84. data/test/dummy/tmp/cache/assets/D9B/350/sprockets%2Fb77ea162d3f4a5a427c1f2a6cd9db666 +0 -0
  85. data/test/dummy/tmp/cache/assets/D9F/6A0/sprockets%2F415cba7de981a2df5af982b546bbf064 +0 -0
  86. data/test/dummy/tmp/cache/assets/DBC/7B0/sprockets%2Fbd0fd218d2e084da2a4a3026cf71a9ef +0 -0
  87. data/test/dummy/tmp/cache/assets/DC2/AF0/sprockets%2F3cd60b3d8a714ddcdc4256558f0aedc0 +0 -0
  88. data/test/dummy/tmp/cache/assets/{D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 → DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994} +0 -0
  89. data/test/dummy/tmp/cache/assets/DDD/DA0/sprockets%2Ffef9a2b73f2ed6a6042b5f4cd88279df +0 -0
  90. data/test/dummy/tmp/cache/assets/DDF/F90/sprockets%2Ffdb9a7e2104ed9ab57d12896fdb5f9d7 +0 -0
  91. data/test/dummy/tmp/cache/assets/{CF7/670/sprockets%2F00b214e322c484fcc1555dafaa240947 → DE1/6A0/sprockets%2Fcae9aba95894da8a28fa8a5387dc565f} +0 -0
  92. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  93. data/test/dummy/tmp/cache/assets/E1B/AD0/sprockets%2F150cafe2db298a20f82fbadac1d7a7e2 +0 -0
  94. data/test/dummy/tmp/cache/assets/{D6B/5D0/sprockets%2F48da0deeef45ff0cac611596e0774114 → E1D/010/sprockets%2Fdffad412d86bfdfbb1f307d711da21d3} +0 -0
  95. data/test/dummy/tmp/cache/assets/E3D/7F0/sprockets%2Faa9db9e2e4799a861f0fff2d7ab09cee +0 -0
  96. data/test/dummy/tmp/cache/assets/E55/150/sprockets%2F7ade5edd1b6d232bd5eab48b3bdc64c8 +0 -0
  97. data/test/dummy/tmp/cache/sass/570e82feeccb881a24a9919fb3feaf73dcbe19fa/_bootstrap.scssc +0 -0
  98. data/test/dummy/tmp/cache/sass/900d735417fe8d5104d4de0e0165ff7cb5492466/main.css.scssc +0 -0
  99. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_accordion.scssc +0 -0
  100. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_alerts.scssc +0 -0
  101. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_breadcrumbs.scssc +0 -0
  102. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_button-groups.scssc +0 -0
  103. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_buttons.scssc +0 -0
  104. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_carousel.scssc +0 -0
  105. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_close.scssc +0 -0
  106. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_code.scssc +0 -0
  107. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_component-animations.scssc +0 -0
  108. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_dropdowns.scssc +0 -0
  109. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_forms.scssc +0 -0
  110. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_grid.scssc +0 -0
  111. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_hero-unit.scssc +0 -0
  112. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_labels-badges.scssc +0 -0
  113. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_layouts.scssc +0 -0
  114. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_mixins.scssc +0 -0
  115. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_modals.scssc +0 -0
  116. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_navbar.scssc +0 -0
  117. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_navs.scssc +0 -0
  118. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_pager.scssc +0 -0
  119. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_pagination.scssc +0 -0
  120. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_popovers.scssc +0 -0
  121. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_progress-bars.scssc +0 -0
  122. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_reset.scssc +0 -0
  123. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_scaffolding.scssc +0 -0
  124. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_sprites.scssc +0 -0
  125. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_tables.scssc +0 -0
  126. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_thumbnails.scssc +0 -0
  127. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_tooltip.scssc +0 -0
  128. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_type.scssc +0 -0
  129. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_utilities.scssc +0 -0
  130. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_variables.scssc +0 -0
  131. data/test/dummy/tmp/cache/sass/ac81519228da4075394a77780983d95f3f77aa1d/_wells.scssc +0 -0
  132. data/test/dummy/tmp/pids/server.pid +1 -0
  133. metadata +251 -65
  134. data/test/dummy/app/assets/javascripts/main.js +0 -0
  135. data/test/dummy/app/assets/stylesheets/contacts.css +0 -0
  136. data/test/dummy/app/assets/stylesheets/main.css +0 -0
  137. data/test/dummy/app/views/contacts/_form.html.erb +0 -21
  138. data/test/dummy/app/views/contacts/edit.html.erb +0 -4
  139. data/test/dummy/app/views/contacts/index.html.erb +0 -19
  140. data/test/dummy/app/views/contacts/new.html.erb +0 -4
  141. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  142. data/test/dummy/app/views/main/index.html.erb +0 -9
  143. data/test/dummy/tmp/cache/assets/BAB/A00/sprockets%2F347f335128024408181207cbc0461526 +0 -0
  144. data/test/dummy/tmp/cache/assets/C77/F30/sprockets%2F021780432569bfa6c8135d5d4111f2e8 +0 -0
  145. data/test/dummy/tmp/cache/assets/C89/150/sprockets%2F1ff78c0e818b9e0311560396b734719e +0 -0
  146. data/test/dummy/tmp/cache/assets/CE1/BA0/sprockets%2F263ecf6bc5196b70405d900e7c44c946 +0 -0
  147. data/test/dummy/tmp/cache/assets/D06/B40/sprockets%2F25fca4643219052b0d5c66cf2c71f72f +0 -0
  148. data/test/dummy/tmp/cache/assets/D11/430/sprockets%2F25ea8d6063b1eb98361b1196f2fce807 +0 -0
  149. data/test/dummy/tmp/cache/assets/D24/5A0/sprockets%2F3a89b583dd80975d1e0968e730de5bc9 +0 -0
  150. data/test/dummy/tmp/cache/assets/D2D/490/sprockets%2F52514897c01dab621a0d9892aafb1ea2 +0 -0
  151. data/test/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -177
  152. data/test/dummy/tmp/cache/assets/D84/170/sprockets%2Fd09fc89236193cb0ff9deb09b97c648d +0 -0
  153. data/test/dummy/tmp/cache/assets/DA5/7E0/sprockets%2F87a5f378354ce6e80dda84ab1cfd06f3 +0 -0
  154. data/test/dummy/tmp/cache/assets/DA7/530/sprockets%2Fe36b8fcf5914a3a6bf058abfe7367b19 +0 -0
  155. data/test/dummy/tmp/cache/assets/DAA/470/sprockets%2Faa2b19ddf75cee55d7f2822e3da55779 +0 -0
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 - 2011 Kevin Sylvestre
1
+ Copyright (c) 2010 - 2012 Kevin Sylvestre
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Formula
2
2
 
3
- Formula is a Rails form helper that generates awesome markup. The project aims to let users create semantically beautiful forms without introducing too much syntax. The goal is to make integrating advanced layout systems (such as grid systems) as simple as possible.
3
+ Formula is a Rails form helper that generates awesome markup. The project lets users create semantically beautiful forms without introducing too much syntax.
4
4
 
5
5
  == Requirements
6
6
 
@@ -17,7 +17,7 @@ The gem is tested with:
17
17
  == Installation
18
18
 
19
19
  gem install formula
20
-
20
+
21
21
  == Examples
22
22
 
23
23
  <% formula_form_for @user do |f| %>
@@ -31,14 +31,14 @@ The gem is tested with:
31
31
  <%= f.input :password, label: "Password:", hint: "Must be at least six characters." %>
32
32
  <%= f.button 'Save' %>
33
33
  <% end %>
34
-
34
+
35
35
  <% formula_form_for @company do |f|
36
36
  <%= f.input :url, container: { class: 'grid-04' }, input: { class: 'fill' } %>
37
37
  <%= f.input :phone, container: { class: 'grid-04' }, input: { class: 'fill' } %>
38
38
  <%= f.input :email, container: { class: 'grid-04' }, input: { class: 'fill' } %>
39
39
  <%= f.button 'Save', button: { class: 'fancy' } %>
40
40
  <% end %>
41
-
41
+
42
42
  <% formula_form_for @user do |f| %>
43
43
  <%= f.input :email, label: "Email:" %>
44
44
  <%= f.input :password, label: "Password:" %>
@@ -49,7 +49,7 @@ The gem is tested with:
49
49
  <% end %>
50
50
  <%= f.button 'Save', button: { class: 'fancy' } %>
51
51
  <% end %>
52
-
52
+
53
53
  <% formula_form_for @user do |f| %>
54
54
  <%= f.block :favourite %>
55
55
  <% @favourites.each do |favourite| %>
@@ -69,4 +69,4 @@ The gem is tested with:
69
69
 
70
70
  == Copyright
71
71
 
72
- Copyright (c) 2010 - 2011 Kevin Sylvestre. See LICENSE for details.
72
+ Copyright (c) 2010 - 2012 Kevin Sylvestre. See LICENSE for details.
data/lib/formula.rb CHANGED
@@ -1,76 +1,76 @@
1
1
  module Formula
2
-
3
-
2
+
3
+
4
4
  require 'formula/railtie' if defined?(Rails)
5
-
6
-
5
+
6
+
7
7
  # Default class assigned to block (<div class="block">...</div>).
8
8
  mattr_accessor :block_class
9
9
  @@block_class = 'block'
10
-
10
+
11
11
  # Default class assigned to input (<div class="input">...</div>).
12
12
  mattr_accessor :input_class
13
13
  @@input_class = 'input'
14
-
14
+
15
15
  # Default class assigned to association (<div class="association">...</div>).
16
16
  mattr_accessor :association_class
17
17
  @@association_class = 'association'
18
-
18
+
19
19
  # Default class assigned to block with errors (<div class="block errors">...</div>).
20
20
  mattr_accessor :block_error_class
21
21
  @@block_error_class = 'errors'
22
-
22
+
23
23
  # Default class assigned to input with errors (<div class="input errors">...</div>).
24
24
  mattr_accessor :input_error_class
25
25
  @@input_error_class = false
26
-
26
+
27
27
  # Default class assigned to input with errors (<div class="association errors">...</div>).
28
28
  mattr_accessor :association_error_class
29
29
  @@association_error_class = false
30
-
30
+
31
31
  # Default class assigned to error (<div class="error">...</div>).
32
32
  mattr_accessor :error_class
33
33
  @@error_class = 'error'
34
-
34
+
35
35
  # Default class assigned to hint (<div class="hint">...</div>).
36
36
  mattr_accessor :hint_class
37
37
  @@hint_class = 'hint'
38
-
38
+
39
39
  # Default tag assigned to block (<div class="input">...</div>).
40
40
  mattr_accessor :block_tag
41
41
  @@block_tag = :div
42
-
42
+
43
43
  # Default tag assigned to input (<div class="input">...</div>).
44
44
  mattr_accessor :input_tag
45
45
  @@input_tag = :div
46
-
46
+
47
47
  # Default tag assigned to association (<div class="association">...</div>).
48
- mattr_accessor :association_tag
49
- @@association_tag = :div
50
-
48
+ mattr_accessor :association_tag
49
+ @@association_tag = :div
50
+
51
51
  # Default tag assigned to error (<div class="error">...</div>).
52
52
  mattr_accessor :error_tag
53
53
  @@error_tag = :div
54
-
54
+
55
55
  # Default tag assigned to hint (<div class="hint">...</div>).
56
56
  mattr_accessor :hint_tag
57
57
  @@hint_tag = :div
58
-
58
+
59
59
  # Method for file.
60
60
  mattr_accessor :file
61
61
  @@file = [:file?]
62
-
62
+
63
63
  # Default as.
64
64
  mattr_accessor :default_as
65
65
  @@default_as = :string
66
-
67
-
66
+
67
+
68
68
  class FormulaFormBuilder < ActionView::Helpers::FormBuilder
69
-
70
-
71
- # Generate a form button.
69
+
70
+
71
+ # Generate a form button.
72
72
  #
73
- # Options:
73
+ # Options:
74
74
  #
75
75
  # * :container - add custom options to the container
76
76
  # * :button - add custom options to the button
@@ -84,23 +84,23 @@ module Formula
84
84
  # <div class="block">
85
85
  # <%= f.submit("Save")
86
86
  # </div>
87
-
87
+
88
88
  def button(value = nil, options = {})
89
89
  options[:button] ||= {}
90
-
90
+
91
91
  options[:container] ||= {}
92
92
  options[:container][:class] = arrayorize(options[:container][:class]) << ::Formula.block_class
93
-
94
-
93
+
94
+
95
95
  @template.content_tag(::Formula.block_tag, options[:container]) do
96
96
  submit value, options[:button]
97
97
  end
98
98
  end
99
-
100
-
99
+
100
+
101
101
  # Basic container generator for use with blocks.
102
102
  #
103
- # Options:
103
+ # Options:
104
104
  #
105
105
  # * :hint - specify a hint to be displayed ('We promise not to spam you.', etc.)
106
106
  # * :label - override the default label used ('Name:', 'URL:', etc.)
@@ -120,34 +120,34 @@ module Formula
120
120
  # <div class="hint">Please use your full name.</div>
121
121
  # <div class="error">...</div>
122
122
  # </div>
123
-
123
+
124
124
  def block(method = nil, options = {}, &block)
125
125
  options[:error] ||= error(method) if method
126
-
126
+
127
127
  components = "".html_safe
128
-
128
+
129
129
  if method
130
130
  components << self.label(method, options[:label]) if options[:label] or options[:label].nil? and method
131
131
  end
132
-
132
+
133
133
  components << @template.capture(&block)
134
-
134
+
135
135
  options[:container] ||= {}
136
136
  options[:container][:class] = arrayorize(options[:container][:class]) << ::Formula.block_class << method
137
137
  options[:container][:class] << ::Formula.block_error_class if ::Formula.block_error_class.present? and error?(method)
138
-
138
+
139
139
  components << @template.content_tag(::Formula.hint_tag , options[:hint ], :class => ::Formula.hint_class ) if options[:hint ]
140
140
  components << @template.content_tag(::Formula.error_tag, options[:error], :class => ::Formula.error_class) if options[:error]
141
-
141
+
142
142
  @template.content_tag(::Formula.block_tag, options[:container]) do
143
143
  components
144
144
  end
145
145
  end
146
-
147
-
148
- # Generate a suitable form input for a given method by performing introspection on the type.
146
+
147
+
148
+ # Generate a suitable form input for a given method by performing introspection on the type.
149
149
  #
150
- # Options:
150
+ # Options:
151
151
  #
152
152
  # * :as - override the default type used (:url, :email, :phone, :password, :number, :text)
153
153
  # * :label - override the default label used ('Name:', 'URL:', etc.)
@@ -190,42 +190,42 @@ module Formula
190
190
  # <div class="error">...</div>
191
191
  # </div>
192
192
  # </div>
193
-
193
+
194
194
  def input(method, options = {})
195
195
  options[:as] ||= as(method)
196
196
  options[:input] ||= {}
197
-
197
+
198
198
  return hidden_field method, options[:input] if options[:as] == :hidden
199
-
199
+
200
200
  klass = [::Formula.input_class, options[:as]]
201
201
  klass << ::Formula.input_error_class if ::Formula.input_error_class.present? and error?(method)
202
-
202
+
203
203
  self.block(method, options) do
204
204
  @template.content_tag(::Formula.input_tag, :class => klass) do
205
205
  case options[:as]
206
- when :text then text_area method, options[:input]
207
- when :file then file_field method, options[:input]
208
- when :string then text_field method, options[:input]
209
- when :password then password_field method, options[:input]
210
- when :boolean then check_box method, options[:input]
211
- when :url then url_field method, options[:input]
212
- when :email then email_field method, options[:input]
213
- when :phone then phone_field method, options[:input]
214
- when :number then number_field method, options[:input]
215
- when :country then country_select method, options[:input]
216
- when :date then date_select method, options[:input], options[:input].delete(:html) || {}
217
- when :time then time_select method, options[:input], options[:input].delete(:html) || {}
218
- when :datetime then datetime_select method, options[:input], options[:input].delete(:html) || {}
219
- when :select then select method, options[:choices], options[:input], options[:input].delete(:html) || {}
206
+ when :text then text_area method, options[:input]
207
+ when :file then file_field method, options[:input]
208
+ when :string then text_field method, options[:input]
209
+ when :password then password_field method, options[:input]
210
+ when :boolean then check_box method, options[:input]
211
+ when :url then url_field method, options[:input]
212
+ when :email then email_field method, options[:input]
213
+ when :phone then phone_field method, options[:input]
214
+ when :number then number_field method, options[:input]
215
+ when :country then country_select method, options[:input]
216
+ when :date then date_select method, options[:input], options[:input].delete(:html) || {}
217
+ when :time then time_select method, options[:input], options[:input].delete(:html) || {}
218
+ when :datetime then datetime_select method, options[:input], options[:input].delete(:html) || {}
219
+ when :select then select method, options[:choices], options[:input], options[:input].delete(:html) || {}
220
220
  end
221
221
  end
222
222
  end
223
223
  end
224
-
225
-
226
- # Generate a suitable form association for a given method by performing introspection on the type.
224
+
225
+
226
+ # Generate a suitable form association for a given method by performing introspection on the type.
227
227
  #
228
- # Options:
228
+ # Options:
229
229
  #
230
230
  # * :label - override the default label used ('Name:', 'URL:', etc.)
231
231
  # * :error - override the default error used ('invalid', 'incorrect', etc.)
@@ -268,30 +268,30 @@ module Formula
268
268
  # <div class="error">...</div>
269
269
  # </div>
270
270
  # </div>
271
-
272
-
271
+
272
+
273
273
  def association(method, collection, value, text, options = {})
274
274
  options[:as] ||= :select
275
275
  options[:association] ||= {}
276
-
276
+
277
277
  klass = [::Formula.association_class, options[:as]]
278
278
  klass << ::Formula.association_error_class if ::Formula.association_error_class.present? and error?(method)
279
-
279
+
280
280
  self.block(method, options) do
281
281
  @template.content_tag(::Formula.association_tag, :class => klass) do
282
282
  case options[:as]
283
- when :select then collection_select :"#{method}_id", collection, value, text,
283
+ when :select then collection_select :"#{method}_id", collection, value, text,
284
284
  options[:association], options[:association].delete(:html) || {}
285
285
  end
286
286
  end
287
287
  end
288
288
  end
289
-
290
-
291
- private
292
-
293
-
294
- # Introspection on the column to determine how to render a method. The method is used to
289
+
290
+
291
+ private
292
+
293
+
294
+ # Introspection on the column to determine how to render a method. The method is used to
295
295
  # identify a method type (if the method corresponds to a column)
296
296
  #
297
297
  # Returns:
@@ -305,16 +305,16 @@ module Formula
305
305
  # * :date - for columns of type 'date'
306
306
  # * :time - for columns of type 'time'
307
307
  # * nil - for unkown columns
308
-
308
+
309
309
  def type(method)
310
310
  column = @object.column_for_attribute(method) if @object.respond_to?(:column_for_attribute)
311
311
  return column.type if column
312
312
  end
313
-
314
-
315
- # Introspection on an association to determine if a method is a file. This
313
+
314
+
315
+ # Introspection on an association to determine if a method is a file. This
316
316
  # is determined by the methods ability to respond to file methods.
317
-
317
+
318
318
  def file?(method)
319
319
  @files ||= {}
320
320
  @files[method] ||= begin
@@ -322,9 +322,9 @@ module Formula
322
322
  file && ::Formula.file.any? { |method| file.respond_to?(method) }
323
323
  end
324
324
  end
325
-
326
-
327
- # Introspection on the field and method to determine how to render a method. The method is
325
+
326
+
327
+ # Introspection on the field and method to determine how to render a method. The method is
328
328
  # used to generate form element types.
329
329
  #
330
330
  # Returns:
@@ -339,68 +339,68 @@ module Formula
339
339
  # * :time - for time column
340
340
  # * :text - for time column
341
341
  # * :string - for all other cases
342
-
342
+
343
343
  def as(method)
344
-
344
+
345
345
  case "#{method}"
346
- when /url/ then return :url
347
- when /email/ then return :email
348
- when /phone/ then return :phone
349
- when /password/ then return :password
346
+ when /url/ then return :url
347
+ when /email/ then return :email
348
+ when /phone/ then return :phone
349
+ when /password/ then return :password
350
350
  end
351
-
351
+
352
352
  case type(method)
353
- when :string then return :string
354
- when :integer then return :number
355
- when :float then return :number
356
- when :decimal then return :number
357
- when :timestamp then return :datetime
358
- when :datetime then return :datetime
359
- when :date then return :date
360
- when :time then return :time
361
- when :text then return :text
353
+ when :string then return :string
354
+ when :integer then return :number
355
+ when :float then return :number
356
+ when :decimal then return :number
357
+ when :timestamp then return :datetime
358
+ when :datetime then return :datetime
359
+ when :date then return :date
360
+ when :time then return :time
361
+ when :text then return :text
362
362
  end
363
-
363
+
364
364
  return :file if file?(method)
365
-
365
+
366
366
  return ::Formula.default_as
367
-
367
+
368
368
  end
369
-
370
-
371
- # Generate error messages by combining all errors on an object into a comma seperated string
372
- # representation.
373
-
369
+
370
+
371
+ # Generate error messages by combining all errors on an object into a comma seperated string
372
+ # representation.
373
+
374
374
  def error(method)
375
375
  errors = @object.errors[method] if @object
376
376
  errors.to_sentence if errors.present?
377
377
  end
378
-
379
-
378
+
379
+
380
380
  # Identify if error message exists for a given method by checking for the presence of the object
381
381
  # followed by the presence of errors.
382
-
382
+
383
383
  def error?(method)
384
384
  @object.present? and @object.errors[method].present?
385
385
  end
386
-
387
-
388
- # Create an array from a string, a symbol, or an undefined value. The default is to return
386
+
387
+
388
+ # Create an array from a string, a symbol, or an undefined value. The default is to return
389
389
  # the value and assume it has already is valid.
390
-
390
+
391
391
  def arrayorize(value)
392
392
  case value
393
- when nil then return []
394
- when String then value.to_s.split
395
- when Symbol then value.to_s.split
396
- else value
393
+ when nil then return []
394
+ when String then value.to_s.split
395
+ when Symbol then value.to_s.split
396
+ else value
397
397
  end
398
398
  end
399
-
400
-
401
- public
402
-
403
-
399
+
400
+
401
+ public
402
+
403
+
404
404
  # Generates a wrapper around fields_form with :builder set to FormulaFormBuilder.
405
405
  #
406
406
  # Supports:
@@ -418,22 +418,22 @@ module Formula
418
418
  # <%= company_f.input :url %>
419
419
  # <%= company_f.input :phone %>
420
420
  # <% end %>
421
-
421
+
422
422
  def formula_fields_for(record_or_name_or_array, *args, &block)
423
423
  options = args.extract_options!
424
424
  options[:builder] ||= self.class
425
425
  fields_for(record_or_name_or_array, *(args << options), &block)
426
426
  end
427
-
427
+
428
428
  alias :fieldsula_for :formula_fields_for
429
429
 
430
430
 
431
431
  end
432
-
432
+
433
433
  module FormulaFormHelper
434
434
  @@builder = ::Formula::FormulaFormBuilder
435
-
436
-
435
+
436
+
437
437
  # Generates a wrapper around form_for with :builder set to FormulaFormBuilder.
438
438
  #
439
439
  # Supports:
@@ -450,16 +450,16 @@ module Formula
450
450
  # <%= f.input :email %>
451
451
  # <%= f.input :password %>
452
452
  # <% end %>
453
-
453
+
454
454
  def formula_form_for(record_or_name_or_array, *args, &proc)
455
- options = args.extract_options!
456
- options[:builder] ||= @@builder
457
- form_for(record_or_name_or_array, *(args << options), &proc)
455
+ options = args.extract_options!
456
+ options[:builder] ||= @@builder
457
+ form_for(record_or_name_or_array, *(args << options), &proc)
458
458
  end
459
-
459
+
460
460
  alias :formula_for :formula_form_for
461
-
462
-
461
+
462
+
463
463
  # Generates a wrapper around fields_for with :builder set to FormulaFormBuilder.
464
464
  #
465
465
  # Supports:
@@ -477,15 +477,15 @@ module Formula
477
477
  # <%= company_f.input :url %>
478
478
  # <%= company_f.input :phone %>
479
479
  # <% end %>
480
-
480
+
481
481
  def formula_fields_for(record_or_name_or_array, *args, &block)
482
482
  options = args.extract_options!
483
483
  options[:builder] ||= @@builder
484
484
  fields_for(record_or_name_or_array, *(args << options), &block)
485
485
  end
486
-
487
- alias :fieldsula_for :formula_fields_for
488
-
486
+
487
+ alias :fieldsula_for :formula_fields_for
488
+
489
489
  end
490
-
491
- end
490
+
491
+ end