Class: Parcels::Fragments::CssFragment
- Inherits:
-
Object
- Object
- Parcels::Fragments::CssFragment
- Defined in:
- lib/parcels/fragments/css_fragment.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(css_string, source, file, line, options) ⇒ CssFragment
constructor
A new instance of CssFragment.
- #to_css(parcels_environment, context) ⇒ Object
- #to_s ⇒ Object
- #wrapping_css_class_required? ⇒ Boolean
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, ) .assert_valid_keys(:engines, :wrap, :prefix) @css_string = css_string @source = source @file = file @line = line @options = end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
11 12 13 |
# File 'lib/parcels/fragments/css_fragment.rb', line 11 def file @file end |
#line ⇒ Object (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 [:prefix] if [:prefix].kind_of?(String) scss = "#{[:prefix]}\n\n#{scss}" else raise "You supplied a css_prefix (or a :prefix option) that wasn't a String, but, rather: #{[: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_s ⇒ Object
27 28 29 |
# File 'lib/parcels/fragments/css_fragment.rb', line 27 def to_s "<#{self.class.name.demodulize}: from '#{file}', line #{line}, options #{.inspect}>" end |
#wrapping_css_class_required? ⇒ Boolean
23 24 25 |
# File 'lib/parcels/fragments/css_fragment.rb', line 23 def wrapping_css_class_required? wrapped? end |