Sha256: 356ceea5daffe08e3d60818e8589229db303b3881bc04e25c5e4bfd2c3fa4b3d

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

# stdlib
require "ostruct"


module Jekyll
  module AssetsPlugin
    class Configuration
      DEFAULTS = {
        :dirname      => "assets",
        :sources      => %w{_assets/javascripts _assets/stylesheets _assets/images},
        :compress     => { :css => nil, :js => nil },
        :cachebust    => :hard,
        :cache_assets => false,
        :gzip         => %w{ text/css application/javascript }
      }.freeze


      def initialize config = {}
        @data = OpenStruct.new DEFAULTS.merge(config)

        @data.sources  = [ @data.sources ] if @data.sources.is_a? String
        @data.compress = OpenStruct.new @data.compress
        @data.dirname  = @data.dirname.gsub(/^\/+|\/+$/, "")

        # if baseurl not given - autoguess base on dirname
        @data.baseurl ||= "/#{@data.dirname}/".squeeze '/'
      end


      def baseurl
        @data.baseurl.chomp "/"
      end


      def js_compressor
        compressor @data.compress.js
      end


      def css_compressor
        compressor @data.compress.css
      end


      def cachebust
        none?(@data.cachebust) ? :none : @data.cachebust.to_sym
      end


      def cache_assets?
        !!@data.cache_assets
      end


      def gzip
        return @data.gzip if @data.gzip.is_a? Array
        @data.gzip ? DEFAULTS[:gzip] : []
      end


      def method_missing name, *args, &block
        @data.send name, *args, &block
      end


      protected


      def none? val
        val.nil? || val.empty? || "none" == val.to_s.downcase
      end


      def compressor val
        none?(val) ? nil : val.to_sym
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-assets-0.5.3 lib/jekyll/assets_plugin/configuration.rb