<commit_before># Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def post_slug_path(post,tag=nil,author=nil,opts={})
    tag ||= params[:tag]
    author ||= params[:author]
    if params[:tag] && params[:author]
      slug_with_author_tag_path({:slug=>post.slug,:author=>post.author.to_s,:tag=>params[:tag],:year=>post.created_at.year,:day=>post.created_at.day,:month=>post.created_at.month}.merge(opts))
    elsif params[:tag]
      slug_with_tag_path({:slug=>post.slug,:tag=>params[:tag],:year=>post.created_at.year,:day=>post.created_at.day,:month=>post.created_at.month}.merge(opts))
    elsif params[:author]
      slug_with_author_path({:slug=>post.slug,:author=>post.author.to_s,:year=>post.created_at.year,:day=>post.created_at.day,:month=>post.created_at.month}.merge(opts))
    else
      slug_path({:slug=>post.slug,:year=>post.created_at.year,:day=>post.created_at.day,:month=>post.created_at.month}.merge(opts))
    end
  end

  def comment_form_url(post, comment)
    return post_author_slug_comments_path if params[:author]
    post_slug_comments_path
  end

  def custom_posts(tag=nil,author=nil, opts={})
    tag ||= params[:tag]
    author ||= params[:author]
    if tag && author
      posts_with_author_tag_path({:author=>author,:tag=>tag}.merge(opts))
    elsif tag
      posts_with_tag_path({:tag=>tag}.merge(opts))
    elsif author
      posts_with_author_path({:author=>author}.merge(opts))
    else
      posts_path
    end
  end

  def custom_atom_posts(tag=nil,author=nil)
    tag ||= params[:tag]
    author ||= params[:author]
    if tag && author
      posts_with_author_tag_url(:author=>author,:tag=>tag, :format => 'atom')
    elsif tag
      posts_with_tag_url(:tag=>tag, :format => 'atom')
    elsif author
      posts_with_author_url(:author=>author, :format => 'atom')
    else
      posts_url(:format => 'atom')
    end
  end

  def custom_atom_comments(tag=nil, author=nil, post=nil)
    tag ||= params[:tag]
    author ||= params[:author]
    if post
      if tag && author
        slug_comments_with_author_tag_url(:author=>author,:tag=>tag, :format => 'atom')
      elsif tag
        slug_comments_with_tag_url(:tag=>tag, :format => 'atom')
      elsif author
        slug_comments_with_author_url(:author=>author, :format => 'atom')
      else
        slug_comments_url(:format => 'atom')
      end
    else
      if tag && author
        all_comments_with_author_tag_url(:author=>author,:tag=>tag, :format => 'atom')
      elsif tag
        all_comments_with_tag_url(:tag=>tag, :format => 'atom')
      elsif author
        all_comments_with_author_url(:author=>author, :format => 'atom')
      else
        all_comments_url(:format => 'atom')
      end
    end
  end

  def posts_title(post=nil, tag=nil, author=nil)
    title = ''
    title << "#{post.title} - " if post
    if author && tag
      title << "#{fullname(author)} on #{tag} - "
    elsif author
      title << "#{fullname(author)} - "
    end
    title << AppConfig.title
  end

  def fullname(author)
    author+' '+AppConfig.author["writers"][author.to_s.downcase]
  end

  def linked_tag_list(tags)
    tags.collect {|tag| link_to(h(tag), custom_posts(tag, params[:author]))}.join(", ")
  end

  def tag_cloud(tags = [], options = {})
    if params[:author]
      tags = Post.tag_cloud({:author=>params[:author]})
    else
      tags = Post.tag_cloud()
    end
<commit_msg>don't crash when no tags are available<commit_after># Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def post_slug_path(post,tag=nil,author=nil,opts={})
    tag ||= params[:tag]
    author ||= params[:author]
    if params[:tag] && params[:author]
      slug_with_author_tag_path({:slug=>post.slug,:author=>post.author.to_s,:tag=>params[:tag],:year=>post.created_at.year,:day=>post.created_at.day,:month=>post.created_at.month}.merge(opts))
    elsif params[:tag]
      slug_with_tag_path({:slug=>post.slug,:tag=>params[:tag],:year=>post.created_at.year,:day=>post.created_at.day,:month=>post.created_at.month}.merge(opts))
    elsif params[:author]
      slug_with_author_path({:slug=>post.slug,:author=>post.author.to_s,:year=>post.created_at.year,:day=>post.created_at.day,:month=>post.created_at.month}.merge(opts))
    else
      slug_path({:slug=>post.slug,:year=>post.created_at.year,:day=>post.created_at.day,:month=>post.created_at.month}.merge(opts))
    end
  end

  def comment_form_url(post, comment)
    return post_author_slug_comments_path if params[:author]
    post_slug_comments_path
  end

  def custom_posts(tag=nil,author=nil, opts={})
    tag ||= params[:tag]
    author ||= params[:author]
    if tag && author
      posts_with_author_tag_path({:author=>author,:tag=>tag}.merge(opts))
    elsif tag
      posts_with_tag_path({:tag=>tag}.merge(opts))
    elsif author
      posts_with_author_path({:author=>author}.merge(opts))
    else
      posts_path
    end
  end

  def custom_atom_posts(tag=nil,author=nil)
    tag ||= params[:tag]
    author ||= params[:author]
    if tag && author
      posts_with_author_tag_url(:author=>author,:tag=>tag, :format => 'atom')
    elsif tag
      posts_with_tag_url(:tag=>tag, :format => 'atom')
    elsif author
      posts_with_author_url(:author=>author, :format => 'atom')
    else
      posts_url(:format => 'atom')
    end
  end

  def custom_atom_comments(tag=nil, author=nil, post=nil)
    tag ||= params[:tag]
    author ||= params[:author]
    if post
      if tag && author
        slug_comments_with_author_tag_url(:author=>author,:tag=>tag, :format => 'atom')
      elsif tag
        slug_comments_with_tag_url(:tag=>tag, :format => 'atom')
      elsif author
        slug_comments_with_author_url(:author=>author, :format => 'atom')
      else
        slug_comments_url(:format => 'atom')
      end
    else
      if tag && author
        all_comments_with_author_tag_url(:author=>author,:tag=>tag, :format => 'atom')
      elsif tag
        all_comments_with_tag_url(:tag=>tag, :format => 'atom')
      elsif author
        all_comments_with_author_url(:author=>author, :format => 'atom')
      else
        all_comments_url(:format => 'atom')
      end
    end
  end

  def posts_title(post=nil, tag=nil, author=nil)
    title = ''
    title << "#{post.title} - " if post
    if author && tag
      title << "#{fullname(author)} on #{tag} - "
    elsif author
      title << "#{fullname(author)} - "
    end
    title << AppConfig.title
  end

  def fullname(author)
    author+' '+AppConfig.author["writers"][author.to_s.downcase]
  end

  def linked_tag_list(tags)
    tags.collect {|tag| link_to(h(tag), custom_posts(tag, params[:author]))}.join(", ")
  end

  def tag_cloud(tags = [], options = {})
    if params[:author]
      tags = Post.tag_cloud({:author=>params[:author]})
    else
      tags = Post.tag_cloud()
    end
    return "" if tags.size == 0
{'fraction_non_alphanumeric': 0.154487917146145, 'fraction_numerical': 0.00014384349827387802, 'mean_word_length': 3.838552540013918, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2469884', 'n_tokens_mistral': 2375, 'n_tokens_neox': 2378, 'n_words': 400}