<commit_before># encoding: UTF-8
module NodeHelper

  ContentPresenter = Struct.new(:record, :title, :meta, :image, :body, :actions, :css_class) do
    def to_hash
      attrs = members.map(&:to_sym)
      Hash[*attrs.zip(values).flatten]
    end

    def self.collection?
      !!@collection
    end

    def self.collection(&blk)
      was, @collection = @collection, true
      ret = yield
      @collection = was
      ret
    end
  end

  def article_for(record)
    cp = ContentPresenter.new
    cp.record = record
    cp.css_class = 'node '
    cp.css_class << record.class.name.downcase
    cp.css_class << ' new-node' if current_account && record.node.read_status(current_account) == :not_read
    yield cp
    cp.meta ||= posted_by(record)
    cp.body ||= sanitize(ContentPresenter.collection? ?
                         record.truncated_body.sub("[...](suite)", link_to(" (...)", url_for_content(record))) :
                         record.body)
    render 'nodes/content', cp.to_hash
  end

  def editable_field(record, field)
    value = record.send(field)
    obj = ActionController::RecordIdentifier.singular_class_name(record)
    content_tag(:span, value, :class => 'rest_in_place', :"data-attribute" => field, :"data-object" => obj)
  end<commit_msg>Be more resilient for collection mode<commit_after># encoding: UTF-8
module NodeHelper

  ContentPresenter = Struct.new(:record, :title, :meta, :image, :body, :actions, :css_class) do
    def to_hash
      attrs = members.map(&:to_sym)
      Hash[*attrs.zip(values).flatten]
    end

    def self.collection?
      !!@collection
    end

    def self.collection(&blk)
      @collection = true
      yield
    ensure
      @collection = false
    end
  end

  def article_for(record)
    cp = ContentPresenter.new
    cp.record = record
    cp.css_class = 'node '
    cp.css_class << record.class.name.downcase
    cp.css_class << ' new-node' if current_account && record.node.read_status(current_account) == :not_read
    yield cp
    cp.meta ||= posted_by(record)
    cp.body ||= sanitize(ContentPresenter.collection? ?
                         record.truncated_body.sub("[...](suite)", link_to(" (...)", url_for_content(record))) :
                         record.body)
    render 'nodes/content', cp.to_hash
  end

  def editable_field(record, field)
    value = record.send(field)
    obj = ActionController::RecordIdentifier.singular_class_name(record)
    content_tag(:span, value, :class => 'rest_in_place', :"data-attribute" => field, :"data-object" => obj)
  end
{'fraction_non_alphanumeric': 0.13154785348562426, 'fraction_numerical': 0.0007877116975187081, 'mean_word_length': 2.931888544891641, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '6581464', 'n_tokens_mistral': 815, 'n_tokens_neox': 790, 'n_words': 167}