Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin improvements #132

Merged
merged 7 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import (
type noopPluginCaller struct{}

// CallContent implements evaluation.PluginCaller.
func (n *noopPluginCaller) CallContent(ctx context.Context, name string, config evaluation.Configuration, invocation evaluation.Invocation, context plugin.MapData) (result string, diag diagnostics.Diag) {
return "", nil
func (n *noopPluginCaller) CallContent(ctx context.Context, name string, config evaluation.Configuration, invocation evaluation.Invocation, context plugin.MapData) (result *plugin.ContentResult, diag diagnostics.Diag) {
return nil, nil
}

func (n *noopPluginCaller) ContentInvocationOrder(ctx context.Context, name string) (order plugin.InvocationOrder, diag diagnostics.Diag) {
return plugin.InvocationOrderUnspecified, nil
}

// CallData implements evaluation.PluginCaller.
Expand Down
13 changes: 3 additions & 10 deletions cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/blackstork-io/fabric/pkg/diagnostics"
)

func Render(ctx context.Context, blocks *parser.DefinedBlocks, pluginCaller *parser.Caller, docName string) (results []string, diags diagnostics.Diag) {
func Render(ctx context.Context, blocks *parser.DefinedBlocks, pluginCaller *parser.Caller, docName string) (results string, diags diagnostics.Diag) {
doc, found := blocks.Documents[docName]
if !found {
diags.Add(
Expand All @@ -40,20 +40,13 @@ func Render(ctx context.Context, blocks *parser.DefinedBlocks, pluginCaller *par
return
}

func writeResults(dest io.Writer, results []string) (diags diagnostics.Diag) {
func writeResults(dest io.Writer, results string) (diags diagnostics.Diag) {
if len(results) == 0 {
diags.Add("Empty output", "No content was produced")
return
}
w := bufio.NewWriter(dest)

// bufio.Writer preserves the first encountered error,
// so we're only cheking it once at flush
_, _ = w.WriteString(results[0])
for _, result := range results[1:] {
_, _ = w.WriteString("\n\n")
_, _ = w.WriteString(result)
}
w.WriteString(results)
_ = w.WriteByte('\n')
err := w.Flush()
diags.AppendErr(err, "Error while outputing result")
Expand Down
34 changes: 34 additions & 0 deletions docs/plugins/builtin/content-providers/blockquote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: blockquote
plugin:
name: blackstork/builtin
description: ""
tags: []
version: "v0.4.0"
source_github: "https://github.com/blackstork-io/fabric/tree/main/internal/builtin/"
resource:
type: content-provider
type: docs
---

{{< breadcrumbs 2 >}}

{{< plugin-resource-header "blackstork/builtin" "builtin" "v0.4.0" "blockquote" "content provider" >}}

The content provider is built-in, which means it's a part of `fabric` binary. It's available out-of-the-box, no installation required.


#### Configuration

The content provider doesn't support any configuration parameters.

#### Usage

The content provider supports the following execution parameters:

```hcl
content blockquote {
value = <string> # required
}
```

35 changes: 35 additions & 0 deletions docs/plugins/builtin/content-providers/code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: code
plugin:
name: blackstork/builtin
description: ""
tags: []
version: "v0.4.0"
source_github: "https://github.com/blackstork-io/fabric/tree/main/internal/builtin/"
resource:
type: content-provider
type: docs
---

{{< breadcrumbs 2 >}}

{{< plugin-resource-header "blackstork/builtin" "builtin" "v0.4.0" "code" "content provider" >}}

The content provider is built-in, which means it's a part of `fabric` binary. It's available out-of-the-box, no installation required.


#### Configuration

The content provider doesn't support any configuration parameters.

#### Usage

The content provider supports the following execution parameters:

```hcl
content code {
language = <string> # optional
value = <string> # required
}
```

5 changes: 1 addition & 4 deletions docs/plugins/builtin/content-providers/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ The content provider supports the following execution parameters:

```hcl
content text {
absolute_title_size = <number> # optional
code_language = <string> # optional
format_as = <string> # optional
text = <string> # required
value = <string> # required
}
```

36 changes: 36 additions & 0 deletions docs/plugins/builtin/content-providers/title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: title
plugin:
name: blackstork/builtin
description: ""
tags: []
version: "v0.4.0"
source_github: "https://github.com/blackstork-io/fabric/tree/main/internal/builtin/"
resource:
type: content-provider
type: docs
---

{{< breadcrumbs 2 >}}

{{< plugin-resource-header "blackstork/builtin" "builtin" "v0.4.0" "title" "content provider" >}}

The content provider is built-in, which means it's a part of `fabric` binary. It's available out-of-the-box, no installation required.


#### Configuration

The content provider doesn't support any configuration parameters.

#### Usage

The content provider supports the following execution parameters:

```hcl
content title {
absolute_size = <number> # optional
relative_size = <number> # optional
value = <string> # required
}
```

Loading
Loading