<commit_before>module PostsHelper
  def get_edit_route(comment)
    if params[:action] == "show"
      if !comment.attachments.empty? 
        if !comment.attachments.select{|a| a.image?}.empty?     
          space_post_path(comment.space, params[:id] ? params[:id] : comment.id,:edit => comment.id, :form => 'photos')
        else
          space_post_path(comment.space, params[:id] ? params[:id] : comment.id,:edit => comment.id, :form => 'docs')
        end
      else
        space_post_path(comment.space, params[:id] ? params[:id] : comment.id,:edit => comment.id)
      end
    else
      if !comment.attachments.empty? 
        if !comment.attachments.select{|a| a.image?}.empty?     
          space_posts_path(comment.space, :edit => comment.id, :form => 'photos')
        else
          space_posts_path(comment.space, :edit => comment.id, :form => 'docs')
        end
      else
        space_posts_path(comment.space, :edit => comment.id)
      end
    end
  end
  
  def get_reply_route(post,form='')
    if params[:action] == "show"
      space_post_path(post.space, params[:id],:reply_to => post.id, :form => form)
    else
      space_posts_path(post.space, :reply_to => post.id, :form => form)
    end
  end
  
  def first_words( text, size )
    return truncate(text, :lenght => size, :omision => "...")
    
    #!!!! WARNING !!!
    if text.length > size
      cutted_text = text[0..size]
      cutted_text.chop! until cutted_text[-1,1] == " "
      cutted_text.chop!
      cutted_text << "..."
    else
      text
    end
  end
  
  def thread_title(post)
    post.parent_id.nil? ? post.title : post.parent.title
  end
  
  def thread(post)
    post.parent_id.nil? ? post : post.parent
  end
  
  def post_format( text)
   (text.include?("<") && text.include?("</") && text.include?(">")) ? text : simple_format(text)
  end
  
  def get_today_posts(posts)
    posts.select{|x| x.updated_at > Date.yesterday}
  end
  
  def get_yesterday_posts(posts)
    posts.select{|x| x.updated_at > Date.yesterday - 1 && x.updated_at < Date.yesterday}
  end
  
  def get_last_week_posts(posts)<commit_msg>post_format helper bug when argument is nil fixed<commit_after>module PostsHelper
  def get_edit_route(comment)
    if params[:action] == "show"
      if !comment.attachments.empty? 
        if !comment.attachments.select{|a| a.image?}.empty?     
          space_post_path(comment.space, params[:id] ? params[:id] : comment.id,:edit => comment.id, :form => 'photos')
        else
          space_post_path(comment.space, params[:id] ? params[:id] : comment.id,:edit => comment.id, :form => 'docs')
        end
      else
        space_post_path(comment.space, params[:id] ? params[:id] : comment.id,:edit => comment.id)
      end
    else
      if !comment.attachments.empty? 
        if !comment.attachments.select{|a| a.image?}.empty?     
          space_posts_path(comment.space, :edit => comment.id, :form => 'photos')
        else
          space_posts_path(comment.space, :edit => comment.id, :form => 'docs')
        end
      else
        space_posts_path(comment.space, :edit => comment.id)
      end
    end
  end
  
  def get_reply_route(post,form='')
    if params[:action] == "show"
      space_post_path(post.space, params[:id],:reply_to => post.id, :form => form)
    else
      space_posts_path(post.space, :reply_to => post.id, :form => form)
    end
  end
  
  def first_words( text, size )
    return truncate(text, :lenght => size, :omision => "...")
    
    #!!!! WARNING !!!
    if text.length > size
      cutted_text = text[0..size]
      cutted_text.chop! until cutted_text[-1,1] == " "
      cutted_text.chop!
      cutted_text << "..."
    else
      text
    end
  end
  
  def thread_title(post)
    post.parent_id.nil? ? post.title : post.parent.title
  end
  
  def thread(post)
    post.parent_id.nil? ? post : post.parent
  end
  
  def post_format( text)
   text ||=""
   (text.include?("<") && text.include?("</") && text.include?(">")) ? text : simple_format(text)
  end
  
  def get_today_posts(posts)
    posts.select{|x| x.updated_at > Date.yesterday}
  end
  
  def get_yesterday_posts(posts)
    posts.select{|x| x.updated_at > Date.yesterday - 1 && x.updated_at < Date.yesterday}
  end
  
  def get_last_week_posts(posts)
{'fraction_non_alphanumeric': 0.14922933208780945, 'fraction_numerical': 0.0018682858477347033, 'mean_word_length': 2.708225108225108, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 43, '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': '4482504', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1483, 'n_words': 287}