Class: Parcels::Fragments::CssFragment

Inherits:
Object
  • Object
show all
Defined in:
lib/parcels/fragments/css_fragment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(css_string, source, file, line, options) ⇒ CssFragment

Returns a new instance of CssFragment.



13
14
15
16
17
18
19
20
21
# File 'lib/parcels/fragments/css_fragment.rb', line 13

def initialize(css_string, source, file, line, options)
  options.assert_valid_keys(:engines, :wrap, :prefix)

  @css_string = css_string
  @source = source
  @file = file
  @line = line
  @options = options
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



11
12
13
# File 'lib/parcels/fragments/css_fragment.rb', line 11

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



11
12
13
# File 'lib/parcels/fragments/css_fragment.rb', line 11

def line
  @line
end

Class Method Details

.to_css(parcels_environment, context, fragments) ⇒ Object



5
6
7
8
# File 'lib/parcels/fragments/css_fragment.rb', line 5

def to_css(parcels_environment, context, fragments)
  fragments = Array(fragments)
  fragments.map { |f| f.to_css(parcels_environment, context) }.join("\n")
end

Instance Method Details

#to_css(parcels_environment, context) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/parcels/fragments/css_fragment.rb', line 31

def to_css(parcels_environment, context)
  scss = css_string

  if wrapped? && (wrapper_css_class = source.try(:_parcels_widget_outer_element_class))
    scss = %{.#{wrapper_css_class} {
    #{scss}
  }}
  end

  if options[:prefix]
    if options[:prefix].kind_of?(String)
      scss = "#{options[:prefix]}\n\n#{scss}"
    else
      raise "You supplied a css_prefix (or a :prefix option) that wasn't a String, but, rather: #{options[:prefix].inspect}"
    end
  end

  asset_attributes = ::Sprockets::AssetAttributes.new(parcels_environment.sprockets_environment, synthetic_filename)
  processors = asset_attributes.processors
  out = process_with_processors(processors, context, scss)

  header_comment + out
end

#to_sObject



27
28
29
# File 'lib/parcels/fragments/css_fragment.rb', line 27

def to_s
  "<#{self.class.name.demodulize}: from '#{file}', line #{line}, options #{options.inspect}>"
end

#wrapping_css_class_required?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/parcels/fragments/css_fragment.rb', line 23

def wrapping_css_class_required?
  wrapped?
end