Merge the two source-file methods

This commit is contained in:
Ben S 2014-06-18 08:27:06 +01:00
parent 75e8d829f3
commit f6b6d4d6a7
2 changed files with 21 additions and 25 deletions

View File

@ -78,12 +78,6 @@ impl<'a> File<'a> {
Some("hi") => vec![self.path.with_extension("hs")], // Haskell Some("hi") => vec![self.path.with_extension("hs")], // Haskell
Some("o") => vec![self.path.with_extension("c"), self.path.with_extension("cpp")], // C, C++ Some("o") => vec![self.path.with_extension("c"), self.path.with_extension("cpp")], // C, C++
Some("pyc") => vec![self.path.with_extension("py")], // Python Some("pyc") => vec![self.path.with_extension("py")], // Python
_ => vec![],
}
}
pub fn get_source_files_usual(&self) -> Vec<Path> {
match self.ext {
Some("js") => vec![self.path.with_extension("coffee"), self.path.with_extension("ts")], // CoffeeScript, TypeScript Some("js") => vec![self.path.with_extension("coffee"), self.path.with_extension("ts")], // CoffeeScript, TypeScript
Some("css") => vec![self.path.with_extension("sass"), self.path.with_extension("less")], // SASS, Less Some("css") => vec![self.path.with_extension("sass"), self.path.with_extension("less")], // SASS, Less

View File

@ -37,6 +37,9 @@ static TEMP_TYPES: &'static [&'static str] = &[
static CRYPTO_TYPES: &'static [&'static str] = &[ static CRYPTO_TYPES: &'static [&'static str] = &[
"asc", "gpg", "sig", "signature", "pgp" ]; "asc", "gpg", "sig", "signature", "pgp" ];
static COMPILED_TYPES: &'static [&'static str] = &[
"class", "elc", "hi", "o", "pyc" ];
impl FileType { impl FileType {
pub fn style(&self) -> Style { pub fn style(&self) -> Style {
match *self { match *self {
@ -69,6 +72,9 @@ impl<'a> HasType for File<'a> {
else if self.stat.perm.contains(io::UserExecute) { else if self.stat.perm.contains(io::UserExecute) {
return Executable; return Executable;
} }
else if self.name.starts_with("README") {
return Immediate;
}
else if self.ext.is_some() { else if self.ext.is_some() {
let ext = self.ext.unwrap(); let ext = self.ext.unwrap();
if IMAGE_TYPES.iter().any(|&s| s == ext) { if IMAGE_TYPES.iter().any(|&s| s == ext) {
@ -95,28 +101,24 @@ impl<'a> HasType for File<'a> {
else if self.is_tmpfile() || TEMP_TYPES.iter().any(|&s| s == ext) { else if self.is_tmpfile() || TEMP_TYPES.iter().any(|&s| s == ext) {
return Temp; return Temp;
} }
}
if self.name.starts_with("README") {
return Immediate;
}
let source_files = self.get_source_files(); let source_files = self.get_source_files();
if source_files.len() == 0 { if source_files.len() == 0 {
let source_files_usual = self.get_source_files_usual(); return Normal;
if source_files_usual.iter().any(|path| self.dir.contains(path)) {
Temp
}
else {
Normal
}
} }
else if source_files.iter().any(|path| self.dir.contains(path)) { else if source_files.iter().any(|path| self.dir.contains(path)) {
Temp return Temp;
} }
else { else {
Compiled if COMPILED_TYPES.iter().any(|&s| s == ext) {
return Compiled;
} }
else {
return Normal;
}
}
}
return Normal; // no filetype
} }
} }