Sha256: da37a1793d2d53efbdfbddea6a3f2cad0a67662bf5f76fa7039105e5dd18def3

Contents?: true

Size: 1.6 KB

Versions: 12

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "json"

require "sassc"

require "pakyow/support/extension"

require "pakyow/assets/asset"

module Pakyow
  module Assets
    module Types
      class Sass < Asset
        module Behavior
          extend Support::Extension

          def initialize(local_path:, config:, **kwargs)
            super

            @options = @config.sass.to_h
            @options[:load_paths] ||= []
            @options[:load_paths].unshift(File.dirname(@local_path))
            @options[:filename] = @local_path.to_s

            # Set the syntax dynamically based on whether we're in Sass or Scss class.
            #
            @options[:syntax] = self.class.const_get("FORMAT")

            if @config.source_maps
              @options[:source_map_file] = File.basename(@local_path.to_s)
            end
          end

          def process(content)
            @engine = ::SassC::Engine.new(content, @options)
            @engine.render
          rescue StandardError => error
            Pakyow.logger.error "[#{self.class}] #{error}"

            # Be sure to return a string.
            #
            content
          end

          def dependencies
            ensure_content
            @engine.dependencies.map { |dependency|
              dependency.options[:filename]
            }
          end

          def source_map_content
            ensure_content
            @engine.source_map
          end

          apply_extension do
            extension const_get("FORMAT")
            emits :css
          end
        end

        FORMAT = :sass
        include Behavior
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pakyow-assets-1.0.6 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.5 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.4 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.3 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.2 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.1 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.0 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.0.rc5 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.0.rc4 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.0.rc3 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.0.rc2 lib/pakyow/assets/types/sass.rb
pakyow-assets-1.0.0.rc1 lib/pakyow/assets/types/sass.rb