<commit_before>module GriffithCommon
  module ListTableBuilder

    ## add instance methods to class
    def self.included(base)
      base.send :include, ListTableBuilder
    end

    module ListTableBuilder
      include ::ActionView::Helpers::TagHelper

      def list_table_for collection, options = {}
        options = {
          class: 'table table-hover table-condensed',
          div_class: 'table-responsive'
        }.merge(options)

        raise ArgumentError, "Missing block" unless block_given?
        @collection = collection
        content_tag :div, class: "#{options[:div_class]}" do
          content_tag :table , class: "#{options[:class]}" do
            yield(collection)
          end
        end.html_safe
      end

      def list_table_tag(options = {}, &block)
        raise ArgumentError, "Missing block" unless block_given?
        content_tag :table , class: "#{options[:class]}" do |t|
          yield
        end.html_safe
      end

      def item(attribute, value: nil, label: nil, include_blank: false, th_class: 'left', td_class: 'left')
        value = if value.nil?
                  object = eval("@collection.#{attribute}")
                  if object.respond_to? :name
                    object.name
                  else
                    object
                  end
                else
                  value
                end

        label = label || attribute.to_s.titleize
        if value.present? || include_blank
          content_tag :tr do
            content_tag(:th, label, class: th_class) +
            content_tag(:td, value, class: td_class)
          end
        end
      end
    end
  end
end
<commit_msg>allow nil values to be passed<commit_after>module GriffithCommon
  module ListTableBuilder

    ## add instance methods to class
    def self.included(base)
      base.send :include, ListTableBuilder
    end

    module ListTableBuilder
      include ::ActionView::Helpers::TagHelper

      def list_table_for collection, options = {}
        options = {
          class: 'table table-hover table-condensed',
          div_class: 'table-responsive'
        }.merge(options)

        raise ArgumentError, "Missing block" unless block_given?
        @collection = collection
        content_tag :div, class: "#{options[:div_class]}" do
          content_tag :table , class: "#{options[:class]}" do
            yield(collection)
          end
        end.html_safe
      end

      def list_table_tag(options = {}, &block)
        raise ArgumentError, "Missing block" unless block_given?
        content_tag :table , class: "#{options[:class]}" do |t|
          yield
        end.html_safe
      end

      def item(attribute, value: :none, label: nil, include_blank: false, th_class: 'left', td_class: 'left')
        value = if value == :none
                  object = eval("@collection.#{attribute}")
                  if object.respond_to? :name
                    object.name
                  else
                    object
                  end
                else
                  value
                end

        label = label || attribute.to_s.titleize
        if value.present? || include_blank
          content_tag :tr do
            content_tag(:th, label, class: th_class) +
            content_tag(:td, value, class: td_class)
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08875739644970414, 'fraction_numerical': 0.0, 'mean_word_length': 1.7873042044517724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '119983', 'n_tokens_mistral': 911, 'n_tokens_neox': 874, 'n_words': 248}