Skip to content

Commit 32a0c39

Browse files
committed
first README generated from hype!
1 parent 32b9352 commit 32a0c39

File tree

9 files changed

+606
-17
lines changed

9 files changed

+606
-17
lines changed

.hype/badges.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[![Release](https://img.shields.io/github/release/goreleaser/goreleaser.svg)](https://github.com/gopherguides/hype/releases/latest)
2+
[![Go Build Status](https://github.com/gopherguides/hype/actions/workflows/tests.yml/badge.svg)](https://github.com/gopherguides/hype/actions)
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/goherguides/hype.svg)](https://pkg.go.dev/github.com/gopherguides/hype)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/gopherguides/hype)](https://goreportcard.com/report/github.com/gopherguides/hype)
5+
[![Slack](https://img.shields.io/badge/Slack-hype-brightgreen)](https://gophers.slack.com/archives/C05SKNHQY3U)

.hype/license.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License
2+
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://github.com/gopherguides/hype">Hype</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://github.com/gopherguides">Gopher Guides LLC</a> is licensed under <a href="http://creativecommons.org/licenses/by-nc-sa/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">Attribution-NonCommercial-ShareAlike 4.0 International<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/sa.svg?ref=chooser-v1"></a></p>
3+

.hype/module.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<include src="badges.md"></include>
2+
3+
# Hype
4+
Hype is a content generation tool that use traditional Markdown syntax, and allows it to be extended for almost any use to create dynamic, rich, automated output that is easily maintainable and reusable.
5+
6+
## Created with Hype
7+
8+
This README was created with hype. Here was the command we used to create it:
9+
10+
From the `.hype` directory, run:
11+
12+
```
13+
hype export -format=markdown -f module.md > ../README.md
14+
```
15+
16+
<include src="quickstart/module.md"></include>
17+
18+
# README Source
19+
20+
You can view the source for this entire readme in the [.hype](https://github.com/gopherguides/corp/tree/main/.hype) directory.
21+
22+
Here is the current structure that we are using to create this readme:
23+
24+
<cmd exec="tree" src=".">
25+
26+
27+
# Issues
28+
29+
There are several issues that still need to be worked on. Please see the issues tab if you are interested in helping.
30+
31+
<include src="license.md"></include>

.hype/quickstart/includes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<include src="code/code.md"></include>
2+
3+
<include src="sourceable/sourceable.md"></include>

.hype/quickstart/module.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Quick Start Guide
2+
3+
For more in depth examples, you can read our quick start guide
4+
[here](https://www.gopherguides.com/articles/golang-hype-quickstart).
5+
6+
# The Basics
7+
8+
This is the syntax to include a code sample in your document:
9+
10+
```
11+
<code src="src/hello/main.go" snippet="example"></code>
12+
```
13+
14+
The above code snippet does the following:
15+
16+
- Includes the code snippet specified in the source code
17+
- Validates that the code compiles
18+
19+
Here is the source file:
20+
21+
```go
22+
package main
23+
24+
import "fmt"
25+
26+
// snippet: example
27+
func main() {
28+
fmt.Println("Hello World")
29+
}
30+
31+
// snippet: example
32+
```
33+
34+
Notice the use of the `snippet` comment. The format for the comment is:
35+
36+
```
37+
// snippet: <snippet_name_here>
38+
```
39+
40+
You must have a beginning and an ending snippet for the code to work.
41+
42+
The output of including that tag will be as follows:
43+
44+
<code src="src/hello/main.go" snippet="example"></code>
45+
46+
A `snippet` is not required in your `code` tag. They default behavior of a `code` tag is to include the entire source file.
47+
48+
If we leave the tag out, it will result in the following code being included:
49+
50+
<code src="src/hello/main.go"></code>
51+
52+
Notice that none of the `snippet` comments were in the output? This is because hype recognizes them as directives for the document, and will not show them in the actual output.
53+
54+
# Go Specific Commands
55+
56+
There are a number of [Go](https://go.dev/) specific commands you can run as well. Anything from executing the code and showing the output, to including go doc (from the standard library or your own source code), etc.
57+
58+
Let's look at how we use the `go` tag.
59+
60+
Here is the source code of the Go file we are going to include. Notice the use of the `snippet` comments to identify the area of code we want included. We'll see how to specify that in the next section when we include it in our markdown.
61+
62+
# Running Go Code
63+
64+
The following command will include the go source code, run it, and include the output of the program as well:
65+
66+
```
67+
<go src="src/hello" run="."></go>
68+
```
69+
Here is the result that will be included in your document from the above command:
70+
71+
<go src="src/hello" run="."></go>
72+
73+
## Running and Showing the Code
74+
75+
If you want to both run and show the code with the same tag, you can add the `code` attribute to the tag:
76+
77+
```
78+
<go src="src/hello" run="." code="main.go"></go>
79+
```
80+
81+
Now the source code is includes, as well as the output of the program:
82+
83+
<go src="src/hello" run="." code="main.go"></go>
84+
85+
## Snippets with Go
86+
87+
You can also specify the snippet in a `go` tag as well. The result is that it will only include the code snippet in the included source:
88+
89+
```
90+
<go src="src/hello" run="." code="main.go#example"></go>
91+
```
92+
93+
You can see now that only the snippet is included, but the output is still the same:
94+
95+
<go src="src/hello" run="." code="main.go#example"></go>
96+
97+
## Invalid Code
98+
99+
What if you want to include an example of code that does not compile? We still want the code to be parsed and included, even though the code doesn't compile. For this, we can state the expected output of the program.
100+
101+
```
102+
<go src="src/broken" run="." code="main.go#example" exit="1"></go>
103+
```
104+
105+
The result now includes the snippet, and the error output from trying to compile the invalid source code.
106+
107+
<go src="src/broken" run="." code="main.go#example" exit="1"></go>
108+
109+
### GoDoc
110+
111+
While there are a number of `godoc` commands that will allow you to put your documentation from your code directly into your articles as well. Here are some of the commands.
112+
113+
Here is the basic usage first:
114+
115+
```
116+
<go doc="-short context"></go>
117+
```
118+
119+
Here is the output for the above command:
120+
121+
<go doc="-short context"></go>
122+
123+
You can also be more specific.
124+
125+
```
126+
<go doc="-short context.WithCancel"></go>
127+
```
128+
129+
Here is the output for the above command:
130+
<go doc="-short context.WithCancel"></go>
131+
132+
For more examples, see the [hype repo](https://www.github.com/gopherguides/hype).
133+
134+
135+
# Arbitrary Commands
136+
137+
You can also use the `cmd` tag and the `exec` attribute to run arbitrary commands and include them in your documentation. Here is the command to run the `tree` command and include it in our documentation:
138+
139+
```
140+
<cmd exec="tree" src="."></cmd>
141+
```
142+
143+
Here is the output:
144+
145+
<cmd exec="tree" src="."></cmd>
146+
147+
# The Export Command
148+
149+
There are several options for running the `hype` command. Most notable is the `export` option:
150+
151+
```
152+
$ hype export -h
153+
154+
Usage of hype:
155+
-f string
156+
optional file name to preview, if not provided, defaults to module.md (default "module.md")
157+
-format string
158+
content type to export to: markdown, html (default "markdown")
159+
-timeout duration
160+
timeout for execution, defaults to 30 seconds (30s) (default 5s)
161+
-v enable verbose output for debugging
162+
163+
Usage: hype export [options]
164+
165+
Examples:
166+
hype export -format html
167+
hype export -f README.md -format html
168+
hype export -f README.md -format markdown -timeout=10s
169+
```
170+
171+
This allows you to see your compiled document either as a single markdown, or as an html document that you can preview in the browser.
172+
173+
# Including Markdown
174+
175+
To include a markdown file, use the include tag. This will run that markdown file through the hype.Parser being used and append the results to the current document.
176+
177+
The paths specified in the src attribute of the include are relative to the markdown file they are used in. This allows you to move entire directory structures around in your project without having to change references within the documents themselves.
178+
179+
The following code will parse the code/code.md and sourceable/sourceable.md documents and append them to the end of the document they were included in.
180+
181+
<code src="includes.md"></code>
182+
183+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import "fmt"
4+
5+
// snippet: example
6+
func main() {
7+
fmt.Prin("Hello World")
8+
}
9+
10+
// snippet: example

.hype/quickstart/src/hello/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import "fmt"
4+
5+
// snippet: example
6+
func main() {
7+
fmt.Println("Hello World")
8+
}
9+
10+
// snippet: example

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
default: test install
1+
default: test install hype
22

33
test:
44
go test -timeout 10s -race -cover ./...
55

66
install:
7-
go install -v ./cmd/hype
7+
go install -v ./cmd/hype
8+
9+
hype:
10+
pushd .hype;hype export -format=markdown -f module.md > ../README.md;popd

0 commit comments

Comments
 (0)