Class: Assets::Compiler::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/assets/compiler/base.rb

Direct Known Subclasses

Javascript

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ Base

Returns a new instance of Base.



18
19
20
21
# File 'lib/assets/compiler/base.rb', line 18

def initialize(paths)
	self.source_path, self.destination_path = paths
	self.staleness_checker = Checker.new(self)
end

Instance Attribute Details

#destination_pathObject

Returns the value of attribute destination_path.



6
7
8
# File 'lib/assets/compiler/base.rb', line 6

def destination_path
  @destination_path
end

#source_pathObject

Returns the value of attribute source_path.



6
7
8
# File 'lib/assets/compiler/base.rb', line 6

def source_path
  @source_path
end

#staleness_checkerObject

Returns the value of attribute staleness_checker.



6
7
8
# File 'lib/assets/compiler/base.rb', line 6

def staleness_checker
  @staleness_checker
end

Class Method Details

.create(type, paths) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/assets/compiler/base.rb', line 8

def self.create(type, paths)
	begin
		klass = Assets::Compiler.const_get(type.to_s.capitalize)
	rescue NameError
		raise InvalidCompiler, "No compiler found for #{type}"
	end

	klass.new(paths)
end

Instance Method Details

#compile!Object



23
24
25
26
27
28
29
# File 'lib/assets/compiler/base.rb', line 23

def compile!
	outdated_files.each do |file|
		destination_file = destination_for_file(file)
		FileUtils.mkdir_p(File.dirname(destination_file))
		compile_file(file, destination_file)
	end
end

#destination_for_file(file) ⇒ Object



31
32
33
34
# File 'lib/assets/compiler/base.rb', line 31

def destination_for_file(file)
	relative_path = file.sub(source_path, '')	
	File.join(destination_path, relative_path)
end