Module: NitroRails::ComponentsHelper
- Defined in:
- app/helpers/nitro_rails/components_helper.rb
Instance Method Summary collapse
Instance Method Details
#clock ⇒ Object
30 31 32 33 34 |
# File 'app/helpers/nitro_rails/components_helper.rb', line 30 def clock content_tag(:div, class: "clock", data: { controller: "clock" }) do content_tag(:span, Time.now.strftime("%-I:%M %p"), class: "clock-time", data: { "clock-target": "time" }) end end |
#inline_svg(path, **options) ⇒ Object
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 |
# File 'app/helpers/nitro_rails/components_helper.rb', line 3 def inline_svg(path, **) () do || .concat(:class, "inline-svg") .concat(:class, "svg-#{path.split("/").last}") .concat(:class, .delete(:size)) .concat(:style, "transform: rotate(#{options.delete(:rotate)}deg);") if [:rotate] end # Rails.cache.clear svg = Rails.cache.fetch("inline_svg/#{path}", expires_in: 12.hours) do app_path = Rails.root.join("app/assets/images/svgs/#{path}.svg") gem_path = NitroRails::Engine.root.join("app/assets/images/nitro_rails/#{path}.svg") if File.exist?(app_path) File.read(app_path).html_safe elsif File.exist?(gem_path) File.read(gem_path).html_safe else "(SVG file not found: #{path})" end end content_tag(:div, **) do render inline: svg end end |
#search_bar(**options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/nitro_rails/components_helper.rb', line 36 def (**) [:class] = "search-bar #{options[:class]}" [:data] ||= {} [:data][:controller] = "search" content_tag(:div, **) do content_tag(:i, "", class: "fas fa-search") + form_with(url: '/', method: :get, data: { turbo: false }) do text_field_tag(:query, params[:query], class: "search-bar-input", placeholder: "Search", data: { action: "keyup->search#search" }) end end end |