Browse files

Rename variable to contextPathURL

  • Loading branch information...
1 parent e9daccb commit a8afe61225afc5954cc0966c3c45e198ceafacca @pukkaone committed Nov 19, 2011
@@ -74,7 +74,7 @@ Starting in the top distribution directory (where this file is
located), run the commands:
cd ruby/core
- rake
+ rake dist
## Project
@@ -36,7 +36,7 @@
* Extracts content from an HTML page and renders it in a layout. The layout
* is a template given these variables:
* <dl>
- * <dt>baseURL
+ * <dt>contextPathURL
* <dd>request context path with '/' appended to the end
* <dt>title
* <dd>content of the {@code title} element from the page
@@ -107,7 +107,7 @@ public void execute(
Writer writer)
Page page = parsePage(pageHtml);
- page.baseURL = request.getContextPath() + "/";
+ page.contextPathURL = request.getContextPath() + "/";
page.requestContextPath = request.getContextPath();
template.execute(page, messages, writer);
@@ -28,7 +28,7 @@
* Page data to render in a layout.
class Page {
- String baseURL;
+ String contextPathURL;
String requestContextPath;
String title;
String body;
@@ -1,7 +1,8 @@
+<!DOCTYPE html>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <base data-href="baseURL">
+ <meta charset="UTF-8">
+ <base data-href="contextPathURL">
<link rel="stylesheet" href="static/styles/petclinic.css" type="text/css">
<title>PetClinic :: a Spring Framework demonstration</title>
@@ -12,7 +13,7 @@
<table class="footer">
- <td><a data-href="baseURL">Home</a></td>
+ <td><a data-href="contextPathURL">Home</a></td>
<td align="right"><img src="static/images/springsource-logo.png" alt="Sponsored by SpringSource"/></td>
@@ -12,19 +12,20 @@ This application is modified to use Mullet templates to render the views.
## Application resource URLs
-The original JSP files use the `spring:url` tag to generate URLs to resources
-served by the application. The `spring:url` tag (and the JSTL `c:url` tag)
-necessarily prepends the context path to the generated URL because the context
-path is decided when the application is deployed. The developer cannot
-assume the application will run under a specific context path.
-Replacing each `spring:url` tag with a variable is an onerous task when a page
-has a lot of links because you must set those variables in the model passed to
-the template. I chose instead to use the `base` HTML element, which specifies
-a base URL to prepend to relative URLs found in the document. I set the base
-URL to the application content path. and refer to application resources using
-relative URLs. The template view makes a variable named `baseURL` available to
-the template. Its value is the context path with a trailing '/' character.
+The context path affects the URL where the browser should send requests for
+application resources, such as where to post form submissions. The context
+path is decided when the application is deployed, so the developer can't assume
+the application will run under a specific context path. The `spring:url` tag
+(and the JSTL `c:url` tag) takes a relative URL and generates a URL the browser
+can use by prepending the context path.
+I could replace each `spring:url` tag with a variable, but that's an onerous
+task because I would have to set a variable for each link I want to render.  I
+chose a solution requiring only one variable. The `base` HTML element sets the
+base URL of resources specified by a relative URL.  The view implicitly sets a
+variable named `contextPathURL` to the value of the context path. The template
+renders that variable in the `base` element, and I changed the links specified
+by `spring:url` to plain relative URLs.
## Add URL properties to model classes
@@ -21,7 +21,7 @@ end
desc 'Get version'
task :version do
- tag = `git describe`
+ tag = `git describe`.chomp()
if tag !~ /^\d/
tag = '0.0.0'

0 comments on commit a8afe61

Please sign in to comment.