<commit_before>define [
  "underscore"
  "models/base/model"
  "lib/utils"
  "lib/formatters"
], (_, Model, utils, formatters)  ->
  "use strict"

  class Post extends Model

    destroy: ->
      @apiCall "delete", message: @get "id"

    getAttributes: ->
      # Because we could render template before the date has been
      # fetched.
      return {} if _(@attributes).isEmpty()

      recommendations = utils.truncate \
        @get("recommendations").map((u) -> "@" + u)
      recommendationsTitle = if recommendations.length
        "Рекомендовали: " + recommendations.join ", "
      else if utils.isLogged()
        "Рекомендовать"
      else
        "Рекомендации"

      recommended = utils.getUser() in @get "recommendations"

      canDelete = utils.getUser() == @get "user"

      formattedText = formatters.format @get("text"), @get("format")

      _({recommendationsTitle,
         recommended,
         canDelete,
         formattedText}).extend @attributes<commit_msg>Truncate big posts [#36]<commit_after>define [
  "underscore"
  "models/base/model"
  "lib/utils"
  "lib/formatters"
], (_, Model, utils, formatters)  ->
  "use strict"

  class Post extends Model

    destroy: ->
      @apiCall "delete", message: @get "id"

    SHORT_POST_LENGTH: 500

    getAttributes: ->
      # Because we could render template before the date has been
      # fetched.
      return {} if _(@attributes).isEmpty()

      recommendations = utils.truncate \
        @get("recommendations").map((u) -> "@" + u)
      recommendationsTitle = if recommendations.length
        "Рекомендовали: " + recommendations.join ", "
      else if utils.isLogged()
        "Рекомендовать"
      else
        "Рекомендации"

      recommended = utils.getUser() in @get "recommendations"

      canDelete = utils.getUser() == @get "user"

      text = @get "text"
      # Skip truncate for single post
      if this instanceof Post
        # XXX: Of course it is much better to shrink post based on
        # it's rendered size but jquery.dotdotdot is so horrible slow.
        # (About 38ms for single middle-sized div. What the fuck?)
        if text.length > @SHORT_POST_LENGTH
          text = text[...@SHORT_POST_LENGTH]
          text += " […](/p/#{@get 'id'} \"Читать дальше\")"
      formattedText = formatters.format text, @get("format")

      _({
          recommendationsTitle
          recommended
          canDelete
          formattedText
        }).extend @attributes
{'fraction_non_alphanumeric': 0.11954765751211632, 'fraction_numerical': 0.002827140549273021, 'mean_word_length': 2.4546722454672247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '5492115', 'n_tokens_mistral': 758, 'n_tokens_neox': 744, 'n_words': 193}