Sha256: ff7b2371d4afa2d62c2493a56e6a8674ff1be125e79565cc9285c53106e791de

Contents?: true

Size: 1.95 KB

Versions: 4

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

module RailsDevtools
  class Routes::RouteCard < Components::ApplicationComponent
    def initialize(route:, engine:)
      @route = route
      @engine = engine
    end

    def view_template
      a(
        href: helpers.route_path(
          @route.id
        ),
        data: { turbo_frame: "drawer_content", action: "click->checkbox#toggle" },
        class: "group flex w-full"
      ) do
        div(class: "card card-compact bg-white text-sm w-full shadow-sm") do
          div(class: "card-body") do
            div(class: "flex flex-col sm:flex-row justify-between sm:items-center gap-y-2 sm:gap-x-2") do
              div(class: "flex items-center") do
                h2(class: "inline-flex card-title !mb-0 leading-none text-base items-center") do
                  route_name
                end
                redirection_badge
                no_matching_controller_alert
                engine_badge
              end
              div(class: "flex gap-2 items-center justify-between sm:justify-normal") do
                div(class: "truncate") { @route.path.gsub("(.:format)", "") }
                div(class: "badge badge-sm ml-1") { @route.verb }
              end
            end
          end
        end
      end
    end

    private

    def route_name
      if @route.inline?
        @route.name
      else
        "#{@route.name}_path"
      end
    end

    def no_matching_controller_alert
      return unless @route.kind == "controller"
      return if @route.controller_info.action_exists?

      span(class: "text-error ml-1") do
        render Components::Lucide::TriangleAlert.new(width: 16, height: 16)
      end
    end

    def engine_badge
      return unless @route.engine?

      span(class: "badge badge-sm badge-accent ml-1") { "engine" }
    end

    def redirection_badge
      return unless @route.redirection?

      span(class: "badge badge-sm badge-accent ml-1") { @route.redirection_info.status }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_devtools-0.1.3 app/views/rails_devtools/routes/route_card.rb
rails_devtools-0.1.2 app/views/rails_devtools/routes/route_card.rb
rails_devtools-0.1.1 app/views/rails_devtools/routes/route_card.rb
rails_devtools-0.1.0 app/views/rails_devtools/routes/route_card.rb