Skip to content

Instantly share code, notes, and snippets.

@listenlight
Created April 14, 2022 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save listenlight/14022344e54a12a31eae98b68c6803af to your computer and use it in GitHub Desktop.
Save listenlight/14022344e54a12a31eae98b68c6803af to your computer and use it in GitHub Desktop.
Basic functionality for word count of replies to a topic, not counting author's posts
# plugins/wordcount/plugin.rb
after_initialize do
  add_to_serializer(:topic_list_item, :word_count_of_replies) do
    object.posts.where.not(user: object.user).sum(:word_count)
  end
end
# topic-posts-column.hbr
<{{view.tagName}} class='num posts-map posts {{view.likesHeat}} topic-list-data' title='{{view.title}}'>
  <button class="btn-link posts-map badge-posts {{view.likesHeat}}" aria-label="{{view.title}}">
    {{raw-plugin-outlet name="topic-list-before-reply-count"}}
    {{number topic.replyCount noTitle="true" ariaLabel=view.title}}
    # sample change, from "2" to "2 (220w)"
    ({{number topic.word_count_of_replies noTitle="true" ariaLabel="wordcount of replies"}}w)
  </button>
</{{view.tagName}}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment