Sha256: 1f4712471f64f74df634fb9510fc8e5aa648a097042c093a8209b40f87796300

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

module Octopress
  module Assets
    class Sass < Asset
      def initialize(plugin, type, file, media)
        @file = file
        @type = type
        @plugin_type = plugin.type
        @root = plugin.assets_path
        @dir = File.join(plugin.namespace, type)
        @exists = {}
        @media = media || 'all'
      end

      def media
        @media
      end

      def tag
        "<link href='/#{File.join(@dir, @file)}' media='#{@media}' rel='stylesheet' type='text/css'>"
      end

      def user_load_path(site)
        File.join site.source, Plugins.custom_dir(site), @dir, File.dirname(@file)
      end

      def theme_load_path
        File.expand_path(File.join(@root, @type))
      end

      # Remove sass files from Jekyll's static_files array so it doesn't end up in the
      # compiled site directory. 
      #
      def remove_static_file(site)
        site.static_files.clone.each do |sf|
          if sf.kind_of?(Jekyll::StaticFile) && sf.path == path(site).to_s
            site.static_files.delete(sf)
          end
        end
      end

      def compile(site)
        unless @compiled
          options = Plugins.sass_options(site)
          if @plugin_type == 'local_plugin'
            remove_static_file(site)
            @compiled = Plugins.compile_sass_file(path(site).to_s, options)
          else
            # If the plugin isn't a local plugin, add source paths to allow overrieds on @imports.
            #
            options[:load_paths] = [user_load_path(site), theme_load_path]
            @compiled = Plugins.compile_sass_file(path(site).to_s, options)
          end
        end

        @compiled
      end

      def copy(site)
        site.static_files << StaticFileContent.new(compile(site), destination)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
octopress-ink-1.0.0.alpha.14 lib/octopress-ink/assets/sass.rb
octopress-ink-1.0.0.alpha.13 lib/octopress-ink/assets/sass.rb
octopress-ink-1.0.0.alpha.12 lib/octopress-ink/assets/sass.rb