Compare commits

...

17 Commits

Author SHA1 Message Date
Mark Dumay
daab751299 Merge pull request #673 from gethinode/validation
Refactor alert and args shortcodes
2023-12-25 09:07:31 +01:00
Mark Dumay
9e82ff8de5 Merge branch 'main' into validation 2023-12-25 08:59:10 +01:00
mark
52b2c23565 Bump package release 2023-12-25 08:58:17 +01:00
mark
617fd688db Refactor args shortcode 2023-12-25 08:47:36 +01:00
mark
2cf7fff3ba Refactor alert 2023-12-25 08:31:27 +01:00
Mark Dumay
a34d3fde1f Merge pull request #672 from gethinode/validation
Refactor abbr and accordion shortcodes
2023-12-25 08:29:09 +01:00
Mark Dumay
be054a723e Merge branch 'main' into validation 2023-12-25 08:03:42 +01:00
mark
fc43f6a52e Refine comments 2023-12-25 08:03:13 +01:00
mark
195d3cb69b Refactor accordion 2023-12-25 08:03:06 +01:00
mark
92c69b6011 Fix empty args 2023-12-25 07:27:08 +01:00
mark
ea78805587 Support bool, int, and float represented as string 2023-12-25 06:53:16 +01:00
mark
76e90ea321 Fix required arguments test 2023-12-25 06:52:07 +01:00
mark
b300758aa5 Update build stats 2023-12-25 05:55:56 +01:00
mark
68c44c55d4 Refactor abbr shortcode 2023-12-25 05:55:47 +01:00
mark
228a89f61d Support unnamed args 2023-12-25 05:55:25 +01:00
mark
2645453de2 Update card comments 2023-12-25 04:57:56 +01:00
mark
5ce069a4c0 Improve handling of module args 2023-12-24 14:59:35 +01:00
18 changed files with 414 additions and 213 deletions

33
data/structures/abbr.yml Normal file
View File

@@ -0,0 +1,33 @@
comment: >-
Creates an HTML element that shows the long form of an abbrevitation. The abbreviation data is centrally stored in a
data file. By default, the shortcode uses "abbr.yaml" with translation support.
The data file is expected to store key-value pairs, where "id" is the lower-case abbrevation and "long" its long
form. The following example illustrates this using YML:
- id: css
long: "Cascading Style Sheets"
arguments:
key:
type: string
position: 0
optional: false
comment: >-
Case-insensitive key of the abbreviation. In shorthand notation, this is
the first (and only) matched argument. Non-alphanumeric keys must be quoted.
data:
type: string
default: abbr.yaml
optional: true
comment: >-
Filename of the abbrevation input. You can omit the file extension. The
file should reside in the "data" folder. The data supports language
extensions. For example, "abbr.en.yaml" refers to the English translation
of the abbrevation data. The filename "abbr.yaml" is used when no suitable
translation is found.
class:
type: string
optional: true
comment: >-
Class attribute of the abbr element. For example, specify "initialism" for
a slightly smaller font size.

View File

@@ -0,0 +1,23 @@
comment: >-
Defines an individual accordion item.
arguments:
header:
type: string
optional: false
comment: >-
Header of the accordion item.
show:
type: bool
optional: true
comment: >-
flag to indicate an item should be shown as collapsed.
class:
type: string
optional: true
comment: >-
Class attribute of the accordion item.
body:
optional: false
comment: >-
Content of the accordion item.
group: shortcode

View File

@@ -0,0 +1,19 @@
comment: >-
Use the accordion to show a group of vertically collapsing and expanding
items. Add accordion-item inner elements for each accordion item.
arguments:
id:
type: string
optional: true
comment: >-
ID of the accordion, defaults to “accordion-n” with a sequential number n.
always-open:
type: bool
optional: true
comment: >-
Flag to make accordion items stay open when another item is opened.
class:
type: string
optional: true
comment: >-
Class attribute of the accordion, e.g. “w-50”.

52
data/structures/alert.yml Normal file
View File

