Class: ViewComponent::ScopedStyles::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/view_component/scoped_styles/configuration.rb

Overview

Global settings for ViewComponent::ScopedStyles.

Configure in an initializer:

ViewComponent::ScopedStyles.configure do |config|
  config.components_path = File.join("app", "view_components")
  config.assets_path = File.join("app", "assets", "stylesheets")
  config.stylesheet_name = "components.scoped.css"
  config.components_layer = "components"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



44
45
46
47
48
49
50
# File 'lib/view_component/scoped_styles/configuration.rb', line 44

def initialize
  @components_path = File.join("app", "components")
  @assets_path = File.join("app", "assets", "stylesheets")
  @stylesheet_name = "components.scoped.css"
  @components_layer = nil
  @css_class_prefix = "c-"
end

Instance Attribute Details

#assets_pathString

Directory where the bundled scoped stylesheet is written, relative to Rails.root.

Returns:

  • (String)

    default: “app/assets/stylesheets”



24
25
26
# File 'lib/view_component/scoped_styles/configuration.rb', line 24

def assets_path
  @assets_path
end

#components_layerString?

Optional CSS cascade layer name for the bundled scoped stylesheet.

When set, the bundled stylesheet is wrapped in @layer <name> { … } so you can control specificity relative to other layers in your app.

Returns:

  • (String, nil)

    default: nil (no layer wrapper)



37
38
39
# File 'lib/view_component/scoped_styles/configuration.rb', line 37

def components_layer
  @components_layer
end

#components_pathString

Directory where ViewComponent classes live, relative to Rails.root.

Returns:

  • (String)

    default: “app/components”



19
20
21
# File 'lib/view_component/scoped_styles/configuration.rb', line 19

def components_path
  @components_path
end

#css_class_prefixString

Prefix prepended to scoped class names (e.g. “c-”“c-a1b2c3d4”).

Returns:

  • (String)

    default: “c-”



42
43
44
# File 'lib/view_component/scoped_styles/configuration.rb', line 42

def css_class_prefix
  @css_class_prefix
end

#stylesheet_nameString

Filename of the bundled scoped stylesheet within #assets_path.

Returns:

  • (String)

    default: “components.scoped.css”



29
30
31
# File 'lib/view_component/scoped_styles/configuration.rb', line 29

def stylesheet_name
  @stylesheet_name
end