Class: Assette::CompiledFile

Inherits:
Array
  • Object
show all
Defined in:
lib/assette/compiled_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ CompiledFile

Returns a new instance of CompiledFile.



6
7
8
# File 'lib/assette/compiled_file.rb', line 6

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/assette/compiled_file.rb', line 4

def file
  @file
end

Instance Method Details

#add_dependency(d) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/assette/compiled_file.rb', line 10

def add_dependency d
  c = []
  c << "\n"
  c << file.comment_str % "Start: #{d.path}"
  c << code_for_dependency(d)
  c << file.comment_str % "End: #{d.path}"
  
  self << c.join("\n")
end

#code_for_dependency(d) ⇒ Object



31
32
33
# File 'lib/assette/compiled_file.rb', line 31

def code_for_dependency d
  post_process(d)
end

#content_typeObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/assette/compiled_file.rb', line 35

def content_type
  return mime_type.content_type if mime_type

  case file.target_class.outputs
  when :js
    'text/javascript'
  when :css
    'text/css'
  else
    'text/plain'
  end
end

#mime_typeObject



48
49
50
# File 'lib/assette/compiled_file.rb', line 48

def mime_type
  target_class.mime_type
end

#post_process(file) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/assette/compiled_file.rb', line 20

def post_process file
  str = file.code
  PostProcessor::POST_PROCESSORS[target_class.outputs].each do |processor|
    p = processor.new(file, str, :parent => @file)

    str.replace(p.process)
  end
  
  str
end

#target_classObject



52
53
54
# File 'lib/assette/compiled_file.rb', line 52

def target_class
  file.target_class
end