@@ -0,0 +1,52 @@
comment: >-
Use the alert shortcode to display a contextual feedback message. The inner
content is used as alert text.
arguments:
class:
type: string
optional: true
comment: >-
Class attribute of the alert element.
color:
type: select
optional: true
default: danger
comment: >-
Theme color of the alert.
options:
values:
- primary
- secondary
- success
- danger
- warning
- info
- light
- dark
- white
- black
dismissible:
type: bool
optional: true
default: false
comment: >-
Flag to indicate the alert is dismissible.
icon:
type: string
optional: true
comment: >-
Font Awesome icon to include.
type:
type: select
optional: true
comment: >-
Type of the alert, generates an alert with related color and icon.
options:
values:
- danger
- info
body:
optional: false
comment: >-
Alert text.
group: shortcode

20
data/structures/args.yml Normal file
View File

@@ -0,0 +1,20 @@
comment: >-
Generates a markdown table of structured arguments. The argument definitions are
expected to be defined in a data file identified by a provided structure name.
arguments:
structure:
type: string
position: 0
optional: false
comment: >-
Name of the data file that contains argument definitions. Supported data
formats include JSON, TOML, YAML, and XML. You can omit the file
extension. The file should reside in the "data/structures" folder.
group:
type: string
position: 1
optional: true
comment: >-
Name of the group filter. This is typically used when a shortcode and
partial have common arguments. The group filter binds a specific argument
to a particular group. By default, an argument belongs to all groups.

View File

@@ -7,12 +7,13 @@ arguments:
type: string
optional: true
comment: >-
Title of the card.
Title of the card, replaces the title of the referenced page (if any).
path:
type: path
optional: true
comment: >-
Path of the page, override with other parameters.
Path of the page that the card reference to. If omitted, specify the
title, icon, thumbnail, and description (inner content) as needed.
href:
type: url
optional: true

View File

@@ -314,7 +314,6 @@
"pb-4",
"pb-5",
"pb-md-0",
"pe-1",
"pe-3",
"position-absolute",
"position-fixed",

View File

@@ -1,5 +1,12 @@
{{- define "partials/optional-scripts.html" -}}
{{- $modules := site.Params.modules.optional | intersect .Params.modules -}}
{{ $page_modules := slice }}
{{ if reflect.IsMap .Params.modules }}
{{ $page_modules = .Params.modules }}
{{ else }}
{{ $page_modules = $page_modules | append .Params.modules }}
{{ end }}
{{- $modules := site.Params.modules.optional | intersect $page_modules -}}
{{- range $index, $mod := $modules -}}
{{- $filename := printf "js/%s.bundle.js" $mod -}}
{{- $match := printf "js/modules/%s/**.js" $mod -}}

View File

@@ -0,0 +1,14 @@
{{ $input := . }}
{{ $output := "" }}
{{ if eq (printf "%T" $input) "bool" }}
{{ $output = $input }}
{{ else if eq $input "true" }}
{{ $output = true }}
{{ else if eq $input "false" }}
{{ $output = false }}
{{ else }}
{{ errorf "Cannot cast '%s' to bool" $input }}
{{ end }}
{{ return $output }}

View File

@@ -14,7 +14,7 @@
{{ $error = true }}
{{ end }}
{{ $args := .args | default slice }}
{{ $args := .args | default dict }}
{{ $definitions := (index site.Data.structures $structure).arguments }}
{{ if not $definitions }}
@@ -22,54 +22,97 @@
{{ $error = true }}
{{ end }}
{{ $namedArgs := true }}
{{ if not $error }}
{{ range $key, $val := $args }}
{{ $def := index $definitions $key }}
{{ if and (not $val) $def.default }}{{ $val = $def.default }}{{ end }}
{{/* validate type */}}
{{ $expected := slice | append $def.type }}
{{ $extra := slice }}
{{ range $expected }}
{{ $alias := index $aliases . }}
{{ if $alias }}{{ $extra = $extra | append $alias }}{{ end }}
{{ end }}
{{ if $extra }}{{ $expected = $expected | append $extra }}{{ end }}
{{ $actual := printf "%T" $val }}
{{ if $val }}
{{ if not (in $expected $actual ) }}
{{ warnf "[%s] argument '%s': expected type '%s', got '%s'" $structure $key (delimit $expected ", ") $actual }}
{{ $error = true }}
{{ $def := "" }}
{{ if eq (printf "%T" $key) "string" }}
{{ $def = index $definitions $key }}
{{ else }}
{{ $namedArgs = false }}
{{ range $d := $definitions }}
{{ if eq $d.position $key }}{{ $def = $d }}{{ end }}
{{ end }}
{{ end }}
{{/* validate permitted values */}}
{{ if and $def.options.values (eq $actual "select") }}
{{ if and (not $def.optional) (not (in $def.options.values $val)) }}
{{ warnf "[%s] argument '%s': unexpected value '%s'" $structure $key $val }}
{{ $error = true }}
{{ if not $def }}
{{ if eq (printf "%T" $key) "string" }}
{{ warnf "[%s] unsupported argument '%s'" $structure $key }}
{{ else if eq (printf "%T" $key) "int" }}
{{ warnf "[%s] unsupported argument at index %d (value: '%s')" $structure $key $val }}
{{ else }}
{{ warnf "[%s] unsupported argument value '%s'" $structure $val }}
{{ end }}
{{ else if and $def.options.min (in (slice "int" "float" "float64") $actual) }}
{{ if lt $val $def.options.min }}
{{ warnf "[%s] argument '%s': value '%s' out of range [$d, $d]" $structure $key $val $def.options.min $def.options.max}}
{{ $error = true }}
{{ $error = true }}
{{ else }}
{{ if and (not $val) $def.default }}{{ $val = $def.default }}{{ end }}
{{/* validate type */}}
{{ $expected := slice | append $def.type }}
{{ $extra := slice }}
{{ range $expected }}
{{ $alias := index $aliases . }}
{{ if $alias }}{{ $extra = $extra | append $alias }}{{ end }}
{{ end }}
{{ else if and $def.options.max (in (slice "int" "float" "float64") $actual) }}
{{ if (gt $val $def.options.max) }}
{{ warnf "[%s] argument '%s': value '%s' out of range [$d, $d]" $structure $key $val $def.options.min $def.options.max}}
{{ $error = true }}
{{ if $extra }}{{ $expected = $expected | append $extra }}{{ end }}
{{ $actual := printf "%T" $val }}
{{/* cast supported types from string */}}
{{ if and (in $expected "bool") (in (slice "true" "false") $val) }}
{{ $actual = "bool" }}
{{ else if and (in $expected "int") (findRE `^-?\d+$` $val) }}
{{ $actual = "int" }}
{{ else if and (in $expected "float") (findRE `^(?:[1-9]\d*|0)?(?:\.\d+)?$` $val) }}
{{ $actual = "float" }}
{{ end }}
{{ if $val }}
{{ if not (in $expected $actual ) }}
{{ warnf "[%s] argument '%s': expected type '%s', got '%s'" $structure $key (delimit $expected ", ") $actual }}
{{ $error = true }}
{{ end }}
{{ end }}
{{/* validate permitted values */}}
{{ if and $def.options.values (eq $actual "select") }}
{{ if and (not $def.optional) (not (in $def.options.values $val)) }}
{{ warnf "[%s] argument '%s': unexpected value '%s'" $structure $key $val }}
{{ $error = true }}
{{ end }}
{{ else if and $def.options.min (in (slice "int" "float" "float64") $actual) }}
{{ if lt $val $def.options.min }}
{{ warnf "[%s] argument '%s': value '%s' out of range [$d, $d]" $structure $key $val $def.options.min $def.options.max}}
{{ $error = true }}
{{ end }}
{{ else if and $def.options.max (in (slice "int" "float" "float64") $actual) }}
{{ if (gt $val $def.options.max) }}
{{ warnf "[%s] argument '%s': value '%s' out of range [$d, $d]" $structure $key $val $def.options.min $def.options.max}}
{{ $error = true }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{/* validate required arguments */}}
{{ $max := len $args }}
{{ $expected := 0 }}
{{ range $key, $val := $definitions }}
{{ if not $val.optional }}
{{ if $namedArgs }}
{{ if not (isset $args $key) }}
{{ warnf "[%s] argument '%s': expected value" $structure $key }}
{{ $error = true }}
{{ end }}
{{ else }}
{{ $expected = add $expected 1 }}
{{ end }}
{{ end }}
{{ end }}
{{/* validate required arguments */}}
{{ range $key, $val := $definitions }}
{{ if not $val.optional }}
{{ if not (in $args $key )}}
{{ warnf "[%s] argument '%s': expected value" $structure $key }}
{{ $error = true }}
{{ end }}
{{ end }}
{{ if lt $max $expected }}
{{ warnf "[%s] expected '%d' args, got '%d'" $structure $expected $max }}
{{ $error = true }}
{{ end }}
{{ end }}

View File

@@ -1,46 +1,37 @@
<!--
Creates an HTML element that shows the long form of an abbrevitation. The abbreviation data is centrally stored in a
data file. By default, the shortcode uses "abbr.yaml" with translation support.
The data file is expected to store key-value pairs, where "id" is the lower-case abbrevation and "long" its long
form. The following example illustrates this using YML:
- id: css
long: "Cascading Style Sheets"
The shortcode supports the following arguments:
"key" Required case-insensitive key of the abbreviation. In shorthand notation, this is the first (and
only) matched argument.
"data" Optional filename of the abbrevation input. It defaults to "abbr.yaml" with translation support.
You can omit the file extension. The file should reside in the "data" folder. The data supports
language extensions. For example, "abbr.en.yaml" refers to the English translation of the
abbrevation data. The filename "abbr.yaml" is used when no suitable translation is found.
"class" Optional class attribute of the abbr element. For example, specify "initialism" for a slightly
smaller font size.
Copyright © 2023 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
-->
{{ $error := false }}
<!-- Validate and initialize arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "abbr" "args" .Params) }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ $error = true }}
{{ end }}
<!-- Initialize arguments and default values -->
{{ $key := "" }}
{{- if .IsNamedParams }}{{ $key = .Get "key" }}{{ else }}{{ $key = .Get 0 }}{{ end }}
{{ $data := "abbr" }}
{{ $class := "" }}
{{ $title := "" }}
{{ $entries := slice }}
{{ if not $key -}}
{{ errorf "Missing param 'key': %s" .Position -}}
{{ $error = true }}
{{ end -}}
{{- $data := .Get "data" | default "abbr" -}}
{{ if not $data -}}
{{ errorf "Missing param 'data': %s" .Position -}}
{{ $error = true }}
{{ end -}}
{{- $class := .Get "class" | default "" -}}
{{- if .IsNamedParams }}
{{ $key = .Get "key" }}
{{- $data := .Get "data" | default "abbr" -}}
{{- $class := .Get "class" | default "" -}}
{{ else }}
{{ $key = .Get 0 }}
{{ end }}
<!-- Main code -->
{{ if not $error }}
{{/* Try language-specific file first */}}
{{ $path := path.Join (path.Dir $data) (printf "%s.%s" (path.BaseName $data) .Page.Language.Lang) (path.Ext $data) }}
{{ $entries := index site.Data $path }}
{{ $entries = index site.Data $path }}
{{/* Use exact provided path as backup */}}
{{ if not $entries -}}
{{ $entries = index site.Data $data }}
@@ -49,20 +40,19 @@
{{ errorf "Invalid abbrevation data '%s': %s" $data .Position -}}
{{ $error = true }}
{{ end -}}
{{ end }}
{{ $title := "" }}
{{ if not $error }}
{{ $elements := (where $entries "id" (lower $key)) }}
{{ if gt (len $elements) 0 }}
{{ $title = index (index $elements 0) "long" }}
{{ end -}}
{{ if not $title -}}
{{ errorf "Cannot find value for '%s': %s" $key .Position -}}
{{ $error = true }}
{{ end -}}
{{ end }}
{{ if not $error }}
{{ $elements := (where $entries "id" (lower $key)) }}
{{ if gt (len $elements) 0 }}
{{ $title = index (index $elements 0) "long" }}
{{ end -}}
{{ if not $title -}}
{{ errorf "Cannot find value for '%s': %s" $key .Position -}}
{{ $error = true }}
{{ end -}}
{{ end }}
{{ if not $error }}
<abbr {{ with $class }}class="{{ . }}"{{ end }} title="{{ $title }}" tabindex="0">{{ $key }}</abbr>
{{ end }}
{{ end }}
{{ if not $error }}
<abbr {{ with $class }}class="{{ . }}"{{ end }} title="{{ $title }}" tabindex="0">{{ $key }}</abbr>
{{ end }}

View File

