Last active
April 26, 2019 13:01
-
-
Save StefanFabian/4a33c4c040e7ed7311964269a8b0c2e0 to your computer and use it in GitHub Desktop.
doT C++ Code file template for the VSCode extension File Template Manager
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
{{ | |
let date = new Date($.DATE); | |
let date_string = date.getDate().toString().padStart(2, '0') + '.' + (date.getMonth() + 1).toString().padStart(2, '0') + '.' + date.getFullYear(); | |
let paths = $.DIR.split('/'); | |
let index = paths.lastIndexOf('src'); | |
let has_ns = index > 0 && index < paths.length; | |
let ns = ""; | |
if (has_ns) { | |
ns = paths[index - 1]; | |
} | |
let header_dir = ns; | |
if (index + 1 < paths.length) { | |
header_dir += '/' + paths.slice(index + 1).join('/'); | |
} | |
}} | |
// | |
// Created by {{= $.AUTHOR }} on {{= date_string }}. | |
// | |
#include "{{=header_dir}}/{{=$.NAME}}.h" | |
{{? has_ns }} | |
namespace {{=ns}} | |
{ | |
} // namespace {{=ns}} | |
{{?}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This template may be too specific for your use case but it could be a good starting point.
It assumes a folder structure of
[...]/${PROJECT}/src/.../code_file.cpp
where
${PROJECT}
is also the namespace.Required variables
It requires a variable named AUTHOR to be set in File Templates Manager's settings.
To do so, open the VS Code settings search for "Custom Vars" and
edit in the settings.json
.In the settings.json add the following line
"templates.customVars": { "AUTHOR": "Your Name" }
Full example:
Creating a code file named
some_project/src/some_example_class.cpp
will create:You can change the format of the date by changing the date_string variable in the third line.