Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. config.wrappers :inline_checkbox, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
  2. b.use :html5
  3. b.wrapper :tag => 'div', :class => 'controls' do |ba|
  4. ba.use :label_input, :wrap_with => { :class => 'checkbox inline' }
  5. ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
  6. end
  7. end
  8.  
  9. config.wrappers :inline_checkbox_two, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
  10. b.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
  11. # everything else should use the same definition as the above
  12. end
  13.  
  14. module WrapperHelper
  15.  
  16. # options:
  17. # - wrapper [Hash]
  18. # - label_input [Hash]
  19. # - error [Hash]
  20. def self.inline_input(b, **kwargs)
  21. wrapper_opts = {
  22. tag: 'div',
  23. class: 'control-group'
  24. error_class: 'error'
  25. }.merge(kwargs[:wrapper] || {}) # merge defaults with passed `wrapper` keyword argument
  26. b.wrapper(wrapper_opts) do |ba|
  27. ba.use :label_input,
  28. { wrap_with: { class: 'checkbox inline' } }.merge(kwargs[:label_input] || {})
  29. ba.use :error,
  30. { wrap_with: { tag: 'span', class: 'help-inline' } }.merge(kwargs[:error] || {})
  31. end
  32. end
  33. end
  34.  
  35. config.wrappers :html5_inline_checkbox do |b|
  36. config.use :html5
  37. WrapperHelper.inline_input(b)
  38. end
  39.  
  40. config.wrappers :inline_checkbox_with_helpers do |b|
  41. b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
  42. WrapperHelper.inline_input(b)
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement