Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves to conf-based Assets management (like the scala starter sample) #83

Merged
merged 3 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion play-java-starter-example/app/controllers/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@

import views.html.*;

import javax.inject.Inject;

/**
* This controller contains an action to handle HTTP requests
* to the application's home page.
*/
public class HomeController extends Controller {

private final AssetsFinder assetsFinder;

@Inject
public HomeController(AssetsFinder assetsFinder) {
this.assetsFinder = assetsFinder;
}

/**
* An action that renders an HTML page with a welcome message.
* The configuration in the <code>routes</code> file means that
* this method will be called when the application receives a
* <code>GET</code> request with a path of <code>/</code>.
*/
public Result index() {
return ok(index.render("Your new application is ready."));
return ok(
index.render(
"Your new application is ready.",
assetsFinder
));
}

}
8 changes: 4 additions & 4 deletions play-java-starter-example/app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@*
* This template takes a single argument, a String containing a
* message to display.
*@
@(message: String)
* This template takes a two arguments, a String containing a
* message to display and an AssetsFinder to locate static assets.
*@
@(message: String)(implicit assetsFinder: AssetsFinder)

@*
* Call the `main` template with two arguments. The first
Expand Down
8 changes: 4 additions & 4 deletions play-java-starter-example/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* two arguments, a `String` for the title of the page and an `Html`
* object to insert into the body of the page.
*@
@(title: String)(content: Html)
@(title: String)(content: Html)(implicit assetsFinder: AssetsFinder)

<!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
10 changes: 7 additions & 3 deletions play-java-starter-example/app/views/welcome.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ <h2>Why do you see this page?</h2>
</p>

<pre><code>public Result index() {
return ok(index.render("Your new application is ready."));
return ok(
index.render(
"Your new application is ready.",
assetsFinder
));
}</code></pre>

<p>
Expand All @@ -51,11 +55,11 @@ <h2>Why do you see this page?</h2>
The template is defined in the <code>app/views/index.scala.html</code> file and compiled as a standard Java class.
</p>

<pre><code>@@(message: String)
<pre><code>@@(message: String)(implicit assetsFinder: AssetsFinder)

@@main("Welcome to Play") {

@@play20.welcome(message, style = "Java")
@@welcome(message, style = "Java")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While doing applies changes after the PR comments, I've noticed welcome.scala.html had yet another copy of the code. I've raised #84 to tackle this never-ending duplication.


}</code></pre>

Expand Down
2 changes: 1 addition & 1 deletion play-java-starter-example/conf/routes
Original file line number Diff line number Diff line change
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)
2 changes: 1 addition & 1 deletion play-scala-starter-example/app/views/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* 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", assetsFinder) {
@main("Welcome to Play") {

@*
* Get an `Html` object by calling the built-in Play welcome
Expand Down
2 changes: 1 addition & 1 deletion play-scala-starter-example/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* object to insert into the body of the page and an `AssetFinder`
* to define to reverse route static assets.
*@
@(title: String, assetsFinder: AssetsFinder)(content: Html)
@(title: String)(content: Html)(implicit assetsFinder: AssetsFinder)

<!DOCTYPE html>
<html lang="en">
Expand Down
2 changes: 1 addition & 1 deletion play-scala-starter-example/app/views/welcome.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2>Why do you see this page?</h2>
The template is defined in the <code>app/views/index.scala.html</code> file and compiled as a Scala function.
</p>

<pre><code>@@(message: String)
<pre><code>@@(message: String)(implicit assetsFinder: AssetsFinder)

@@main("Welcome to Play") {

Expand Down