Module: Grandstand::MainHelper
- Defined in:
- app/helpers/grandstand/main_helper.rb
Instance Method Summary collapse
-
#active_on(*conditions) ⇒ Object
Returns ‘active’ if the current page matches the passed URL hash.
-
#button(*args) ⇒ Object
Renders a <button> tag.
-
#button_link_to(*args) ⇒ Object
Similar to button, but generates a link instead of a button element.
- #button_options(options) ⇒ Object
- #expand(*controllers) ⇒ Object
- #expand_link(section) ⇒ Object
- #hide(condition) ⇒ Object
-
#wrap_grandstand_form(&block) ⇒ Object
A form wrapper that’s used to override the default field_error_proc in a thread-safeish way.
Instance Method Details
#active_on(*conditions) ⇒ Object
Returns ‘active’ if the current page matches the passed URL hash. This will require the controller to match. If one or more action is passed, those actions (or params) must match as well. If not, it lets the controller mean it’s active.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/grandstand/main_helper.rb', line 6 def active_on(*conditions) match = lambda do |condition| controllers = Array(condition.delete(:controller)).compact.flatten.map(&:to_s).uniq actions = Array(condition.delete(:action)).compact.map(&:to_s).flatten.uniq controllers.include?(controller_name) && (actions.empty? || actions.include?(action_name) || actions.include?(params[:return_to])) end = {} if conditions.any?(&match) [:class] = 'active' end end |
#button(*args) ⇒ Object
Renders a <button> tag. Helpful for forms and the like.
<%= button("Save Changes", :class => "blue") %>
… produces
<button class="button blue"><span class="inner"><span>Save Changes</span></span></button>
26 27 28 29 30 31 |
# File 'app/helpers/grandstand/main_helper.rb', line 26 def (*args) label = args.shift = {:name => 'submit', :value => label}.merge(args. || {}) , icon = () content_tag(:button, ) { content_tag(:span, :class => icon ? "#{icon} icon" : nil) { label } } end |
#button_link_to(*args) ⇒ Object
Similar to button, but generates a link instead of a button element. Useful for providing buttons to GET actions:
<%= button_link_to("Get Help", support_path, :icon => "help") %>
… produces
<a class="button blue" href="/support"><span class="inner"><span class="help icon">Get Help</span></span></button>
The extra spans are for any sliding door styling you may be interested in adding. Adding :icon to the options will give the inner-most span a class of “#:icon icon”, allowing you to add extra images inside of your button.
44 45 46 47 |
# File 'app/helpers/grandstand/main_helper.rb', line 44 def (*args) , icon = (args. || {}) link_to(content_tag(:span, :class => icon ? "#{icon} icon" : nil) { args.shift }, *args.push()) end |
#button_options(options) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/grandstand/main_helper.rb', line 49 def () classes = %w(button) if icon = .delete(:icon) classes.push('has-icon') end if .delete(:default) classes.push('default') end classes.push([:class].to_s.split(' ')) if [:class] [:class] = classes.uniq.join(' ') [, icon] end |
#expand(*controllers) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/grandstand/main_helper.rb', line 62 def (*controllers) = controllers. [:class] = Array([:class]).compact [:class].push(:expandable) section = controllers.first controllers.map!(&:to_s) if controllers.include?(controller_name) || !((session[:expand] ||= []) & controllers).empty? [:class].push(:expanded) end raw %( class="#{[:class].join(' ')}") end |
#expand_link(section) ⇒ Object
74 75 76 |
# File 'app/helpers/grandstand/main_helper.rb', line 74 def (section) link_to(raw('<span></span>'), '#', :class => 'expand', :rel => section) end |
#hide(condition) ⇒ Object
78 79 80 |
# File 'app/helpers/grandstand/main_helper.rb', line 78 def hide(condition) raw ' style="display:none;"' if condition end |
#wrap_grandstand_form(&block) ⇒ Object
A form wrapper that’s used to override the default field_error_proc in a thread-safeish way. The new field_error_proc returns a <div> with class “errors” on it, instead of an irritating “fieldWithErrors” classname that nobody likes or wants to use. Only used in admin at the moment.
85 86 87 88 89 90 |
# File 'app/helpers/grandstand/main_helper.rb', line 85 def wrap_grandstand_form(&block) field_error_proc = ActionView::Base.field_error_proc ActionView::Base.field_error_proc = Proc.new {|html_tag, instance| raw("<div class=\"errors\">#{html_tag}</div>") } concat(capture(&block)) ActionView::Base.field_error_proc = field_error_proc end |