Skip to content

Feature - Issue #170 - Update YAML Viewer #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions modules/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,22 @@ func renderHorizontalHtmlTable(m yaml.MapSlice) string {
key := mi.Key
value := mi.Value

if key != nil && reflect.TypeOf(key).String() == "yaml.MapSlice" {
switch key.(type) {
case yaml.MapSlice:
key = renderHorizontalHtmlTable(key.(yaml.MapSlice))
}
thead += fmt.Sprintf("<th>%v</th>", key)

if value != nil && reflect.TypeOf(value).String() == "yaml.MapSlice" {
switch value.(type) {
case yaml.MapSlice:
value = renderHorizontalHtmlTable(value.(yaml.MapSlice))
case []interface {}:
value = value.([]interface{})
v := make([]yaml.MapSlice, len(value.([]interface{})))
for i, vs := range value.([]interface{}) {
v[i] = vs.(yaml.MapSlice)
}
value = renderVerticalHtmlTable(v)
}
tbody += fmt.Sprintf("<td>%v</td>", value)
}
Expand All @@ -65,9 +74,10 @@ func renderVerticalHtmlTable(m []yaml.MapSlice) string {
value := mi.Value

table += `<tr>`
if key != nil && reflect.TypeOf(key).String() == "yaml.MapSlice" {
switch key.(type) {
case yaml.MapSlice:
key = renderHorizontalHtmlTable(key.(yaml.MapSlice))
} else if key != nil && reflect.TypeOf(key).String() == "[]interface {}" {
case []interface {}:
var ks string
for _, ki := range key.([]interface{}) {
log.Info("KI: %v", ki)
Expand All @@ -78,21 +88,25 @@ func renderVerticalHtmlTable(m []yaml.MapSlice) string {
}
table += fmt.Sprintf("<td>%v</td>", key)

if value != nil && reflect.TypeOf(value).String() == "yaml.MapSlice" {
switch value.(type) {
case yaml.MapSlice:
value = renderHorizontalHtmlTable(value.(yaml.MapSlice))
} else if value != nil && reflect.TypeOf(value).String() == "[]interface {}" {
case []interface {}:
value = value.([]interface{})
v := make([]yaml.MapSlice, len(value.([]interface{})))
for i, vs := range value.([]interface{}) {
v[i] = vs.(yaml.MapSlice)
}
value = renderVerticalHtmlTable(v)
}
if key == "slug" {

switch key {
case "slug":
value = fmt.Sprintf(`<a href="content/%v.md">%v</a>`, value, value)
case "link":
value = fmt.Sprintf(`<a href="%v/01.md">%v</a>`, value, value)
}
table += fmt.Sprintf("<td>%v</td>", value)

table += `</tr>`
}
table += "</table>"
Expand Down
6 changes: 3 additions & 3 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st

readmeExist := isSupportedMarkup || markup.IsReadmeFile(blob.Name())
ctx.Data["ReadmeExist"] = readmeExist
isYaml := yaml.IsYamlFile(blob.Name())
ctx.Data["IsYaml"] = isYaml
isTocYaml := blob.Name() == "toc.yaml"
ctx.Data["IsTocYaml"] = isTocYaml
if readmeExist && isSupportedMarkup {
yamlHtml := yaml.RenderMarkdownYaml(buf)
markupBody := markup.Render(blob.Name(), yaml.StripYamlFromText(buf), path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())
ctx.Data["FileContent"] = string(append(yamlHtml, markupBody...))
} else if isYaml {
} else if isTocYaml {
rendered, err := yaml.RenderYaml(buf)
if err == nil {
ctx.Data["FileContent"] = string(rendered)
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
{{end}}
</h4>
<div class="ui attached table segment">
<div class="file-view {{if .IsMarkdown}}markdown{{else if .IsYaml}}markdown yaml{{else if .IsTextFile}}code-view{{end}} has-emoji">
<div class="file-view {{if .IsMarkdown}}markdown{{else if .IsTocYaml}}markdown yaml{{else if .IsTextFile}}code-view{{end}} has-emoji">
{{if .IsMarkdown}}
<article class="markdown-body" itemprop="text">
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
</article>
{{else if .IsYaml}}
{{else if .IsTocYaml}}
<article class="markdown-body" itemprop="text">
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
</article>
Expand Down