-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee1e63c
commit 3324e99
Showing
20 changed files
with
774 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
using Dict = System.Collections.Generic.Dictionary<string, object>; | ||
|
||
namespace Butterfly.Message { | ||
public class SendMessageFileParser { | ||
|
||
protected Dictionary<string, Func<string, Dict, string, string>> evaluatorByExtension; | ||
|
||
public SendMessageFileParser(Dictionary<string, Func<string, Dict, string, string>> evaluatorByExtension = null) { | ||
if (evaluatorByExtension==null) { | ||
this.evaluatorByExtension = new Dictionary<string, Func<string, Dict, string, string>> { | ||
["liquid"] = ScribanEvaluator.Evaluate, | ||
["txt"] = SimpleEvaluator.Evaluate | ||
}; | ||
} | ||
else { | ||
this.evaluatorByExtension = evaluatorByExtension; | ||
} | ||
} | ||
|
||
public SendMessage Parse(string fileName) { | ||
if (!File.Exists(fileName)) throw new Exception("Could not find file '" + fileName + "'"); | ||
var extension = Path.GetExtension(fileName); | ||
if (!this.evaluatorByExtension.TryGetValue(extension, out Func<string, Dict, string, string> evaluator)) throw new Exception($"Unknown evaluator extension {extension}"); | ||
|
||
string text = File.ReadAllText(fileName); | ||
return SendMessage.Parse(text, evaluator, Path.GetDirectoryName(fileName)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.