Passed
Pull Request — main (#166)
by Yume
02:09
created

layout.Base   F

Complexity

Conditions 19

Size

Total Lines 73
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 19
eloc 56
nop 6
dl 0
loc 73
rs 0.5999
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like layout.Base often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
// Code generated by templ - DO NOT EDIT.
2
3
// templ: version: v0.2.543
4
package layout
5
6
//lint:file-ignore SA4006 This context is only used if a nested component is present.
7
8
import "github.com/a-h/templ"
9
import "context"
10
import "io"
11
import "bytes"
12
13
import "github.com/memnix/memnix-rest/app/v2/views/partials"
14
15
func Base(title, username string, fromProtected, isError bool, errMsgs, sucMsgs []string) templ.Component {
16
	return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
17
		templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
18
		if !templ_7745c5c3_IsBuffer {
19
			templ_7745c5c3_Buffer = templ.GetBuffer()
20
			defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
21
		}
22
		ctx = templ.InitializeContext(ctx)
23
		templ_7745c5c3_Var1 := templ.GetChildren(ctx)
24
		if templ_7745c5c3_Var1 == nil {
25
			templ_7745c5c3_Var1 = templ.NopComponent
26
		}
27
		ctx = templ.ClearChildren(ctx)
28
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"en\" data-theme=\"dark\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"Go/Echo+Templ+Htmx: Full stack application using Golang&#39;s Echo framework &amp; Templ templating language with user session management + CRUD to a SQLite database (To Do List) and HTMX in the frontend\"><script src=\"https://unpkg.com/[email protected]\"></script><meta name=\"google\" content=\"notranslate\"><title>")
29
		if templ_7745c5c3_Err != nil {
30
			return templ_7745c5c3_Err
31
		}
32
		var templ_7745c5c3_Var2 string
33
		templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title)
34
		if templ_7745c5c3_Err != nil {
35
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/layout/base.layout.templ`, Line: 18, Col: 17}
36
		}
37
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
38
		if templ_7745c5c3_Err != nil {
39
			return templ_7745c5c3_Err
40
		}
41
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</title><script src=\"/htmx.min.js\"></script><script src=\"https://cdn.tailwindcss.com\"></script><link href=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/full.min.css\" rel=\"stylesheet\" type=\"text/css\"></head><body class=\"sample-transition\" hx-boost=\"true\"><header>")
42
		if templ_7745c5c3_Err != nil {
43
			return templ_7745c5c3_Err
44
		}
45
		if !isError {
46
			templ_7745c5c3_Err = partials.Navbar(username, fromProtected).Render(ctx, templ_7745c5c3_Buffer)
47
			if templ_7745c5c3_Err != nil {
48
				return templ_7745c5c3_Err
49
			}
50
		}
51
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</header>")
52
		if templ_7745c5c3_Err != nil {
53
			return templ_7745c5c3_Err
54
		}
55
		var templ_7745c5c3_Var3 = []any{}
56
		templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var3...)
57
		if templ_7745c5c3_Err != nil {
58
			return templ_7745c5c3_Err
59
		}
60
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<main class=\"")
61
		if templ_7745c5c3_Err != nil {
62
			return templ_7745c5c3_Err
63
		}
64
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ.CSSClasses(templ_7745c5c3_Var3).String()))
65
		if templ_7745c5c3_Err != nil {
66
			return templ_7745c5c3_Err
67
		}
68
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
69
		if templ_7745c5c3_Err != nil {
70
			return templ_7745c5c3_Err
71
		}
72
		templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer)
73
		if templ_7745c5c3_Err != nil {
74
			return templ_7745c5c3_Err
75
		}
76
		templ_7745c5c3_Err = partials.FlashMessages(errMsgs, sucMsgs).Render(ctx, templ_7745c5c3_Buffer)
77
		if templ_7745c5c3_Err != nil {
78
			return templ_7745c5c3_Err
79
		}
80
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</main></body></html>")
81
		if templ_7745c5c3_Err != nil {
82
			return templ_7745c5c3_Err
83
		}
84
		if !templ_7745c5c3_IsBuffer {
85
			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
86
		}
87
		return templ_7745c5c3_Err
88
	})
89
}
90