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 = "
" 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 = '' - 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 << 'Read the <%= link_to "full article", wiki_page_path(wiki_page.id) %>.
-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 %> +Read the <%= link_to "full article", wiki_page_path(post_set.wiki_page.id) %>.
+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 %> +