Class: Cataract::Backends::PureImpl::Serializer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cataract/pure/serializer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Serializes one stylesheet's rules to a CSS string, compact or formatted. One instance per #stylesheet_to_s / #stylesheet_to_formatted_s call - the accumulating result, the rules/media being serialized, and the compact-vs-formatted knobs all live on ivars instead of being threaded through every helper as parameters.

Instance Method Summary collapse

Constructor Details

#initialize(rules, charset, has_nesting, selector_lists, media_queries, media_query_lists, formatted:) ⇒ Serializer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Serializer.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cataract/pure/serializer.rb', line 15

def initialize(rules, charset, has_nesting, selector_lists, media_queries, media_query_lists, formatted:)
  @rules = rules
  @charset = charset
  @has_nesting = has_nesting
  @selector_lists = selector_lists || {}
  @media_queries = media_queries || []
  @media_query_lists = media_query_lists || {}
  @formatted = formatted
  @result = +''

  if formatted
    @opening_brace = " {\n"
    @closing_brace = "}\n"
    @media_indent = '  '
    @decl_indent_base = '  '
    @decl_indent_media = '    '
    @add_blank_lines = true
  else
    @opening_brace = ' { '
    @closing_brace = " }\n"
    @media_indent = ''
    @decl_indent_base = nil
    @decl_indent_media = nil
    @add_blank_lines = false
  end
end

Instance Method Details

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serialize the stylesheet to a CSS string (compact or formatted, depending on how this Serializer was constructed).

Returns:

  • (String)

    CSS string



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cataract/pure/serializer.rb', line 46

def to_s
  @result << "@charset \"#{@charset}\";\n" unless @charset.nil?

  build_mq_id_to_list_id!

  if @has_nesting
    @formatted ? serialize_with_nesting_formatted : serialize_with_nesting_compact
  else
    serialize_with_grouping
  end

  @result
end