From 40745a2e6ef044534fd226ba6602d36314729c43 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 28 Oct 2011 19:21:44 -0400 Subject: [PATCH] added new landing page --- .gitignore | 9 ++-- app/assets/javascripts/common.js | 25 +++++----- app/assets/javascripts/landings.js | 8 +++ .../stylesheets/common/030_links.css.scss | 4 ++ .../stylesheets/specific/landing.css.scss | 44 +++++++++++++++++ .../stylesheets/specific/posts.css.scss | 8 +++ app/controllers/landings_controller.rb | 6 +++ app/helpers/landings_helper.rb | 2 + app/logical/popular_post_explorer.rb | 30 ++++++++++++ app/models/post.rb | 23 +++++++++ app/presenters/post_presenter.rb | 7 +++ app/presenters/tag_set_presenter.rb | 11 +++-- app/views/landings/_image.html.erb | 1 + app/views/landings/_tag.html.erb | 8 +++ app/views/landings/show.html.erb | 22 +++++++++ app/views/layouts/blank.html.erb | 17 +++++++ app/views/moderator/post/queues/show.html.erb | 8 ++- config/routes.rb | 49 +++++++++---------- 18 files changed, 234 insertions(+), 48 deletions(-) create mode 100644 app/assets/javascripts/landings.js create mode 100644 app/assets/stylesheets/specific/landing.css.scss create mode 100644 app/controllers/landings_controller.rb create mode 100644 app/helpers/landings_helper.rb create mode 100644 app/logical/popular_post_explorer.rb create mode 100644 app/views/landings/_image.html.erb create mode 100644 app/views/landings/_tag.html.erb create mode 100644 app/views/landings/show.html.erb create mode 100644 app/views/layouts/blank.html.erb diff --git a/.gitignore b/.gitignore index 20c73819c..51e59b310 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,9 @@ .bundle config/database.yml config/danbooru_local_config.rb -lib/danbooru_image_resizer/*.so -lib/danbooru_image_resizer/*.o -lib/danbooru_image_resizer/*.bundle -lib/danbooru_image_resizer/*.log db/*.sqlite3 log/*.log -tmp/**/* -tmp/upload_* +tmp/* public/data vendor/cache/*.gem .sass-cache @@ -16,3 +11,5 @@ vendor/cache/*.gem coverage *~ *.swp +tmp/*.jpg +tmp/*.png diff --git a/app/assets/javascripts/common.js b/app/assets/javascripts/common.js index 4ed12d1e3..841046273 100644 --- a/app/assets/javascripts/common.js +++ b/app/assets/javascripts/common.js @@ -8,17 +8,20 @@ $(document).ready(function() { $("table.striped tbody tr:even").addClass("even"); $("table.striped tbody tr:odd").addClass("odd"); - // More link - $("#site-map-link").click(function(e) { - $("#more-links").toggle(); - e.preventDefault(); - e.stopPropagation(); - }); - $("#more-links").hide().offset({top: $("#site-map-link").offset().top + $("#site-map-link").height() + 10, left: $("#site-map-link").offset().left}); - - $(document).click(function(e) { - $("#more-links").hide(); - }); + if ($("#site-map-link").length > 0) { + // More link + $("#site-map-link").click(function(e) { + $("#more-links").toggle(); + e.preventDefault(); + e.stopPropagation(); + }); + + $("#more-links").hide().offset({top: $("#site-map-link").offset().top + $("#site-map-link").height() + 10, left: $("#site-map-link").offset().left}); + + $(document).click(function(e) { + $("#more-links").hide(); + }); + } // Ajax links $("a[data-remote=true]").click(function(e) { diff --git a/app/assets/javascripts/landings.js b/app/assets/javascripts/landings.js new file mode 100644 index 000000000..5b65fcf0f --- /dev/null +++ b/app/assets/javascripts/landings.js @@ -0,0 +1,8 @@ +$(function() { + $("#c-landings div.data").each(function(i, div) { + var $div = $(div); + var $image = $div.prev(); + + $div.width($image.width() - 10).height($image.height() - 10).offset({top: $image.position().top, left: $image.position().left}); + }); +}); diff --git a/app/assets/stylesheets/common/030_links.css.scss b/app/assets/stylesheets/common/030_links.css.scss index ec1322e72..536b1b62a 100644 --- a/app/assets/stylesheets/common/030_links.css.scss +++ b/app/assets/stylesheets/common/030_links.css.scss @@ -31,4 +31,8 @@ a.login { a.forum-updated { font-style: italic; +} + +a.wiki-link { + margin-right: 0.3em; } \ No newline at end of file diff --git a/app/assets/stylesheets/specific/landing.css.scss b/app/assets/stylesheets/specific/landing.css.scss new file mode 100644 index 000000000..11496c929 --- /dev/null +++ b/app/assets/stylesheets/specific/landing.css.scss @@ -0,0 +1,44 @@ +div#c-landings { + div#a-show { + padding-top: 4em; + width: 960px; + margin: auto; + + h1 { + text-align: center; + font-size: 4em; + } + + p.slogan { + text-align: center; + font-size: 1.5em; + font-weight: bold; + } + + div.column { + width: 480px; + vertical-align: top; + float: left; + background-color: #000; + } + + div.landing-post { + overflow: hidden; + } + + div.landing-post:hover img { + opacity: 0.25; + } + + div.landing-post:hover div.data { + opacity: 1.0; + } + + div.landing-post div.data { + position: absolute; + color: white; + padding: 5px; + cursor: pointer; + } + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index 0bff800a5..5b8aa2777 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -26,6 +26,14 @@ article.post-preview { } } +div.text-post-medium { + height: 150px; + width: 480px; + text-align: center; + line-height: 480px; + border: 1px solid #CCC; +} + article.post-preview.blacklisted-active { display: none; } diff --git a/app/controllers/landings_controller.rb b/app/controllers/landings_controller.rb new file mode 100644 index 000000000..b5cee9f90 --- /dev/null +++ b/app/controllers/landings_controller.rb @@ -0,0 +1,6 @@ +class LandingsController < ApplicationController + def show + @explorer = PopularPostExplorer.new + render :layout => "blank" + end +end diff --git a/app/helpers/landings_helper.rb b/app/helpers/landings_helper.rb new file mode 100644 index 000000000..121afc025 --- /dev/null +++ b/app/helpers/landings_helper.rb @@ -0,0 +1,2 @@ +module LandingsHelper +end diff --git a/app/logical/popular_post_explorer.rb b/app/logical/popular_post_explorer.rb new file mode 100644 index 000000000..44bdf54fd --- /dev/null +++ b/app/logical/popular_post_explorer.rb @@ -0,0 +1,30 @@ +class PopularPostExplorer + attr_reader :col1, :col2, :posts + + def initialize + load_posts + sort_posts + end + +private + + def load_posts + # Post.tag_match("order:rank").where("image_width >= ?", Danbooru.config.medium_image_width).limit(5).offset(offset) + @posts = Post.where("image_width >= ?", Danbooru.config.medium_image_width).limit(50) + end + + def sort_posts + height1, height2 = 0, 0 + @col1, @col2 = [], [] + + posts.each do |post| + if height1 > height2 + @col2 << post + height2 += post.medium_image_height + else + @col1 << post + height1 += post.medium_image_height + end + end + end +end diff --git a/app/models/post.rb b/app/models/post.rb index d170d2391..c20116d2a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -473,6 +473,29 @@ class Post < ActiveRecord::Base def has_tag?(tag) tag_string =~ /(?:^| )#{tag}(?:$| )/ end + + def essential_tag_string + tag_categories = Tag.categories_for(tag_array) + tag_array.each do |tag| + if tag_categories[tag] == Danbooru.config.tag_category_mapping["copyright"] + return "copyright: " + tag + end + end + + tag_array.each do |tag| + if tag_categories[tag] == Danbooru.config.tag_category_mapping["character"] + return "character: " + tag + end + end + + tag_array.each do |tag| + if tag_categories[tag] == Danbooru.config.tag_category_mapping["artist"] + return "artist: " + tag + end + end + + return tag_array.first + end end module FavoriteMethods diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 623cc4d2b..994d18a40 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -32,6 +32,13 @@ class PostPresenter < Presenter def preview_html PostPresenter.preview(@post) end + + def medium_image_html(template, options = {}) + return "" if @post.is_deleted? && !CurrentUser.user.is_janitor? + return "" if !Danbooru.config.can_user_see_post?(CurrentUser.user, @post) + + template.render("posts/partials/show/medium_image", :post => @post) + end def image_html(template) return template.content_tag("p", "This image was deleted.") if @post.is_deleted? && !CurrentUser.user.is_janitor? diff --git a/app/presenters/tag_set_presenter.rb b/app/presenters/tag_set_presenter.rb index 7d524c59a..8862d9ee7 100644 --- a/app/presenters/tag_set_presenter.rb +++ b/app/presenters/tag_set_presenter.rb @@ -36,12 +36,13 @@ private html << %{
  • } current_query = template.params[:tags] || "" + if categories[tag] == 1 + html << %{? } + else + html << %{? } + end + if CurrentUser.user.is_privileged? - if categories[tag] == 1 - html << %{? } - else - html << %{? } - end html << %{+ } html << %{ } end diff --git a/app/views/landings/_image.html.erb b/app/views/landings/_image.html.erb new file mode 100644 index 000000000..0424849a8 --- /dev/null +++ b/app/views/landings/_image.html.erb @@ -0,0 +1 @@ +

    <%= post.essential_tag_string %>

    \ No newline at end of file diff --git a/app/views/landings/_tag.html.erb b/app/views/landings/_tag.html.erb new file mode 100644 index 000000000..288d029eb --- /dev/null +++ b/app/views/landings/_tag.html.erb @@ -0,0 +1,8 @@ + +
    + <% @explorer.search(tag, 300).each do |post| %> + <%= post.presenter.medium_image_html(self, :max_height => 300) %> + <% end %> +
    \ No newline at end of file diff --git a/app/views/landings/show.html.erb b/app/views/landings/show.html.erb new file mode 100644 index 000000000..479ceb803 --- /dev/null +++ b/app/views/landings/show.html.erb @@ -0,0 +1,22 @@ +
    +
    +

    <%= link_to Danbooru.config.app_name, posts_path %>

    +

    Find good art fast

    + +
    + <% @explorer.col1.each do |post| %> + <%= render "image", :post => post %> + <% end %> +
    + +
    + <% @explorer.col2.each do |post| %> + <%= render "image", :post => post %> + <% end %> +
    +
    +
    + +<% content_for(:page_title) do %> + <%= Danbooru.config.app_name %> +<% end %> diff --git a/app/views/layouts/blank.html.erb b/app/views/layouts/blank.html.erb new file mode 100644 index 000000000..9fbd324e2 --- /dev/null +++ b/app/views/layouts/blank.html.erb @@ -0,0 +1,17 @@ + + + + <%= yield :page_title %> + + + <%= csrf_meta_tag %> + <%= auto_discovery_link_tag :atom, posts_path(:format => "atom", :tags => params[:tags]) %> + <%= stylesheet_link_tag "application", :media => "screen" %> + <%= javascript_include_tag "application" %> + <%= Danbooru.config.custom_html_header_content %> + <%= yield :html_header %> + + + <%= yield :layout %> + + diff --git a/app/views/moderator/post/queues/show.html.erb b/app/views/moderator/post/queues/show.html.erb index f42012cfe..530b8c1b5 100644 --- a/app/views/moderator/post/queues/show.html.erb +++ b/app/views/moderator/post/queues/show.html.erb @@ -27,7 +27,13 @@ <% @posts.each do |post| %>
    diff --git a/config/routes.rb b/config/routes.rb index 289e1945f..4336d2e9f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,11 +30,24 @@ Danbooru::Application.routes.draw do end end end + namespace :explore do + resources :posts, :only => [:popular, :hot] do + collection do + get :popular + get :hot + end + end + end + namespace :maintenance do + namespace :user do + resource :password_reset, :only => [:new, :create, :edit, :update] + resource :login_reminder, :only => [:new, :create] + end + end + resources :advertisements do resources :hits, :controller => "advertisement_hits", :only => [:create] end - resource :source, :only => [:show] - resource :related_tag, :only => [:show] resources :artists do member do put :revert @@ -60,12 +73,13 @@ Danbooru::Application.routes.draw do end resource :dtext_preview, :only => [:create] resources :favorites - resources :forum_topics resources :forum_posts do collection do get :search end end + resources :forum_topics + resources :ip_bans resources :janitor_trials do collection do get :test @@ -76,13 +90,12 @@ Danbooru::Application.routes.draw do end end resources :jobs - resources :ip_bans + resource :landing resources :mod_actions resources :notes do collection do get :search end - member do put :revert end @@ -105,14 +118,16 @@ Danbooru::Application.routes.draw do put :revert end end + resources :post_appeals, :only => [:new, :index, :create] + resources :post_flags, :only => [:new, :index, :create] resources :post_versions, :only => [:index, :search] do collection do get :search end end - resources :post_flags, :only => [:new, :index, :create] - resources :post_appeals, :only => [:new, :index, :create] - resource :session + resource :related_tag, :only => [:show] + resource :session + resource :source, :only => [:show] resources :tags do collection do get :search @@ -147,22 +162,6 @@ Danbooru::Application.routes.draw do end resources :wiki_page_versions, :only => [:index, :show] - namespace :explore do - resources :posts, :only => [:popular, :hot] do - collection do - get :popular - get :hot - end - end - end - - namespace :maintenance do - namespace :user do - resource :password_reset, :only => [:new, :create, :edit, :update] - resource :login_reminder, :only => [:new, :create] - end - end - # aliases resources :wpages, :controller => "wiki_pages" resources :ftopics, :controller => "forum_topics" @@ -172,5 +171,5 @@ Danbooru::Application.routes.draw do match "/static/site_map" => "static#site_map", :as => "site_map" match "/static/terms_of_service" => "static#terms_of_service", :as => "terms_of_service" - root :to => "posts#index" + root :to => "landings#show" end