Skip to content

Commit

Permalink
minor XmlReader refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
CezarCretu committed Mar 18, 2014
1 parent ae9aa74 commit fdcdb46
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions RequireJsNet/Configuration/XmlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,30 @@ private RequireShim GetShim(XElement root)
if (shimEl != null)
{
shim.ShimEntries = shimEl.Descendants("dependencies")
.Select(r => new ShimEntry
{
Exports = r.Attribute("exports") != null ? r.Attribute("exports").Value : "",
For = r.Attribute("for").Value,
Dependencies = r.Descendants("add")
.Select(x => new RequireDependency
{
Dependency = x.Attribute("dependency").Value
}).ToList()
}).ToList();
.Select(ShimEntryReader).ToList();
}
return shim;
}

private ShimEntry ShimEntryReader(XElement element)
{
return new ShimEntry
{
Exports = element.Attribute("exports") != null ? element.Attribute("exports").Value : "",
For = element.Attribute("for").Value,
Dependencies = DependenciesReader(element)
};
}

private List<RequireDependency> DependenciesReader(XElement element)
{
return element.Descendants("add")
.Select(x => new RequireDependency
{
Dependency = x.Attribute("dependency").Value
}).ToList();
}

private RequireMap GetMap(XElement root)
{
var map = new RequireMap();
Expand All @@ -81,19 +91,30 @@ private RequireMap GetMap(XElement root)
if (mapEl != null)
{
map.MapElements = mapEl.Descendants("replace")
.Select(r => new RequireMapElement
{
For = r.Attribute("for").Value,
Replacements = r.Descendants("add")
.Select(x => new RequireReplacement
{
NewKey = x.Attribute("new").Value,
OldKey = x.Attribute("old").Value
}).ToList()
}).ToList();
.Select(MapElementReader).ToList();
}
return map;
}



private RequireMapElement MapElementReader(XElement element)
{
return new RequireMapElement
{
For = element.Attribute("for").Value,
Replacements = ReplacementsReader(element)
};
}

private List<RequireReplacement> ReplacementsReader(XElement element)
{
return element.Descendants("add")
.Select(x => new RequireReplacement
{
NewKey = x.Attribute("new").Value,
OldKey = x.Attribute("old").Value
}).ToList();
}
}
}

0 comments on commit fdcdb46

Please sign in to comment.