-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize template for both simple and dynamic documents.
- Loading branch information
Remi Caput
committed
Feb 20, 2016
1 parent
cc44992
commit fe78c4e
Showing
12 changed files
with
113 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ namespace Cottle | |
{ | ||
enum CommandType | ||
{ | ||
None, | ||
AssignFunction, | ||
AssignValue, | ||
Composite, | ||
|
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,29 @@ | ||
using System; | ||
using Cottle.Parsers; | ||
using Cottle.Parsers.Post; | ||
using Cottle.Parsers.Post.Optimizers; | ||
|
||
namespace Cottle | ||
{ | ||
static class ParserFactory | ||
{ | ||
public static IParser BuildParser (ISetting setting) | ||
{ | ||
IParser parser; | ||
|
||
parser = new DefaultParser (setting.BlockBegin, setting.BlockContinue, setting.BlockEnd, setting.Escape); | ||
|
||
if (setting.Optimize) | ||
{ | ||
parser = new PostParser (parser, new IOptimizer[] | ||
{ | ||
ConstantMapOptimizer.Instance, | ||
IfOptimizer.Instance, | ||
ReturnOptimizer.Instance | ||
}); | ||
} | ||
|
||
return parser; | ||
} | ||
} | ||
} |
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,33 @@ | ||
using System; | ||
|
||
namespace Cottle.Parsers.Post.Optimizers | ||
{ | ||
/// <summary> | ||
/// Simplify "if" command with constant condition. | ||
/// </summary> | ||
class IfOptimizer : AbstractOptimizer | ||
{ | ||
#region Attributes | ||
|
||
public static readonly IfOptimizer Instance = new IfOptimizer (); | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
public override Command Optimize (Command command) | ||
{ | ||
while (command != null && command.Type == CommandType.If && command.Operand.Type == ExpressionType.Constant) | ||
{ | ||
if (command.Operand.Value.AsBoolean) | ||
return command.Body; | ||
|
||
command = command.Next; | ||
} | ||
|
||
return command ?? Command.NoOp; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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