Class: Spree::ColorsPreviewStylesPresenter
- Inherits:
-
Object
- Object
- Spree::ColorsPreviewStylesPresenter
- Defined in:
- app/presenters/spree/colors_preview_styles_presenter.rb
Constant Summary collapse
- UNSAFE_CSS_CHARS =
/[<>"'\\;{}\r\n]/
Instance Method Summary collapse
-
#initialize(colors) ⇒ ColorsPreviewStylesPresenter
constructor
A new instance of ColorsPreviewStylesPresenter.
- #to_s ⇒ Object
Constructor Details
#initialize(colors) ⇒ ColorsPreviewStylesPresenter
Returns a new instance of ColorsPreviewStylesPresenter.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/presenters/spree/colors_preview_styles_presenter.rb', line 5 def initialize(colors) @colors = colors.compact_blank.map do |color| case color when String color_name = CGI.unescapeHTML(color.strip) { name: color_name, filter_name: color_name } when Hash color_name = CGI.unescapeHTML(color[:name].strip) filter_name = color[:filter_name].present? ? CGI.unescapeHTML(color[:filter_name].strip) : color_name { name: color_name, filter_name: filter_name } end end end |
Instance Method Details
#to_s ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/presenters/spree/colors_preview_styles_presenter.rb', line 21 def to_s @to_s ||= if renderable_colors.any? css = ['<style>'] renderable_colors.each do |color| css_color = css_colors_hash[color[:filter_name]] color_name = color[:name] css << <<~CSS @supports(background: #{css_color}) { .color-input[value="#{color_name}"] ~ .label-container .color-preview, [data-color="#{color_name}"] .color-preview { background: #{css_color}; display: inline-flex; } .color-input[value="#{color_name}"] ~ .label-container .color-label, [data-color="#{color_name}"] .color-label { display: none; } } CSS end css << '</style>' css.join("\n") end end |