Module: Railsui::ThemeHelper

Defined in:
lib/railsui/theme_helper.rb

Instance Method Summary collapse

Instance Method Details



45
46
47
48
49
50
51
# File 'lib/railsui/theme_helper.rb', line 45

def conditional_link_to(route_helper, options = {}, &)
  if Rails.application.routes.url_helpers.method_defined?(route_helper)
    link_to(send(route_helper), options, &)
  else
    (:div, options, &)
  end
end

#custom_colors_cssObject



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(options = {})
  id = options[:id] || "22"
  variant = options[:variant] || "men"

  "https://randomuser.me/api/portraits/#{variant}/#{id}.jpg"
end

#fake_git_hashObject



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


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, options = {}, html_options = {}, &block)
  if block
    html_options = options
    options = name
    name = block
  end

  url = url_for(options)
  starts_with = html_options.delete(:starts_with)
  html_options[:class] = Array.wrap(html_options[:class])
  active_class = html_options.delete(:active_class) || "rui-nav-link-active"
  inactive_class = html_options.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
  html_options[:class] << classes unless classes.empty?

  html_options.except!(:class) if html_options[:class].empty?

  return link_to url, html_options, &block if block

  link_to name, url, html_options
end

#page_exists?(page) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/railsui/theme_helper.rb', line 62

def page_exists?(page)
  Railsui::Pages.page_exists?(page)
end

#railsui_body_classesObject



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_headObject



58
59
60
# File 'lib/railsui/theme_helper.rb', line 58

def railsui_head
  render "rui/shared/railsui_head"
end

#railsui_launcherObject



34
35
36
# File 'lib/railsui/theme_helper.rb', line 34

def railsui_launcher
  render partial: "railsui/shared/launcher"
end