Skip to content

Commit 82682c5

Browse files
Clean up
1 parent da1d1c3 commit 82682c5

File tree

5 files changed

+27
-50
lines changed

5 files changed

+27
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [ ] Preview window (#6)
55
- [ ] File globbing pattern support (#49)
66
- [ ] Run compilers from a node server
7+
- [x] Sass/LESS dependent file support
78

89
Features that have a checkmark are complete and available for
910
download in the

src/WebCompiler/Dependencies/DependencyResolverBase.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using System.IO;
33
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
64

75
namespace WebCompiler
86
{
@@ -11,12 +9,12 @@ namespace WebCompiler
119
/// </summary>
1210
public abstract class DependencyResolverBase
1311
{
14-
private Dictionary<string, WebCompiler.Dependencies> _dependencies;
12+
private Dictionary<string, Dependencies> _dependencies;
1513

1614
/// <summary>
1715
/// Stores all resolved dependencies
1816
/// </summary>
19-
protected Dictionary<string, WebCompiler.Dependencies> Dependencies
17+
protected Dictionary<string, Dependencies> Dependencies
2018
{
2119
get
2220
{
@@ -40,17 +38,17 @@ public Dictionary<string, Dependencies> GetDependencies(string projectRootPath)
4038
{
4139
if (_dependencies == null)
4240
{
43-
_dependencies = new Dictionary<string, WebCompiler.Dependencies>();
41+
_dependencies = new Dictionary<string, Dependencies>();
4442

4543
List<string> files = new List<string>();
46-
foreach(var pattern in this.SearchPatterns)
44+
foreach (var pattern in this.SearchPatterns)
4745
{
48-
files.AddRange(System.IO.Directory.GetFiles(projectRootPath, pattern, System.IO.SearchOption.AllDirectories));
46+
files.AddRange(Directory.GetFiles(projectRootPath, pattern, SearchOption.AllDirectories));
4947
}
50-
48+
5149
foreach (var path in (from p in files select p.ToLowerInvariant()))
5250
{
53-
this.UpdateFileDependencies(path);
51+
UpdateFileDependencies(path);
5452
}
5553
}
5654

@@ -61,6 +59,5 @@ public Dictionary<string, Dependencies> GetDependencies(string projectRootPath)
6159
/// Updates the dependencies for the given file
6260
/// </summary>
6361
public abstract void UpdateFileDependencies(string path);
64-
6562
}
6663
}

src/WebCompiler/Dependencies/DependencyService.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
62

73
namespace WebCompiler
84
{
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace WebCompiler
1+
namespace WebCompiler
82
{
93
class LessDependencyResolver : SassDependencyResolver
104
{
115
public override string[] SearchPatterns
126
{
13-
get
14-
{
15-
return new string[] { "*.less" };
16-
}
7+
get { return new string[] { "*.less" }; }
178
}
189
}
1910
}

src/WebCompiler/Dependencies/SassDependencyResolver.cs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.IO;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
73

84
namespace WebCompiler
95
{
106
class SassDependencyResolver : DependencyResolverBase
117
{
12-
138
public override string[] SearchPatterns
149
{
15-
get
16-
{
17-
return new string[] { "*.scss","*.sass"};
18-
}
10+
get { return new[] { "*.scss", "*.sass" }; }
1911
}
2012

2113
/// <summary>
@@ -28,18 +20,18 @@ public override void UpdateFileDependencies(string path)
2820
{
2921
path = path.ToLowerInvariant();
3022

31-
if (!this.Dependencies.ContainsKey(path))
32-
this.Dependencies[path] = new WebCompiler.Dependencies();
23+
if (!Dependencies.ContainsKey(path))
24+
Dependencies[path] = new Dependencies();
3325

3426
//remove the dependencies registration of this file
3527
this.Dependencies[path].DependentOn = new HashSet<string>();
3628
//remove the dependentfile registration of this file for all other files
37-
foreach (var dependenciesPath in this.Dependencies.Keys)
29+
foreach (var dependenciesPath in Dependencies.Keys)
3830
{
3931
var lowerDependenciesPath = path.ToLowerInvariant();
40-
if (this.Dependencies[lowerDependenciesPath].DependentFiles.Contains(path))
32+
if (Dependencies[lowerDependenciesPath].DependentFiles.Contains(path))
4133
{
42-
this.Dependencies[lowerDependenciesPath].DependentFiles.Remove(path);
34+
Dependencies[lowerDependenciesPath].DependentFiles.Remove(path);
4335
}
4436
}
4537

@@ -50,17 +42,17 @@ public override void UpdateFileDependencies(string path)
5042
var matches = System.Text.RegularExpressions.Regex.Matches(content, "@import\\s+(url\\()?(['\"])(.*?)(\\2)\\)?;");
5143
foreach (System.Text.RegularExpressions.Match match in matches)
5244
{
53-
FileInfo importedfile = new FileInfo(System.IO.Path.Combine(info.DirectoryName, match.Groups[3].Value));
45+
FileInfo importedfile = new FileInfo(Path.Combine(info.DirectoryName, match.Groups[3].Value));
5446
var dependencyFilePath = importedfile.FullName.ToLowerInvariant();
5547

56-
if (!this.Dependencies[path].DependentOn.Contains(dependencyFilePath))
57-
this.Dependencies[path].DependentOn.Add(dependencyFilePath);
48+
if (!Dependencies[path].DependentOn.Contains(dependencyFilePath))
49+
Dependencies[path].DependentOn.Add(dependencyFilePath);
5850

59-
if (!this.Dependencies.ContainsKey(dependencyFilePath))
60-
this.Dependencies[dependencyFilePath] = new WebCompiler.Dependencies();
51+
if (!Dependencies.ContainsKey(dependencyFilePath))
52+
Dependencies[dependencyFilePath] = new Dependencies();
6153

62-
if (!this.Dependencies[dependencyFilePath].DependentFiles.Contains(path))
63-
this.Dependencies[dependencyFilePath].DependentFiles.Add(path);
54+
if (!Dependencies[dependencyFilePath].DependentFiles.Contains(path))
55+
Dependencies[dependencyFilePath].DependentFiles.Add(path);
6456
}
6557
}
6658
}

0 commit comments

Comments
 (0)