diff options
author | Phil Hughes <me@iamphill.com> | 2016-03-09 10:19:41 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-03-10 13:54:54 +0000 |
commit | a9ea06ed2967e67d102c83e2bd6c9653778e64bc (patch) | |
tree | a169e98b12143a1fca91bb712ae610f0c417c40b /app/helpers | |
parent | f3afcb87b74685edb91eb9cfa839758275af9a0e (diff) | |
download | gitlab-ce-a9ea06ed2967e67d102c83e2bd6c9653778e64bc.tar.gz |
Fixed ruby style errors
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/dropdowns_helper.rb | 105 |
1 files changed, 75 insertions, 30 deletions
diff --git a/app/helpers/dropdowns_helper.rb b/app/helpers/dropdowns_helper.rb index 73a8794c25f..74f326e0b83 100644 --- a/app/helpers/dropdowns_helper.rb +++ b/app/helpers/dropdowns_helper.rb @@ -1,50 +1,36 @@ module DropdownsHelper - def dropdown_tag(toggle_text, id: nil, toggle_class: nil, dropdown_class: nil, title: false, filter: false, placeholder: "", footer_content: false, data: {}, &block) + def dropdown_tag(toggle_text, options: {}, &block) content_tag :div, class: "dropdown" do - toggle_hash = data.merge({toggle: "dropdown"}) + data_attr = { toggle: "dropdown" } - dropdown_output = "" - dropdown_output += content_tag :button, class: "dropdown-menu-toggle #{toggle_class}", id: id, type: "button", data: toggle_hash do - output = content_tag(:span, toggle_text, class: "dropdown-toggle-text") - output << icon('chevron-down') - output.html_safe + if options.has_key?(:data) + data_attr = options[:data].merge(data_attr) end - dropdown_output += content_tag :div, class: "dropdown-menu dropdown-select #{dropdown_class}" do - output = "" + dropdown_output = dropdown_toggle(toggle_text, data_attr, options) - if title - output += content_tag :div, class: "dropdown-title" do - title_output = content_tag(:span, title) + dropdown_output << content_tag(:div, class: "dropdown-menu dropdown-select #{options[:dropdown_class] if options.has_key?(:dropdown_class)}") do + output = "" - title_output += content_tag :button, class: "dropdown-title-button dropdown-menu-close", aria: {label: "close"}, type: "button" do - icon('times') - end.html_safe - end + if options.has_key?(:title) + output << dropdown_title(options[:title]) end - if filter - output += content_tag :div, class: "dropdown-input" do - filter_output = search_field_tag nil, nil, class: "dropdown-input-field", placeholder: placeholder - filter_output += icon('search') - - filter_output.html_safe - end + if options.has_key?(:filter) + output << dropdown_filter(options[:placeholder]) end - output += content_tag :div, class: "dropdown-content" do - capture(&block) if block && !footer_content + output << content_tag(:div, class: "dropdown-content") do + capture(&block) if block && !options.has_key?(:footer_content) end - if block && footer_content - output += content_tag :div, class: "dropdown-footer" do + if block && options.has_key?(:footer_content) + output << content_tag(:div, class: "dropdown-footer") do capture(&block) end end - output += content_tag :div, class: "dropdown-loading" do - icon('spinner spin') - end + output << dropdown_loading output.html_safe end @@ -52,4 +38,63 @@ module DropdownsHelper dropdown_output.html_safe end end + + def dropdown_toggle(toggle_text, data_attr, options) + content_tag(:button, class: "dropdown-menu-toggle #{options[:toggle_class] if options.has_key?(:toggle_class)}", id: (options[:id] if options.has_key?(:id)), type: "button", data: data_attr) do + output = content_tag(:span, toggle_text, class: "dropdown-toggle-text") + output << icon('chevron-down') + output.html_safe + end + end + + def dropdown_title(title, back: false) + content_tag :div, class: "dropdown-title" do + title_output = "" + + if back + title_output << content_tag(:button, class: "dropdown-title-button dropdown-menu-back", aria: { label: "Go back" }, type: "button") do + icon('arrow-left') + end + end + + title_output << content_tag(:span, title) + + title_output << content_tag(:button, class: "dropdown-title-button dropdown-menu-close", aria: { label: "Close" }, type: "button") do + icon('times') + end + + title_output.html_safe + end + end + + def dropdown_filter(placeholder) + content_tag :div, class: "dropdown-input" do + filter_output = search_field_tag nil, nil, class: "dropdown-input-field", placeholder: placeholder + filter_output << icon('search') + + filter_output.html_safe + end + end + + def dropdown_content(&block) + content_tag(:div, class: "dropdown-content") do + if block + capture(&block) + end + end + end + + def dropdown_footer(&block) + content_tag(:div, class: "dropdown-footer") do + if block + capture(&block) + end + end + end + + def dropdown_loading + content_tag :div, class: "dropdown-loading" do + icon('spinner spin') + end + end end |