Sha256: 1886c951e00d8c4cd6eb3c3435dd002fd679ac8ac8d4f4b64c92aea5cd68d893

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

module Gumdrop
  module Support
    module BasePackager

      def compress_output(content, opts)
        case opts[:compress]

        when true, :jsmin
          require 'jsmin'
          JSMin.minify content

        when :yuic
          require "yui/compressor"
          compressor = YUI::JavaScriptCompressor.new(:munge => opts[:obfuscate])
          compressor.compress(content)

        when :uglify
          require "uglifier"
          Uglifier.compile( content, :mangle=>opts[:obfuscate])

        when :packr
          require 'packr'
          Packr.pack(content, :shrink_vars => true, :base62 => false, :private=>false)

        when false
          content

        else
          # UNKNOWN Compressor type!
          @site.report "Unknown javascript compressor type! (#{ opts[:compressor] })", :warning
          content
        end
      end
      
      def keep_src(name, content, opts)
        if opts[:keep_src] or opts[:keep_source]
          ext= File.extname name
          page name.gsub(ext, "#{opts.fetch(:source_postfix, '-src')}#{ext}") do
            content
          end
        end
      end
      
      def prune_src(name, opts)
        if opts[:prune] and opts[:root]
          sp = File.expand_path( @site.config.source_dir )
          rp = File.expand_path(opts[:root])
          relative_root = rp.gsub(sp, '')[1..-1]
          rrlen= relative_root.length - 1
          @site.content_hash.keys.each do |path|
            if path[0..rrlen] == relative_root and name != path
              @site.content_hash.delete path
            end
          end
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gumdrop-0.8.0 lib/gumdrop/support/base_packager.rb