Conditions | 18 |
Total Lines | 71 |
Code Lines | 55 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
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. |
||
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's Echo framework & 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\"><link rel=\"stylesheet\" href=\"/style.css\"><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: 17, 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><link rel=\"preconnect\" href=\"https://fonts.bunny.net\"><link href=\"https://fonts.bunny.net/css?family=nunito:500,600|syne:500,600\" rel=\"stylesheet\"></head><body class=\"sample-transition\" hx-boost=\"true\"><header>") |
||
42 | if templ_7745c5c3_Err != nil { |
||
43 | return templ_7745c5c3_Err |
||
44 | } |
||
45 | templ_7745c5c3_Err = partials.Navbar(username, fromProtected).Render(ctx, templ_7745c5c3_Buffer) |
||
46 | if templ_7745c5c3_Err != nil { |
||
47 | return templ_7745c5c3_Err |
||
48 | } |
||
49 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</header>") |
||
50 | if templ_7745c5c3_Err != nil { |
||
51 | return templ_7745c5c3_Err |
||
52 | } |
||
53 | var templ_7745c5c3_Var3 = []any{} |
||
54 | templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var3...) |
||
55 | if templ_7745c5c3_Err != nil { |
||
56 | return templ_7745c5c3_Err |
||
57 | } |
||
58 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<main class=\"") |
||
59 | if templ_7745c5c3_Err != nil { |
||
60 | return templ_7745c5c3_Err |
||
61 | } |
||
62 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ.CSSClasses(templ_7745c5c3_Var3).String())) |
||
63 | if templ_7745c5c3_Err != nil { |
||
64 | return templ_7745c5c3_Err |
||
65 | } |
||
66 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") |
||
67 | if templ_7745c5c3_Err != nil { |
||
68 | return templ_7745c5c3_Err |
||
69 | } |
||
70 | templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer) |
||
71 | if templ_7745c5c3_Err != nil { |
||
72 | return templ_7745c5c3_Err |
||
73 | } |
||
74 | templ_7745c5c3_Err = partials.FlashMessages(errMsgs, sucMsgs).Render(ctx, templ_7745c5c3_Buffer) |
||
75 | if templ_7745c5c3_Err != nil { |
||
76 | return templ_7745c5c3_Err |
||
77 | } |
||
78 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</main><footer></footer></body></html>") |
||
79 | if templ_7745c5c3_Err != nil { |
||
80 | return templ_7745c5c3_Err |
||
81 | } |
||
82 | if !templ_7745c5c3_IsBuffer { |
||
83 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) |
||
84 | } |
||
85 | return templ_7745c5c3_Err |
||
86 | }) |
||
88 |