# frozen_string_literal: true module CriticalCssGenerator::Helpers def critical_css @critical_css_cache.try(:[], :css) end def critical_css_enabled? @critical_css_enabled end def critical_css? critical_css.present? && critical_css.instance_of?(String) end def critical_css_asset(attrs) append_critical_css_asset(attrs) nil end def critical_css_tags(preserve_content: true, &block) content = capture(&block) if critical_css_enabled? && critical_css? css_tags = content_tag(:style, critical_css.html_safe, type: 'text/css') css_tags = "#{css_tags}#{content}".html_safe if preserve_content css_tags.html_safe else append_css_tags_assets(content) content end end end