@@ -1,27 +1,41 @@
<!--
Defines an individual accordion item. The shortcode supports the following arguments:
"header" Required header of the accordion element.
"class" Optional class attribute of the inner accordion element.
"show" Optional flag to indicate an item should be shown as collapsed.
Copyright © 2023 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
-->
{{ $error := false }}
<!-- Validate arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "accordion-item" "args" .Params) }}
{{ if .Parent }}
{{ errorf "Invalid arguments: %s" .Parent.Position -}}
{{ else }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ end }}
{{ $error = true }}
{{ end }}
{{ if not .Parent }}
{{ errorf "Cannot use isolated accordion-item, wrap it in an accordion: %s" .Position -}}
{{ $error = true }}
{{ end }}
<!-- Initialize arguments and default values -->
{{- $id := .Ordinal -}}
{{- $parent := printf "accordion-%d" .Parent.Ordinal -}}
{{- with (.Parent.Get "id") -}}
{{- $parent = . -}}
{{ $parent := "" }}
{{ if not $error }}
{{- $parent = printf "accordion-%d" .Parent.Ordinal -}}
{{- with (.Parent.Get "id") -}}
{{- $parent = . -}}
{{- end -}}
{{- end -}}
{{- $id := .Ordinal -}}
{{ $header := .Get "header" | default "" -}}
{{ if not $header -}}
{{ if .Parent }}
{{ errorf "Missing value for param 'header': %s" .Parent.Position -}}
{{ else }}
{{ errorf "Missing value for param 'header': %s" .Position -}}
{{ end }}
{{ end -}}
{{ $header := .Get "header" -}}
{{ $class := .Get "class" | default "" -}}
{{ $body := trim .Inner " \r\n" -}}
{{ if not $body -}}
{{ if .Parent }}
@@ -29,27 +43,24 @@
{{ else }}
{{ errorf "Missing inner element text: %s" .Position -}}
{{ end }}
{{ $error = true }}
{{ end -}}
{{ $supportedFlags := slice "true" "false" -}}
{{ $showParam := "false" -}}
<!-- Main code -->
{{ $show := false -}}
{{ with .Get "show" }}{{ $showParam = . }}{{ end -}}
{{ if in $supportedFlags $showParam -}}
{{ if eq $showParam "true" }}{{ $show = true }}{{ else }}{{ $show = false }}{{ end -}}
{{ else -}}
{{ errorf "Invalid value for param 'show': %s" $showParam -}}
{{ end -}}
{{ if not $error }}
{{ with .Get "show" }}{{ $show = partial "utilities/CastBool.html" . }}{{ end -}}
<div class="accordion-item">
{{- with $header -}}
<h2 class="accordion-header m-0" id="{{ $parent }}-heading-{{ $id }}">
<button class="accordion-button{{ if not $show }} collapsed{{ end }}" type="button" data-bs-toggle="collapse" data-bs-target="#{{ $parent }}-item-{{ $id }}" aria-expanded="false" aria-controls="{{ $parent }}-item-{{ $id }}">
{{ . }}
</button>
</h2>
{{- end -}}
<div id="{{ $parent }}-item-{{ $id }}" class="accordion-collapse collapse{{ if $show }} show{{ end }}{{ with $class }} {{ . }}{{ end }}" aria-labelledby="{{ $parent }}-heading-{{ $id }}" data-bs-parent="#{{ $parent }}">
<div class="accordion-body">{{ $body | .Page.RenderString | safeHTML }}</div>
<div class="accordion-item">
{{- with $header -}}
<h2 class="accordion-header m-0" id="{{ $parent }}-heading-{{ $id }}">
<button class="accordion-button{{ if not $show }} collapsed{{ end }}" type="button" data-bs-toggle="collapse" data-bs-target="#{{ $parent }}-item-{{ $id }}" aria-expanded="false" aria-controls="{{ $parent }}-item-{{ $id }}">
{{ . }}
</button>
</h2>
{{- end -}}
<div id="{{ $parent }}-item-{{ $id }}" class="accordion-collapse collapse{{ if $show }} show{{ end }}{{ with $class }} {{ . }}{{ end }}" aria-labelledby="{{ $parent }}-heading-{{ $id }}" data-bs-parent="#{{ $parent }}">
<div class="accordion-body">{{ $body | .Page.RenderString | safeHTML }}</div>
</div>
</div>
</div>
{{ end }}

View File

