-
Notifications
You must be signed in to change notification settings - Fork 6
/
part.d
96 lines (84 loc) · 2.02 KB
/
part.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Copyright © DiamondMVC 2019
* License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
* Author: Jacob Jensen (bausshf)
*/
module diamond.templates.part;
import diamond.templates.contentmode;
import diamond.templates.grammar;
/**
* Wrapper for a template part.
* Template parts are the aprsed parts of the view.
*/
final class Part
{
package(diamond.templates):
/// The name.
immutable(string) _name;
/// The current grammar.
Grammar _currentGrammar;
/// The seek index.
size_t _seekIndex;
/// The content.
string _content;
final:
/// Creates a new template part.
this()
{
_name = "html";
}
/// Increases the seek index.
void increaseSeekIndex() pure nothrow
{
_seekIndex++;
}
/// Decreases the seek index.
void decreaseSeekIndex() pure nothrow {
_seekIndex--;
}
/**
* Checks whether it's the start of the part or not.
* Returns:
* True if it's start of the part, false otherwise.
*/
auto isStart()
{
return _seekIndex == 1;
}
/**
* Checks whether the current character will end the scope of this part.
* Params:
* currentChar = The current char.
* Returns:
* True if the character marks the end of the part, false otherwise.
*/
auto isEnd(char currentChar) nothrow
{
return (_currentGrammar !is null &&
currentChar == _currentGrammar.endCharacter && _seekIndex < 1);
}
@property
{
/// Sets the current grammar.
void currentGrammar(Grammar newGrammar)
{
_currentGrammar = newGrammar;
}
}
public:
@property
{
/// Gets the current grammar.
Grammar currentGrammar() { return _currentGrammar; }
/// Gets the name of the part.
const(string) name() { return _currentGrammar ? _currentGrammar.name : _name; }
/// Gets the content of the part.
const(string) content() { return _content; }
/// Gets the content mode.
const(ContentMode) contentMode()
{
return !_currentGrammar ?
ContentMode.appendContent : _currentGrammar.contentMode;
}
}
}