Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
iss #22: consolidate all project configs & hardcoded value at one object
Browse files Browse the repository at this point in the history
  • Loading branch information
maizy committed Aug 7, 2014
1 parent 3b3a59c commit 80f8f6d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 99 deletions.
2 changes: 1 addition & 1 deletion app/controllers/Frontend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Frontend extends Controller with WithViewContext {
}

def about = Action { implicit request =>
Ok(views.html.about()) //TODO: use project config
Ok(views.html.about())
}

}
7 changes: 3 additions & 4 deletions app/controllers/Status.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package controllers

import play.api.mvc.{Action, Controller}
import play.api.Play.current
import hedgehog.controllers.WithViewContext
import hedgehog.clients.github
import hedgehog.Config.playAppInstance

/**
* Copyright (c) Nikita Kovaliov, maizy.ru, 2013
* Copyright (c) Nikita Kovaliov, maizy.ru, 2013-2014
* See LICENSE.txt for details.
*/
object Status extends Controller with WithViewContext {
def index = Action { implicit request =>
Ok(views.html.status(github.Config.fromPlayApp(current)))
Ok(views.html.status(playAppInstance))
}
}
26 changes: 26 additions & 0 deletions app/hedgehog/Config.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package hedgehog

import play.api.{Configuration, Play}

/**
* Main project config used for wrapping app.configuration,
* store hardcoded values and for other config builders.
*
* Copyright (c) Nikita Kovaliov, maizy.ru, 2014
* See LICENSE.txt for details.
*/
class Config (appConfiguration: Configuration) {
val apiBaseUrl = appConfiguration.getString("github.api_url")
.getOrElse("https://api.github.com").stripSuffix("/")
lazy val githubClientConfig = new hedgehog.clients.github.Config(apiBaseUrl)


val version = "0.0.1" //TODO: sync with build.sbt (generate on project builded)
val projectRepoUrl = "https://github.com/maizy/hedGeHog"
val copyrightYears = "2013-2014"
}


object Config {
val playAppInstance = new Config(Play.current.configuration)
}
10 changes: 0 additions & 10 deletions app/hedgehog/clients/github/Config.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package hedgehog.clients.github

import java.util.regex.Pattern
import play.api.Application

/**
* Copyright (c) Nikita Kovaliov, maizy.ru, 2014
Expand All @@ -27,12 +26,3 @@ class Config(val apiBaseUrl: String) {
}
}
}


object Config {
def fromPlayApp(app: Application) = {
val baseUrl = app.configuration.getString("github.api_url")
.getOrElse("https://api.github.com").stripSuffix("/")
new Config(baseUrl)
}
}
8 changes: 5 additions & 3 deletions app/hedgehog/views/ViewContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import play.api.mvc.{AnyContent, Request}
import play.api.i18n
import play.api.Play.current

import hedgehog.Config.playAppInstance

/**
* Copyright (c) Nikita Kovaliov, maizy.ru, 2013
* See LICENSE.txt for details.
Expand All @@ -13,9 +15,9 @@ class ViewContext(
val requestLang: i18n.Lang) {
lazy val availableLanguages = i18n.Lang.availables
val lang: i18n.Lang = requestLang
val hedgehogRepoUrl = "https://github.com/maizy/hedGeHog"
val version = "0.0.1"
val copyrightYears = "2013-2014"
val projectRepoUrl = playAppInstance.projectRepoUrl
val version = playAppInstance.version
val copyrightYears = playAppInstance.copyrightYears

def Messages(key: String, args: Any*) = {
i18n.Messages(key, args)(lang)
Expand Down
2 changes: 1 addition & 1 deletion app/views/about.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h1>@c.Messages("About")</h1>
<p class="lead">
hedGeHog v&thinsp;@c.version<br/>
@c.Messages("Author"): Nikita Kovaliov, @c.copyrightYears<br/>
<a href="@c.hedgehogRepoUrl">@c.hedgehogRepoUrl</a>
<a href="@c.projectRepoUrl">@c.projectRepoUrl</a>
</p>
</div>
}
2 changes: 1 addition & 1 deletion app/views/parts/footer.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<li>·</li>
<li><a href="@routes.Frontend.about">@c.Messages("footer.About")</a></li>
<li>·</li>
<li><a href="@c.hedgehogRepoUrl/issues?state=open">@c.Messages("footer.Issues")</a></li>
<li><a href="@c.projectRepoUrl/issues?state=open">@c.Messages("footer.Issues")</a></li>
<li>·</li>
<li>
<span class="hedgehog_language-picker b-language-picker-footer">
Expand Down
4 changes: 2 additions & 2 deletions app/views/status.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(githubConfig: hedgehog.clients.github.Config)(implicit c: hedgehog.views.ViewContext)
@(config: hedgehog.Config)(implicit c: hedgehog.views.ViewContext)

@templates.main(nav = "status") {
<h1>@c.Messages("Status")</h1>
Expand All @@ -9,7 +9,7 @@ <h3>Some configs:</h3>
<tbody>
<tr>
<td>github base api url</td>
<td>@githubConfig.apiBaseUrl</td>
<td>@config.apiBaseUrl</td>
</tr>
</tbody>
</table>
Expand Down
77 changes: 0 additions & 77 deletions conf/application.conf

This file was deleted.

0 comments on commit 80f8f6d

Please sign in to comment.