Module: Railsui::ApplicationHelper

Defined in:
app/helpers/railsui/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#box_check_classesObject



95
96
97
98
99
100
101
# File 'app/helpers/railsui/application_helper.rb', line 95

def box_check_classes
  "text-indigo-600 form-checkbox rounded focus:outline-hidden ring-2 ring-transparent focus:ring-slate-100  mr-2 border-slate-500 size-5
  focus:dark:ring-slate-700
  focus:dark:ring-opacity-20
  focus:dark:bg-slate-600  dark:bg-slate-700
  dark:ring-transparent"
end

#box_label_classes(options = {}) ⇒ Object



91
92
93
# File 'app/helpers/railsui/application_helper.rb', line 91

def box_label_classes(options={})
  "rounded-lg bg-white shadow-sm border border-slate-200 block select-none hover:shadow-none group bg-gradient-to-br from-white to-slate-50 dark:from-slate-700 dark:to-slate-800 dark:border-slate-600 dark:shadow-sm #{options[:offset] == false ? "px-4 pb-4 pt-1" : "p-4" }"
end

#button_classes(variant: "black", size: "md") ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'app/helpers/railsui/application_helper.rb', line 235

def button_classes(variant: "black", size: "md")
  base_classes = "rounded-md px-3 py-[5px] ring-4 ring-transparent text-base transition-colors ease-in-out duration-300 disabled:opacity-50 disabled:pointer-events-none disabled:cursor-not-allowed text-center text-[14.5px] font-semibold inline-flex gap-2 items-center justify-center"

  size_classes =
    case size
    when "lg"
      "py-3 px-6 text-lg"
    when "sm"
      "py-0.5 px-3 text-[13.5px]"
    else # md
      "py-[5px] px-3 text-[14.5px]"
    end

  variant_classes =
  case variant
  when "white"
    "bg-white hover:bg-neutral-50/50 hover:shadow-none shadow-xs text-neutral-800/80 border border-neutral-300 shadow-neutral-300/20 focus:ring-4 hover:border-neutral-600/40 focus:ring-neutral-100/70 focus:border-neutral-300/90 dark:bg-neutral-700/60 dark:text-white dark:border-neutral-500/30 dark:shadow-neutral-950/40 dark:hover:bg-neutral-800/90 dark:focus:ring-neutral-700/80 dark:focus:border-neutral-500/80"
  when "offwhite"
    "bg-neutral-200/20 hover:bg-neutral-50/50 hover:shadow-none shadow-xs text-neutral-800/80 border border-neutral-300/80 shadow-neutral-300/20 focus:ring-4 hover:border-neutral-600/40 focus:ring-neutral-100/70 focus:border-neutral-300/90 dark:bg-neutral-700/60 dark:border-neutral-500/30 dark:shadow-neutral-950/40 dark:hover:bg-neutral-800/90 dark:focus:ring-neutral-700/80 dark:focus:border-neutral-500/80"
  when "transparent"
    "bg-transparent text-neutral-700 focus:ring-neutral-100/70 hover:bg-neutral-50/70 hover:text-neutral-800 dark:focus:ring-neutral-600/80 dark:hover:bg-neutral-900 focus:outline focus:outline-neutral-200/80 dark:focus:outline-neutral-700/80 dark:text-neutral-200"
  when "black"
    "bg-neutral-950 text-neutral-100 focus:ring-neutral-100/70 hover:text-neutral-50 hover:ring-4 hover:ring-black/10 focus:outline focus:outline-neutral-200/80 dark:focus:outline-neutral-700/80 dark:bg-neutral-50 dark:text-neutral-950 dark:hover:bg-neutral-100/80 dark:hover:text-neutral-950 dark:focus:ring-neutral-700/30"
  end

  [base_classes, size_classes, variant_classes].join(" ")
end

#calloutObject



124
125
126
# File 'app/helpers/railsui/application_helper.rb', line 124

def callout
  "railsui/shared/callout"
end

#code(code) ⇒ Object



44
45
46
# File 'app/helpers/railsui/application_helper.rb', line 44

def code(code)
   :span, html_escape(code), class: "text-neutral-900 font-mono font-semibold text-[15px] dark:text-rose-400 bg-neutral-100 px-1 py-px dark:bg-transparent rounded whitespace-pre"
end


189
190
191
192
193
194
195
196
# File 'app/helpers/railsui/application_helper.rb', line 189

def component_link(name, href)
   :li do
    link_to name, href, class: "block py-0.5 text-neutral-500 hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-white truncate", data: {
      action: "click->railsui-smooth#scroll",
      railsui_scroll_spy_target: "link"
    }
  end
end

#dividerObject



198
199
200
# File 'app/helpers/railsui/application_helper.rb', line 198

def divider
   :hr, nil, class: "my-6 dark:border-neutral-700/80 border-neutral-200/70"
end

#doc_label(type) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/helpers/railsui/application_helper.rb', line 109

