Instantly share code, notes, and snippets.

Embed
What would you like to do?
ReAdABLE.HumanFormat: a new standard format easier to read, write and maintain to generate Markdown (and much more coming). Just copy and paste .ReAdABLE.HumanFormat.deploy.ps1 oneliner content in Powershell to download.
$demo="ReAdABLE.Human.Format";$github='https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542';$githublib='https://gist.github.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8';$demofolder="C:\red\demos\$demo";$exefolder="C:\red";$exeurl='https://static.red-lang.org/dl/win/red-063.exe';Add-Type -AssemblyName Microsoft.VisualBasic;$demofolder=[Microsoft.VisualBasic.Interaction]::InputBox("Enter folder for $demo demo:", $demo, $demofolder);if ($demofolder -ne $null) {$demo=Split-Path $demofolder -Leaf;Function Get-Github-Links {Param($uri);[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;$WebResponse = Invoke-WebRequest -Uri "$uri";return $ResponseLinks=$WebResponse.Links | Select href};Function Filter-Link {Param($filter);$links = $AllLinks | Where-Object {$_.href -match "$filter"};$link=$links[0].href;return $link};Function Get-Github-Url {Param($filename);$link=Filter-Link $filename;$url="https://gist.githubusercontent.com$link";return $url};$AllLinks = Get-Github-Links $github;$src=Get-Github-Url 'ReAdABLE.Human.Format.red';New-Item -ItemType Directory -Force -Path $red-folder;New-Item -ItemType Directory -Force -Path $demofolder;$Webcli=New-Object System.Net.WebClient;if (!(Test-Path `"$exefolder\red.exe`")) {$Webcli.DownloadFile("$exeurl","$exefolder\red.exe")};"Red [] `n print to-local-file what-dir `n do read $src" | Out-File -filepath "$demofolder\$demo.red" -Encoding "UTF8";"cd `"%~dp0`"`r`n" | Out-File -filepath "$demofolder\$demo.bat" -Encoding ASCII;"IF DEFINED RED_HOME (start `"%~n0`" `"%RED_HOME%\red.exe`" `"%~n0.red`" %1) ELSE (start `"%~n0`" `"$exefolder\red.exe`" `"%~n0.red`" %1)" | Out-File -filepath "$demofolder\$demo.bat" -Encoding ASCII -Append;cmd.exe /c "$demofolder\$demo.bat";Add-Type -AssemblyName PresentationFramework;$msgBox=[System.Windows.MessageBox]::Show('Would you like to download the source?','Download','YesNo','Question');switch ($msgBox) {'Yes' {New-Item -ItemType Directory -Force -Path "$demofolder\lib";$link=Get-Github-Url "ReAdABLE.Human.Format.lib.red";$Webcli.DownloadFile($link,"$demofolder\lib\ReAdABLE.Human.Format.lib.red");$Webcli.DownloadFile($src,"$demofolder\$demo.red");$link=Get-Github-Url "How.to.setup.github.repository.red";$Webcli.DownloadFile($link,"$demofolder\How.to.setup.github.repository.red");$link=Get-Github-Url "How.to.write.good.article.red";$Webcli.DownloadFile($link,"$demofolder\How.to.write.good.article.red");New-Item -ItemType Directory -Force -Path "$demofolder\deploy";$link=Get-Github-Url ".ReAdABLE.HumanFormat.deploy.ps1";$Webcli.DownloadFile($link,"$demofolder\deploy\$demo.deploy.ps1");$link=Get-Github-Url "ReAdABLE.HumanFormat.deploy.red";$Webcli.DownloadFile($link,"$demofolder\deploy\$demo.deploy.red")} 'No' {}};$AllLinks = Get-Github-Links $githublib;$link=Get-Github-Url '.system.user.apps.authoring.library.red';New-Item -ItemType Directory -Force -Path "$demofolder\.libraries";$Webcli.DownloadFile($link,"$demofolder\.libraries\.system.user.apps.authoring.library.red");start explorer.exe -ArgumentList "/select, `"$demofolder\$demo.red`""}
Red [
Title: "How.to.setup.github.repository.red"
]
Tutorial: [
Title: {How to setup a new github repository}
Introduction: [
.title: {Create a new repository}
.text: {Click on "+" top menu icon and select "New repository" }
.image: https://i.imgur.com/nhYNxfD.png
.text: {Give a repository name}
.image: https://i.imgur.com/25U7jku.png
.text: {You should get your repository created}
]
Setup-Github-Pages: [
.title: {Setup Github Pages}
.text: {Click on "Settings" button}
.image: https://i.imgur.com/A4A98qe.png
.text: {Scroll down and click on "choose a theme"}
.image: https://i.imgur.com/y9DTpfR.png
.text: {Pick a theme}
.image: https://i.imgur.com/ym4xqWG.png
.text: {You should get a new Readme.md file}
.image: https://i.imgur.com/TUtsafY.png
.text: {Commit the change by clicking on the green button at the bottom of the page}
.image: https://i.imgur.com/kfjSJE0.png
]
Clone-Github-in-VSCode: [
.title: {Clone Github Repository in VSCode}
.text: {Copy the url on Github by clicking on the green button "clone or download"}
.image: https://i.imgur.com/5ZXyoD0.png
.text: {In VSCode type Ctrl+Shift+P then Git}
.image: https://i.imgur.com/1nTzE4n.png
.text: {Paste the url in VSCode and enter the target folder}
.image: https://i.imgur.com/G22I6Rr.png
.text: {after validation you could open the cloned repository in a new VSCode workspace}
.image: https://i.imgur.com/0XQfkia.png
.references: [
https://blog.velingeorgiev.com/how-to-clone-git-project-with-visual-studio-code
https://stackoverflow.com/questions/38307647/clone-github-repository-in-vscode
]
]
Update-Github-Repository: [
.title: {Push update to Github}
.text: {In VSCode type Ctrl+Shift+P then "Git Stage All"}
.image: ""
.text: {In VSCode type Ctrl+Shift+P then "Git Commit"}
.image: ""
.text: {In VSCode type Ctrl+Shift+P then "Git Push"
Enter login and password:}
.image: https://i.imgur.com/iG983KO.png
]
]
do read %lib/ReAdABLE.Human.Format.lib.red
.markdown-gen
Red [
Title: "How.to.write.good.article.red"
Credit: https://www.c-sharpcorner.com/article/how-to-write-good-articles/
]
Article: [
Title: {How To Write Good Articles}
Credit: [
.title: {Credit}
.text: {
[How To Write Good Articles by Sibeesh Venu](https://www.c-sharpcorner.com/article/how-to-write-good-articles/)
}
]
Point-1: [
.title: {Point 1: Introduction}
.text: {
Type your introduction here, see guidance and example.
}
.guidance: {
An introduction is very important when you write an article. A good introduction can make the reader want to read further. Trust me, it is very useful too. In this part you can describe what exactly you are going to say/do in the rest of the article. It must be brief. And please never use any code blocks in your introduction, that is never meant to be there. This is the part which lets your readers understand where/what exactly you are intending to do.
}
.example: {
I am neither an expert nor a guru. But still I suppose I have improved by writing articles for the past two years. I still remember my first article, there were so many mistakes. Remember one thing: “Mistakes are the key to success.” Here I will point out a few things which I follow while writing articles. Please feel free to add your own points to this article. I hope you will like this.
}
]
Point-2: [
.title: {Point 2: Background}
.text: {
In this part, you can explain what made you write this article. You can explain the problems you faced here, or when you had this problem. This should be brief too, here you can also include source code. Please do remember that this is just the background, so it is not advisable to include full source code and explain it here.
}
.guidance: {
In this part, you can explain what made you write this article. You can explain the problems you faced here, or when you had this problem. This should be brief too, here you can also include source code. Please do remember that this is just the background, so it is not advisable to include full source code and explain it here.
}
.example: {
Example: Last week one of my friends asked this question: "How do you write good articles?" I am dedicating this article to him. I hope he will like this.
}
]
Point-3: [
.title: {Point 3: What are you going to do?}
.text: {
Here you can explain the things which you are going to do in this article. You can list them for better readability. You can explain these points one by one. You can also add some code snippets. But whenever you add any code, please try to explain even if it is basic. That will help some beginners to understand things more easily. You may feel that this basic explanation is not necessary as you have so much experience and you may be good at it. But what about the beginners? I always believe they are the real beneficiaries of your articles. We must concentrate on both kinds of users; i.e., beginners and experienced.
}
.image: https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/how-to-write-good-articles/Images/What-you-are-going-to-do.jpg
.guidance: {
Here you can explain the things which you are going to do in this article. You can list them for better readability. You can explain these points one by one. You can also add some code snippets. But whenever you add any code, please try to explain even if it is basic. That will help some beginners to understand things more easily. You may feel that this basic explanation is not necessary as you have so much experience and you may be good at it. But what about the beginners? I always believe they are the real beneficiaries of your articles. We must concentrate on both kinds of users; i.e., beginners and experienced.
}
]
Point-4: [
.title: {Point 4: How are you going to do it?}
.text: {
This can be the continuation of point three. This is where you can explain the possible ways that you can fix your problem, or the possible ways to achieve the same tasks. Any tasks can be achieved in different ways right? So when you write any article, you must think from all perspectives.
This will make your article rich in content. And this is where you must concentrate more on the coding part. When you write code in your article, it must be formatted well. If you use WordPress as a CMS (Content Management System) for your blog, you can go for any syntax highlighter plugins, or you can customize your own. If you post the article in any of the social communities, please use their formatting options.
If you have any images which explain the workflow for any tasks, it is always advisable to include those. An image is more understandable than reading the content, but always limit yourself to not include more than 10 images per article. When you include the images, please try to convert them to a particular size (example: width: 650 PX), this will make your article look good. But no worries if you have a low resolution image, and if you think enlarging that will cause any clarity issues, you can always use the same without conversion.
One thing you must remember is that you can always include all the things you have tried and what the output was that you got from it. If you do so, your reader will see that if he or she does that, they will get the same output. So it is not only about the the scenario which works fine, but also about the errors/problems.
}
.guidance: {
This can be the continuation of point three. This is where you can explain the possible ways that you can fix your problem, or the possible ways to achieve the same tasks. Any tasks can be achieved in different ways right? So when you write any article, you must think from all perspectives.
This will make your article rich in content. And this is where you must concentrate more on the coding part. When you write code in your article, it must be formatted well. If you use WordPress as a CMS (Content Management System) for your blog, you can go for any syntax highlighter plugins, or you can customize your own. If you post the article in any of the social communities, please use their formatting options.
If you have any images which explain the workflow for any tasks, it is always advisable to include those. An image is more understandable than reading the content, but always limit yourself to not include more than 10 images per article. When you include the images, please try to convert them to a particular size (example: width: 650 PX), this will make your article look good. But no worries if you have a low resolution image, and if you think enlarging that will cause any clarity issues, you can always use the same without conversion.
One thing you must remember is that you can always include all the things you have tried and what the output was that you got from it. If you do so, your reader will see that if he or she does that, they will get the same output. So it is not only about the the scenario which works fine, but also about the errors/problems.
}
]
Point-5: [
.title: {Point 5: Always include output}
.text: {
An output is the outcome of what we tried, right? So what if you don't include that? Isn’t that bad? You can include the output as an image or any content. It can be any result set too.
}
.guidance: {
An output is the outcome of what we tried, right? So what if you don't include that? Isn’t that bad? You can include the output as an image or any content. It can be any result set too.
}
]
Point-6: [
.title: {Point 6: Include source code as a downloadable format}
.text: {
Please add source code as a downloadable format whenever possible. This will definitely help your reader, so that he/she doesn’t need to worry about the initial set up. We all are a community, guys, and we love helping each other. Am I right?
}
.guidance: {
Please add source code as a downloadable format whenever possible. This will definitely help your reader, so that he/she doesn’t need to worry about the initial set up. We all are a community, guys, and we love helping each other. Am I right?
}
]
Point-7: [
.title: {Point 7: Format the entire content}
.text: {
There are so many things you must concentrate on when it comes to formatting. I am listing a few of them here.
- Use the same font for the entire article
- Use bold for the headings
- Highlight the lines, if it is very important (Example: Notes)
- Use code formatter when you write codes
- Resize and align images properly
- Make sure that that headings start with a capital letter (CamelCasing)
}
.guidance: {
There are so many things you must concentrate on when it comes to formatting. I am listing a few of them here.
- Use the same font for the entire article
- Use bold for the headings
- Highlight the lines, if it is very important (Example: Notes)
- Use code formatter when you write codes
- Resize and align images properly
- Make sure that that headings start with a capital letter (CamelCasing)
}
]
Point-8: [
.title: {Point 8: Give credit}
.text: {
This is very important. Whenever you take something from any site, please try to give credit to the content owner by providing the links/name. For example, if you are taking an image from any site, you can include the site name just below the image. Trust me, this will make you genuine. And in the end, it is all about being genuine right?
}
.guidance: {
This is very important. Whenever you take something from any site, please try to give credit to the content owner by providing the links/name. For example, if you are taking an image from any site, you can include the site name just below the image. Trust me, this will make you genuine. And in the end, it is all about being genuine right?
}
]
Point-9: [
.title: {Point 9: Write a conclusion}
.text: {
The conclusion is the last part of your article; you can summarize the things you have written here. And also if you want, you can always ask some questions to your readers so that the bond between you and your readers will be in multibind format (Yes, like we have in Angular JS. LOL). You can always ask for feedback; feedback is something that we all are looking for. Each and every piece of feedback is valuable whether it is negative or positive. If you get any negative feedback, be happy and try to improve on the things that are being suggested.
In a speech in South Africa in 1890 Mahatma Gandhi said this:
* * “A customer is the most important visitor on our premises. He is not dependent on us. We are dependent on him. He is not an interruption of our work. He is the purpose of it. He is not an outsider of our business. He is part of it. We are not doing him a favour by serving him. He is doing us a favour by giving us the opportunity to do so.”
}
.guidance: {
The conclusion is the last part of your article; you can summarize the things you have written here. And also if you want, you can always ask some questions to your readers so that the bond between you and your readers will be in multibind format (Yes, like we have in Angular JS. LOL). You can always ask for feedback; feedback is something that we all are looking for. Each and every piece of feedback is valuable whether it is negative or positive. If you get any negative feedback, be happy and try to improve on the things that are being suggested.
In a speech in South Africa in 1890 Mahatma Gandhi said this:
* * “A customer is the most important visitor on our premises. He is not dependent on us. We are dependent on him. He is not an interruption of our work. He is the purpose of it. He is not an outsider of our business. He is part of it. We are not doing him a favour by serving him. He is doing us a favour by giving us the opportunity to do so.”
}
]
]
do read %lib/ReAdABLE.Human.Format.lib.red
markdown-gen
Red [
Title: "ReAdABLE.Human.Format.lib.red"
Description: {Presenting the ReAdABLE Human Format written in its own format for highly productive aspiring Writer}
History: [
v1.0: {initial version}
v1.1: {
- added .code and .text sections (.text is same as content)
- support multiple paragraphs with same labels
}
]
Todo: {
.code tabs are not well indented
}
ReAdABLE-Human-Format: [
{
Article: [
Title: "Title of the article"
Sub-Title: {Sub-title of the article}
Paragraphs: [ ; optional paragraph is supported out of paragraphs
Paragraph: [
.title: [
"Title for Paragraph P1"
.mandatory: yes
]
.content: {Content for Paragraph P1}
.text: {same as content}
.code: {code}
.image: http://optional.image-1.jpg
.text: {multiple text instances supported}
]
Paragraph: [
.title: {anonymous paragraph with non-unique label}
]
[
.title: {anonymous paragraph with no label}
]
]
]
}
]
]
;===========================================================================================
; PREAMBLE
;===========================================================================================
; loading library
REMOTE-LIB: false
unless ((REMOTE-LIB = false) and (exists? lib: %.system.user.apps.authoring.library.red)) [
print "Loading remote lib"
do read https://gist.githubusercontent.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8/raw/2dec6c1f92fe1834632d998ffb831539caa23d63/.github.lib.red
github-url-entry: https://gist.github.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8
lib: get-github-url github-url-entry %.system.user.apps.authoring.library.red
]
do read lib
;launched script path (first one may be different from current executing script)
script-path: system/options/script
either none? script-path [
short-filename: "ReAdABLE.Human.Format.red"
][
short-filename: .get-short-filename/wo-extension script-path
]
;===========================================================================================
; DATA
;===========================================================================================
; don't forget to toggle word-wrap in VSCode
; if no article has been loaded
if ((not value? 'Article) and (not value? 'Tutorial)) [
Article: [
Title: "Presenting the ReAdABLE Human Format"
Sub-Title: {written in its own format for highly productive Business Article or Software Documentation Writer
}
Mode: Anonymous-Paragraph-Support ; by default or choose No-Anonymous-Paragraph-Support
Paragraphs: [
P0: [
.title: ""
.content: {This is a continuously updated article, come back from time to time.
}
]
P1: [
.title: {Goal of the ReAdABLE Human Format}
.content: {
The **ReAdABLE Human Format** aims at **Agile Documentation** by making WRITING and READING document easier for End User and Developer alike, while allowing a high degree of flexibility. It is not an alternative to [JSON](https://www.json.org/) or [YAML](https://en.wikipedia.org/wiki/YAML) which are targeting machine automation. It's closer to [Markdown](https://daringfireball.net/projects/markdown/) simplicity for writer, while being even simpler (less code to memorize) and targeting larger goal than just outputting formatted document (we'll see that in a future article only). It can still embed markdown for convenient formatting, for example the JSON link above is written as:
```
[JSON](https://www.json.org/)
```
}
.image: https://i.snag.gy/qfjICd.jpg
]
P2: [
.title: {Origin: personal and professional hindrances}
.content: {
As for any good idea (sorry, I forgot humility on this one !), it comes from a few personal and professional hindrances encountered by own self.
Lastly, I have written 2 tutorials on [Dev.to](https://dev.to/lepinekong/red-for-hopeless-programmers---part-ii-258) about [Redlang](http://red-lang.org) then I stopped because it took me too much time and energy to publish on that online platform (it's not specific to dev.to though, it is for any others like medium).
Also in professional environment these latest years I've been many times in a situation where I have to reverse the features of big applications due to lack of documentation spending entire weeks on that task while having to multi-task on others - though I'm paid to do so, it eats consequent budget and you can multiply this loss by the number of people on that project - some I'm involved are as big as 10 to 30 millions euros though I'd managed only 1/4 to 1/3 of the whole. I realized that it is due to the huge productivity problem about writing them that it is for Project Manager, Business Analyst or Developer. In big corporations heavy software development is often outsourced so that it is dangerous to have barely no documentation. From Knowledge Management viewpoint, especially in regulated industries like Banking, Insurance or Pharmaceutical, this is even outlawed for certain types of projects.
Though you cannot revolutionize things by changing a big company methodology Corpus - often, if not all of it is in Microsoft Word format - it is possible to generate these latter from a more usable text format that won't harass business analyst or developer. Versioning and tracking documents will also become easier with widely spread standard tools (among developers: [Git](https://git-scm.com/)).
More generally, since I'm a child, I've always been obsessed with doing things easier because I'm just lazy! Paradoxically this push me to sometimes work hard to build the tools I need to achieve that goal.
To make a secret confession, I'm passionate about programming concepts and software development related to business process, but I hate coding because I have the same repulsion as Bret Victor - though he is a great programmer and creative mind, famous for his seminal presentation that you don't want to miss ["Inventing on principle"](https://vimeo.com/36579366), who says:
>“It sounds weird, when I want to make a thing, especially when I want to create something in software, there’s this initial layer of disgust that I have to push through, where I’m not manipulating the thing that I want to make, I’m writing a bunch of text into a text editor.”
>[(source: "Saving the world from code")](https://www.theatlantic.com/technology/archive/2017/09/saving-the-world-from-code/540393/)
}]
P3: [
.title: {Example: authoring a web article}
.content: {
Concretely let's take a simple example of an author who are used to write dozens of articles each year, he can systematize the way he organize them with a structure such as:
```
Article: [
Title: "Title of the article"
Sub-Title: {Sub-title of the article}
Paragraphs: [
P1: [
.title: "Title for Paragraph P1"
.content: {Content for Paragraph P1}
.image: http://optional.image-1.jpg
]
.
.
.
Pn: [
.title: "Title for Paragraph P1"
.content: {Content for Paragraph P1}
.image: http://optional.image-n.jpg
]
Conclusion: [
.title: "Conclusion"
.content: {Content for Conclusion}
]
]
]
```
I'm actually using this structure for writing the article you are reading now - eat your own dog's food.
}
.image: https://i.snag.gy/pADrP6.jpg
]
P4: [
.title: {An other example: a glossary structure}
.content: {
An other example is a glossary structure below. My first attempt was to use Markdown before I realise it really sucks as it mixed presentation with content whereas the ReAdABLE format is pure content so that you can output any kind of presentation you need.
```
Git.Glossary: [
Repository: [
.definition: {
The purpose of Git is to manage a set of files, as they change over time. Git stores this information in a data structure called a repository.
}
.note: {
A git repository contains, among other things, the following:
- A set of commit objects.
- A set of references to commit objects, called heads.
}
.see-also: [commit-object heads]
.references: [
https://www.sbf5.com/~cduan/technical/git/git-1.shtml
]
]
Commit-Object: [
.definition: {
A commit object contains three things:
- A set of files, reflecting the state of a project at a given point in time.
- References to parent commit objects.
- An SHA1 name, a 40-character string that uniquely identifies the commit object. The name is composed of a hash of relevant aspects of the commit, so identical commits will always have the same name.
}
.see-also: [parent-commit-object]
.references: [
https://www.sbf5.com/~cduan/technical/git/git-1.shtml
]
]
]
```
}
.image: https://i.snag.gy/lA4ed5.jpg
]
P5: [
.title: {Processing format to output markdown}
.content: {
How to process such kind of structure to output markdown or word document? That's the other beauty of this format. It is based on a gem language called [Rebol](http://www.rebol.com/) invented by [Carl Sassenrath (known for being Amiga OS Architect)](https://en.wikipedia.org/wiki/Carl_Sassenrath) with a modernized version named [Red-lang](https://www.red-lang.org/). So it can be easily be processed. For the article structure above, without any special library, you can type this below the data using free [Visual Studio Code](https://code.visualstudio.com/) and [Red extension](https://marketplace.visualstudio.com/items?itemName=red-auto.red):
```
; - 1. Extract the children of Article's block by name (Title, Sub-Title, Paragraphs):
title: select Article to-set-word 'Title ; or using library: .select Article 'Title
sub-title: select Article to-set-word 'Sub-Title
Paragraphs: select Article to-set-word 'Paragraphs ; -> [P1: [.title: ...] P2: [.title: ...]
; - 2. Transform Paragraphs block to Object:
oParagraphs: Object Paragraphs ; by converting into object we can use values-of to get-rid of labels Pi
Paragraphs-blocks: values-of oParagraphs ; -> [[.title: ...] [.title: ...]]
; - 3. Iterate through Paragraphs-blocks:
foreach paragraph-block Paragraphs-blocks [
title: .select paragraph-block '.title
content: .select paragraph-block '.content
image: .select paragraph-block '.image
]
```
}
.image: https://i.snag.gy/qYCBuP.jpg
]
P6: [
.title: {Example of a full app markdown converter}
.content: {
If you want to test a full app which converts a list of VSCode Extensions to markdown which [demo is published on Medium](https://medium.com/@lepinekong/test-md-842c4a3bc6ec), just copy this [oneliner](https://gist.githubusercontent.com/lepinekong/a1b1bdff993fdfdb969e933eb14cd266/raw/8d08005efd8da8a267230d28aa9af5e0206e170a/install.red.and.run.script.with.powershell) in Powershell within any directory.
}
]
P7: [
.title: {Processing in other programming languages}
.content: {
What about processing in other programming languages? You don't even need to create a parser as there are binding for [Java, Android and .NET](https://github.com/red/red/tree/master/bridges) and natively C since the core is written in that language so that you can create a nodejs module to embed Red language.
}
]
Conclusion: [
.title: {Conclusion}
.content: {
This format has very little formalism to memorize so is easier to write or much more productive than JSON, YAML or even our beloved Markdown (just try the ReAdABLE Human Format, you'll really see!):
- Enclose Structures and Sub-Structures within Brackets
- Each Structure can define as many fields as needed using the format
> Key: Value
- String value use `"` or `{}`, this latter accepts multiple-lines content including markdown
The source of this article in **ReAdABLE Human Format** is available at
[https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542](https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542)
Just paste the content of .ReAdABLE.HumanFormat.deploy.ps1 in Powershell at:
https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542
It will install Red and the source of the Article, the markdown and a batch file to re-execute it.
}
]
]
]
]
;===========================================================================================
; SPIKE
;===========================================================================================
;to play with the format set .spike to true
.spike: false
if .spike [
; - 1. Extract the children of article by name:
title: select Article to-set-word 'Title ; extract title from Article - if using library: .select Article 'Title
print title
;Sub-title: select Article to-set-word 'Sub-Title ; extract sub-title from Article
;print Sub-Title
Paragraphs: select Article to-set-word 'Paragraphs ; extract all labels-and-paragraphs from Articles
;-> [P1: [.title: ...] P2: [.title: ...]
;probe Paragraphs
;print length? Paragraphs
; - 2. Transform Paragraphs block to Object
; oParagraphs: Object Paragraphs ; convert paragraphs to object for easing extraction with values-of
; Paragraphs-blocks: values-of oParagraphs ; extract all paragraphs details with their labels
; ; -> [[.title: ...] [.title: ...]]
; probe Paragraphs-blocks
; print length? Paragraphs-blocks
Paragraphs-Blocks: extract/index Paragraphs 2 2
; ; - 3. Iterate through Paragraphs-blocks
; foreach paragraph-block Paragraphs-blocks [
; title: .select paragraph-block '.title ; select title from paragraph block (using library .select method)
; content: .select paragraph-block '.content ; select content from paragraph block (using library .select method)
; image: .select paragraph-block '.image ; select image from paragraph block (using library .select method)
; ]
forall Paragraphs-Blocks [
Paragraph-Content: Paragraphs-Blocks/1
forall Paragraph-Content [
label: Paragraph-Content/1
value: Paragraph-Content/2
Paragraph-Content: next Paragraph-Content
]
]
]
;===========================================================================================
; PROGRAM
;===========================================================================================
.markdown-gen: function [ /input <=input-file /output =>output-file [file! url! string! unset!]][
condition: (not value? 'article) and (not value? 'tutorial)
either (condition) [
.default-input-file: %ReAdABLE.Human.Format.data.red
.default-output-file: %ReAdABLE.Human.Format.md
unless input [
<=input-file: .default-input-file
]
unless output [
=>output-file: .default-output-file
]
print ["reading" <=input-file "..."]
do read <=input-file
][
]
if not value? 'article [
if value? 'Tutorial [
System/words/Article: Tutorial
]
]
either output [
=>output-file: .to-file =>output-file
][
=>output-file: .to-file reduce [short-filename ".md"]
]
if exists? =>output-file [
delete =>output-file
print ["deleting..." =>output-file]
]
use ["global .emit you don't need to touch"][
; start cloning global .emit function
spec: spec-of :.emit
body: body-of :.emit
; attach body words meaning to same meaning as in local context of '=>output-file
bind body '=>output-file
emit: function spec body
; end cloning global .emit function
]
use ["alert messages you can customize"][
message-processing: function[][
.do-events/no-wait ; this is just to make console run smoother
print "processing..."
.do-events/no-wait
]
refresh-screen: function[][
.do-events/no-wait
]
]
use ["generic formatting functions you can customize"][
emit-title-level: function [.title .title-level][
title: .title
n: .title-level
title: .replace/all title " " ""
marker: copy ""
repeat i n [append marker {#}]
emit [newline marker { } title newline]
]
emit-title: function[.title][
unless none? .title [
emit-title-level .title 1
]
]
.title: :emit-title
emit-sub-title: function[.title][
unless none? .title [
emit-title-level .title 2
]
]
.sub-title: :emit-sub-title
emit-paragraph-title: function[.title][
unless ((none? .title) or (.title = "")) [
emit-title-level .title 3
]
]
.paragraph-title: :emit-paragraph-title
emit-image: function[image][
unless none? image [
emit [
{![} image {]}
{(} image {)
}
]
]
]
.image: :emit-image
emit-content: function [content][
content-block: copy []
either find content {```} [
use [lines flag flag_line][
lines: .read/lines content
flag: false
forall lines [
line: lines/1
i: index? lines
if find line {```} [
.replace/all line " " ""
flag: not flag; flag: false -> true
either flag [
line: rejoin [newline newline line]
][
append line newline
append line newline
]
]
either flag = true [
.replace/all line " " ""
append line newline
][
.replace/all line " " ""
]
append content-block line
]
]
content: copy ""
forall content-block [
i: index? content-block
n: length? content-block
append content content-block/1
unless i = n [
unless find content newline [
append content newline
]
]
]
][
content: .replace/all content " " ""
]
emit content
]
.content: :emit-content
]
;-------------------------------------------------------------------------
{
Article: [
Title: "Title of the article"
Sub-Title: {Sub-title of the article}
Paragraphs: [
P1: [
.title: "Title for Paragraph P1"
.content: {Content for Paragraph P1}
.image: http://optional.image-1.jpg
]
]
]
}
title: .select Article 'Title ; extract title from Article
Sub-title: .select Article 'Sub-Title ; extract sub-title from Article
Paragraphs: .select Article 'Paragraphs ; extract all paragraphs from Articles
;-> [P1: [.title: ...] P2: [.title: ...]
if none? Paragraphs [
Paragraphs: copy []
forall Article [
label: Article/1
value: Article/2
if block? value [
if set-word? label [
append Paragraphs label
append/only Paragraphs value
]
]
]
]
; oParagraphs: Object Paragraphs ; convert paragraphs to object for easing extraction with values-of
; Paragraphs-blocks: values-of oParagraphs ; extract all paragraphs details without labels
Paragraphs-Blocks: extract/index Paragraphs 2 2
; -> [[.title: ...] [.title: ...]]
;--------------------------------------------------------------------------
message-processing ; this is for notifying user
;--------------------------------------------------------------------------
.title title ; emit markdown for article's title
.sub-title sub-title ; emit markdown for article's sub-title
forall Paragraphs-Blocks [
Paragraph-Content: Paragraphs-Blocks/1
forall Paragraph-Content [
refresh-screen
label: Paragraph-Content/1
value: Paragraph-Content/2
if (form label) = ".title" [
title: value
.paragraph-title title ; emit markdown for paragraph title
]
if (((form label) = ".text" ) or ((form label) = ".content" )) [
content: value
.content content ; emit markdown content with code block when any
]
if (form label) = ".code" [
content: rejoin [
{```}
newline
value
newline
{```}
]
.content content ; emit markdown content with code block when any
]
if (form label) = ".image" [
image: value
.image image ; emit markdown for embedding image
]
Paragraph-Content: next Paragraph-Content
]
; title: .select paragraph-block '.title ; select title from paragraph block
; .paragraph-title title ; emit markdown for paragraph title
; content: .select paragraph-block '.content ; select content from paragraph block
; .content content ; emit markdown content with code block when any
; image: .select paragraph-block '.image ; select image from paragraph block
; .image image ; emit markdown for embedding image
]
print (.to-full-path =>output-file) ; print file output path for info
]
markdown-gen: :.markdown-gen
; script-path: system/options/script
; script-filename: .get-short-filename script-path
; Unless .spike [
; if article [
; print "To generate again, type: markdown-gen %output-file-name for example:"
; print "markdown-gen %ReAdABLE.Human.Format.md"
; print "executing..."
; short-filename: .get-short-filename/wo-extension script-path
; markdown-file: .to-file reduce [short-filename ".md"] ; example: %ReAdABLE.Human.Format.md
; ;.markdown-gen (markdown-file) ; calling markdown generation specifying output-file
; ;input-file: to-red-file %ReAdABLE.Human.Format.red
; output-file: markdown-file
; .markdown-gen/output output-file
; ]
; ]
Red [
Title: "ReAdABLE.Human.Format.red"
Github-Url:
Previous-Github-Url: https://gist.githubusercontent.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542/raw/9fa57356721601e4d0b2d728f6329086c0d84410/ReAdABLE.Human.Format.red
]
Article: [
Title: "Presenting the ReAdABLE Human Format"
Sub-Title: {written in its own format for highly productive Business Article or Software Documentation Writer
}
Mode: Anonymous-Paragraph-Support ; by default or choose No-Anonymous-Paragraph-Support
Paragraphs: [
P0: [
.title: ""
.content: {This is a continuously updated article, come back from time to time.
}
]
P1: [
.title: {Goal of the ReAdABLE Human Format}
.content: {
The **ReAdABLE Human Format** aims at **Agile Documentation** by making WRITING and READING document easier for End User and Developer alike, while allowing a high degree of flexibility. It is not an alternative to [JSON](https://www.json.org/) or [YAML](https://en.wikipedia.org/wiki/YAML) which are targeting machine automation. It's closer to [Markdown](https://daringfireball.net/projects/markdown/) simplicity for writer, while being even simpler (less code to memorize) and targeting larger goal than just outputting formatted document (we'll see that in a future article only). It can still embed markdown for convenient formatting, for example the JSON link above is written as:
```
[JSON](https://www.json.org/)
```
}
.image: https://i.snag.gy/qfjICd.jpg
]
P2: [
.title: {Origin: personal and professional hindrances}
.content: {
As for any good idea (sorry, I forgot humility on this one !), it comes from a few personal and professional hindrances encountered by own self.
Lastly, I have written 2 tutorials on [Dev.to](https://dev.to/lepinekong/red-for-hopeless-programmers---part-ii-258) about [Redlang](http://red-lang.org) then I stopped because it took me too much time and energy to publish on that online platform (it's not specific to dev.to though, it is for any others like medium).
Also in professional environment these latest years I've been many times in a situation where I have to reverse the features of big applications due to lack of documentation spending entire weeks on that task while having to multi-task on others - though I'm paid to do so, it eats consequent budget and you can multiply this loss by the number of people on that project - some I'm involved are as big as 10 to 30 millions euros though I'd managed only 1/4 to 1/3 of the whole. I realized that it is due to the huge productivity problem about writing them that it is for Project Manager, Business Analyst or Developer. In big corporations heavy software development is often outsourced so that it is dangerous to have barely no documentation. From Knowledge Management viewpoint, especially in regulated industries like Banking, Insurance or Pharmaceutical, this is even outlawed for certain types of projects.
Though you cannot revolutionize things by changing a big company methodology Corpus - often, if not all of it is in Microsoft Word format - it is possible to generate these latter from a more usable text format that won't harass business analyst or developer. Versioning and tracking documents will also become easier with widely spread standard tools (among developers: [Git](https://git-scm.com/)).
More generally, since I'm a child, I've always been obsessed with doing things easier because I'm just lazy! Paradoxically this push me to sometimes work hard to build the tools I need to achieve that goal.
To make a secret confession, I'm passionate about programming concepts and software development related to business process, but I hate coding because I have the same repulsion as Bret Victor - though he is a great programmer and creative mind, famous for his seminal presentation that you don't want to miss ["Inventing on principle"](https://vimeo.com/36579366), who says:
>“It sounds weird, when I want to make a thing, especially when I want to create something in software, there’s this initial layer of disgust that I have to push through, where I’m not manipulating the thing that I want to make, I’m writing a bunch of text into a text editor.”
>[(source: "Saving the world from code")](https://www.theatlantic.com/technology/archive/2017/09/saving-the-world-from-code/540393/)
}]
P3: [
.title: {Example: authoring a web article}
.content: {
Concretely let's take a simple example of an author who are used to write dozens of articles each year, he can systematize the way he organize them with a structure such as:
```
Article: [
Title: "Title of the article"
Sub-Title: {Sub-title of the article}
Paragraphs: [
P1: [
.title: "Title for Paragraph P1"
.content: {Content for Paragraph P1}
.image: http://optional.image-1.jpg
]
.
.
.
Pn: [
.title: "Title for Paragraph P1"
.content: {Content for Paragraph P1}
.image: http://optional.image-n.jpg
]
Conclusion: [
.title: "Conclusion"
.content: {Content for Conclusion}
]
]
]
```
I'm actually using this structure for writing the article you are reading now - eat your own dog's food.
}
.image: https://i.snag.gy/pADrP6.jpg
]
P4: [
.title: {An other example: a glossary structure}
.content: {
An other example is a glossary structure below. My first attempt was to use Markdown before I realise it really sucks as it mixed presentation with content whereas the ReAdABLE format is pure content so that you can output any kind of presentation you need.
```
Git.Glossary: [
Repository: [
.definition: {
The purpose of Git is to manage a set of files, as they change over time. Git stores this information in a data structure called a repository.
}
.note: {
A git repository contains, among other things, the following:
- A set of commit objects.
- A set of references to commit objects, called heads.
}
.see-also: [commit-object heads]
.references: [
https://www.sbf5.com/~cduan/technical/git/git-1.shtml
]
]
Commit-Object: [
.definition: {
A commit object contains three things:
- A set of files, reflecting the state of a project at a given point in time.
- References to parent commit objects.
- An SHA1 name, a 40-character string that uniquely identifies the commit object. The name is composed of a hash of relevant aspects of the commit, so identical commits will always have the same name.
}
.see-also: [parent-commit-object]
.references: [
https://www.sbf5.com/~cduan/technical/git/git-1.shtml
]
]
]
```
}
.image: https://i.snag.gy/lA4ed5.jpg
]
P5: [
.title: {Processing format to output markdown}
.content: {
How to process such kind of structure to output markdown or word document? That's the other beauty of this format. It is based on a gem language called [Rebol](http://www.rebol.com/) invented by [Carl Sassenrath (known for being Amiga OS Architect)](https://en.wikipedia.org/wiki/Carl_Sassenrath) with a modernized version named [Red-lang](https://www.red-lang.org/). So it can be easily be processed. For the article structure above, without any special library, you can type this below the data using free [Visual Studio Code](https://code.visualstudio.com/) and [Red extension](https://marketplace.visualstudio.com/items?itemName=red-auto.red):
```
; - 1. Extract the children of Article's block by name (Title, Sub-Title, Paragraphs):
title: select Article to-set-word 'Title ; or using library: .select Article 'Title
sub-title: select Article to-set-word 'Sub-Title
Paragraphs: select Article to-set-word 'Paragraphs ; -> [P1: [.title: ...] P2: [.title: ...]
; - 2. Transform Paragraphs block to Object:
oParagraphs: Object Paragraphs ; by converting into object we can use values-of to get-rid of labels Pi
Paragraphs-blocks: values-of oParagraphs ; -> [[.title: ...] [.title: ...]]
; - 3. Iterate through Paragraphs-blocks:
foreach paragraph-block Paragraphs-blocks [
title: .select paragraph-block '.title
content: .select paragraph-block '.content
image: .select paragraph-block '.image
]
```
}
.image: https://i.snag.gy/qYCBuP.jpg
]
P6: [
.title: {Example of a full app markdown converter}
.content: {
If you want to test a full app which converts a list of VSCode Extensions to markdown which [demo is published on Medium](https://medium.com/@lepinekong/test-md-842c4a3bc6ec), just copy this [oneliner](https://gist.githubusercontent.com/lepinekong/a1b1bdff993fdfdb969e933eb14cd266/raw/8d08005efd8da8a267230d28aa9af5e0206e170a/install.red.and.run.script.with.powershell) in Powershell within any directory.
}
]
P7: [
.title: {Processing in other programming languages}
.content: {
What about processing in other programming languages? You don't even need to create a parser as there are binding for [Java, Android and .NET](https://github.com/red/red/tree/master/bridges) and natively C since the core is written in that language so that you can create a nodejs module to embed Red language.
}
]
Conclusion: [
.title: {Conclusion}
.content: {
This format has very little formalism to memorize so is easier to write or much more productive than JSON, YAML or even our beloved Markdown (just try the ReAdABLE Human Format, you'll really see!):
- Enclose Structures and Sub-Structures within Brackets
- Each Structure can define as many fields as needed using the format
> Key: Value
- String value use `"` or `{}`, this latter accepts multiple-lines content including markdown
The source of this article in **ReAdABLE Human Format** is available at
[https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542](https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542)
Just paste the content of .ReAdABLE.HumanFormat.deploy.ps1 in Powershell at:
https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542
It will install Red and the source of the Article, the markdown and a batch file to re-execute it.
}
]
]
]
If error? try [
do read %lib/ReAdABLE.Human.Format.lib.red
][
remote-lib: https://gist.githubusercontent.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542/raw/048e38b57d629e1380d3b5aed27e6ebc194e71ff/ReAdABLE.Human.Format.lib.red
do read remote-lib
]
.markdown-gen
Red [
File: "ReAdABLE.Human.Format.deploy.red"
Title: "Powershell Deployment script generator"
Source-Url: https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542
Description: {This script will generate ReAdABLE.Human.Format.deploy.ps1
the Zero Install Oneliner Powershell Script}
History: [
v1.0: [{Initial Version} https://gist.githubusercontent.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542/raw/1c04b8a560f046050eda12170a17c479f2e2bed8/ReAdABLE.HumanFormat.deploy.gen.red]
v2.0: [{Data Separation from Program}]
]
Last-Execution: [
; TODO:
DateTime:
Pass:
]
Flowchart: [
; TODO:
Preamble: [
flag-remote? [
Yes: [load-remote-library]
No: [exist-local-library? [
Yes: load-local-library
No: load-remote-library
]
]
]
]
Main: [
check-file-name-in-header -> OK? [
Yes: []
No: [update-file-name-in-header]
]
]
]
Links: [
Powershell: [
https://mcpmag.com/articles/2013/01/22/pshell-invoke-webrequest.aspx
https://www.jaapbrasser.com/quicktip-select-all-links-using-invoke-webrequest/
]
DOS: [
https://blogs.msdn.microsoft.com/zainala/2008/08/05/using-0-inside-the-batch-file-to-get-the-file-info/
https://htipe.wordpress.com/2008/10/09/the-dp0-variable/
[difference between ~dp0 and cd to find the current directory](https://www.computerhope.com/forum/index.php?topic=54333.0)
http://www.robvanderwoude.com/battech_defined.php
]
]
]
;===========================================================================================
; PREAMBLE
;===========================================================================================
; loading library
REMOTE-LIB: false
unless ((REMOTE-LIB = false) and (exists? lib: %../.libraries/.system.user.apps.authoring.library.red)) [
print "Loading remote lib"
either exists? %../.libraries/.github.lib.red [
print "Executing %../.libraries/.github.lib.red"
do %../.libraries/.github.lib.red
][
do read https://gist.githubusercontent.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8/raw/2dec6c1f92fe1834632d998ffb831539caa23d63/.github.lib.red
]
github-url-entry: https://gist.github.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8
lib: get-github-url github-url-entry %.system.user.apps.authoring.library.red
]
lib-src: read lib
if url? lib [
print ["updating local lib .system.user.apps.authoring.library.red see log.txt"]
write %../.libraries/.system.user.apps.authoring.library.red lib-src
write %../.libraries/log.txt rejoin ["library-date: " now]
]
do lib-src
if file? lib [
if exists? lib [
do read %../.libraries/log.txt
library-date
diff-date: difference now library-date
if (diff-date/hour > (24 * 7)) [
print "Checking remote lib"
do read https://gist.githubusercontent.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8/raw/2dec6c1f92fe1834632d998ffb831539caa23d63/.github.lib.red
github-url-entry: https://gist.github.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8
remote-lib-url: get-github-url github-url-entry %.system.user.apps.authoring.library.red
remote-lib: read remote-lib-url
local-SHA256: checksum lib 'SHA256
remote-SHA256: checksum remote-lib 'SHA256
either (remote-SHA256 = local-SHA256)[][
ans: ask "Remote lib has been update: do you want to update? (Y/N, N by default): "
if (ans = "Y") [
write lib remote-lib
do read %lib
]
]
]
]
]
;self script path
script-path: system/options/script ; example: %/c/rebol/.system.user/.data/.activities/myArticles/HOOD/ReAdable.Format/deploy/ReAdABLE.HumanFormat.deploy.red
script-filename: .get-short-filename script-path
short-filename: .get-short-filename/wo-extension script-path
check-filename: function[][
src: read script-path
Description: rejoin [{This script will generate } short-filename {.ps1
the Zero Install Oneliner Powershell Script}]
parse src [
thru {File: "} mark1:
to {"} mark2:
(change/part mark1 script-filename mark2)
thru "Description: {" mark1:
to "}" mark2:
(change/part mark1 Description mark2)
]
;write-clipboard src
write script-path src
]
get-script-header: function[][
self-script: Redlang.get-program/header script-path
loaded-header: load self-script
return make object! loaded-header/2
]
DEBUG_ONELINER: false
debug-oneliner: function[][
{Will split ps1 source code generated line by line and copy to clipboard}
file: .to-file [short-filename ".ps1"]
do-trace 155 [probe file] script-path
src: read file
block: split src ";"
out: copy ""
forall block [
element: trim/head/tail block/1
unless (element = "") [
append out element
unless (tail? next next block) [append out newline]
back back block
]
]
write-clipboard out
]
if DEBUG_ONELINER = true [
debug-oneliner
print "DEBUG_ONELINER=true => exit; set it back to false."
]
;===========================================================================================
; DATA
;===========================================================================================
template: [
source: {
$demo="<%short-filename%>"
$github='<%Source-Url%>'
$githublib='https://gist.github.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8'
$demofolder="C:\red\demos\$demo"
$exefolder="C:\red"
$exeurl='https://static.red-lang.org/dl/win/red-063.exe'
Add-Type -AssemblyName Microsoft.VisualBasic
$demofolder=[Microsoft.VisualBasic.Interaction]::InputBox("Enter folder for $demo demo:", $demo, $demofolder)
if ($demofolder -ne $null) {$demo=Split-Path $demofolder -Leaf
Function Get-Github-Links {Param($uri)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$WebResponse = Invoke-WebRequest -Uri "$uri"
return $ResponseLinks=$WebResponse.Links | Select href}
Function Filter-Link {Param($filter)
$links = $AllLinks | Where-Object {$_.href -match "$filter"}
$link=$links[0].href
return $link}
Function Get-Github-Url {Param($filename)
$link=Filter-Link $filename
$url="https://gist.githubusercontent.com$link"
return $url}
$AllLinks = Get-Github-Links $github
$src=Get-Github-Url 'ReAdABLE.Human.Format.red'
New-Item -ItemType Directory -Force -Path $red-folder
New-Item -ItemType Directory -Force -Path $demofolder
$Webcli=New-Object System.Net.WebClient
if (!(Test-Path `"$exefolder\red.exe`")) {$Webcli.DownloadFile("$exeurl","$exefolder\red.exe")}
"Red [] `n print to-local-file what-dir `n do read $src" | Out-File -filepath "$demofolder\$demo.red" -Encoding "UTF8"
"cd `"%~dp0`"`r`n" | Out-File -filepath "$demofolder\$demo.bat" -Encoding ASCII
"IF DEFINED RED_HOME (start `"%~n0`" `"%RED_HOME%\red.exe`" `"%~n0.red`" %1) ELSE (start `"%~n0`" `"$exefolder\red.exe`" `"%~n0.red`" %1)" | Out-File -filepath "$demofolder\$demo.bat" -Encoding ASCII -Append
cmd.exe /c "$demofolder\$demo.bat"
Add-Type -AssemblyName PresentationFramework
$msgBox=[System.Windows.MessageBox]::Show('Would you like to download the source?','Download','YesNo','Question')
switch ($msgBox) {'Yes' {$Webcli.DownloadFile($src,"$demofolder\$demo.red")
$Webcli.DownloadFile($src,"$demofolder\How.to.setup.github.repository.red")
New-Item -ItemType Directory -Force -Path "$demofolder\lib"
$link=Get-Github-Url "ReAdABLE.Human.Format.lib.red"
$Webcli.DownloadFile($link,"$demofolder\lib\ReAdABLE.Human.Format.lib.red")
New-Item -ItemType Directory -Force -Path "$demofolder\deploy"
$link=Get-Github-Url ".ReAdABLE.HumanFormat.deploy.ps1"
$Webcli.DownloadFile($link,"$demofolder\deploy\$demo.deploy.ps1")
$link=Get-Github-Url "ReAdABLE.HumanFormat.deploy.red"
$Webcli.DownloadFile($link,"$demofolder\deploy\$demo.deploy.red")} 'No' {}}
$AllLinks = Get-Github-Links $githublib
$link=Get-Github-Url '.system.user.apps.authoring.library.red'
New-Item -ItemType Directory -Force -Path "$demofolder\.libraries"
$Webcli.DownloadFile($link,"$demofolder\.libraries\.system.user.apps.authoring.library.red")
start explorer.exe -ArgumentList "/select, `"$demofolder\$demo.red`""}
}
]
;===========================================================================================
; PROGRAM
;===========================================================================================
; self-script: Redlang.get-program/header script-path
; loaded-header: load self-script
; header: make object! loaded-header/2
script-header: get-script-header
Source-Url: script-header/Source-Url ; Github url for source
check-filename
src: .select template 'source
demo-short-filename: replace (copy short-filename) ".deploy" ""
src: .expand src [
short-filename: (demo-short-filename)
Source-Url: (Source-Url)
]
out: copy ""
block: .read/lines src
forall block [
element: trim/head/tail block/1
unless (element = "") [
append out element
unless (tail? next next block) [append out ";"]
back back block
]
]
ps1-file: rejoin [short-filename ".ps1"]
write ps1-file out
print [ps1-file "has been generated."]
;===========================================================================================
; DOC GENERATION
;===========================================================================================
;TODO:
flowchart: script-header/flowchart
write-clipboard mold flowchart
Red [
File: "ReAdABLE.Human.Format.deploy.red"
Title: "Powershell Deployment script generator"
Source-Url: https://gist.github.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542
Description: {This script will generate ReAdABLE.Human.Format.deploy.ps1
the Zero Install Oneliner Powershell Script}
History: [
v1.0: [{Initial Version} https://gist.githubusercontent.com/lepinekong/b59fa3e8d386dea1ebaa1a096488c542/raw/1c04b8a560f046050eda12170a17c479f2e2bed8/ReAdABLE.HumanFormat.deploy.gen.red]
v2.0: [{Data Separation from Program}]
]
Last-Execution: [
; TODO:
DateTime:
Pass:
]
Flowchart: [
; TODO:
Preamble: [
flag-remote? [
Yes: [load-remote-library]
No: [exist-local-library? [
Yes: load-local-library
No: load-remote-library
]
]
]
]
Main: [
check-file-name-in-header -> OK? [
Yes: []
No: [update-file-name-in-header]
]
]
]
Links: [
Powershell: [
https://mcpmag.com/articles/2013/01/22/pshell-invoke-webrequest.aspx
https://www.jaapbrasser.com/quicktip-select-all-links-using-invoke-webrequest/
]
DOS: [
https://blogs.msdn.microsoft.com/zainala/2008/08/05/using-0-inside-the-batch-file-to-get-the-file-info/
https://htipe.wordpress.com/2008/10/09/the-dp0-variable/
[difference between ~dp0 and cd to find the current directory](https://www.computerhope.com/forum/index.php?topic=54333.0)
http://www.robvanderwoude.com/battech_defined.php
]
]
]
;===========================================================================================
; PREAMBLE
;===========================================================================================
; loading library
REMOTE-LIB: false
unless ((REMOTE-LIB = false) and (exists? lib: %../.libraries/.system.user.apps.authoring.library.red)) [
print "Loading remote lib"
either exists? %../.libraries/.github.lib.red [
print "Executing %../.libraries/.github.lib.red"
do %../.libraries/.github.lib.red
][
do read https://gist.githubusercontent.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8/raw/2dec6c1f92fe1834632d998ffb831539caa23d63/.github.lib.red
]
github-url-entry: https://gist.github.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8
lib: get-github-url github-url-entry %.system.user.apps.authoring.library.red
]
lib-src: read lib
if url? lib [
print ["updating local lib .system.user.apps.authoring.library.red see log.txt"]
write %../.libraries/.system.user.apps.authoring.library.red lib-src
write %../.libraries/log.txt rejoin ["library-date: " now]
]
do lib-src
if file? lib [
if exists? lib [
do read %../.libraries/log.txt
library-date
diff-date: difference now library-date
if (diff-date/hour > (24 * 7)) [
print "Checking remote lib"
do read https://gist.githubusercontent.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8/raw/2dec6c1f92fe1834632d998ffb831539caa23d63/.github.lib.red
github-url-entry: https://gist.github.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8
remote-lib-url: get-github-url github-url-entry %.system.user.apps.authoring.library.red
remote-lib: read remote-lib-url
local-SHA256: checksum lib 'SHA256
remote-SHA256: checksum remote-lib 'SHA256
either (remote-SHA256 = local-SHA256)[][
ans: ask "Remote lib has been update: do you want to update? (Y/N, N by default): "
if (ans = "Y") [
write lib remote-lib
do read %lib
]
]
]
]
]
;self script path
script-path: system/options/script ; example: %/c/rebol/.system.user/.data/.activities/myArticles/HOOD/ReAdable.Format/deploy/ReAdABLE.HumanFormat.deploy.red
script-filename: .get-short-filename script-path
short-filename: .get-short-filename/wo-extension script-path
check-filename: function[][
src: read script-path
Description: rejoin [{This script will generate } short-filename {.ps1
the Zero Install Oneliner Powershell Script}]
parse src [
thru {File: "} mark1:
to {"} mark2:
(change/part mark1 script-filename mark2)
thru "Description: {" mark1:
to "}" mark2:
(change/part mark1 Description mark2)
]
;write-clipboard src
write script-path src
]
get-script-header: function[][
self-script: Redlang.get-program/header script-path
loaded-header: load self-script
return make object! loaded-header/2
]
DEBUG_ONELINER: false
debug-oneliner: function[][
{Will split ps1 source code generated line by line and copy to clipboard}
file: .to-file [short-filename ".ps1"]
do-trace 155 [probe file] script-path
src: read file
block: split src ";"
out: copy ""
forall block [
element: trim/head/tail block/1
unless (element = "") [
append out element
unless (tail? next next block) [append out newline]
back back block
]
]
write-clipboard out
]
if DEBUG_ONELINER = true [
debug-oneliner
print "DEBUG_ONELINER=true => exit; set it back to false."
]
;===========================================================================================
; DATA
;===========================================================================================
template: [
source: {
$demo="<%short-filename%>"
$github='<%Source-Url%>'
$githublib='https://gist.github.com/lepinekong/7574892bfefe7e53e7bd4dd4759f30f8'
$demofolder="C:\red\demos\$demo"
$exefolder="C:\red"
$exeurl='https://static.red-lang.org/dl/win/red-063.exe'
Add-Type -AssemblyName Microsoft.VisualBasic
$demofolder=[Microsoft.VisualBasic.Interaction]::InputBox("Enter folder for $demo demo:", $demo, $demofolder)
if ($demofolder -ne $null) {$demo=Split-Path $demofolder -Leaf
Function Get-Github-Links {Param($uri)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$WebResponse = Invoke-WebRequest -Uri "$uri"
return $ResponseLinks=$WebResponse.Links | Select href}
Function Filter-Link {Param($filter)
$links = $AllLinks | Where-Object {$_.href -match "$filter"}
$link=$links[0].href
return $link}
Function Get-Github-Url {Param($filename)
$link=Filter-Link $filename
$url="https://gist.githubusercontent.com$link"
return $url}
$AllLinks = Get-Github-Links $github
$src=Get-Github-Url 'ReAdABLE.Human.Format.red'
New-Item -ItemType Directory -Force -Path $red-folder
New-Item -ItemType Directory -Force -Path $demofolder
$Webcli=New-Object System.Net.WebClient
if (!(Test-Path `"$exefolder\red.exe`")) {$Webcli.DownloadFile("$exeurl","$exefolder\red.exe")}
"Red [] `n print to-local-file what-dir `n do read $src" | Out-File -filepath "$demofolder\$demo.red" -Encoding "UTF8"
"cd `"%~dp0`"`r`n" | Out-File -filepath "$demofolder\$demo.bat" -Encoding ASCII
"IF DEFINED RED_HOME (start `"%~n0`" `"%RED_HOME%\red.exe`" `"%~n0.red`" %1) ELSE (start `"%~n0`" `"$exefolder\red.exe`" `"%~n0.red`" %1)" | Out-File -filepath "$demofolder\$demo.bat" -Encoding ASCII -Append
cmd.exe /c "$demofolder\$demo.bat"
Add-Type -AssemblyName PresentationFramework
$msgBox=[System.Windows.MessageBox]::Show('Would you like to download the source?','Download','YesNo','Question')
switch ($msgBox) {'Yes' {New-Item -ItemType Directory -Force -Path "$demofolder\lib"
$link=Get-Github-Url "ReAdABLE.Human.Format.lib.red"
$Webcli.DownloadFile($link,"$demofolder\lib\ReAdABLE.Human.Format.lib.red")
$Webcli.DownloadFile($src,"$demofolder\$demo.red")
$link=Get-Github-Url "How.to.setup.github.repository.red"
$Webcli.DownloadFile($link,"$demofolder\How.to.setup.github.repository.red")
$link=Get-Github-Url "How.to.write.good.article.red"
$Webcli.DownloadFile($link,"$demofolder\How.to.write.good.article.red")
New-Item -ItemType Directory -Force -Path "$demofolder\deploy"
$link=Get-Github-Url ".ReAdABLE.HumanFormat.deploy.ps1"
$Webcli.DownloadFile($link,"$demofolder\deploy\$demo.deploy.ps1")
$link=Get-Github-Url "ReAdABLE.HumanFormat.deploy.red"
$Webcli.DownloadFile($link,"$demofolder\deploy\$demo.deploy.red")} 'No' {}}
$AllLinks = Get-Github-Links $githublib
$link=Get-Github-Url '.system.user.apps.authoring.library.red'
New-Item -ItemType Directory -Force -Path "$demofolder\.libraries"
$Webcli.DownloadFile($link,"$demofolder\.libraries\.system.user.apps.authoring.library.red")
start explorer.exe -ArgumentList "/select, `"$demofolder\$demo.red`""}
}
]
;===========================================================================================
; PROGRAM
;===========================================================================================
; self-script: Redlang.get-program/header script-path
; loaded-header: load self-script
; header: make object! loaded-header/2
script-header: get-script-header
Source-Url: script-header/Source-Url ; Github url for source
check-filename
src: .select template 'source
demo-short-filename: replace (copy short-filename) ".deploy" ""
src: .expand src [
short-filename: (demo-short-filename)
Source-Url: (Source-Url)
]
out: copy ""
block: .read/lines src
forall block [
element: trim/head/tail block/1
unless (element = "") [
append out element
unless (tail? next next block) [append out ";"]
back back block
]
]
ps1-file: rejoin [short-filename ".ps1"]
write ps1-file out
print [ps1-file "has been generated."]
;===========================================================================================
; DOC GENERATION
;===========================================================================================
;TODO:
flowchart: script-header/flowchart
write-clipboard mold flowchart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment