Module: Railsui::ThemeHelper
- Defined in:
- lib/railsui/theme_helper.rb
Instance Method Summary collapse
- #conditional_link_to(route_helper, options = {}) ⇒ Object
- #custom_colors_css ⇒ Object
- #demo_avatar_url(options = {}) ⇒ Object
- #fake_git_hash ⇒ Object
- #nav_link_to(name = nil, options = {}, html_options = {}, &block) ⇒ Object
- #page_exists?(page) ⇒ Boolean
- #railsui_body_classes ⇒ Object
- #railsui_head ⇒ Object
- #railsui_launcher ⇒ Object
Instance Method Details
#conditional_link_to(route_helper, options = {}) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/railsui/theme_helper.rb', line 45 def conditional_link_to(route_helper, = {}, &) if Rails.application.routes.url_helpers.method_defined?(route_helper) link_to(send(route_helper), , &) else content_tag(:div, , &) end end |
#custom_colors_css ⇒ Object
53 54 55 56 |
# File 'lib/railsui/theme_helper.rb', line 53 def custom_colors_css # keep for legacy rails ui apps temporarily # Tailwind v4 has moved to CSS configuration end |
#demo_avatar_url(options = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/railsui/theme_helper.rb', line 38 def demo_avatar_url( = {}) id = [:id] || "22" variant = [:variant] || "men" "https://randomuser.me/api/portraits/#{variant}/#{id}.jpg" end |
#fake_git_hash ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/railsui/theme_helper.rb', line 77 def fake_git_hash characters = "abcdef0123456789" hash_length = 7 hash = "" hash_length.times do random_index = rand(characters.length) hash += characters[random_index] end hash end |
#nav_link_to(name = nil, options = {}, html_options = {}, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/railsui/theme_helper.rb', line 5 def nav_link_to(name = nil, = {}, = {}, &block) if block = = name name = block end url = url_for() starts_with = .delete(:starts_with) [:class] = Array.wrap([:class]) active_class = .delete(:active_class) || "rui-nav-link-active" inactive_class = .delete(:inactive_class) || "" active = if (paths = Array.wrap(starts_with)) && paths.present? paths.any? { |path| request.path.start_with?(path) } else request.path == url end classes = active ? active_class : inactive_class [:class] << classes unless classes.empty? .except!(:class) if [:class].empty? return link_to url, , &block if block link_to name, url, end |
#page_exists?(page) ⇒ Boolean
62 63 64 |
# File 'lib/railsui/theme_helper.rb', line 62 def page_exists?(page) Railsui::Pages.page_exists?(page) end |
#railsui_body_classes ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/railsui/theme_helper.rb', line 66 def railsui_body_classes # Fetch any additional body classes set in content_for :body_classes content_classes = content_for(:body_classes).to_s.strip # Combine existing Railsui config classes with any additional classes combined_classes = [Railsui.config.body_classes.to_s.strip, content_classes].reject(&:empty?).join(" ") # Return the combined classes or an empty string if none combined_classes.presence || "" end |
#railsui_head ⇒ Object
58 59 60 |
# File 'lib/railsui/theme_helper.rb', line 58 def railsui_head render "rui/shared/railsui_head" end |
#railsui_launcher ⇒ Object
34 35 36 |
# File 'lib/railsui/theme_helper.rb', line 34 def railsui_launcher render partial: "railsui/shared/launcher" end |