Class: Sinatra::Minify::Compressor

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/minify/compressor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, file, package) ⇒ Compressor

Returns a new instance of Compressor.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
# File 'lib/sinatra/minify/compressor.rb', line 11

def initialize(type, file, package)
  @type        = type.to_s
  @file        = file
  @package     = package
  @command     = :"minify_#{@type}"
  @host        = ENV["MINIFY_SITE_URL"] || "http://localhost:4567"

  raise ArgumentError  if not ['js', 'css'].include?(type)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/sinatra/minify/compressor.rb', line 9

def file
  @file
end

#packageObject (readonly)

Returns the value of attribute package.



8
9
10
# File 'lib/sinatra/minify/compressor.rb', line 8

def package
  @package
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/sinatra/minify/compressor.rb', line 7

def type
  @type
end

Instance Method Details

#buildObject

Rebuilds the minified .min.* files.



22
23
24
25
26
# File 'lib/sinatra/minify/compressor.rb', line 22

def build
  FileUtils.mkdir_p(File.dirname(file))
  File.open(file, 'w') { |f| f.write minify(concatenated) }
  file
end

#cleanObject

Deletes all minified files.



29
30
31
# File 'lib/sinatra/minify/compressor.rb', line 29

def clean
  File.unlink(file)  if File.exists?(file)
end