layout.Base   F
last analyzed

Complexity

Conditions 31

Size

Total Lines 128
Code Lines 99

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 31
eloc 99
nop 4
dl 0
loc 128
rs 0
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.663
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
import "github.com/memnix/memnix-rest/domain"
15
16
func Base(title, username string, fromProtected bool, nonce domain.Nonce) templ.Component {
17
	return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
18
		templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
19
		if !templ_7745c5c3_IsBuffer {
20
			templ_7745c5c3_Buffer = templ.GetBuffer()
21
			defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
22
		}
23
		ctx = templ.InitializeContext(ctx)
24
		templ_7745c5c3_Var1 := templ.GetChildren(ctx)
25
		if templ_7745c5c3_Var1 == nil {
26
			templ_7745c5c3_Var1 = templ.NopComponent
27
		}
28
		ctx = templ.ClearChildren(ctx)
29
		_, 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=\"A spaced repetition app boosted by AI for learning and memorizing anything.\"><meta name=\"htmx-config\" content=\"{&#34;selfRequestsOnly&#34;:&#34;true&#34;}\"><meta name=\"google\" content=\"notranslate\"><link rel=\"stylesheet\" href=\"/static/css/pico.orange.min.css\" nonce=\"")
30
		if templ_7745c5c3_Err != nil {
31
			return templ_7745c5c3_Err
32
		}
33
		var templ_7745c5c3_Var2 string
34
		templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(nonce.PicoCSSNonce)
35
		if templ_7745c5c3_Err != nil {
36
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/layout/base.layout.templ`, Line: 18, Col: 91}
37
		}
38
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
39
		if templ_7745c5c3_Err != nil {
40
			return templ_7745c5c3_Err
41
		}
42
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><script src=\"/static/js/css-scope-inline.js\" nonce=\"")
43
		if templ_7745c5c3_Err != nil {
44
			return templ_7745c5c3_Err
45
		}
46
		var templ_7745c5c3_Var3 string
47
		templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(nonce.CSSScopeInlineNonce)
48
		if templ_7745c5c3_Err != nil {
49
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/layout/base.layout.templ`, Line: 19, Col: 81}
50
		}
51
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
52
		if templ_7745c5c3_Err != nil {
53
			return templ_7745c5c3_Err
54
		}
55
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></script><title>")
56
		if templ_7745c5c3_Err != nil {
57
			return templ_7745c5c3_Err
58
		}
59
		var templ_7745c5c3_Var4 string
60
		templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(title)
61
		if templ_7745c5c3_Err != nil {
62
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/layout/base.layout.templ`, Line: 21, Col: 17}
63
		}
64
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
65
		if templ_7745c5c3_Err != nil {
66
			return templ_7745c5c3_Err
67
		}
68
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</title><script src=\"/static/js/htmx.min.js\" nonce=\"")
69
		if templ_7745c5c3_Err != nil {
70
			return templ_7745c5c3_Err
71
		}
72
		var templ_7745c5c3_Var5 string
73
		templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(nonce.HtmxNonce)
74
		if templ_7745c5c3_Err != nil {
75
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/layout/base.layout.templ`, Line: 22, Col: 63}
76
		}
77
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
78
		if templ_7745c5c3_Err != nil {
79
			return templ_7745c5c3_Err
80
		}
81
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" defer></script><script src=\"/static/js/hyperscript.min.js\" nonce=\"")
82
		if templ_7745c5c3_Err != nil {
83
			return templ_7745c5c3_Err
84
		}
85
		var templ_7745c5c3_Var6 string
86
		templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(nonce.HyperscriptNonce)
87
		if templ_7745c5c3_Err != nil {
88
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/layout/base.layout.templ`, Line: 23, Col: 77}
89
		}
90
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
91
		if templ_7745c5c3_Err != nil {
92
			return templ_7745c5c3_Err
93
		}
94
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" defer></script><script src=\"/static/js/preload.js\" nonce=\"")
95
		if templ_7745c5c3_Err != nil {
96
			return templ_7745c5c3_Err
97
		}
98
		var templ_7745c5c3_Var7 string
99
		templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(nonce.PreloadNonce)
100
		if templ_7745c5c3_Err != nil {
101
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/layout/base.layout.templ`, Line: 24, Col: 65}
102
		}
103
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
104
		if templ_7745c5c3_Err != nil {
105
			return templ_7745c5c3_Err
106
		}
107
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" defer></script><script defer nonce=\"")
108
		if templ_7745c5c3_Err != nil {
109
			return templ_7745c5c3_Err
110
		}
111
		var templ_7745c5c3_Var8 string
112
		templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(nonce.UmamiNonce)
113
		if templ_7745c5c3_Err != nil {
114
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/layout/base.layout.templ`, Line: 25, Col: 41}
115
		}
116
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
117
		if templ_7745c5c3_Err != nil {
118
			return templ_7745c5c3_Err
119
		}
120
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" src=\"https://umami.memnix.app/script.js\" data-domains=\"beta.memnix.app,memnix.app\" data-website-id=\"9dde32bf-4daa-4d93-9d66-c22c74895024\"></script><link rel=\"icon\" href=\"/static/img/favicon.ico\" type=\"image/x-icon\"></head><body class=\"sample-transition\" hx-boost=\"true\" hx-ext=\"preload\"><header class=\"container\">")
121
		if templ_7745c5c3_Err != nil {
122
			return templ_7745c5c3_Err
123
		}
124
		templ_7745c5c3_Err = partials.Navbar(username, fromProtected).Render(ctx, templ_7745c5c3_Buffer)
125
		if templ_7745c5c3_Err != nil {
126
			return templ_7745c5c3_Err
127
		}
128
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</header><main class=\"container\">")
129
		if templ_7745c5c3_Err != nil {
130
			return templ_7745c5c3_Err
131
		}
132
		templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer)
133
		if templ_7745c5c3_Err != nil {
134
			return templ_7745c5c3_Err
135
		}
136
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</main><footer></footer></body></html>")
137
		if templ_7745c5c3_Err != nil {
138
			return templ_7745c5c3_Err
139
		}
140
		if !templ_7745c5c3_IsBuffer {
141
			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
142
		}
143
		return templ_7745c5c3_Err
144
	})
145
}
146