module BootstrapHelper
Public Instance Methods
dropdown(text, icon = nil, &block)
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 26 def dropdown(text, icon = nil, &block) content_tag :li, class: 'nav-item dropdown' do build_a_tag_for_dropdown text: text, icon: icon, &block end end
dropdown_divider()
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 41 def dropdown_divider content_tag(:div, class: 'dropdown-divider') do end end
dropdown_item(text, link)
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 32 def dropdown_item(text, link) link_to(text, link, class: 'dropdown-item') end
dropdown_model_item(model:, route:, pluralize: nil)
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 36 def dropdown_model_item(model:, route:, pluralize: nil) title = pluralize || model.model_name.human.pluralize(:ru) dropdown_item title, route end
Private Instance Methods
active?(path, options = {})
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 48 def active?(path, options = {}) :active if uri_state(path, options).in? %i[active chosen] end
active_uri_state(options:, uri:, request_uri:, root_url:, root:)
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 98 def active_uri_state(options:, uri:, request_uri:, root_url:, root:) if uri_state_is_inactive?(options: options) :inactive elsif uri_state_is_active?(request_uri: request_uri, options: options, root_url: root_url, uri: uri) :active else request_uri.start_with?(uri) && !root ? :chosen : :inactive end end
build_a_tag_for_dropdown(text:, icon:) { |block| ... }
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 75 def build_a_tag_for_dropdown(text:, icon:, &block) concat(link_to('#', **dropdown_link_attributes(text)) do if icon concat content_tag :span, '', class: "glyphicon glyphicon-#{icon}" concat ' ' end concat text end) concat(content_tag(:div, class: 'dropdown-menu', aria: { labelledby: text }) do yield(block) end) end
dropdown_link_attributes(text)
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 88 def dropdown_link_attributes(text) { class: 'nav-link dropdown-toggle', id: text, role: :button, data: { toggle: :dropdown }, aria: { haspopup: true, expanded: false } } end
uri_state(uri, options = {})
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 52 def uri_state(uri, options = {}) root_url = request.host_with_port + '/' root = uri == '/' || uri == root_url request_uri = if uri.start_with? root_url request.url else request.path end active_uri_state options: options, uri: uri, request_uri: request_uri, root_url: root_url, root: root end
uri_state_is_active?(request_uri:, options:, root_url:, uri:)
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 112 def uri_state_is_active?(request_uri:, options:, root_url:, uri:) uri == request_uri || (options[:root] && (request_uri == '/') || (request_uri == root_url)) end
uri_state_is_inactive?(options:)
click to toggle source
# File lib/trap/helpers/bootstrap_helper.rb, line 108 def uri_state_is_inactive?(options:) !options[:method].nil? || !options['data-method'].nil? end