@@ -1,34 +1,31 @@
<!--
Displays a group of vertically collapsing and expanding items. Add accordion-item inner elements for each accordion
item. The shortcode supports the following arguments:
"id": Optional id of the accordion, defaults to "accordion-" with a sequential number.
"always-open": Optional flag to make accordion items stay open when another item is opened.
"class": Optional class attribute of the accordion element, e.g. “w-50”.
Copyright © 2023 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
-->
{{- $id := printf "accordion-%d" .Ordinal -}}
{{ with .Get "id" }}
{{ $id = . }}
{{ $error := false }}
<!-- Validate arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "accordion" "args" .Params) }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ $error = true }}
{{ end }}
{{- $class := .Get "class" | default "" -}}
{{- $openParam := "false" -}}
{{- $open := false -}}
{{- with .Get "always-open" }}{{ $openParam = . }}{{ end -}}
{{- $supportedFlags := slice "true" "false" -}}
{{- if in $supportedFlags $openParam -}}
{{- if eq $openParam "true" }}{{ $open = true }}{{ end -}}
{{- else -}}
{{- errorf "Invalid value for param 'always-open': %s" .Position -}}
{{- $error = true -}}
{{- end -}}
<!-- Main code -->
{{ if not $error }}
{{- $id := printf "accordion-%d" .Ordinal -}}
{{ with .Get "id" }}{{ $id = . }}{{ end }}
{{- $class := .Get "class" | default "" -}}
{{- $open := false -}}
{{ with .Get "always-open" }}{{ $open = partial "utilities/CastBool.html" . }}{{ end -}}
{{- $body := .Inner -}}
{{- if $open -}}
{{- $pattern := printf "data-bs-parent=\"#%s\"" $id -}}
{{- $body = (replace .Inner $pattern "") | .Page.RenderString | safeHTML }}
{{- end -}}
{{- $body := .Inner -}}
{{- if $open -}}
{{- $pattern := printf "data-bs-parent=\"#%s\"" $id -}}
{{- $body = (replace .Inner $pattern "") | .Page.RenderString | safeHTML }}
{{- end -}}
<div id="{{ $id }}" class="accordion mb-3{{ with $class }} {{ . }}{{ end }}">
{{- $body -}}
</div>
<div id="{{ $id }}" class="accordion mb-3{{ with $class }} {{ . }}{{ end }}">
{{- $body -}}
</div>
{{ end }}

View File

@@ -1,61 +1,41 @@
<!--
Displays an alert. The shortcode supports the following arguments:
"color": Optional theme color of the alert, either "primary" (default), "secondary", "success", "danger",
"warning", "info", "light", "dark", "white" or "black".
"dismissible" Optional flag to indicate the alert is dismissible, defaults to false.
"icon" Optional class and name of a Font Awesome icon to include.
"type" Optional type of the alert, either "danger" or "info". Generates an alert with related color and
icon.
"class": Optional class attribute of the alert element.
Copyright © 2023 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
-->
{{- $error := false -}}
{{ $color := "primary" -}}
{{ $icon := "" }}
{{ $type := "" -}}
{{ $error := false }}
{{ with .Get "type" }}{{ $type = . }}{{ end -}}
{{ $supportedTypes := slice "danger" "info" -}}
{{ if $type }}
{{ if not (in $supportedTypes $type) -}}
{{ errorf "Invalid value for param 'type': %s" .Position -}}
{{ $error = true -}}
{{ else }}
{{ $color = $type }}
{{ if eq $type "danger" }}{{ $icon = "fas triangle-exclamation" }}{{ else }}{{ $icon = "fa lightbulb" }}{{ end }}
{{ end -}}
{{ end -}}
<!-- Validate arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "alert" "args" .Params) }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ $error = true }}
{{ end }}
{{ with .Get "color" }}{{ $color = . }}{{ end -}}
{{ $supportedColors := slice "primary" "secondary" "success" "danger" "warning" "info" "light" "dark" -}}
{{ if not (in $supportedColors $color) -}}
{{ errorf "Invalid value for param 'color': %s" .Position -}}
{{ $error = true -}}
{{ end -}}
{{ with .Get "icon" }}{{ $icon = . }}{{ end }}
<!-- Initialize arguments -->
{{ $color := .Get "color" | default "danger" -}}
{{ $icon := .Get "icon" | default "" }}
{{ $type := .Get "type" | default "" -}}
{{ if eq $type "danger" }}{{ $icon = "fas triangle-exclamation" }}{{ else if eq $type "info" }}{{ $icon = "fa lightbulb" }}{{ end }}
{{ with $icon }}
{{ $icon = partial "assets/icon.html" (dict "icon" (printf "%s fa-2x fa-fw" .)) }}
{{ end }}
{{ $dismissibleParam := "false" -}}
{{ $dismissible := false -}}
{{ with .Get "dismissible" }}{{ $dismissibleParam = . }}{{ end -}}
{{ $supportedFlags := slice "true" "false" -}}
{{ if in $supportedFlags $dismissibleParam -}}
{{ if eq $dismissibleParam "true" }}{{ $dismissible = true }}{{ end -}}
{{ else -}}
{{ errorf "Invalid value for param 'dismissible': %s" .Position -}}
{{ $error = true -}}
{{ end -}}
{{ with .Get "dismissible" }}{{ $dismissible = partial "utilities/CastBool.html" . }}{{ end -}}
{{- $class := .Get "class" | default "" -}}
{{ $body := trim .Inner " \r\n" -}}
{{ if not $body -}}
{{ errorf "Missing inner element text: %s" .Position -}}
{{ $error = true }}
{{ end -}}
<!-- Main code -->
{{- if not $error -}}
<div class="d-flex alert alert-{{ $color }} {{ if $dismissible }}alert-dismissible fade show{{ end }}{{ with $class }} {{ . }}{{ end }}" role="alert">
{{ with $icon }}<div class="pt-1 pe-2">{{ . }}</div>{{ end }}
<div class="flex-grow-1 my-auto">
{{ trim .Inner " \r\n" | .Page.RenderString | safeHTML -}}
{{ $body | .Page.RenderString | safeHTML -}}
{{ if $dismissible }}<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ T "close" }}"></button>{{ end }}
</div>
</div>

