diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 768e9a41c..0ef93728e 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -299,6 +299,8 @@ div#notice { } div#page { + margin: 0 30px; + aside#sidebar { width: 20%; float: left; diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d80164d4f..897e4c716 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/helpers/pagination_helper.rb b/app/helpers/pagination_helper.rb index cb17822f5..cb57aa851 100644 --- a/app/helpers/pagination_helper.rb +++ b/app/helpers/pagination_helper.rb @@ -11,11 +11,11 @@ module PaginationHelper html = "" unless records.is_first_page? - html << '
  • ' + link_to("« Previous", params.merge(:after_id => records.first_id)) + '
  • ' + html << '
  • ' + link_to("« Previous", params.merge(:page => "b#{records.first_id}")) + '
  • ' end unless records.is_last_page? - html << '
  • ' + link_to("Next »", params.merge(:before_id => records.last_id)) + '
  • ' + html << '
  • ' + link_to("Next »", params.merge(:page => "a#{records.last_id}")) + '
  • ' end html << "
    " diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb new file mode 100644 index 000000000..30432a084 --- /dev/null +++ b/app/logical/post_sets/post.rb @@ -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 diff --git a/app/presenters/post_set_presenter.rb b/app/presenters/post_set_presenter.rb index 7afcd572f..4255e904a 100644 --- a/app/presenters/post_set_presenter.rb +++ b/app/presenters/post_set_presenter.rb @@ -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 = '
    ' - if wiki_page.nil? - html << '

    ' - 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 << '

    ' - else - html << '

    ' - html << template.h(wiki_page.title) - html << '

    ' - html << template.format_text(wiki_page.body) - end - html << '
    ' - html.html_safe - end - end - def post_previews_html html = "" diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 6b5f4dc6e..883999f9c 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -29,10 +29,7 @@
    - <% 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} %>
    diff --git a/app/views/posts/partials/index/_posts.html.erb b/app/views/posts/partials/index/_posts.html.erb index 1dc50001f..0adae71ec 100644 --- a/app/views/posts/partials/index/_posts.html.erb +++ b/app/views/posts/partials/index/_posts.html.erb @@ -5,7 +5,7 @@
    - <%= 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 %>
    diff --git a/app/views/wiki_pages/_excerpt.html.erb b/app/views/wiki_pages/_excerpt.html.erb index 17af121cf..1938acb23 100644 --- a/app/views/wiki_pages/_excerpt.html.erb +++ b/app/views/wiki_pages/_excerpt.html.erb @@ -1,25 +1,26 @@ -
    -

    Wiki

    - -
    - (hide) - (show) -
    +<% if post_set.has_wiki? %> +
    +

    Wiki

    -
    - <% if wiki_page %> -
    - <%= format_text(wiki_page.presenter.excerpt) %> +
    + (hide) + (show) +
    -

    Read the <%= link_to "full article", wiki_page_path(wiki_page.id) %>.

    -
    - <% else %> -

    There is currently no wiki page for the tag "<%= tag %>". You can <%= link_to "create one", new_wiki_page_path(:wiki_page => {:title => tag}) %>.

    - <% end %> +
    + <% if post_set.wiki_page %> +
    + <%= format_text(post_set.wiki_page.presenter.excerpt) %> + +

    Read the <%= link_to "full article", wiki_page_path(post_set.wiki_page.id) %>.

    +
    + <% else %> +

    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}) %>.

    + <% end %> +
    -
    +<% end %> \ No newline at end of file