Sha256: 7008884d1d28c674732f8a8755046f867c9845fa77e250c98616f4d825213b1b
Contents?: true
Size: 1 KB
Versions: 2
Compression:
Stored size: 1 KB
Contents
require "css_parser" module Lookbook class InspectorPanel::Component < Lookbook::BaseComponent attr_reader :panel_styles, :panel_html, :id def initialize(id:, name:, system: false, **html_attrs) @id = id @name = name @system = system @panel_html = nil @panel_styles = nil super(**html_attrs) end def before_render if @system == false panel_dom = ::Nokogiri::HTML::fragment(content) style_tags = panel_dom.css('style') if style_tags.any? css_parser = ::CssParser::Parser.new @panel_styles = "" style_tags.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 style_tag.unlink end @panel_html = panel_dom.to_html.html_safe end end @panel_html ||= content end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lookbook-1.0.0.beta.7 | app/components/lookbook/inspector_panel/component.rb |
lookbook-1.0.0.beta.6 | app/components/lookbook/inspector_panel/component.rb |