def doc_label(type)
  case type
  when :javascript
     :p, "JavaScript", class:"bg-yellow-300 text-black rounded-full px-3 py-1 font-semibold inline-block text-xs mb-3"
  when :stimulus
     :p, "Stimulus.js", class: "bg-yellow-300 text-black rounded-full px-3 py-1 font-semibold inline-block text-xs mb-3"
  when :ruby
     :p, "Ruby", class: "bg-red-700 text-white rounded-full px-3 py-1 font-semibold inline-block text-xs mb-3"
  when :tutorial
     :p, "Tutorial", class: "bg-blue-500 text-white rounded-full px-3 py-1 font-semibold inline-block text-xs mb-3"
  when :demo
     :p, "Demo", class: "bg-emerald-50 text-emerald-600 rounded-full px-3 py-1 font-semibold inline-block text-xs mb-3"
  end
end

#email_viewer(subject = "A sample subject", variant: nil, &block) ⇒ Object



86
87
88
89
# File 'app/helpers/railsui/application_helper.rb', line 86

def email_viewer(subject="A sample subject", variant: nil, &block)
  variant ||= "gray" # Default to gray if no variant specified
  render "railsui/shared/rui_email_preview", subject: subject, variant: variant, block: block, flush: true
end

#engine_icon_path(icon_path) ⇒ Object



206
207
208
# File 'app/helpers/railsui/application_helper.rb', line 206

def engine_icon_path(icon_path)
  "/#{Railsui::Engine.root.join("app/assets/images/#{icon_path}")}"
end

#exampleObject



185
186
187
# File 'app/helpers/railsui/application_helper.rb', line 185

def example
  "railsui/shared/code_example"
end

#heading(options = {}) ⇒ Object



77
78
79
80
81
82
83
84
# File 'app/helpers/railsui/application_helper.rb', line 77

def heading(options={})
  text = options[:text] || "Enter some text"
  tag = options[:tag] || :h2
  id = options[:id]
  classes = options[:class]

   tag.to_sym, text, id: id, class: "#{classes} tracking-[-0.025em]"
end

#help_textObject



103
104
105
106
107
# File 'app/helpers/railsui/application_helper.rb', line 103

def help_text
   :div, class: "prose prose-sm prose-neutral dark:prose-invert max-w-full" do
    yield
  end
end

#input_classesObject



227
228
229
# File 'app/helpers/railsui/application_helper.rb', line 227

def input_classes
  "rounded-md px-4 py-2 border border-neutral-300/80 bg-white focus:border-neutral-500/80 focus:ring-4 focus:ring-neutral-100/80 focus:shadow-none focus:outline-hidden dark:bg-neutral-800 dark:border-neutral-700/80 dark:focus:border-neutral-500 placeholder-neutral-500/60 dark:focus:ring-neutral-500/40 dark:placeholder:text-neutral-300/60 font-normal antialiased font-sans w-full dark:text-neutral-50 text-neutral-800"
end

#label_classesObject



231
232
233
# File 'app/helpers/railsui/application_helper.rb', line 231

def label_classes
  "block mb-2 font-medium text-[14px] dark:text-white"
end

#main_app_asset_exists?(asset_name) ⇒ Boolean

Returns:

  • (Boolean)


273
274
275
276
277
278
279
280
281
282
283
# File 'app/helpers/railsui/application_helper.rb', line 273

def main_app_asset_exists?(asset_name)
  # Check if the host app has the specified compiled asset
  # tailwindcss-rails puts compiled CSS in app/assets/builds/
  builds_path = Rails.root.join("app/assets/builds/#{asset_name}.css")
  return true if File.exist?(builds_path)

  # Fallback to checking Sprockets for other assets
  Rails.application.assets.resolver.resolve("#{asset_name}.css").present?
rescue
  false
end


3
4
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
# File 'app/helpers/railsui/application_helper.rb', line 3

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) || "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

#preview(variant = nil) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/helpers/railsui/application_helper.rb', line 128

def preview(variant = nil)
  case variant
  when "base"
    "railsui/shared/preview"
  when "zinc"
    "railsui/shared/preview_zinc"
  when "dark_zinc"
    "railsui/shared/preview_dark_zinc"
  when "gray"
    "railsui/shared/preview_gray"
  when "dark"
    "railsui/shared/preview_dark"
  else
    "railsui/shared/preview"
  end
end


145
146
147
148
149
# File 'app/helpers/railsui/application_helper.rb', line 145

def quick_link(title: nil, component: nil)
   :li do
    link_to title.capitalize, "##{component.parameterize}-#{title.parameterize}", class: "text-sm py-1 px-3 rounded font-medium inline-block bg-white border border-slate-300 hover:shadow-sm hover:border-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:hover:border-slate-600 dark:hover:bg-slate-700/80 transition ease-in-out duration-200", data: { action: "click->railsui-smooth#scroll" }
  end
end

