github.com/wfusion/gofusion@v1.1.14/common/infra/watermill/docs/layouts/shortcodes/load-snippet-partial.html (about) 1 {{ $file := (.Get "file") }} 2 {{ $content := readFile $file }} 3 4 {{ $first_line_contains := (.Get "first_line_contains") }} 5 {{ $last_line_contains := (.Get "last_line_contains") }} 6 {{ $last_line_equals := (.Get "last_line_equals") }} 7 8 {{ $show_line := false }} 9 10 {{/*if true, first or last line was not found*/}} 11 {{ $first_line_found := false}} 12 {{ $last_line_found := false}} 13 14 {{ $padding_after := (.Get "padding_after" | default "0" | int) }} 15 16 {{ $first_line_num := 0 }} 17 {{ $last_line_num := 0 }} 18 19 {{ $linkFile := $file }} 20 {{ $repo := "watermill" }} 21 22 {{ if in $file "src-link/watermill-" }} 23 {{ $repo = index (findRE "watermill-[a-z]+" $linkFile) 0 }} 24 {{ $linkFile = replace $linkFile $repo "" }} 25 {{ $linkFile = replace $linkFile "src-link//" "" }} 26 {{ else if in $linkFile "src-link/" }} 27 {{ $linkFile = replace $linkFile "src-link/" "" }} 28 {{ else }} 29 {{ $linkFile = print "docs/content/" $linkFile }} 30 {{ end }} 31 32 {{ $lines := slice }} 33 34 {{ range $elem_key, $elem_val := split $content "\n" }} 35 {{ $line_num := (add $elem_key 1) }} 36 37 {{ if and (not $first_line_found) (in $elem_val $first_line_contains) }} 38 {{ if ne $elem_key 0 }} 39 {{ $lines = $lines | append "// ..." }} 40 {{ end }} 41 42 {{ $show_line = true }} 43 {{ $first_line_found = true}} 44 {{ $first_line_num = $line_num }} 45 {{ end }} 46 47 {{ if $show_line }} 48 {{ $lines = $lines | append $elem_val }} 49 {{ end }} 50 51 {{ if and ($first_line_found) (in $elem_val $last_line_contains) (ne $last_line_contains "") }} 52 {{ $last_line_found = true }} 53 {{ end }} 54 55 {{ if and ($first_line_found) (eq $elem_val $last_line_equals) (ne $last_line_equals "") }} 56 {{ $last_line_found = true }} 57 {{ end }} 58 59 {{ if and $last_line_found $show_line }} 60 {{ if gt $padding_after 0 }} 61 {{ $padding_after = sub $padding_after 1}} 62 {{ else }} 63 {{ $lines = $lines | append "// ..." }} 64 {{ $show_line = false }} 65 {{ $last_line_num = $line_num }} 66 {{ end }} 67 {{ end }} 68 {{ end }} 69 70 <small class="smaller">Full source: [github.com/ThreeDotsLabs/{{ $repo }}/{{ $linkFile }}](https://github.com/ThreeDotsLabs/{{ $repo }}/tree/master/{{ $linkFile }}{{ if ne $first_line_num 0 }}#L{{ $first_line_num }}{{ end }})</small> 71 72 {{ highlight (delimit $lines "\n") (.Get "type" | default "go") "" }} 73 74 {{if not $first_line_found }} 75 {{ errorf "`first_line_contains` %s not found in %s snippet" $first_line_contains $file }} 76 {{end}} 77 78 {{if and (not $last_line_found) (ne $last_line_contains "") }} 79 {{ errorf "`last_line_contains` %s not found in %s snippet" $last_line_contains $file }} 80 {{end}}