Class: InspectorPanel::Component
- Inherits:
-
Lookbook::BaseComponent
- Object
- Lookbook::BaseComponent
- InspectorPanel::Component
- Defined in:
- app/components/lookbook/inspector_panel/component.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#panel_html ⇒ Object
readonly
Returns the value of attribute panel_html.
-
#panel_styles ⇒ Object
readonly
Returns the value of attribute panel_styles.
Instance Method Summary collapse
- #before_render ⇒ Object
-
#initialize(id:, name:, system: false, **html_attrs) ⇒ Component
constructor
A new instance of Component.
Constructor Details
#initialize(id:, name:, system: false, **html_attrs) ⇒ Component
Returns a new instance of Component.
7 8 9 10 11 12 13 14 |
# File 'app/components/lookbook/inspector_panel/component.rb', line 7 def initialize(id:, name:, system: false, **html_attrs) @id = id @name = name @system = system @panel_html = nil @panel_styles = nil super(**html_attrs) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'app/components/lookbook/inspector_panel/component.rb', line 5 def id @id end |
#panel_html ⇒ Object (readonly)
Returns the value of attribute panel_html.
5 6 7 |
# File 'app/components/lookbook/inspector_panel/component.rb', line 5 def panel_html @panel_html end |
#panel_styles ⇒ Object (readonly)
Returns the value of attribute panel_styles.
5 6 7 |
# File 'app/components/lookbook/inspector_panel/component.rb', line 5 def panel_styles @panel_styles end |
Instance Method Details
#before_render ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/components/lookbook/inspector_panel/component.rb', line 16 def before_render if @system == false panel_dom = ::Nokogiri::HTML.fragment(content) = panel_dom.css("style") if .any? css_parser = ::CssParser::Parser.new @panel_styles = "" .each do |style_tag| css_parser.load_string! style_tag.text css_parser.each_selector do |selector, declarations, specificity| @panel_styles += "##{id} #{selector} { #{declarations} }\n" end end @panel_html = content.gsub(/<style(?:\s[^>]*)?>.*<\/style>/, "").html_safe end end @panel_html ||= content end |