Skip to content

Commit

Permalink
docs: rename generated functions dir to funcs (#154) (#160)
Browse files Browse the repository at this point in the history
Cloudflare treats the "functions" dir as a special directory, so files
in this dir will not be deployed. This is now fixed by changing that
directory to "funcs" instead.

See cloudflare/workers-sdk#2240
  • Loading branch information
jaredallard authored Oct 3, 2024
1 parent a1d2562 commit f46a773
Show file tree
Hide file tree
Showing 29 changed files with 74 additions and 11 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions docs/functions/index.md → docs/funcs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
order: 10
path:
---

# Functions
Expand Down
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions docs/funcs/module_Call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
order: 1011
title: module.Call
---

<!-- Generated by tools/docgen. DO NOT EDIT. -->

# module.Call

Call executes a template function by name with the provided arguments.
The function must have been exported by the module that provides it
through the [Export] function.

Attempting to call a function that does not exist will return an error
outside of the first pass where it will return `nil` instead.

The template that is called must return a value using the `return`
template function, which is only available in this context.

In addition, all of the file, stencil and other functions are in the
context of the parent template, not the template being called.

`.` in a template function acts the same way as it does for [TplStencil.ApplyTemplate](#TplStencil.ApplyTemplate) (`stencil.ApplyTemplate`). Meaning, it points to [Values](#Values). The caller passed data is accessible on `.Data`.

Example:

```go
// module-a
{{- define "HelloWorld" }}
{{- return (printf "Hello, %s!" .Data) }}
{{- end }}
{{ module.Export "HelloWorld" }}

// module-b
{{ module.Call "module-b.HelloWorld" "Jared" }}
// Output: Hello, Jared
```
25 changes: 25 additions & 0 deletions docs/funcs/module_Export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
order: 1012
title: module.Export
---

<!-- Generated by tools/docgen. DO NOT EDIT. -->

# module.Export

Export registers a function to allow it to be called by other templates.

This is only able to be called in library templates and the function's
name must start with a capital letter. Function names are also only
eligible to be exported once, if a function is exported twice the second
call will be a runtime error.

Example:

```go
{{- define "HelloWorld" }}
{{- return (printf "Hello, %s!" .Data) }}
{{- end }}

{{ module.Export "HelloWorld" }}
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/guide/basic-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ across the run!

One of the powerful parts of stencil is the ability to create an
arbitrary number of files with a single template. This is done with the
[`file.Create`](/functions/file.Create) function. Let's create a
[`file.Create`](/funcs/file.Create) function. Let's create a
`greeter.go.tpl` template in the `templates/` directory that'll create
`<greeting>.go` based on the `greetings` argument.

Expand Down Expand Up @@ -222,6 +222,6 @@ We've created a module, used it in a test application via the
`replacements` map in the `stencil.yaml` and used a block. Optionally
we've also created multiple files with a template. This is just the
beginning of what you can do with modules. Modules have a rich amount of
[functions](/functions/) available to them. Check out the
[functions](/funcs/) available to them. Check out the
[reference](/reference/) for more information about modules and how to
use them.
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ hero:
actions:
- theme: brand
text: About
link: /about/problem-statement.html
link: /about/problem-statement
- theme: alt
text: Guide
link: /guide/installation.html
link: /guide/installation
- theme: alt
text: GitHub
link: https://github.com/rgst-io/stencil
Expand All @@ -26,9 +26,9 @@ features:
title: <a href="/about">Development Lifecycle Management</a>
details: Treat your generated files as APIs by persisting changes in customizable "blocks" to allow rendering more than once
- icon: 🧱
title: <a href="/reference/modules.html">Modular</a>
title: <a href="/reference/modules">Modular</a>
details: Templates can be composed through importable modules allowing easy customization
- icon: 🛠️
title: <a href="/reference/native-extensions.html">Native Extensions</a>
title: <a href="/reference/native-extensions">Native Extensions</a>
details: Need to interface with an API or implement custom parsing/merging logic? Stencil supports native extensions in <i>any</i> language to implement that logic
---
8 changes: 4 additions & 4 deletions docs/reference/template-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ This directory is used for storing all of the go-templates that a module owns. B

For example, if a module had a template at `templates/helloWorld.tpl` it would by default be written to `./helloWorld`

This can be changed with the [`file.SetPath`](/functions/file.SetPath) function as needed.
This can be changed with the [`file.SetPath`](/funcs/file.SetPath) function as needed.

Templates can also call `file.Create` to create a new file within a loop. For more information see the [`file.Create` documentation](/functions/file.Create)
Templates can also call `file.Create` to create a new file within a loop. For more information see the [`file.Create` documentation](/funcs/file.Create)

#### Library Templates

Expand Down Expand Up @@ -121,9 +121,9 @@ There's a few limitations with aliasing arguments:

## Module Hooks

Module hooks enable other modules to write to a section of a file in your module. This can be done with the [`stencil.GetModuleHook "name"`](/functions/stencil.GetModuleHook) function. This returns a `[]interface{}`, or for non-gophers a list of any type. You can process this with a `range` or in any other method you'd like to generate whatever you need for your DSL.
Module hooks enable other modules to write to a section of a file in your module. This can be done with the [`stencil.GetModuleHook "name"`](/funcs/stencil.GetModuleHook) function. This returns a `[]interface{}`, or for non-gophers a list of any type. You can process this with a `range` or in any other method you'd like to generate whatever you need for your DSL.

A module can write to a module hook with the [`stencil.AddToModuleHook "importPath" "hookName"`](/functions/stencil.AddToModuleHook) function.
A module can write to a module hook with the [`stencil.AddToModuleHook "importPath" "hookName"`](/funcs/stencil.AddToModuleHook) function.

## Updating a Module

Expand Down
2 changes: 1 addition & 1 deletion tools/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func generateMarkdown(_ slogext.Logger) ([]file, error) {
func saveMarkdown(log slogext.Logger, files []file) error {
for _, f := range files {
log.Infof(" -> Writing %s", f.Name)
if err := os.WriteFile(filepath.Join("docs", "functions", f.Name+".md"), []byte(f.Contents), 0o600); err != nil {
if err := os.WriteFile(filepath.Join("docs", "funcs", f.Name+".md"), []byte(f.Contents), 0o600); err != nil {
return err
}
}
Expand Down

0 comments on commit f46a773

Please sign in to comment.