Sha256: 7167151d5b6959789ad9d2a69c24317ac97470feed293b45192227a4d1ab8178

Contents?: true

Size: 621 Bytes

Versions: 1

Compression:

Stored size: 621 Bytes

Contents

require "yui/compressor"

module Papercat
  class Stylesheet < Document
    
    YUI_JAR_FILE = "#{Papercat::Engine.root}/vendor/yuicompressor-2.4.8.jar"
    COMPRESSOR = YUI::CssCompressor.new({jar_file: YUI_JAR_FILE})
    
    store_accessor :data, :pathname, :source, :body
    
    validates_with UniquenessValidator, key: :pathname
    
    validates_presence_of :source

    before_save :minify
    
    def as_json options = {}
      super(options.update(methods: [:pathname, :source], except: [:data]))
    end
    
    private
    
    def minify
      self.body = COMPRESSOR.compress(source)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
papercat-0.0.2 app/models/papercat/stylesheet.rb