Class: Rake::Minify::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/minify/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = nil) ⇒ Source

Returns a new instance of Source.



4
5
6
7
8
9
10
# File 'lib/rake/minify/source.rb', line 4

def initialize(source, options=nil)
  options ||= {}
  @source = source
  @minify = optional_boolean(options[:minify], true)
  @coffee_bare = optional_boolean(options[:bare], false)
  @coffee = options[:coffeescript]
end

Instance Attribute Details

#minifyObject (readonly)

Returns the value of attribute minify.



2
3
4
# File 'lib/rake/minify/source.rb', line 2

def minify
  @minify
end

#sourceObject (readonly)

Returns the value of attribute source.



2
3
4
# File 'lib/rake/minify/source.rb', line 2

def source
  @source
end

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rake/minify/source.rb', line 12

def build
  coffee_script! if coffee?

  if source.respond_to? :call
    output = source.call
  else
    output = Kernel.open(source) { |input| input.read }
  end

  output = CoffeeScript.compile(output, :bare => @coffee_bare) if coffee?
  output = JSMin.minify(output).strip if minify

  output
end

#coffee?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rake/minify/source.rb', line 27

def coffee?
  source =~ /\.coffee$/ or @coffee
end