#render_snippet(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/railsui/application_helper.rb', line 48

def render_snippet(options={})
  active_tab = options[:active_tab] ||= "html"
  html_filename = options[:html_filename] ||= ".html"
  erb_filename = options[:erb_filename] ||= ".html.erb"
  haml_filename = options[:haml_filename] ||= ".haml.erb"
  js_filename = options[:js_filename] ||= ".js"
  ruby_filename = options[:ruby_filename] ||= ".rb"
  css_filename = options[:css_filename] ||= ".css"


  render partial: "railsui/shared/snippet", locals: {
    active_tab: active_tab,
    html_filename: html_filename,
    erb_filename: erb_filename,
    haml_filename: haml_filename,
    js_filename: js_filename,
    ruby_filename: ruby_filename,
    css_filename: css_filename
  }
end

#route_verb_classes(verb) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/helpers/railsui/application_helper.rb', line 151

def route_verb_classes(verb)
  case verb
  when "GET"
    "bg-indigo-50 text-indigo-500 dark:bg-indigo-400/50 dark:text-indigo-100"
  when "PATCH"
    "bg-cyan-50 text-cyan-500 dark:bg-cyan-400/50 dark:text-cyan-100"
  when "PUT"
    "bg-amber-50 text-amber-500 dark:bg-amber-400/50 dark:text-amber-100"
  when "POST"
    "bg-emerald-50 text-emerald-500 dark:bg-emerald-400/50 dark:text-emerald-100"
  when "DELETE"
    "bg-rose-50 text-rose-500 dark:bg-rose-400/50 dark:text-rose-100"
  else
    "bg-slate-50 text-slate-500 dark:bg-slate-700 dark:text-slate-100"
  end
end

#rui_badge(label, variant: :blue) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'app/helpers/railsui/application_helper.rb', line 210

def rui_badge(label, variant: :blue)
  variant_class =
    case variant
    when :blue
      "bg-blue-500 text-white"
    when :green
      "bg-green-500 text-white"
    when :red
      "bg-red-500 text-white"
    when :yellow
      "bg-yellow-500 text-black"
    when :gray
      "bg-neutral-200 text-neutral-700"
    end
   :div, label, class: "#{variant_class} rounded-full px-2 py-1 text-xs font-semibold inline-flex my-0"
end

#snippet_classes(variant: "active") ⇒ Object



264
265
266
267
268
269
270
271
# File 'app/helpers/railsui/application_helper.rb', line 264

def snippet_classes(variant: "active")
  case variant
  when "active"
    "bg-white px-3 py-1.5 rounded-md shadow flex items-center justify-center gap-2 text-[13px] font-semibold focus:ring-4 focus:ring-blue-600 group dark:bg-neutral-800/90 dark:text-neutral-100 dark:focus:ring-blue-600/50 dark:text-neutral-300"
  when "inactive"
    "bg-transparent px-3 py-1.5 rounded-md shadow-none flex items-center justify-center gap-2 text-[13px] font-semibold dark:text-neutral-300"
  end
end

#system_nav_item(label:, path:) ⇒ Object



202
203
204
# File 'app/helpers/railsui/application_helper.rb', line 202

def system_nav_item(label:, path:)
  render "railsui/shared/system_nav_item", label: label, path: path
end

#tag_label(tag) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
# File 'app/helpers/railsui/application_helper.rb', line 168

def tag_label(tag)
  base_classes = "rounded text-xs px-1 py-px font-semibold inline-flex items-center justify-center"

  case tag
  when "marketing"
     :div, tag.humanize, class: "#{base_classes} bg-indigo-50 text-indigo-500 dark:bg-indigo-500/40 dark:text-indigo-200"
  when "admin"
     :div, tag.humanize, class: "#{base_classes} bg-sky-50 text-sky-500 dark:bg-sky-500/40 dark:text-sky-200"
  else
     :div, tag.humanize, class: "#{base_classes} bg-slate-50 text-slate-500 dark:bg-slate-500/40 dark:text-slate-200"
  end
end

#theme_colors(group, val) ⇒ Object



181
182
183
# File 'app/helpers/railsui/application_helper.rb', line 181

def theme_colors(group,val)
  Railsui::Default::THEME_COLORS[Railsui.config.theme.to_sym][group][val]
end

#theme_keyObject



73
74
75
# File 'app/helpers/railsui/application_helper.rb', line 73

def theme_key
  theme_name.to_sym
end

#theme_nameObject



69
70
71
# File 'app/helpers/railsui/application_helper.rb', line 69

def theme_name
  Railsui.config.theme
end


33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/railsui/application_helper.rb', line 33

def theme_preview_link(theme)
  case theme
  when Railsui::Default::THEMES[:hound]
    Railsui::Default::THEME_PREVIEW_LINK[:hound]
  when Railsui::Default::THEMES[:shepherd]
    Railsui::Default::THEME_PREVIEW_LINK[:shepherd]
  else
    nil
  end
end