* Continued work on improving post view templates
* Added statistics-based estimator for related tag calculator * Fleshed out IpBan class based on changes to Danbooru 1.xx
This commit is contained in:
@@ -2,27 +2,20 @@ class PostPresenter < Presenter
|
||||
def initialize(post)
|
||||
@post = post
|
||||
end
|
||||
|
||||
def tag_list_html
|
||||
end
|
||||
|
||||
|
||||
def image_html(template, current_user)
|
||||
return "" if @post.is_deleted? && !current_user.is_janitor?
|
||||
return template.content_tag("p", "This image was deleted.") if @post.is_deleted? && !current_user.is_janitor?
|
||||
return template.content_tag("p", "You need a privileged account to see this image.") if !Danbooru.config.can_see_post?(@post, current_user)
|
||||
|
||||
if @post.is_flash?
|
||||
template.render(:partial => "posts/flash", :locals => {:post => @post})
|
||||
template.render(:partial => "posts/partials/show/flash", :locals => {:post => @post})
|
||||
elsif @post.is_image?
|
||||
template.image_tag(
|
||||
@post.file_url_for(current_user),
|
||||
:alt => @post.tag_string,
|
||||
:width => @post.image_width_for(current_user),
|
||||
:height => @post.image_height_for(current_user),
|
||||
"data-original-width" => @post.image_width,
|
||||
"data-original-height" => @post.image_height
|
||||
)
|
||||
template.render(:partial => "posts/partials/show/image", :locals => {:post => @post})
|
||||
end
|
||||
end
|
||||
|
||||
def note_html
|
||||
def tag_list_html(template, current_user)
|
||||
@tag_set_presenter ||= TagSetPresenter.new(@post.tag_array)
|
||||
@tag_set_presenter.tag_list_html(template, :show_extra_links => current_user.is_privileged?)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,4 +2,8 @@ class Presenter
|
||||
def h(s)
|
||||
CGI.escapeHTML(s)
|
||||
end
|
||||
|
||||
def u(s)
|
||||
URI.escape(s)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,36 +5,42 @@
|
||||
=end
|
||||
|
||||
class TagSetPresenter < Presenter
|
||||
def initialize(source)
|
||||
@category_cache = {}
|
||||
def initialize(tags)
|
||||
@tags = tags
|
||||
fetch_categories
|
||||
end
|
||||
|
||||
def to_list_html(template, options = {})
|
||||
ul_class_attribute = options[:ul_class] ? %{class="#{options[:ul_class]}"} : ""
|
||||
ul_id_attribute = options[:ul_id] ? %{id="#{options[:ul_id]}"} : ""
|
||||
|
||||
def tag_list_html(template, options = {})
|
||||
html = ""
|
||||
html << "<ul #{ul_class_attribute} #{ul_id_attribute}>"
|
||||
html << "<ul>"
|
||||
@tags.each do |tag|
|
||||
html << build_list_item(tag, template, options)
|
||||
end
|
||||
html << "</ul>"
|
||||
html
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
private
|
||||
def fetch_categories(tags)
|
||||
def fetch_categories
|
||||
@category_cache ||= Tag.categories_for(@tags)
|
||||
end
|
||||
|
||||
def category_for(tag)
|
||||
@category_cache[tag]
|
||||
end
|
||||
|
||||
def build_list_item(tag, template, options)
|
||||
html = ""
|
||||
html << "<li>"
|
||||
html << %{<li data-tag-type="#{category_for(tag)}">}
|
||||
|
||||
if options[:show_extra_links]
|
||||
html << %{<a href="/wiki_pages/#{u(tag)}">?</a> }
|
||||
html << %{<a href="#" class="search-inc-tag">+</a> }
|
||||
html << %{<a href="#" class="search-exl-tag">-</a> }
|
||||
end
|
||||
|
||||
humanized_tag = tag.tr("_", " ")
|
||||
html << %{a href="/posts?tags=#{u(tag)}">#{h(humanized_tag)}</a>}
|
||||
html << %{<a href="/posts?tags=#{u(tag)}">#{h(humanized_tag)}</a>}
|
||||
html << "</li>"
|
||||
html
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user