fixed post listing
This commit is contained in:
@@ -299,6 +299,8 @@ div#notice {
|
||||
}
|
||||
|
||||
div#page {
|
||||
margin: 0 30px;
|
||||
|
||||
aside#sidebar {
|
||||
width: 20%;
|
||||
float: left;
|
||||
|
||||
@@ -4,7 +4,8 @@ class PostsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def index
|
||||
@posts = Post.search(params[:search]).paginate(params[:page])
|
||||
@post_set = PostSets::Post.new(params)
|
||||
@posts = @post_set.posts
|
||||
respond_with(@posts)
|
||||
end
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ module PaginationHelper
|
||||
html = "<menu>"
|
||||
|
||||
unless records.is_first_page?
|
||||
html << '<li>' + link_to("« Previous", params.merge(:after_id => records.first_id)) + '</li>'
|
||||
html << '<li>' + link_to("« Previous", params.merge(:page => "b#{records.first_id}")) + '</li>'
|
||||
end
|
||||
|
||||
unless records.is_last_page?
|
||||
html << '<li>' + link_to("Next »", params.merge(:before_id => records.last_id)) + '</li>'
|
||||
html << '<li>' + link_to("Next »", params.merge(:page => "a#{records.last_id}")) + '</li>'
|
||||
end
|
||||
|
||||
html << "</menu>"
|
||||
|
||||
43
app/logical/post_sets/post.rb
Normal file
43
app/logical/post_sets/post.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
module PostSets
|
||||
class Post
|
||||
attr_reader :tags, :page, :posts
|
||||
|
||||
def initialize(params)
|
||||
@tags = Tag.scan_query(params[:tags])
|
||||
@page = [params[:page].to_i, 1].max
|
||||
@posts = ::Post.tag_match(tag_string).paginate(page)
|
||||
end
|
||||
|
||||
def tag_string
|
||||
@tag_string ||= tags.join(" ")
|
||||
end
|
||||
|
||||
def has_wiki?
|
||||
if tags.any?
|
||||
::WikiPage.titled(tag_string).exists?
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def wiki_page
|
||||
if tags.any?
|
||||
::WikiPage.titled(tag_string).first
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def is_single_tag?
|
||||
tags.size == 1
|
||||
end
|
||||
|
||||
def tag
|
||||
tag_string
|
||||
end
|
||||
|
||||
def presenter
|
||||
@presenter ||= PostSetPresenter.new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,39 +1,19 @@
|
||||
require 'pp'
|
||||
|
||||
class PostSetPresenter < Presenter
|
||||
attr_accessor :posts, :tag_set_presenter
|
||||
attr_accessor :post_set, :tag_set_presenter
|
||||
|
||||
def initialize(posts)
|
||||
@posts = posts
|
||||
@tag_set_presenter = TagSetPresenter.new(RelatedTagCalculator.calculate_from_sample_to_array(@post_set.tags).map {|x| x[0]})
|
||||
def initialize(post_set)
|
||||
@post_set = post_set
|
||||
@tag_set_presenter = TagSetPresenter.new(RelatedTagCalculator.calculate_from_sample_to_array(@post_set.tag_string).map {|x| x[0]})
|
||||
end
|
||||
|
||||
def posts
|
||||
post_set.posts
|
||||
end
|
||||
|
||||
def tag_list_html(template)
|
||||
tag_set_presenter.tag_list_html(template)
|
||||
end
|
||||
|
||||
def wiki_html(template)
|
||||
if post_set.has_wiki?
|
||||
wiki_page = WikiPage.find_by_title(post_set.tags)
|
||||
html = '<section>'
|
||||
if wiki_page.nil?
|
||||
html << '<p>'
|
||||
html << 'There is no wiki for this tag.'
|
||||
html << ' '
|
||||
html << template.link_to("Create a new page", template.new_wiki_page_path(:title => post_set.tags))
|
||||
html << '.'
|
||||
html << '</p>'
|
||||
else
|
||||
html << '<h2>'
|
||||
html << template.h(wiki_page.title)
|
||||
html << '</h2>'
|
||||
html << template.format_text(wiki_page.body)
|
||||
end
|
||||
html << '</section>'
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def post_previews_html
|
||||
html = ""
|
||||
|
||||
|
||||
@@ -29,10 +29,7 @@
|
||||
</aside>
|
||||
|
||||
<section id="content">
|
||||
<% if @post_set.has_wiki? && @post_set.page < 2 %>
|
||||
<%= render :partial => "wiki_pages/excerpt", :locals => {:wiki_page => @post_set.wiki_page, :tag => @post_set.tag} %>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "wiki_pages/excerpt", :locals => {:post_set => @post_set} %>
|
||||
<%= render :partial => "posts/partials/index/posts", :locals => {:post_set => @post_set} %>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="clearfix"></div>
|
||||
|
||||
<div class="paginator">
|
||||
<%= smart_paginator(post_set) do |page| %>
|
||||
<%= link_to(page, posts_path(:page => page, :tags => params[:tags])) %>
|
||||
<%= smart_paginator(post_set.posts) do |page| %>
|
||||
<%= link_to(page, posts_path(:page => page, :tags => post_set.tags)) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
<!--
|
||||
- wiki_page
|
||||
- tag
|
||||
- post_set
|
||||
-->
|
||||
|
||||
<div id="wiki-page-excerpt">
|
||||
<h1>Wiki</h1>
|
||||
|
||||
<div id="hide-or-show-wiki-page-excerpt">
|
||||
<span id="hide-wiki-page-excerpt">(hide)</span>
|
||||
<span id="show-wiki-page-excerpt">(show)</span>
|
||||
</div>
|
||||
<% if post_set.has_wiki? %>
|
||||
<div id="wiki-page-excerpt">
|
||||
<h1>Wiki</h1>
|
||||
|
||||
<div id="wiki-page-excerpt-content">
|
||||
<% if wiki_page %>
|
||||
<div class="prose">
|
||||
<%= format_text(wiki_page.presenter.excerpt) %>
|
||||
<div id="hide-or-show-wiki-page-excerpt">
|
||||
<span id="hide-wiki-page-excerpt">(hide)</span>
|
||||
<span id="show-wiki-page-excerpt">(show)</span>
|
||||
</div>
|
||||
|
||||
<p>Read the <%= link_to "full article", wiki_page_path(wiki_page.id) %>.</p>
|
||||
</div>
|
||||
<% else %>
|
||||
<p>There is currently no wiki page for the tag "<%= tag %>". You can <%= link_to "create one", new_wiki_page_path(:wiki_page => {:title => tag}) %>.</p>
|
||||
<% end %>
|
||||
<div id="wiki-page-excerpt-content">
|
||||
<% if post_set.wiki_page %>
|
||||
<div class="prose">
|
||||
<%= format_text(post_set.wiki_page.presenter.excerpt) %>
|
||||
|
||||
<p>Read the <%= link_to "full article", wiki_page_path(post_set.wiki_page.id) %>.</p>
|
||||
</div>
|
||||
<% else %>
|
||||
<p>There is currently no wiki page for the tag "<%= post_set.tag_string %>". You can <%= link_to "create one", new_wiki_page_path(:wiki_page => {:title => post_set.tag_string}) %>.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user