1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
package useflags
import "net/http"
import "strconv"
import "strings"
import "soko/pkg/app/layout"
import "soko/pkg/database"
import "soko/pkg/models"
import "github.com/go-pg/pg/v10"
templ showUseflagHeader(useflag models.Useflag) {
<div class="kk-header-container">
<div class="container">
<div class="row">
<div class="col-12">
<div class="row mt-3 pt-2">
<div class="col-md-5">
<h1 class="stick-top kk-package-title" id="package-title">
<small class="kk-package-cat">
<a href="/useflags" class={ "text-dark", "ml-1", templ.KV("text-capitalize", useflag.UseExpand == "") }>
if useflag.UseExpand != "" {
{ useflag.UseExpand }
} else {
{ useflag.Scope } USE flag
}
</a>
</small>
<div>
<div class="kk-package-name" style="margin-left: 0px!important;">
<span class="fa fa-fw fa-sliders"></span>
<span class="ml-2">
if useflag.UseExpand != "" {
{ strings.TrimPrefix(useflag.Name, useflag.UseExpand + "_") }
} else {
{ useflag.Name }
}
</span>
</div>
</div>
</h1>
</div>
if useflag.Scope != "local" {
<div class="col-md-7">
<p class="lead kk-package-maindesc">
{ useflag.Description }
</p>
</div>
}
<div class="col-md-12 pt-4 mt-1"></div>
</div>
</div>
</div>
</div>
</div>
}
templ show(useflag models.Useflag, localUseflags, otherUseExpands []models.Useflag, Packages []string) {
@showUseflagHeader(useflag)
<div class="tab-content" id="myTabContent">
<div class="container mb-5">
<div class="row">
<div class="col-12">
if len(otherUseExpands) != 0 {
<h3 class="mb-2">Other “{ useflag.UseExpand }” USE_EXPAND flag values</h3>
<div class="card">
<div class="table-responsive">
<table class="table">
<thead>
<th>Use Flag</th>
<th>Description</th>
</thead>
<tbody>
for _, use := range otherUseExpands {
<tr>
<th class="kk-nobreak-cell">
<a href={ templ.URL("/useflags/" + use.Name) }>{ use.Name }</a>
</th>
<td>{ use.Description }</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
if len(localUseflags) != 0 {
<h3 class="mb-2">Packages describing “{ useflag.Name }” as local USE flag</h3>
<div class="card mb-4 border-top-0">
<div class="table-responsive">
<table class="table mb-0">
<thead>
<th>Package</th>
<th>“{ useflag.Name }” Flag Description</th>
</thead>
<tbody>
for _, use := range localUseflags {
<tr>
<th class="kk-nobreak-cell">
<a href={ templ.URL("/packages/" + use.Package) }>{ use.Package }</a>
</th>
<td>{ use.Description }</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
if len(Packages) != 0 {
<h3 class="mb-2 pt-2">All packages providing a “{ useflag.Name }” USE flag ({ strconv.Itoa(len(Packages)) })</h3>
<div class="card">
<div class="card-body">
<ul class="kk-col-list kk-3col-list kk-useflag-listing mb-0">
for _, pkg := range Packages {
<li><a href={ templ.URL("/packages/" + pkg) }>{ pkg }</a></li>
}
</ul>
</div>
</div>
}
</div>
</div>
</div>
</div>
}
// Show renders a template to show a given USE flag
func Show(w http.ResponseWriter, r *http.Request) {
useFlagName := r.PathValue("useflag")
var useflags []models.Useflag
err := database.DBCon.Model(&useflags).
Where("name = ?", useFlagName).
Order("scope", "package").
Select()
if err != nil || len(useflags) < 1 {
http.NotFound(w, r)
return
}
var packages []string
err = database.DBCon.Model((*models.Version)(nil)).
Column("atom").Distinct().
Where("useflags::jsonb @> ?", "\""+useFlagName+"\"").
Order("atom").
Select(&packages)
if err != nil && err != pg.ErrNoRows {
http.Error(w, http.StatusText(http.StatusInternalServerError),
http.StatusInternalServerError)
return
}
useflag := useflags[0]
var localUseFlags, otherUseExpands []models.Useflag
if use := useflags[len(useflags)-1]; use.Scope == "use_expand" {
err := database.DBCon.Model(&otherUseExpands).
Column("name", "description").
Where("use_expand = ?", useflag.UseExpand).
Order("name").
Select()
if err != nil && err != pg.ErrNoRows {
http.Error(w, http.StatusText(http.StatusInternalServerError),
http.StatusInternalServerError)
return
}
} else if useflag.Scope == "global" {
localUseFlags = useflags[1:]
} else {
localUseFlags = useflags
}
layout.Layout(useFlagName, "useflags",
show(useflag, localUseFlags, otherUseExpands, packages)).Render(r.Context(), w)
}
|