mirror of
https://github.com/pantor/inja.git
synced 2026-05-07 21:35:23 +00:00
Add Child Inheritance Feature (#198)
* add block and extend feature * constify, code cleaning * update single include * add html language to readme * clean tests * constantify, update year
This commit is contained in:
+29
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2020 Pantor. All rights reserved.
|
||||
// Copyright (c) 2021 Pantor. All rights reserved.
|
||||
|
||||
#ifndef INCLUDE_INJA_NODE_HPP_
|
||||
#define INCLUDE_INJA_NODE_HPP_
|
||||
@@ -28,6 +28,8 @@ class ForArrayStatementNode;
|
||||
class ForObjectStatementNode;
|
||||
class IfStatementNode;
|
||||
class IncludeStatementNode;
|
||||
class ExtendsStatementNode;
|
||||
class BlockStatementNode;
|
||||
class SetStatementNode;
|
||||
|
||||
|
||||
@@ -48,6 +50,8 @@ public:
|
||||
virtual void visit(const ForObjectStatementNode& node) = 0;
|
||||
virtual void visit(const IfStatementNode& node) = 0;
|
||||
virtual void visit(const IncludeStatementNode& node) = 0;
|
||||
virtual void visit(const ExtendsStatementNode& node) = 0;
|
||||
virtual void visit(const BlockStatementNode& node) = 0;
|
||||
virtual void visit(const SetStatementNode& node) = 0;
|
||||
};
|
||||
|
||||
@@ -331,6 +335,30 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class ExtendsStatementNode : public StatementNode {
|
||||
public:
|
||||
const std::string file;
|
||||
|
||||
explicit ExtendsStatementNode(const std::string& file, size_t pos) : StatementNode(pos), file(file) { }
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
};
|
||||
};
|
||||
|
||||
class BlockStatementNode : public StatementNode {
|
||||
public:
|
||||
const std::string name;
|
||||
BlockNode block;
|
||||
BlockNode *const parent;
|
||||
|
||||
explicit BlockStatementNode(BlockNode *const parent, const std::string& name, size_t pos) : StatementNode(pos), parent(parent), name(name) { }
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
};
|
||||
};
|
||||
|
||||
class SetStatementNode : public StatementNode {
|
||||
public:
|
||||
const std::string key;
|
||||
|
||||
Reference in New Issue
Block a user