Module: Avo::ApplicationHelper

Instance Method Summary collapse

Instance Method Details

#a_button(**args, &block) ⇒ Object



23
24
25
26
27
# File 'app/helpers/avo/application_helper.rb', line 23

def a_button(**args, &block)
  render Avo::ButtonComponent.new(is_link: false, **args) do
    capture(&block) if block.present?
  end
end


29
30
31
32
33
# File 'app/helpers/avo/application_helper.rb', line 29

def a_link(path = nil, **args, &block)
  render Avo::ButtonComponent.new(path, is_link: true, **args) do
    capture(&block) if block.present?
  end
end

#button_classes(extra_classes = nil, color: nil, variant: nil, size: :md, active: false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/avo/application_helper.rb', line 35

def button_classes(extra_classes = nil, color: nil, variant: nil, size: :md, active: false)
  classes = "inline-flex flex-grow-0 items-center text-sm font-semibold leading-6 fill-current whitespace-nowrap transition duration-100 rounded transform transition duration-100 active:translate-x-px active:translate-y-px cursor-pointer disabled:cursor-not-allowed #{extra_classes}"

  if color.present?
    if variant.present? && (variant.to_sym == :outlined)
      classes += " bg-white border"

      classes += " hover:border-#{color}-700 border-#{color}-500 text-#{color}-600 hover:text-#{color}-700 disabled:border-gray-300 disabled:text-gray-600"
    else
      classes += " text-white bg-#{color}-500 hover:bg-#{color}-600 disabled:bg-#{color}-300"
    end
  else
    classes += " text-gray-700 bg-white hover:bg-gray-100 disabled:bg-gray-300"
  end

  size = size.present? ? size.to_sym : :md
  classes += case size
  when :xs
    " p-2 py-1"
  when :sm
    " py-1 px-4"
  when :md
    " py-2 px-4"
  when :xl
    " py-3 px-4"
  else
    " p-4"
  end

  classes
end

#empty_state(**args) ⇒ Object



19
20
21
# File 'app/helpers/avo/application_helper.rb', line 19

def empty_state(**args)
  render Avo::EmptyStateComponent.new(**args)
end

#get_model_class(model) ⇒ Object



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

def get_model_class(model)
  if model.instance_of?(Class)
    model
  else
    model.class
  end
end

#input_classes(extra_classes = "", has_error: false) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/helpers/avo/application_helper.rb', line 78

def input_classes(extra_classes = "", has_error: false)
  classes = "appearance-none inline-flex bg-gray-25 disabled:cursor-not-allowed text-gray-600 disabled:opacity-50 rounded py-2 px-3 leading-tight border focus:border-gray-600 focus-visible:ring-0 focus:text-gray-700 placeholder:text-gray-300"

  classes += if has_error
    " border-red-600"
  else
    " border-gray-200"
  end

  classes += " #{extra_classes}"

  classes
end

#render_license_warning(title: "", message: "", icon: "exclamation") ⇒ Object



11
12
13
14
15
16
17
# File 'app/helpers/avo/application_helper.rb', line 11

def render_license_warning(title: "", message: "", icon: "exclamation")
  render partial: "avo/sidebar/license_warning", locals: {
    title: title,
    message: message,
    icon: icon
  }
end

#render_license_warningsObject



5
6
7
8
9
# File 'app/helpers/avo/application_helper.rb', line 5

def render_license_warnings
  render partial: "avo/sidebar/license_warnings", locals: {
    license: Avo::App.license.properties
  }
end

#root_path_without_urlObject



104
105
106
107
108
# File 'app/helpers/avo/application_helper.rb', line 104

def root_path_without_url
  Avo::App.root_path.to_s.delete_prefix(request.base_url.to_s).delete_suffix "/"
rescue
  Avo.configuration.root_path
end

#svg(file_name, **args) ⇒ Object

Use inline_svg gem but with our own finder implementation.



68
69
70
71
72
73
74
75
76
# File 'app/helpers/avo/application_helper.rb', line 68

def svg(file_name, **args)
  return if file_name.blank?

  file_name = "#{file_name}.svg" unless file_name.end_with? ".svg"

  with_asset_finder(::Avo::SvgFinder) do
    inline_svg file_name, **args
  end
end

#white_panel_classesObject



92
93
94
# File 'app/helpers/avo/application_helper.rb', line 92

def white_panel_classes
  "bg-white rounded shadow-md"
end