| Conditions | 23 |
| Total Lines | 83 |
| Code Lines | 62 |
| 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 partials.FlashMessages 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. |
||
| 13 | func FlashMessages(errMsgs, sucMsgs []string) templ.Component { |
||
| 14 | return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { |
||
| 15 | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) |
||
| 16 | if !templ_7745c5c3_IsBuffer { |
||
| 17 | templ_7745c5c3_Buffer = templ.GetBuffer() |
||
| 18 | defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) |
||
| 19 | } |
||
| 20 | ctx = templ.InitializeContext(ctx) |
||
| 21 | templ_7745c5c3_Var1 := templ.GetChildren(ctx) |
||
| 22 | if templ_7745c5c3_Var1 == nil { |
||
| 23 | templ_7745c5c3_Var1 = templ.NopComponent |
||
| 24 | } |
||
| 25 | ctx = templ.ClearChildren(ctx) |
||
| 26 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div>") |
||
| 27 | if templ_7745c5c3_Err != nil { |
||
| 28 | return templ_7745c5c3_Err |
||
| 29 | } |
||
| 30 | if len(errMsgs) != 0 { |
||
| 31 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div role=\"alert\" class=\"alert alert-error w-fit min-w-[384px] mx-auto mt-12\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"stroke-current shrink-0 h-6 w-6\" fill=\"none\" viewBox=\"0 0 24 24\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z\"></path></svg> ") |
||
| 32 | if templ_7745c5c3_Err != nil { |
||
| 33 | return templ_7745c5c3_Err |
||
| 34 | } |
||
| 35 | for _, msg := range errMsgs { |
||
| 36 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span>") |
||
| 37 | if templ_7745c5c3_Err != nil { |
||
| 38 | return templ_7745c5c3_Err |
||
| 39 | } |
||
| 40 | var templ_7745c5c3_Var2 string |
||
| 41 | templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(msg) |
||
| 42 | if templ_7745c5c3_Err != nil { |
||
| 43 | return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/partials/flashmessages.partial.templ`, Line: 18, Col: 16} |
||
| 44 | } |
||
| 45 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) |
||
| 46 | if templ_7745c5c3_Err != nil { |
||
| 47 | return templ_7745c5c3_Err |
||
| 48 | } |
||
| 49 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span>") |
||
| 50 | if templ_7745c5c3_Err != nil { |
||
| 51 | return templ_7745c5c3_Err |
||
| 52 | } |
||
| 53 | } |
||
| 54 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<button class=\"text-3xl font-black\" _=\"on click remove the closest <div/>\">×</button></div>") |
||
| 55 | if templ_7745c5c3_Err != nil { |
||
| 56 | return templ_7745c5c3_Err |
||
| 57 | } |
||
| 58 | } |
||
| 59 | if len(sucMsgs) != 0 { |
||
| 60 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div role=\"alert\" class=\"alert alert-success w-fit min-w-[384px] mx-auto mt-12\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"stroke-current shrink-0 h-6 w-6\" fill=\"none\" viewBox=\"0 0 24 24\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z\"></path></svg> ") |
||
| 61 | if templ_7745c5c3_Err != nil { |
||
| 62 | return templ_7745c5c3_Err |
||
| 63 | } |
||
| 64 | for _, msg := range sucMsgs { |
||
| 65 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span>") |
||
| 66 | if templ_7745c5c3_Err != nil { |
||
| 67 | return templ_7745c5c3_Err |
||
| 68 | } |
||
| 69 | var templ_7745c5c3_Var3 string |
||
| 70 | templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(msg) |
||
| 71 | if templ_7745c5c3_Err != nil { |
||
| 72 | return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/partials/flashmessages.partial.templ`, Line: 39, Col: 16} |
||
| 73 | } |
||
| 74 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) |
||
| 75 | if templ_7745c5c3_Err != nil { |
||
| 76 | return templ_7745c5c3_Err |
||
| 77 | } |
||
| 78 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span>") |
||
| 79 | if templ_7745c5c3_Err != nil { |
||
| 80 | return templ_7745c5c3_Err |
||
| 81 | } |
||
| 82 | } |
||
| 83 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<button class=\"text-3xl font-black\" _=\"on click remove the closest <div/>\">×</button></div>") |
||
| 84 | if templ_7745c5c3_Err != nil { |
||
| 85 | return templ_7745c5c3_Err |
||
| 86 | } |
||
| 87 | } |
||
| 88 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>") |
||
| 89 | if templ_7745c5c3_Err != nil { |
||
| 90 | return templ_7745c5c3_Err |
||
| 91 | } |
||
| 92 | if !templ_7745c5c3_IsBuffer { |
||
| 93 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) |
||
| 94 | } |
||
| 95 | return templ_7745c5c3_Err |
||
| 96 | }) |
||
| 98 |