Class: Distil::SourceFile
- Inherits:
-
Object
- Object
- Distil::SourceFile
show all
- Includes:
- ErrorReporter
- Defined in:
- lib/distil/source-file.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
error, #has_errors?, #has_warnings?, #ignore_warnings, #ignore_warnings=, #report, #total_error_count, #total_warning_count, warning
Constructor Details
#initialize(filepath, project) ⇒ SourceFile
Returns a new instance of SourceFile.
14
15
16
17
18
19
|
# File 'lib/distil/source-file.rb', line 14
def initialize(filepath, project)
@full_path= File.expand_path(filepath)
@project= project
@dependencies=[]
project.cache_file(self)
end
|
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
6
7
8
|
# File 'lib/distil/source-file.rb', line 6
def dependencies
@dependencies
end
|
#full_path ⇒ Object
Returns the value of attribute full_path.
6
7
8
|
# File 'lib/distil/source-file.rb', line 6
def full_path
@full_path
end
|
#is_asset ⇒ Object
Returns the value of attribute is_asset.
7
8
9
|
# File 'lib/distil/source-file.rb', line 7
def is_asset
@is_asset
end
|
#language ⇒ Object
Returns the value of attribute language.
7
8
9
|
# File 'lib/distil/source-file.rb', line 7
def language
@language
end
|
#project ⇒ Object
Returns the value of attribute project.
6
7
8
|
# File 'lib/distil/source-file.rb', line 6
def project
@project
end
|
Instance Method Details
#add_asset(file) ⇒ Object
101
102
103
104
|
# File 'lib/distil/source-file.rb', line 101
def add_asset(file)
file.is_asset=true
assets << file
end
|
#add_dependency(file) ⇒ Object
92
93
94
95
|
# File 'lib/distil/source-file.rb', line 92
def add_dependency(file)
return if @dependencies.include?(file)
@dependencies << file
end
|
#assets ⇒ Object
97
98
99
|
# File 'lib/distil/source-file.rb', line 97
def assets
@assets||=Set.new
end
|
#basename(suffix = "") ⇒ Object
60
61
62
|
# File 'lib/distil/source-file.rb', line 60
def basename(suffix="")
File.basename(@full_path, suffix)
end
|
#content ⇒ Object
72
73
74
|
# File 'lib/distil/source-file.rb', line 72
def content
@content ||= File.read(full_path)
end
|
#content_type ⇒ Object
68
69
70
|
# File 'lib/distil/source-file.rb', line 68
def content_type
@content_type || self.class.content_type || File.extname(full_path)[1..-1]
end
|
#copy_to(folder, prefix) ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/distil/source-file.rb', line 106
def copy_to(folder, prefix)
relative= path_relative_to_folder(prefix)
target_path= File.join(folder, relative)
FileUtils.mkdir_p final_target_folder
FileUtils.cp self.full_path, File.dirname(target_path)
target_path
end
|
#dirname ⇒ Object
56
57
58
|
# File 'lib/distil/source-file.rb', line 56
def dirname
File.dirname(@full_path)
end
|
#error(message, line = nil) ⇒ Object
25
26
27
|
# File 'lib/distil/source-file.rb', line 25
def error(message, line=nil)
super(message, self, line)
end
|
#extension ⇒ Object
64
65
66
|
# File 'lib/distil/source-file.rb', line 64
def extension
@extension || self.class.extension || File.extname(full_path)[1..-1]
end
|
#last_modified ⇒ Object
80
81
82
|
# File 'lib/distil/source-file.rb', line 80
def last_modified
@last_modified ||= File.stat(@full_path).mtime
end
|
#minified_content(source = content) ⇒ Object
84
85
86
|
# File 'lib/distil/source-file.rb', line 84
def minified_content(source=content)
return source
end
|
#output_path ⇒ Object
29
30
31
32
33
|
# File 'lib/distil/source-file.rb', line 29
def output_path
@output_path ||= File.join(project.output_path, relative_path)
end
|
#path_relative_to(path) ⇒ Object
#path_relative_to_folder(folder) ⇒ Object
#relative_path ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/distil/source-file.rb', line 35
def relative_path
return @relative_path if @relative_path
if full_path.starts_with?(project.output_path)
@relative_path= Project.path_relative_to_folder(full_path, project.output_path)
else
@relative_path=Project.path_relative_to_folder(full_path, project.source_path)
end
end
|
#rewrite_content_relative_to_path(path) ⇒ Object
76
77
78
|
# File 'lib/distil/source-file.rb', line 76
def rewrite_content_relative_to_path(path)
content
end
|
#to_s ⇒ Object
48
49
50
|
# File 'lib/distil/source-file.rb', line 48
def to_s
@full_path
end
|
#to_str ⇒ Object
52
53
54
|
# File 'lib/distil/source-file.rb', line 52
def to_str
@full_path
end
|
#warning(message, line = nil) ⇒ Object
21
22
23
|
# File 'lib/distil/source-file.rb', line 21
def warning(message, line=nil)
super(message, self, line)
end
|