Sha256: c034e7470578f4b2d910df971bbad608f5e5d4baf1af6ff503e1a355c4f51f37

Contents?: true

Size: 628 Bytes

Versions: 1

Compression:

Stored size: 628 Bytes

Contents

# frozen_string_literal: true

module ViewComponentScopedCss
  #
  # Class for holding the <style></style> of the component called on each request.
  #
  class CurrentContext < ActiveSupport::CurrentAttributes
    attribute :css

    def self.render
      return if css.empty?

      css.values.join("\n").html_safe
    end

    def self.add(view_component_class)
      self.css ||= {}
      self.css[view_component_class.name] ||= ViewComponentScopedCss::Tag.new(view_component_class).call
      self.css[view_component_class.name]
    end

    resets { self.css = {} } if ViewComponentScopedCss.config.compile_cache
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
view_component_scoped_css-0.1.2 lib/view_component_scoped_css/current_context.rb