View File

@@ -1,21 +1,33 @@
<!--
Copyright © 2023 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
-->
{{ $error := false }}
<!-- Validate arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "args" "args" .Params) }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ $error = true }}
{{ end }}
<!-- Initialize arguments -->
{{ $structure := "" }}
{{- if .IsNamedParams }}{{ $structure = .Get "structure" }}{{ else }}{{ $structure = .Get 0 }}{{ end }}
{{ if not $structure }}
{{- errorf "Invalid or missing value for param 'structure': %s" .Position -}}
{{ $error = true }}
{{ end }}
{{ $definitions := (index site.Data.structures $structure).arguments }}
{{ if not $definitions }}
{{- errorf "Cannot find data structure '%s': %s" $structure .Position -}}
{{ $error = true }}
{{ end }}
{{ $group := "" }}
{{- if .IsNamedParams }}{{ $group = .Get "group" }}{{ else }}{{ $group = .Get 1 }}{{ end }}
{{- if .IsNamedParams }}{{ $group = .Get "group" | default "" }}{{ else }}{{ $group = .Get 1 | default "" }}{{ end }}
{{ $definitions := "" }}
{{ if not $error }}
{{ $definitions = (index site.Data.structures $structure).arguments }}
{{ if not $definitions }}
{{- errorf "Cannot find data structure '%s': %s" $structure .Position -}}
{{ $error = true }}
{{ end }}
{{ end }}
<!-- Main code -->
{{ if not $error }}
{{ $table := printf "| %s | %s | %s | %s | %s |\n| --- | --- | --- | --- | --- |"
(T "name") (T "type") (T "required") (T "default") (T "comment")
@@ -47,9 +59,9 @@
{{ $max := "" }}
{{ if and $val.options.values (eq $type "select") }}
{{ $comment = printf "%s %s: [%s]." $comment (T "supportedValues") (delimit $val.options.values ", ") }}
{{ else if $val.options.min (in (slice "int" "float" "float64") $type) }}
{{ else if and $val.options.min (in (slice "int" "float" "float64") $type) }}
{{ $min = $val.options.min }}
{{ else if $val.options.max (in (slice "int" "float" "float64") $type) }}
{{ else if and $val.options.max (in (slice "int" "float" "float64") $type) }}
{{ $max = $val.options.max }}
{{ end }}
{{ if and $min $max }}

View File

@@ -6,7 +6,7 @@
{{ $error := false }}
<!-- Validate and initialize arguments -->
<!-- Validate arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "card" "args" .Params) }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ $error = true }}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@gethinode/hinode",
"version": "0.22.0-alpha2",
"version": "0.22.0-alpha3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@gethinode/hinode",
"version": "0.22.0-alpha2",
"version": "0.22.0-alpha3",
"license": "MIT",
"devDependencies": {
"@fullhuman/postcss-purgecss": "^5.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.22.0-alpha2",
"version": "0.22.0-alpha3",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",