Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkideal committed Sep 28, 2024
1 parent af47d07 commit 50778ce
Show file tree
Hide file tree
Showing 91 changed files with 439 additions and 111 deletions.
6 changes: 3 additions & 3 deletions src/compile/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@ func newTemplateContext(info templateContextInfo) *templateContext {
// Output (for c++):
//
// ```cpp
// // Code generated by "next v0.0.1"; DO NOT EDIT.
// // Code generated by "next 0.0.1"; DO NOT EDIT.
// ```
//
// Output (for c):
//
// ```c
// /* Code generated by "next v0.0.1"; DO NOT EDIT. */
// /* Code generated by "next 0.0.1"; DO NOT EDIT. */
// ```
"head": tc.head,

Expand Down Expand Up @@ -742,7 +742,7 @@ func (tc *templateContext) head() string {
}
header := tc.compiler.flags.header
if header == "" {
header = `Code generated by "next ` + builder.Info().Version + `"; DO NOT EDIT.`
header = `Code generated by "next ` + strings.TrimPrefix(builder.Info().Version, "v") + `"; DO NOT EDIT.`
}
return strings.ReplaceAll(p, "%T%", header)
}
Expand Down
77 changes: 72 additions & 5 deletions website/docs/api/latest/map.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
pagination_prev: null
pagination_next: null
---

# Map {#user-content-Map}

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

`Map` represents a language map file. Usually, it is a text file that contains key-value pairs separated by a equal sign. The key is the name of the language feature. The built-in keys are:

- **ext**: the file extension for the language
Expand All @@ -25,13 +29,23 @@ pagination_next: null
- **map**: the map type for the language
- **box**: the box replacement for the language (for java, e.g., box(int) = Integer)

Here is an example of a language map file for the Java language:
Here are some examples of language map files:

<Tabs
defaultValue="java"
values={[
{ label: 'java.map', value: 'java' },
{ label: 'cpp.map', value: 'cpp' },
{ label: 'protobuf.map', value: 'protobuf' },
]}>

<TabItem value="java">
```map title="java.map"
ext=.java
comment=// %T%
# primitive types
int=int
int8=byte
int16=short
Expand All @@ -49,18 +63,72 @@ vector=List<box(%T%)>
array=%T%[]
# box types
box(int)=Integer
box(byte)=Byte
box(short)=Short
box(long)=Long
box(float)=Float
box(double)=Double
box(boolean)=Boolean
```
:::note
````
</TabItem>

<TabItem value="cpp">
```map title="cpp.map"
ext=.h
comment=// %T%
int=int
int8=int8_t
int16=int16_t
int32=int32_t
int64=int64_t
float32=float
float64=double
bool=bool
string=std::string
byte=unsigned char
bytes=std::vector<unsigned char>
any=std::any
map=std::unordered_map<%K%, %V%>
vector=std::vector<%T%>
array=std::array<%T%, %N%>
````

</TabItem>

<TabItem value="protobuf">
```map title="protobuf.map"
ext=.proto
comment=// %T%
int=int32
int8=int32
int16=int32
int32=int32
int64=int64
float32=float
float64=double
bool=bool
string=string
byte=int8
bytes=bytes
any=google.protobuf.Any
map=map<%K%, %V%>
vector=repeated %T.E%
array=repeated %T.E%
````
</TabItem>

</Tabs>

:::tip

- The `%T%`, `%K%`, `%V%` and `%N%` are placeholders for the type, key type, value type and number of array elements.
- `%T.E%` is the final element type of `%T%`. It's useful if you need to get the final element type of a vector or array.
- Line comments are started with the `#` character and it must be the first character of the line (leading spaces are allowed).

```plain title="java.map"
Expand All @@ -69,9 +137,8 @@ ext=.java # This is an invalid comment
# Comment must be the first character of the line
# This is a valid comment (leading spaces are allowed)
```
````

See [Builtin Map Files](https://github.com/gopherd/next/tree/main/builtin) for more information.

:::

20 changes: 18 additions & 2 deletions website/docs/api/latest/object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pagination_next: null
---
# Object {#user-content-Object}

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

`Object` is a generic object type. These objects can be used as parameters for the `Context/next` function, like `{{next .}}`.

###### .Typeof {#user-content-Object__Typeof}
Expand Down Expand Up @@ -1717,7 +1720,15 @@ import "path/to/file2.next";
package a;
```

```npl title="file.npl"
<Tabs
defaultValue="file"
values={[
{ label: 'file.npl', value: 'file' },
{ label: 'package.npl', value: 'package' },
]}>

<TabItem value="file">
```npl
{{- define "meta/this" -}}file{{- end -}}

{{range this.Imports.List}}
Expand All @@ -1730,8 +1741,10 @@ Output (for file1.next):
```
file1
```
</TabItem>
```npl title="package.npl"
<TabItem value="package">
```npl
{{- define "meta/this" -}}package{{- end -}}

{{range this.Imports.List}}
Expand All @@ -1744,6 +1757,9 @@ Output:
```
a
```
</TabItem>
</Tabs>
</div>
Expand Down
4 changes: 2 additions & 2 deletions website/docs/api/preview/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ Example:
Output (for c++):

```cpp
// Code generated by "next v0.0.1"; DO NOT EDIT.
// Code generated by "next 0.0.1"; DO NOT EDIT.
```

Output (for c):

```c
/* Code generated by "next v0.0.1"; DO NOT EDIT. */
/* Code generated by "next 0.0.1"; DO NOT EDIT. */
```

## lang {#user-content-Context_lang}
Expand Down
Loading

0 comments on commit 50778ce

Please sign in to comment.