changeset 2:b216e48fc4a5 draft

add display.html
author e085711
date Thu, 13 Sep 2012 01:40:32 +0900
parents 6875b5685dda
children cb113e610e08
files app/controllers/Application.java app/views/Application/index.html app/views/Application/tags/display.html eclipse/classes/controllers/Application.class eclipse/classes/controllers/Tasks.class eclipse/classes/models/Comment.class eclipse/classes/models/Post.class eclipse/classes/models/Task.class eclipse/classes/models/User.class tmp/bytecode/DEV/_app_views_Application_index.html tmp/bytecode/DEV/controllers.Application
diffstat 11 files changed, 119 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/Application.java	Thu Sep 13 01:02:58 2012 +0900
+++ b/app/controllers/Application.java	Thu Sep 13 01:40:32 2012 +0900
@@ -10,8 +10,9 @@
 public class Application extends Controller {
 
     public static void index() {
-    	List tasks = Task.find("order by id desc").fetch();
-    	render(tasks);
+    	Post frontPost = Post.find("order by postedAt desc").first();
+    	List<Post> olderPosts = Post.find("order by postedAt desc").from(1).fetch(10);
+    	render(frontPost,olderPosts);
     }
     
     public static void createTask(String title) {
--- a/app/views/Application/index.html	Thu Sep 13 01:02:58 2012 +0900
+++ b/app/views/Application/index.html	Thu Sep 13 01:40:32 2012 +0900
@@ -1,39 +1,71 @@
 #{extends 'main.html' /}
 #{set title:'Home' /}
 
-#{ifnot tasks}
-	<p>
-		No tasks 
-	</p>
-#{/ifnot}
-
-<ul>
-	#{list items:tasks, as:'task'}
-		<li>
-			<input type="checkbox" id="${task.id}" ${task.done ? 'checked':'' }>
-			${task.title}
-		</li>
-	#{/list}
-
-</ul>
+#{if frontPost}
+	<div class="post">
+		<h2 class="post-title">
+			<a href="#">${frontPost.title}</a>
+		</h2>
+		
+		<div clas="post-metadata">
+			<span class="post-author">by ${frontPost.author.fullname}</span>
+			<span class="post-data">by ${frontPost.postedAt.format('MMM dd')}</span>
+			<span class="post-comments">
+				&nbsp;|&nbsp;
+				${frontPost.comments.size() ?:'no'}
+				comment${frontPost.comments.size().pluralize()}
+				#{if frontPost.comments}
+					,latest by ${PfrontPost.comments[-1].author}
+					
+				#{/if}
+			</span>
+		</div>
+		<div class="post-content">
+			${frontPost.content.nl2br()}
+		</div>
+	</div>
 
-<p>
-	<a id="createTask" href="#">Create a new task</a>
-</p>
+	#{if olderPosts}
+		<div class="older-posts">
+			<h3>Older posts <span class="from">from this blog</span></h3>
+			
+			#{list items:olderPosts, as:'oldPost'}
+				<div class="post">
+					<h2 class="post-title">
+						<a href="#">${oldPost.title}</a>
+					</h2>
+					<div class="post-metadata">
+						<span class="post-author">
+							by ${oldPost.author.fullname}
+						</span>
+						<span class="post-date">
+							${oldPost.postedAt.format('dd MMM yy')}
+						</span>
+						<div class="post-comments">
+							${oldPost.comments.size() ?:'no'}
+							comment${oldPost.comments.size().pluralize()}
+							#{if oldPost.comments}
+								- latest by ${oldPost.comments[-1].author}
+							#{/if}
+						</div>
+					</div>
+				</div>
+			#{/list}
+		</div>
 
-<script type="text/javascript" charset="utf-8">
-	// Create a task
-	$('#createTask').click(function() {
-		$.post('@{createTask()}', {title: prompt('Task title ?')}, function(task){
-			$('ul').prepend(
-				'<li><input type="checkbox" id="'+task.id+'">'+task.title+'</li>'
-			)}, 'json')
-	})
+	#{/if}
+
+#{/if}
+
 
-	// change status
-	$('input').live('click', function() {
-		$.post('@{changeStatus()}', {id: $(this).attr('id'), done: $(this).val()})
-	})
-	
+#{else}
+	<div class="empty">
+		There is currently nothing to read here.
+	</div>
+#{/else}
 
-</script>
\ No newline at end of file
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/views/Application/tags/display.html	Thu Sep 13 01:40:32 2012 +0900
@@ -0,0 +1,52 @@
+*{ Display a post in one of these modes: 'full','home'or'teaser' }#
+
+<div class="post ${_as == 'teaser' ? 'teaser' :''}">
+
+	<h2 class="post-title">
+		<a href="#">${_post.title}</a>
+	</h2>
+	
+	<div class="post-metadata">
+		<span class="post-author">by ${_post.author.fullname})</span>
+		<span class="post-date">${_post.postedAt.format('dd MMM yy')}</span>
+		#{if _as != 'full'}
+			<span class="post-comments">
+				&nbsp;|&nbsp; ${_post.comments.size() ?:'no'}
+				comment${_post.comments.size().pluralize()}
+				#{if _post.comments}
+					, latest by ${_post.comments[-1].author}
+				#{/if}
+			</span>
+		#{/if}
+	</div>
+	#{if _as !='teaser'}
+		<div class="post-content">
+			<div class="about">Detail:</div>
+			${_post.content.nl2br()}
+		</div>
+	#{/if}
+</div>
+
+#{if _as=='full'}
+	<div class="comments">
+		<h3>
+			${_post.comments.size() ?:'no'}
+			comment${_post.comments.size().pluralize()}
+		</h3>
+	
+	#{list items:_post.comments, as:'comment'}
+		<div class="comment">
+			<div class="comment-metadata">
+				<span class="comment-author">by ${comment.author},</span>
+				<span class="comment-data">
+					${comment.postedAt.format('dd MMM yy')}
+				</span>
+			</div>
+		</div>
+		<div class="comment-content">
+			<div class="about">Detail:</div>
+			${comment.content.escape().nl2br()}
+		</div>
+	#{/list}
+	</div>		
+#{/if}
\ No newline at end of file
Binary file eclipse/classes/controllers/Application.class has changed
Binary file eclipse/classes/controllers/Tasks.class has changed
Binary file eclipse/classes/models/Comment.class has changed
Binary file eclipse/classes/models/Post.class has changed
Binary file eclipse/classes/models/Task.class has changed
Binary file eclipse/classes/models/User.class has changed
Binary file tmp/bytecode/DEV/_app_views_Application_index.html has changed
Binary file tmp/bytecode/DEV/controllers.Application has changed