Skip to content

Commit

Permalink
feat: add the row and col shortcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jun 29, 2023
1 parent 853f21a commit 751fddc
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
41 changes: 41 additions & 0 deletions layouts/partials/bootstrap/col.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- $size := "" }}
{{- $offset := "" }}
{{- $class := "" }}
{{- if .IsNamedParams }}
{{- with .Get "size" }}{{ $size = . }}{{ end }}
{{- with .Get "offset" }}{{ $offset = . }}{{ end }}
{{- with .Get "class" }}{{ $class = . }}{{ end }}
{{- else }}
{{- with .Get 0 }}{{ $size = . }}{{ end }}
{{- with .Get 1 }}{{ $offset = . }}{{ end }}
{{- with .Get 2 }}{{ $class = . }}{{ end }}
{{- end }}
{{- $classes := slice }}
{{- with $size }}
{{- $sizes := split . " " }}
{{- range $sizes }}
{{- $kv := split . ":" }}
{{- if gt (len $kv) 1 }}
{{- $classes = $classes | append (printf "col-%s-%s" (index $kv 0) (index $kv 1)) }}
{{- else }}
{{- $classes = $classes | append (printf "col-%s" .) }}
{{- end }}
{{- end }}
{{- else }}
{{- $classes = $classes | append "col" }}
{{- end }}
{{- with $offset }}
{{- $offsets := split . " " }}
{{- range $offsets }}
{{- $kv := split . ":" }}
{{- if gt (len $kv) 1 }}
{{- $classes = $classes | append (printf "offset-%s-%s" (index $kv 0) (index $kv 1)) }}
{{- else }}
{{- $classes = $classes | append (printf "offset-%s" .) }}
{{- end }}
{{- end }}
{{- end }}
{{- with $class }}{{ $classes = $classes | append . }}{{ end }}
<div class="{{ delimit $classes ` ` }}">
{{ .Inner }}
</div>
24 changes: 24 additions & 0 deletions layouts/partials/bootstrap/row.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- $cols := "" }}
{{- $class := "" }}
{{- if .IsNamedParams }}
{{- with .Get "cols" }}{{ $class = . }}{{ end }}
{{- with .Get "class" }}{{ $class = . }}{{ end }}
{{- else }}
{{- with .Get 0 }}{{ $cols = . }}{{ end }}
{{- with .Get 1 }}{{ $class = . }}{{ end }}
{{- end }}
{{- $classes := slice "row" }}
{{- with $cols }}
{{- range split . " " }}
{{- $kv := split . ":" }}
{{- if gt (len $kv) 1 }}
{{- $classes = $classes | append (printf "row-cols-%s-%s" (index $kv 0) (index $kv 1)) }}
{{- else }}
{{- $classes = $classes | append (printf "row-cols-%s" .) }}
{{- end }}
{{- end }}
{{- end }}
{{- with $class }}{{ $classes = $classes | append . }}{{ end }}
<div class="{{ delimit $classes ` ` }}">
{{ .Inner }}
</div>
2 changes: 2 additions & 0 deletions layouts/shortcodes/bootstrap/col.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- if .Inner }}{{ end }}
{{- partial "bootstrap/col" . }}
2 changes: 2 additions & 0 deletions layouts/shortcodes/bootstrap/row.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- if .Inner }}{{ end }}
{{- partial "bootstrap/row" . }}
2 changes: 2 additions & 0 deletions layouts/shortcodes/bs/col.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- if .Inner }}{{ end }}
{{- partial "bootstrap/col" . }}
2 changes: 2 additions & 0 deletions layouts/shortcodes/bs/row.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- if .Inner }}{{ end }}
{{- partial "bootstrap/row" . }}

0 comments on commit 751fddc

Please sign in to comment.