Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

Commit

Permalink
Changes due to deprecation to Assets finding in 2.6 (#74)
Browse files Browse the repository at this point in the history
* Changes due to deprecation to Assets finding in 2.6

* Using implicits to clean HomeController
  • Loading branch information
rutaihwa authored and wsargent committed Mar 17, 2018
1 parent d36b404 commit dc2b3fe
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
4 changes: 3 additions & 1 deletion app/controllers/HomeController.scala
@@ -1,14 +1,16 @@
package controllers

import javax.inject._

import play.api.mvc._

/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
@Singleton
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
class HomeController @Inject()(cc: ControllerComponents) (implicit assetsFinder: AssetsFinder)
extends AbstractController(cc) {

/**
* Create an Action to render an HTML page with a welcome message.
Expand Down
8 changes: 4 additions & 4 deletions app/views/index.scala.html
@@ -1,15 +1,15 @@
@*
* This template takes a single argument, a String containing a
* message to display.
* This template takes a two arguments, a String containing a
* message to display and an AssetsFinder to locate static assets.
*@
@(message: String)
@(message: String)(implicit assetsFinder: AssetsFinder)

@*
* Call the `main` template with two arguments. The first
* argument is a `String` with the title of the page, the second
* argument is an `Html` object containing the body of the page.
*@
@main("Welcome to Play") {
@main("Welcome to Play", assetsFinder) {

@*
* Get an `Html` object by calling the built-in Play welcome
Expand Down
13 changes: 7 additions & 6 deletions app/views/main.scala.html
@@ -1,19 +1,20 @@
@*
* This template is called from the `index` template. This template
* handles the rendering of the page header and body tags. It takes
* two arguments, a `String` for the title of the page and an `Html`
* object to insert into the body of the page.
* three arguments, a `String` for the title of the page and an `Html`
* object to insert into the body of the page and an `AssetFinder`
* to define to reverse route static assets.
*@
@(title: String)(content: Html)
@(title: String, assetsFinder: AssetsFinder)(content: Html)

<!DOCTYPE html>
<html lang="en">
<head>
@* Here's where we render the page title `String`. *@
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
<link rel="stylesheet" media="screen" href="@assetsFinder.path("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@assetsFinder.path("images/favicon.png")">
<script src="@assetsFinder.path("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@* And here's where we render the `Html` object containing
Expand Down
9 changes: 9 additions & 0 deletions conf/application.conf
Expand Up @@ -347,3 +347,12 @@ db {
# https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
#default.logSql=true
}

## Static assets
# Using configuration and assets finder
# https://www.playframework.com/documentation/latest/AssetsOverview
# Since
play.assets {
path = "/public"
urlPrefix = "/assets"
}
2 changes: 1 addition & 1 deletion conf/routes
Expand Up @@ -10,4 +10,4 @@ GET /count controllers.CountController.count
GET /message controllers.AsyncController.message

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /assets/*file controllers.Assets.versioned(file)

0 comments on commit dc2b3fe

Please sign in to comment.