Sha256: b318ebd92a8a1d9af520e785ffcc8d75813dd9163328a54a21d2f6cf9fec278f

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Proscenium::ViewComponent
  extend ActiveSupport::Autoload

  autoload :TagBuilder

  def before_render
    side_load_assets unless self.class < ReactComponent
  end

  def css_module(name)
    cssm.class_names(name.to_s.camelize(:lower)).join ' '
  end

  private

  # Side load any CSS/JS assets for the component. This will side load any `index.{css|js}` in
  # the component directory.
  def side_load_assets
    Proscenium::SideLoad.append asset_path if Rails.application.config.proscenium.side_load
  end

  def asset_path
    @asset_path ||= "app/components#{virtual_path}"
  end

  def cssm
    @cssm ||= Proscenium::CssModule.new(asset_path)
  end

  # Overrides ActionView::Helpers::TagHelper::TagBuilder, allowing us to intercept the
  # `css_module` option from the HTML options argument of the `tag` and `content_tag` helpers, and
  # prepend it to the HTML `class` attribute.
  def tag_builder
    @tag_builder ||= Proscenium::ViewComponent::TagBuilder.new(self)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
proscenium-0.1.0.alpha3-arm64-darwin lib/proscenium/view_component.rb
proscenium-0.1.0.alpha3-x86_64-darwin lib/proscenium/view_component.rb
proscenium-0.1.0.alpha3-x86_64-linux lib/proscenium/view_component.rb
proscenium-0.1.0.alpha2-x86_64-linux lib/proscenium/view_component.rb
proscenium-0.1.0.alpha2-x86_64-darwin lib/proscenium/view_component.rb
proscenium-0.1.0.alpha2-arm64-darwin lib/proscenium/view_component.rb
proscenium-0.1.0.alpha1-x86_64-linux lib/proscenium/view_component.rb
proscenium-0.1.0.alpha1-x86_64-darwin lib/proscenium/view_component.rb
proscenium-0.1.0.alpha1-arm64-darwin lib/proscenium/view_component.rb