Sha256: 5b938bf96d7757c9a192dc0bda16e252e91a10d0e4ca00e77a3b90c32530b816

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module Maquina
  module ApplicationView
    include Maquina::Engine.routes.url_helpers
    include Phlex::Rails::Helpers::Translate

    delegate :resource_class, :l, :default_url_options, :policy_class, :show_link, :allowed_to?, to: :helpers

    # TODO: Revisit this later
    def image_tag(source, options = {})
      unsafe_raw helpers.image_tag(source, **options)
    end

    def link_to(body, url, html_options = {})
      unsafe_raw helpers.link_to(body, url, html_options)
    end

    def button_to(name, options = nil, html_options = nil)
      unsafe_raw helpers.button_to(name, options, html_options)
    end

    # type: :fill or :outline
    def svg_icon(type, icon:, view_box: "0 0 24 24", stroke_width: 2, css_class: "block h-6 w-6", data: {})
      svg_attributes = if type == :fill
        {xmlns: "http://www.w3.org/2000/svg", fill: "currentColor", viewBox: view_box, "aria-hidden": "true"}
      else
        {xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: view_box, "stroke-width": stroke_width, stroke: "currentColor", "aria-hidden": "true"}
      end

      path_attributes = (type == :fill) ? {} : {"stroke-linecap": "round", "stroke-linejoin": "round"}

      svg(class: css_class, data: data, **svg_attributes) do |markup|
        markup.path(d: icon, **path_attributes)
      end
    end

    def model_human_name(plural: false)
      resource_class.model_name.human(count: plural ? 2 : 1)
    end

    def attribute_human_name(attribute)
      resource_class.human_attribute_name(attribute)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
maquina-0.7.2 app/views/maquina/application_view.rb
maquina-0.7.1 app/views/maquina/application_view.rb
maquina-0.5.2 app/views/maquina/application_view.rb
maquina-0.5.1 app/views/maquina/application_view.rb