How to make posts with code on Developer Community
Hi!
Here is small "How to" again.
Suppose you need to share something with source code. How can we manage it on DC?
Sharing code snippets
1. Add normal post (not Code Package).
2. Paste your code in the post and format it with highlighting as it is described here.
3. If you see that your COS code is highlighted wrong it means that autodetect missed with language. Open the post's HTML ("disable rich-text" button below the Editor) and put class=COS parameter into the code tag.
Example:
#dim test as %Library.Integer
SET test = 123.099
set ^global = %request.Content
Write "Current date """, $ztimestamp, """, result: ", test + ^global = 125.099
do ##class(Cinema.Utils).AddShow("test") // class method call do ##super()
; another one-line comment
d:(^global = 2) ..thisClassMethod(1, 2, "test")
/* * Sub-languages support: */
&sql( SELECT * FROM Cinema.Film WHERE Length > 2 )
&js<for (var i = 0; i < String("test").split("").length); ++i) {
console.log(i);
}>
&html<<!DOCTYPE html>
<html>
<head>
<meta name="test"/>
</head>
<body>
Test
</body>
</html>>
quit $$$OK
4. If you want to highlight another languages and auto highlight works not as expected put the appropriate code class.
Sharing projects and solutions with sources
If you want to share with something significant like demo project do the following:
1. Upload your code on Github in a public repository. Example. Use Atelier to upload COS projects in UDL. If you are using Caché Studio there are plenty of Git Plugins. Try one of the most popular - Caché Tortoise Git.
2. Add normal post and share the link on Github in it. People will fork your repository, will do pull requests, will download it and more.
Code guidelines
Suppose you have your own code guidelines. If not, we can suggest guidelines listed in this repository.
We introduced Code Snippet tag. Please use it if your post contains a good snippet, or one of the answers/comments on your post is a valuable code snippet.
The good option to share the source code of a standalone class or routine is to upload it to the Gist and share the link to the gist in your post.
Post example. Gist example .