fixed post listing
This commit is contained in:
@@ -299,6 +299,8 @@ div#notice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div#page {
|
div#page {
|
||||||
|
margin: 0 30px;
|
||||||
|
|
||||||
aside#sidebar {
|
aside#sidebar {
|
||||||
width: 20%;
|
width: 20%;
|
||||||
float: left;
|
float: left;
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ class PostsController < ApplicationController
|
|||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@posts = Post.search(params[:search]).paginate(params[:page])
|
@post_set = PostSets::Post.new(params)
|
||||||
|
@posts = @post_set.posts
|
||||||
respond_with(@posts)
|
respond_with(@posts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ module PaginationHelper
|
|||||||
html = "<menu>"
|
html = "<menu>"
|
||||||
|
|
||||||
unless records.is_first_page?
|
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
|
end
|
||||||
|
|
||||||
unless records.is_last_page?
|
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
|
end
|
||||||
|
|
||||||
html << "</menu>"
|
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
|
class PostSetPresenter < Presenter
|
||||||
attr_accessor :posts, :tag_set_presenter
|
attr_accessor :post_set, :tag_set_presenter
|
||||||
|
|
||||||
def initialize(posts)
|
def initialize(post_set)
|
||||||
@posts = posts
|
@post_set = post_set
|
||||||
@tag_set_presenter = TagSetPresenter.new(RelatedTagCalculator.calculate_from_sample_to_array(@post_set.tags).map {|x| x[0]})
|
@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
|
end
|
||||||
|
|
||||||
def tag_list_html(template)
|
def tag_list_html(template)
|
||||||
tag_set_presenter.tag_list_html(template)
|
tag_set_presenter.tag_list_html(template)
|
||||||
end
|
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
|
def post_previews_html
|
||||||
html = ""
|
html = ""
|
||||||
|
|
||||||
|
|||||||
@@ -29,10 +29,7 @@
|
|||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<section id="content">
|
<section id="content">
|
||||||
<% if @post_set.has_wiki? && @post_set.page < 2 %>
|
<%= render :partial => "wiki_pages/excerpt", :locals => {:post_set => @post_set} %>
|
||||||
<%= render :partial => "wiki_pages/excerpt", :locals => {:wiki_page => @post_set.wiki_page, :tag => @post_set.tag} %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render :partial => "posts/partials/index/posts", :locals => {:post_set => @post_set} %>
|
<%= render :partial => "posts/partials/index/posts", :locals => {:post_set => @post_set} %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
|
|
||||||
<div class="paginator">
|
<div class="paginator">
|
||||||
<%= smart_paginator(post_set) do |page| %>
|
<%= smart_paginator(post_set.posts) do |page| %>
|
||||||
<%= link_to(page, posts_path(:page => page, :tags => params[:tags])) %>
|
<%= link_to(page, posts_path(:page => page, :tags => post_set.tags)) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
<!--
|
<!--
|
||||||
- wiki_page
|
- post_set
|
||||||
- tag
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<div id="wiki-page-excerpt">
|
<% if post_set.has_wiki? %>
|
||||||
<h1>Wiki</h1>
|
<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>
|
|
||||||
|
|
||||||
<div id="wiki-page-excerpt-content">
|
<div id="hide-or-show-wiki-page-excerpt">
|
||||||
<% if wiki_page %>
|
<span id="hide-wiki-page-excerpt">(hide)</span>
|
||||||
<div class="prose">
|
<span id="show-wiki-page-excerpt">(show)</span>
|
||||||
<%= format_text(wiki_page.presenter.excerpt) %>
|
</div>
|
||||||
|
|
||||||
<p>Read the <%= link_to "full article", wiki_page_path(wiki_page.id) %>.</p>
|
<div id="wiki-page-excerpt-content">
|
||||||
</div>
|
<% if post_set.wiki_page %>
|
||||||
<% else %>
|
<div class="prose">
|
||||||
<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>
|
<%= format_text(post_set.wiki_page.presenter.excerpt) %>
|
||||||
<% end %>
|
|
||||||
|
<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>
|
||||||
</div>
|
<% end %>
|
||||||
Reference in New Issue
Block a user