Yi EungJun 2014-02-21
config: Add application.siteName configuration
You can set your site's name by editing application.siteName in
conf/application.conf. The name is used in the title bar of your web
browser, the main page, the welcome page, the login page and many
others.
@9a6fd581008fbf37c302a8ae0a88dbccf2447a44
app/actors/ValidationEmailSender.java
--- app/actors/ValidationEmailSender.java
+++ app/actors/ValidationEmailSender.java
@@ -46,9 +46,9 @@
         final HtmlEmail htmlEmail = new HtmlEmail();
 
         try {
-            htmlEmail.setFrom(Config.getEmailFromSmtp(), Messages.get("app.name"));
+            htmlEmail.setFrom(Config.getEmailFromSmtp(), utils.Config.getSiteName());
             htmlEmail.addTo(email.email, email.user.name);
-            htmlEmail.setSubject(Messages.get("emails.validation.email.title"));
+            htmlEmail.setSubject(Messages.get("emails.validation.email.title", utils.Config.getSiteName()));
             htmlEmail.setHtmlMsg(getMessage(email.confirmUrl));
             htmlEmail.setCharset("utf-8");
             Mailer.send(htmlEmail);
app/controllers/PasswordResetApp.java
--- app/controllers/PasswordResetApp.java
+++ app/controllers/PasswordResetApp.java
@@ -85,7 +85,7 @@
         try {
             SimpleEmail email = new SimpleEmail();
             email.setFrom(sender)
-                 .setSubject("[" + Messages.get("app.name") + "] " + Messages.get("site.resetPasswordEmail.title"))
+                 .setSubject("[" + utils.Config.getSiteName() + "] " + Messages.get("site.resetPasswordEmail.title"))
                  .addTo(user.email)
                  .setMsg(Messages.get("site.resetPasswordEmail.mailContents") + "\n\n" + resetPasswordUrl)
                  .setCharset("utf-8");
app/models/NotificationMail.java
--- app/models/NotificationMail.java
+++ app/models/NotificationMail.java
@@ -125,7 +125,7 @@
 
         try {
             email.setFrom(Config.getEmailFromSmtp(), event.getSender().name);
-            email.addTo(Config.getEmailFromSmtp(), "Yobi");
+            email.addTo(Config.getEmailFromSmtp(), utils.Config.getSiteName());
 
             for (User receiver : receivers) {
                 email.addBcc(receiver.email, receiver.name);
@@ -171,7 +171,7 @@
 
         if (urlToView != null) {
             doc.body().append(String.format("<hr><a href=\"%s\">%s</a>", urlToView,
-                    "View it on Yobi"));
+                    "View it on " + utils.Config.getSiteName()));
         }
 
         return doc.html();
app/utils/Config.java
--- app/utils/Config.java
+++ app/utils/Config.java
@@ -1,6 +1,7 @@
 
 package utils;
 
+import org.apache.commons.lang3.ObjectUtils;
 import play.Configuration;
 import play.mvc.Http;
 
@@ -10,6 +11,11 @@
 public class Config {
     public static final String DEFAULT_SCHEME = "http";
 
+    public static String getSiteName() {
+        return ObjectUtils.defaultIfNull(
+                play.Configuration.root().getString("application.siteName"), "Yobi");
+    }
+
     public static String getHostport(String defaultValue) {
         play.Configuration config = play.Configuration.root();
 
app/views/code/nohead.scala.html
--- app/views/code/nohead.scala.html
+++ app/views/code/nohead.scala.html
@@ -24,23 +24,23 @@
     		<div class="span12">
     			@Html(Messages("code.nohead"))
     @if(isAllowed(UserApp.currentUser(), project.asResource(), Operation.UPDATE)) {
-                <h5>@Messages("code.nohead.clone", Messages("app.name"))</h5>
+                <h5>@Messages("code.nohead.clone", utils.Config.getSiteName)</h5>
     			<pre><code>git clone @getCodeURL(project)
     cd @project.name/
     echo "# @project.name" > README.md
     git add README.md
-    git commit -m "Hello @Messages("app.name")"
+    git commit -m "Hello @utils.Config.getSiteName"
     git push origin master</code></pre>
-                <h5>@Messages("code.nohead.init", Messages("app.name"))</h5>
+                <h5>@Messages("code.nohead.init", utils.Config.getSiteName)</h5>
                 <pre><code>mkdir @project.name
     cd @project.name/
     echo "# @project.name" > README.md
     git init
     git add README.md
-    git commit -m "Hello @Messages("app.name")"
+    git commit -m "Hello @utils.Config.getSiteName"
     git remote add origin @getCodeURL(project)
     git push origin master</code></pre>
-                <h5>@Messages("code.nohead.remote", Messages("app.name"))</h5>
+                <h5>@Messages("code.nohead.remote", utils.Config.getSiteName)</h5>
                 <pre><code>git remote add origin @getCodeURL(project)
     git push origin master</code></pre>
                 <h5>@Messages("code.nohead.pull.push")</h5>
app/views/code/nohead_svn.scala.html
--- app/views/code/nohead_svn.scala.html
+++ app/views/code/nohead_svn.scala.html
@@ -31,7 +31,7 @@
             <div class="span12">
                 @Html(Messages("code.nohead"))
                 @if(isAllowed(UserApp.currentUser(), project.asResource(), Operation.UPDATE)) {
-                <h5>@Messages("code.nohead.svn.clone", Messages("app.name"))</h5>
+                <h5>@Messages("code.nohead.svn.clone", utils.Config.getSiteName)</h5>
                 <pre><code>svn co @CodeApp.getURL(project) --username @UserApp.currentUser().loginId
     cd @project.name/
     echo "# @project.name" > README.md
app/views/error/notfound_default.scala.html
--- app/views/error/notfound_default.scala.html
+++ app/views/error/notfound_default.scala.html
@@ -3,7 +3,7 @@
 @layout(Messages(messageKey))(""){
     <header class="gnb-outer">
         <div class="gnb-inner">
-            <a href="@routes.Application.index()" class="logo"><h1 class="blind">@Messages("app.name")</h1></a>
+            <a href="@routes.Application.index()" class="logo"><h1 class="blind">@utils.Config.getSiteName</h1></a>
             <ul class="gnb-nav">
                 <li>
                     <a href="@routes.ProjectApp.projects()">@Messages("title.projectList")</a>
app/views/index/index.scala.html
--- app/views/index/index.scala.html
+++ app/views/index/index.scala.html
@@ -3,14 +3,14 @@
 @import utils.TemplateHelper._
 @import utils.JodaDateUtil
 
-@siteLayout("app.name", utils.MenuType.SITE_HOME) {
+@siteLayout(utils.Config.getSiteName, utils.MenuType.SITE_HOME) {
     @if(currentUser != User.anonymous){
     <div class="page-wrap-outer">
         <div class="page-wrap">
             <div class="site-guide-outer hide">
                 <h3>
                     <i class="yobicon-emo-wink"></i>
-                    @Messages("app.welcome",Messages("app.name"))
+                    @Messages("app.welcome",utils.Config.getSiteName)
                     <span>@Messages("app.description")</span>
                 </h3>
                 <div class="site-guide-inner">
app/views/index/partial_intro.scala.html
--- app/views/index/partial_intro.scala.html
+++ app/views/index/partial_intro.scala.html
@@ -11,7 +11,7 @@
         </div>
         <div class="signup-btn">
             <a href="@routes.UserApp.signupForm()" class="ybtn ybtn-success ybtn-padding">
-                @Messages("button.signup",Messages("app.name"))
+                @Messages("button.signup",utils.Config.getSiteName)
             </a>
         </div>
     </div>
@@ -69,7 +69,7 @@
             <img src="/assets/images/sample-image.jpg" >
         </div>
         <div class="get-started">
-            <h2>@Html(Messages("title.gettingStarted",Messages("app.name")))</h2>
+            <h2>@Html(Messages("title.gettingStarted",utils.Config.getSiteName))</h2>
 
             <a href="@routes.ProjectApp.newProjectForm()" class="ybtn ybtn-success ybtn-padding">
                 <i class="yobicon-database-add"></i> @Messages("button.newProject")
app/views/issue/my_list.scala.html
--- app/views/issue/my_list.scala.html
+++ app/views/issue/my_list.scala.html
@@ -1,7 +1,7 @@
 @(title: String, currentPage: com.avaje.ebean.Page[Issue], param:
 models.support.SearchCondition, project:Project)
 
-@siteLayout("app.name", utils.MenuType.SITE_HOME) {
+@siteLayout(utils.Config.getSiteName, utils.MenuType.SITE_HOME) {
     <div>
         <button class="btn-transparent" id="toggleIntro"></button>
     </div>
app/views/project/navbar.scala.html
--- app/views/project/navbar.scala.html
+++ app/views/project/navbar.scala.html
@@ -9,7 +9,7 @@
 </div>
 <header class="gnb-outer">
     <div class="gnb-inner">
-        <a href="@routes.Application.index()" class="logo"><h1 class="blind">@Messages("app.name")</h1></a>
+        <a href="@routes.Application.index()" class="logo"><h1 class="blind">@utils.Config.getSiteName</h1></a>
         <ul class="gnb-nav">
             <li>
                 <a href="@routes.ProjectApp.projects()">@Messages("title.projectList")</a>
app/views/site/lostPassword.scala.html
--- app/views/site/lostPassword.scala.html
+++ app/views/site/lostPassword.scala.html
@@ -4,7 +4,7 @@
 <div class="lost-password">
 	<form id="mailForm" method="post" action="@routes.PasswordResetApp.requestResetPasswordEmail()" class="span7 form-horizontal">
 		<div class="control-group controls">
-			<h3 class="title">[@Messages("app.name")] @Messages("site.resetPasswordEmail.title")</h3>
+			<h3 class="title">[@utils.Config.getSiteName] @Messages("site.resetPasswordEmail.title")</h3>
 		</div>
 
         @if(isSent) {
app/views/siteLayout.scala.html
--- app/views/siteLayout.scala.html
+++ app/views/siteLayout.scala.html
@@ -17,7 +17,7 @@
     </div>
     <header class="gnb-outer">
         <div class="gnb-inner">
-            <a href="@routes.Application.index()" class="logo"><h1 class="blind">@Messages("app.name")</h1></a>
+            <a href="@routes.Application.index()" class="logo"><h1 class="blind">@utils.Config.getSiteName</h1></a>
             <ul class="gnb-nav">
                 <li class="@isActiveMenu(MenuType.PROJECTS)">
                     <a href="@routes.ProjectApp.projects()">@Messages("title.projectList")</a>
app/views/user/edit.scala.html
--- app/views/user/edit.scala.html
+++ app/views/user/edit.scala.html
@@ -13,7 +13,7 @@
 <div class="page-wrap-outer">
     <div class="page-wrap">
         <h1 class="page-title">
-            <span class="gray">@Messages("app.name") / </span>
+            <span class="gray">@utils.Config.getSiteName / </span>
             <a href="@routes.UserApp.userInfo(session.get("loginId"))" style="vertical-align:top;">@user.loginId</a>
         </h1>
 
app/views/user/login.scala.html
--- app/views/user/login.scala.html
+++ app/views/user/login.scala.html
@@ -4,7 +4,7 @@
 <div class="page full">
   <div class="center-wrap tag-line-wrap login">
     <h1 class="title">
-      Log In for <span class="high-light">@Messages("app.name")</span>
+      Log In for <span class="high-light">@utils.Config.getSiteName</span>
     </h1>
     <p class="tag-line">Software development platform for Open Source project.</p>
   </div>
app/views/user/signup.scala.html
--- app/views/user/signup.scala.html
+++ app/views/user/signup.scala.html
@@ -6,7 +6,7 @@
 <div class="page full">
   <div class="center-wrap tag-line-wrap signup">
     <h1 class="title">
-      Sign Up for <span class="high-light">@Messages("app.name")</span>
+      Sign Up for <span class="high-light">@utils.Config.getSiteName</span>
     </h1>
     <p class="tag-line">Software development platform for Open Source project.</p>
   </div>
app/views/welcome/restart.scala.html
--- app/views/welcome/restart.scala.html
+++ app/views/welcome/restart.scala.html
@@ -34,7 +34,7 @@
     <div class="container page-wrap">
         <div class="page">
             <div class="secret-wrap">
-                <a href="@routes.Application.index()" class="logo"><span>@Messages("app.name")</span></a>
+                <a href="@routes.Application.index()" class="logo"><span>@utils.Config.getSiteName</span></a>
 
                 <h3>@Messages("app.restart.welcome")</h3>
                 <p class="secret-box txt-center">
@@ -46,7 +46,7 @@
 </div>
 <footer class="page-footer-outer">
     <div class="page-footer">
-        <span class="provider">Powered by <strong>@Messages("app.name")</strong></span>
+        <span class="provider">Powered by <strong>@utils.Config.getSiteName</strong></span>
     </div>
 </footer>
 </body>
app/views/welcome/secret.scala.html
--- app/views/welcome/secret.scala.html
+++ app/views/welcome/secret.scala.html
@@ -4,7 +4,7 @@
 <html>
 <head>
 <meta charset="utf-8">
-<title>@Messages("app.welcome", Messages("app.name"))</title>
+<title>@Messages("app.welcome", utils.Config.getSiteName)</title>
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
@@ -35,9 +35,9 @@
     <div class="container page-wrap">
         <div class="page">
             <div class="secret-wrap">
-                <a href="@routes.Application.index()" class="logo"><span>@Messages("app.name")</span></a>
+                <a href="@routes.Application.index()" class="logo"><span>@utils.Config.getSiteName</span></a>
 
-                <h3>@Messages("app.welcome", Messages("app.name"))</h3>
+                <h3>@Messages("app.welcome", utils.Config.getSiteName)</h3>
 
                 <div class="alert alert-block secret-box">
                     <h4>@Messages("app.welcome.warning.title")</h4>
@@ -118,7 +118,7 @@
 </div>
     <footer class="page-footer-outer">
     <div class="page-footer">
-        <span class="provider">Powered by <strong>@Messages("app.name")</strong></span>
+        <span class="provider">Powered by <strong>@utils.Config.getSiteName</strong></span>
     </div>
 </footer>
 <script type="text/javascript">
conf/application.conf.default
--- conf/application.conf.default
+++ conf/application.conf.default
@@ -1,6 +1,11 @@
 # This is the main configuration file for the application.
 # ~~~~~
 
+# Site Name
+# ~~~~~~~~~
+# The name of your website
+application.siteName="Yobi"
+
 # Notification
 # ~~~~~
 # Notfication email is delivered by default.
test/utils/ConfigTest.java
--- test/utils/ConfigTest.java
+++ test/utils/ConfigTest.java
@@ -62,4 +62,22 @@
         Helpers.stop(app);
     }
 
+    @Test
+    public void getSiteName() {
+        FakeApplication app;
+        Map<String, String> additionalConfiguration = support.Helpers.makeTestConfig();
+
+        additionalConfiguration.put("application.siteName", "my site");
+        app = support.Helpers.makeTestApplication(additionalConfiguration);
+        Helpers.start(app);
+        assertThat(Config.getSiteName()).isEqualTo("my site");
+        Helpers.stop(app);
+
+        // The default is "Yobi".
+        additionalConfiguration.put("application.scheme", null);
+        app = support.Helpers.makeTestApplication(additionalConfiguration);
+        Helpers.start(app);
+        assertThat(Config.getScheme("https")).isEqualTo("Yobi");
+        Helpers.stop(app);
+    }
 }
Add a comment
List