Class: StyleComponent

Inherits:
Component show all
Defined in:
app/components/style_component.rb

Overview

Style — inline <style> tag.

Usage:

Style(".my-class { color: red; }")

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, slot

Constructor Details

#initialize(css = nil, **kwargs) ⇒ StyleComponent

Returns a new instance of StyleComponent.



9
10
11
12
# File 'app/components/style_component.rb', line 9

def initialize(css = nil, **kwargs)
  @css = css
  super(**kwargs)
end

Instance Method Details

#render_in(context, &block) ⇒ Object



14
15
16
17
18
# File 'app/components/style_component.rb', line 14

def render_in(context, &block)
  @view_context = context
  @css ||= context.capture(&block) if block
  to_s
end

#to_sObject



20
21
22
# File 'app/components/style_component.rb', line 20

def to_s
  tag.style { @css&.html_safe }
end