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.



55
56
57
58
59
60
61
# File 'lib/view_component/scoped_styles/configuration.rb', line 55

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 = "{class_name}_"
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.

Supports template variables:

  • {component_name} — component name with namespaces joined by /, and a trailing Component suffix removed

  • {class_name} — the CSS class being scoped

Example: “{class_name}_” with .component“component_a1b2c3d4”.

To maintain compatibility with versions < 0.5.0 and avoid rewriting existing stylesheets, set this to “c-”.

Returns:

  • (String)

    default: “{class_name}_”



53
54
55
# File 'lib/view_component/scoped_styles/configuration.rb', line 53

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