summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSondre Nilsen <nilsen.sondre@gmail.com>2017-11-30 06:08:40 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-11-30 13:08:40 +0800
commit86ee41ec033105bec50c1cc4eaf0181a37d71574 (patch)
treeeef6df636e02ec33a18da75d6f189b12bd9e2df8 /modules
parent4cf90aa865c49110af38797b8901185ec072ab74 (diff)
downloadgitea-86ee41ec033105bec50c1cc4eaf0181a37d71574.tar.gz
gitea-86ee41ec033105bec50c1cc4eaf0181a37d71574.zip
Expandable commit bodies (#2980)
* Initial working state of expandable commit bodies * Fix all commits having showing button for multiline commits * Refactor checking multiline messages method * Force newlines with <br> in commit body * Show multiple lines in the list view of repositories * Fixed proper newlines and minor refactor Use <pre> instead of <p>, this is so we can use \n instead of having to manually place <br> into the HTML. Makes it easier to display commit bodies. * Fix commit list messages jumping around * Fix indentation in view_list.tmpl * Use vertical-align: baseline instead of top * Refactor commit button toggle function * Remove RenderCommitBodyLink function * Add comments * Add newline at the end of _repository.less * Fix long commit bodies not properly wrapping inside <pre> * Don't split on double newlines * Show the commit body in commit view * Update stylesheets * Add/fix comments and run make fmt * Fix spaces not being tabs
Diffstat (limited to 'modules')
-rw-r--r--modules/templates/helper.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 2b9e593360..42e465aeaa 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -110,8 +110,10 @@ func NewFuncMap() []template.FuncMap {
"EscapePound": func(str string) string {
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str)
},
- "RenderCommitMessage": RenderCommitMessage,
- "RenderCommitMessageLink": RenderCommitMessageLink,
+ "RenderCommitMessage": RenderCommitMessage,
+ "RenderCommitMessageLink": RenderCommitMessageLink,
+ "RenderCommitBody": RenderCommitBody,
+ "IsMultilineCommitMessage": IsMultilineCommitMessage,
"ThemeColorMetaTag": func() string {
return setting.UI.ThemeColorMetaTag
},
@@ -280,6 +282,29 @@ func renderCommitMessage(msg string, opts markup.RenderIssueIndexPatternOptions)
return template.HTML(msgLines[0])
}
+// RenderCommitBody extracts the body of a commit message without its title.
+func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.HTML {
+ return renderCommitBody(msg, markup.RenderIssueIndexPatternOptions{
+ URLPrefix: urlPrefix,
+ Metas: metas,
+ })
+}
+
+func renderCommitBody(msg string, opts markup.RenderIssueIndexPatternOptions) template.HTML {
+ cleanMsg := template.HTMLEscapeString(msg)
+ fullMessage := string(markup.RenderIssueIndexPattern([]byte(cleanMsg), opts))
+ body := strings.Split(strings.TrimSpace(fullMessage), "\n")
+ if len(body) == 0 {
+ return template.HTML("")
+ }
+ return template.HTML(strings.Join(body[1:], "\n"))
+}
+
+// IsMultilineCommitMessage checks to see if a commit message contains multiple lines.
+func IsMultilineCommitMessage(msg string) bool {
+ return strings.Count(strings.TrimSpace(msg), "\n") > 1
+}
+
// Actioner describes an action
type Actioner interface {
GetOpType() models.ActionType