Module: BootstrapNavbar::Helpers
- Defined in:
- lib/bootstrap-navbar/helpers.rb
Defined Under Namespace
Modules: Bootstrap2, Bootstrap3, Bootstrap4, Bootstrap5
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/bootstrap-navbar/helpers.rb', line 2
def self.included(base)
BootstrapNavbar.configuration.bootstrap_version ||= begin
node_package_config = "node_modules/bootstrap/package.json"
case
when bootstrap_gem = %w(bootstrap bootstrap-sass).detect { |gem| Gem.loaded_specs.keys.include?(gem) }
bootstrap_gem_version = Gem.loaded_specs[bootstrap_gem].version
bootstrap_gem_version.segments.take(3).join('.')
when File.exist?(node_package_config)
JSON.load(File.read(node_package_config)).fetch("version")
else
raise "Could not determine Bootstrap version from gems or Node package."
end
end
helper_version = BootstrapNavbar.configuration.bootstrap_version[0]
base.send :include, const_get("Bootstrap#{helper_version}")
end
|
Instance Method Details
#attributes_for_tag(hash) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/bootstrap-navbar/helpers.rb', line 21
def attributes_for_tag(hash)
string = hash.map { |k, v| %(#{k}="#{v}") }.join(' ')
if string.length > 0
' '.dup << string
else
string
end
end
|
#current_url ⇒ Object
51
52
53
54
|
# File 'lib/bootstrap-navbar/helpers.rb', line 51
def current_url
raise StandardError, 'current_url_method is not defined.' if BootstrapNavbar.configuration.current_url_method.nil?
eval BootstrapNavbar.configuration.current_url_method
end
|
#current_url_or_sub_url?(url) ⇒ Boolean
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/bootstrap-navbar/helpers.rb', line 30
def current_url_or_sub_url?(url)
return false if url == '#' || url =~ /\Atel:/
uri, current_uri = [url, current_url].map do |url|
URI.parse(url)
end
return false if uri.is_a?(URI::MailTo) || (!uri.host.nil? && uri.host != current_uri.host)
normalized_path, normalized_current_path = [uri, current_uri].map do |uri|
uri.path.sub(%r(/\z), '')
end
normalized_root_paths = BootstrapNavbar.configuration.root_paths.map do |path|
path.sub(%r(/\z), '')
end
if normalized_root_paths.include?(normalized_path)
normalized_current_path == normalized_path
else
normalized_current_path =~ %r(\A#{Regexp.escape(normalized_path)}(/.+)?\z)
end
end
|
#prepare_html(html) ⇒ Object
56
57
58
|
# File 'lib/bootstrap-navbar/helpers.rb', line 56
def prepare_html(html)
html
end
|