diff --git a/modules/yaml/yaml.go b/modules/yaml/yaml.go index aaf6ac426037b..a5c07e873e7ba 100644 --- a/modules/yaml/yaml.go +++ b/modules/yaml/yaml.go @@ -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("%v", 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("%v", value) } @@ -65,9 +74,10 @@ func renderVerticalHtmlTable(m []yaml.MapSlice) string { value := mi.Value table += `` - 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) @@ -78,9 +88,10 @@ func renderVerticalHtmlTable(m []yaml.MapSlice) string { } table += fmt.Sprintf("%v", 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{}) { @@ -88,11 +99,14 @@ func renderVerticalHtmlTable(m []yaml.MapSlice) string { } value = renderVerticalHtmlTable(v) } - if key == "slug" { + + switch key { + case "slug": value = fmt.Sprintf(`%v`, value, value) + case "link": + value = fmt.Sprintf(`%v`, value, value) } table += fmt.Sprintf("%v", value) - table += `` } table += "" diff --git a/routers/repo/view.go b/routers/repo/view.go index a2ef9ad0af16f..3437334b698c5 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -196,20 +196,20 @@ 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 { - rendered, err := yaml.RenderYaml(buf) - if err == nil { + } else if isTocYaml { + if rendered, err := yaml.RenderYaml(buf); err != nil { + ctx.Flash.ErrorMsg = fmt.Sprintf("Unable to parse %v", err) + ctx.Data["Flash"] = ctx.Flash + ctx.Data["FileContent"] = string(buf) + } else { ctx.Data["FileContent"] = string(rendered) - break } - ctx.Flash.ErrorMsg = fmt.Sprintf("Unable to parse YAML: %v", err) - ctx.Data["Flash"] = ctx.Flash } else { // Building code view blocks with line number on server side. var fileContent string diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index c4034324a6860..f5a092ccb6779 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -36,12 +36,12 @@ {{end}}
-
+
{{if .IsMarkdown}}
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
- {{else if .IsYaml}} + {{else if .IsTocYaml}}
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}