thredded-workgroup 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.rubocop +1 -0
  5. data/.rubocop.yml +65 -0
  6. data/.travis.yml +45 -0
  7. data/CHANGELOG.md +9 -0
  8. data/CODE_OF_CONDUCT.md +49 -0
  9. data/Gemfile +6 -0
  10. data/Guardfile +77 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +125 -0
  13. data/RELEASE_CHECKLIST.md +19 -0
  14. data/Rakefile +161 -0
  15. data/app/assets/images/thredded/workgroup/.keep +0 -0
  16. data/app/assets/javascripts/thredded-workgroup.js +13 -0
  17. data/app/assets/javascripts/thredded/workgroup/follow.js +36 -0
  18. data/app/assets/javascripts/thredded/workgroup/topics.js +18 -0
  19. data/app/assets/stylesheets/thredded-workgroup.scss +3 -0
  20. data/app/assets/stylesheets/thredded/workgroup/_navs.scss +35 -0
  21. data/app/assets/stylesheets/thredded/workgroup/_topics.scss +52 -0
  22. data/app/controllers/thredded/posts_controller.rb +50 -0
  23. data/app/controllers/thredded/workgroup/application_controller.rb +7 -0
  24. data/app/controllers/thredded/workgroup/navs_controller.rb +41 -0
  25. data/app/helpers/thredded/application_helper.rb +9 -0
  26. data/app/helpers/thredded/workgroup/application_helper.rb +7 -0
  27. data/app/view_models/thredded/topic_view.rb +15 -0
  28. data/app/view_models/thredded/topics_page_view.rb +15 -0
  29. data/app/views/layouts/thredded/workgroup/application.html.erb +14 -0
  30. data/app/views/thredded/posts_common/form/_after_content.html.erb +1 -0
  31. data/app/views/thredded/shared/_header.html.erb +4 -0
  32. data/app/views/thredded/topics/_topic.html.erb +51 -0
  33. data/app/views/thredded/topics/_topics_with_last_post.html.erb +14 -0
  34. data/app/views/thredded/topics/topic/_body.html.erb +27 -0
  35. data/app/views/thredded/workgroup/navs/_personal_nav.html.erb +23 -0
  36. data/app/views/thredded/workgroup/navs/all_topics.html.erb +9 -0
  37. data/app/views/thredded/workgroup/navs/awaiting.html.erb +9 -0
  38. data/app/views/thredded/workgroup/navs/following.html.erb +9 -0
  39. data/app/views/thredded/workgroup/navs/unread.html.erb +9 -0
  40. data/bin/console +15 -0
  41. data/bin/dummy-rails +4 -0
  42. data/bin/rails.rb +14 -0
  43. data/bin/rspec +17 -0
  44. data/bin/setup +8 -0
  45. data/bin/update_from_thredded +40 -0
  46. data/config/locales/en.yml +20 -0
  47. data/config/routes.rb +11 -0
  48. data/lib/thredded/workgroup.rb +19 -0
  49. data/lib/thredded/workgroup/engine.rb +26 -0
  50. data/lib/thredded/workgroup/route_delegator.rb +25 -0
  51. data/lib/thredded/workgroup/thredded_route_delegator.rb +19 -0
  52. data/lib/thredded/workgroup/version.rb +6 -0
  53. data/script/create-db-users +42 -0
  54. data/script/dummy-console +3 -0
  55. data/shared.gemfile +27 -0
  56. data/thredded-workgroup.gemspec +65 -0
  57. metadata +520 -0
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ module Thredded
3
+ module Workgroup
4
+ module ApplicationHelper
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require_dependency File.expand_path("../../app/view_models/thredded/topic_view", Thredded::Engine.called_from)
3
+ module Thredded
4
+ class TopicView < Thredded::BaseTopicView
5
+ def path
6
+ anchor = if @read_state.first_unread_post_page
7
+ "unread"
8
+ elsif @topic.last_post
9
+ "post_#{@topic.last_post.id}"
10
+ end
11
+ page = @read_state.first_unread_post_page || @read_state.last_read_post_page
12
+ Thredded::UrlsHelper.topic_path(@topic, page: page, anchor: anchor)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require_dependency File.expand_path("../../app/view_models/thredded/topics_page_view", Thredded::Engine.called_from)
3
+ module Thredded
4
+ module TopicsPageViewWithLastPost
5
+ protected
6
+
7
+ def refine_scope(topics_page_scope)
8
+ super.includes(:last_post)
9
+ end
10
+ end
11
+
12
+ class TopicsPageView
13
+ prepend ::Thredded::TopicsPageViewWithLastPost
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Thredded | <%= yield :thredded_page_title %></title>
5
+ <%= stylesheet_link_tag "thredded-workgroup", media: "all" %>
6
+ <%= csrf_meta_tag %>
7
+ <%= javascript_include_tag 'thredded' %>
8
+ <%== Gravatar.prefetch_dns %>
9
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
10
+ </head>
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ <%= hidden_field_tag 'post_referer', request.referer %>
@@ -0,0 +1,4 @@
1
+ <header role="banner">
2
+ <%= render 'thredded/workgroup/navs/personal_nav' %>
3
+ <%= render 'thredded/shared/nav' %>
4
+ </header>
@@ -0,0 +1,51 @@
1
+ <%= content_tag :article,
2
+ id: dom_id(topic),
3
+ class: ['thredded--topics--topic', topic_css_classes(topic)],
4
+ data: {topic: topic.id, messageboard: topic.messageboard_id} do %>
5
+ <div class="thredded--topics--posts-count"><%= topic.posts_count %></div>
6
+
7
+ <h1 class="thredded--topics--title">
8
+ <span class="thredded--topic-title"><%= link_to topic.title, topic.path %></span>
9
+ <% unless messageboard_or_nil #don't show if being viewed in the context of a messageboard%>
10
+ <cite class="thredded--messageboard-name">
11
+ <%= link_to topic.messageboard_name, topic.messageboard_path %>
12
+ </cite>
13
+ <% end %>
14
+ <svg viewBox="0 0 116 121" class="thredded--topics--follow-icon">
15
+ <% if topic.followed? %>
16
+ <use xlink:href="#thredded-follow-icon"/>
17
+ <% else %>
18
+ <use xlink:href="#thredded-unfollow-icon"/>
19
+ <% end %>
20
+ </svg>
21
+ </h1>
22
+
23
+ <% if topic.categories.any? %>
24
+ <ul class="thredded--topics--categories">
25
+ <%= render topic.categories %>
26
+ </ul>
27
+ <% end %>
28
+
29
+
30
+ <% if topic.blocked? && topic.can_moderate? %>
31
+ <span class="thredded--topics--moderation-state thredded--alert thredded--alert-danger">
32
+ <%= render 'thredded/shared/content_moderation_blocked_state', moderation_record: topic.last_moderation_record %>
33
+ </span>
34
+ <% end %>
35
+
36
+ <%= render partial: 'thredded/topics/followers', locals: {topic: topic} %>
37
+
38
+ <div class='thredded--topic-post-and-last-user thredded--condensed'>
39
+ <div class="thredded--topic-source">
40
+ <cite class="thredded--topics--updated-by">
41
+ <%= topic.last_user.thredded_display_name %>
42
+ <%= time_ago topic.last_post_at %>
43
+ </cite>
44
+ </div>
45
+
46
+ <div class="thredded--last-post">
47
+ <%= render 'thredded/posts_common/content', post: topic.last_post if topic.last_post %>
48
+ </div>
49
+ </div>
50
+
51
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <div class="thredded--svg-definitions">
2
+ <%= inline_svg 'thredded/follow.svg', id:"thredded-follow-icon" %>
3
+ <%= inline_svg 'thredded/unfollow.svg', id:"thredded-unfollow-icon" %>
4
+ </div>
5
+
6
+ <%= thredded_page do %>
7
+ <%= content_tag :section, class: 'thredded--main-section thredded--topics', 'data-thredded-topics' => true do %>
8
+ <%= render @topics %>
9
+ <% end %>
10
+
11
+ <footer>
12
+ <%= paginate @topics %>
13
+ </footer>
14
+ <% end %>
@@ -0,0 +1,27 @@
1
+ <div class="thredded--topics--posts-count"><%= topic.posts_count %></div>
2
+
3
+ <h1 class="thredded--topics--title">
4
+ <%= link_to topic.title, topic.path %>
5
+ </h1>
6
+
7
+ <% if topic.categories.any? %>
8
+ <ul class="thredded--topics--categories">
9
+ <%= render topic.categories %>
10
+ </ul>
11
+ <% end %>
12
+
13
+ <cite class="thredded--topics--updated-by">
14
+ <%= time_ago topic.updated_at %>
15
+ <%= user_link topic.last_user %>
16
+ </cite>
17
+
18
+ <cite class="thredded--topics--started-by">
19
+ <%= time_ago topic.created_at %>
20
+ <%= user_link topic.user %>
21
+ </cite>
22
+
23
+ <% if topic.blocked? && topic.can_moderate? %>
24
+ <span class="thredded--topics--moderation-state thredded--alert thredded--alert-danger">
25
+ <%= render 'thredded/shared/content_moderation_blocked_state', moderation_record: topic.last_moderation_record %>
26
+ </span>
27
+ <% end %>
@@ -0,0 +1,23 @@
1
+ <ul class="thredded--workgroup">
2
+ <li class="<%= Thredded::Workgroup.navbar_class(params, :unread) %>">
3
+ <%= link_to t('thredded.workgroup.unread.link'), thredded_workgroup.unread_nav_path%>
4
+ </li>
5
+ <li class="<%= Thredded::Workgroup.navbar_class(params, :awaiting) %>">
6
+ <%= link_to thredded_workgroup.awaiting_nav_path do %>
7
+ <span class="expanded"><%= t('thredded.workgroup.awaiting_reply.link') %></span>
8
+ <span class="condensed"><%= t('thredded.workgroup.awaiting_reply.condensed-link') %></span>
9
+ <% end %>
10
+ </li>
11
+ <li class="<%= Thredded::Workgroup.navbar_class(params, :following) %>">
12
+ <%= link_to t('thredded.workgroup.following.link'), thredded_workgroup.following_nav_path %>
13
+ </li>
14
+ <li class="<%= Thredded::Workgroup.navbar_class(params, :all_topics) %>">
15
+ <%= link_to t('thredded.workgroup.all_topics.link'), thredded_workgroup.all_topics_nav_path %>
16
+ </li>
17
+ <li class="<%= Thredded::Workgroup.navbar_class(params, :messageboards) %>">
18
+ <%= link_to thredded.root_path do %>
19
+ <span class="expanded"><%= t('thredded.workgroup.messageboards.link') %></span>
20
+ <span class="condensed"><%= t('thredded.workgroup.messageboards.condensed-link') %></span>
21
+ <% end %>
22
+ </li>
23
+ </ul>
@@ -0,0 +1,9 @@
1
+ <% content_for :thredded_page_title, t('thredded.workgroup.all_topics.title') %>
2
+ <% content_for :thredded_page_id, 'thredded--all_topics' %>
3
+ <% content_for :thredded_breadcrumbs do %>
4
+ <ul class="thredded--navigation-breadcrumbs">
5
+ <li><a><%= t('thredded.workgroup.all_topics.title')%></a></li>
6
+ </ul>
7
+ <% end %>
8
+
9
+ <%= render partial: 'thredded/topics/topics_with_last_post'%>
@@ -0,0 +1,9 @@
1
+ <% content_for :thredded_page_title, "Topics awaiting reply" %>
2
+ <% content_for :thredded_page_id, 'thredded--awaiting_reply' %>
3
+ <% content_for :thredded_breadcrumbs do %>
4
+ <ul class="thredded--navigation-breadcrumbs">
5
+ <li><a><%= t('thredded.workgroup.awaiting_reply.title')%></a></li>
6
+ </ul>
7
+ <% end %>
8
+
9
+ <%= render partial: 'thredded/topics/topics_with_last_post'%>
@@ -0,0 +1,9 @@
1
+ <% content_for :thredded_page_title, t('thredded.workgroup.following.title') %>
2
+ <% content_for :thredded_page_id, 'thredded--following' %>
3
+ <% content_for :thredded_breadcrumbs do %>
4
+ <ul class="thredded--navigation-breadcrumbs">
5
+ <li><a><%= t('thredded.workgroup.following.title')%></a></li>
6
+ </ul>
7
+ <% end %>
8
+
9
+ <%= render partial: 'thredded/topics/topics_with_last_post'%>
@@ -0,0 +1,9 @@
1
+ <% content_for :thredded_page_title, t('thredded.workgroup.unread.title') %>
2
+ <% content_for :thredded_page_id, 'thredded--unread' %>
3
+ <% content_for :thredded_breadcrumbs do %>
4
+ <ul class="thredded--navigation-breadcrumbs">
5
+ <li><a><%= t('thredded.workgroup.unread.title')%></a></li>
6
+ </ul>
7
+ <% end %>
8
+
9
+ <%= render partial: 'thredded/topics/topics_with_last_post'%>
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "thredded/workgroup"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start
data/bin/dummy-rails ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ cd spec/dummy
4
+ BUNDLE_GEMFILE="${BUNDLE_GEMFILE:-../../Gemfile}" bundle exec rails $*
data/bin/rails.rb ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ # This command will automatically be run when you run "rails"
4
+ # with Rails 4 gems installed from the root of your application.
5
+
6
+ ENGINE_ROOT = File.expand_path("../..", __FILE__)
7
+ ENGINE_PATH = File.expand_path("../../lib/thredded/workgroup/engine", __FILE__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
11
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
12
+
13
+ require "rails/all"
14
+ require "rails/engine/commands"
data/bin/rspec ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+ # quick relatively hacky script that assumes you've just done a bundle update thredded using a github (e.g branch, tag) rather
5
+ # than a normal gem version reference for thredded (so you have access to spec/ directory)
6
+ # and updates the relevant parts of this plugin that need it from the thredded gem
7
+ # not 100% sure what the less hacky version might be
8
+ #
9
+ # at very least should make this a more structured file
10
+ # and then also add a notice to the top of the copied files that they have been copied from thredded
11
+
12
+ # store thredded-workgroup config, emoji
13
+ rm -fR tmp/upgradecache
14
+ mkdir -p tmp/upgradecache
15
+ cp ./spec/dummy/config/initializers/thredded_workgroup.rb ./tmp/upgradecache
16
+ mv ./spec/dummy/public/emoji ./tmp/upgradecache/
17
+
18
+ # update spec/dummy from thredded
19
+ rm -fR ./spec/dummy/
20
+ cp -pR $(bundle show thredded)/spec/dummy ./spec/dummy
21
+
22
+ # update some standard helpful files
23
+ cp $(bundle show thredded)/spec/support/features/fake_content.rb spec/support/features/fake_content.rb
24
+
25
+ # restore thredded-workgroup config, emoji
26
+ mv ./tmp/upgradecache/thredded_workgroup.rb ./spec/dummy/config/initializers/
27
+ mkdir -p ./spec/dummy/public/emoji
28
+ cp -R ./tmp/upgradecache/emoji/* ./spec/dummy/public/emoji
29
+
30
+ # update factories from thredded
31
+ cp $(bundle show thredded)/spec/factories.rb ./spec/factories/thredded.rb
32
+ rubocop -o /dev/null -a ./spec
33
+
34
+ git add ./spec/factories/thredded.rb
35
+ git add ./spec/dummy
36
+ echo have a look at some of these...
37
+ git reset spec/dummy/config/application.rb spec/dummy/config/routes.rb spec/dummy/app/assets/stylesheets/_dummy_app.scss spec/dummy/app/assets/javascripts/application.js
38
+
39
+ echo remember to drop and recreate db
40
+ echo rake db:drop db:create db:migrate db:seed
@@ -0,0 +1,20 @@
1
+ ---
2
+ en:
3
+ thredded:
4
+ workgroup:
5
+ unread:
6
+ title: Unread topics you are following
7
+ link: Unread
8
+ awaiting_reply:
9
+ title: Topics you are following where you made the last post
10
+ link: Awaiting reply
11
+ condensed-link: Await
12
+ following:
13
+ title: Topics you are following
14
+ link: Follow
15
+ messageboards:
16
+ link: Messageboards
17
+ condensed-link: M'boards
18
+ all_topics:
19
+ title: All topics
20
+ link: All
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ Thredded::Workgroup::Engine.routes.draw do
3
+ controller "navs" do
4
+ get "unread", action: :unread, as: :unread_nav
5
+ get "following", action: :following, as: :following_nav
6
+ get "all_topics", action: :all_topics, as: :all_topics_nav
7
+ get "awaiting", action: :awaiting, as: :awaiting_nav
8
+ end
9
+
10
+ mount Thredded::Engine => "/"
11
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require "thredded/workgroup/engine"
3
+ require "thredded/workgroup/version"
4
+
5
+ module Thredded
6
+ module Workgroup
7
+ def self.navbar_class(params, target)
8
+ "active" if current_for(params) == target
9
+ end
10
+
11
+ def self.current_for(params)
12
+ if params[:controller].include?("workgroup") # TODO: make this better
13
+ params[:action].to_sym
14
+ else
15
+ :messageboards
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require "thredded/engine"
3
+ require "thredded/workgroup/thredded_route_delegator"
4
+ require "thredded/workgroup/route_delegator"
5
+ module Thredded
6
+ module Workgroup
7
+ class Engine < ::Rails::Engine
8
+ isolate_namespace Thredded::Workgroup
9
+
10
+ %w(app/controllers app/jobs app/view_models lib).each do |path|
11
+ config.autoload_paths << File.expand_path("../../#{path}", File.dirname(__FILE__))
12
+ end
13
+
14
+ config.to_prepare do
15
+ Rails.application.reload_routes!
16
+ ::Thredded::Workgroup::ThreddedRouteDelegator.add_thredded_proxies
17
+ ::Thredded::Workgroup::RouteDelegator.add_my_proxies_to_thredded
18
+ end
19
+ initializer "thredded.setup_assets" do
20
+ Thredded::Workgroup::Engine.config.assets.precompile += %w(
21
+ thredded-workgroup.css
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This includes this module into Thredded Application Controller so we can use
4
+ # url helpers from Thredded PN like unread_nav_path in controllers.
5
+ module Thredded
6
+ module Workgroup
7
+ module RouteDelegator
8
+ def self.add_my_proxies_to_thredded
9
+ thredded_methods = Thredded::Engine.routes.url_helpers.methods
10
+ my_route_helpers = Thredded::Workgroup::Engine.routes.url_helpers
11
+ path_methods = my_route_helpers.methods.select { |s| s.to_s.ends_with?("_path", "_url") }
12
+ .reject { |s| thredded_methods.include?(s) }
13
+ path_methods.each do |method_name|
14
+ send(:define_method, method_name) do |*args|
15
+ my_route_helpers.send(method_name, *args)
16
+ end
17
+ end
18
+ ::Thredded::ApplicationController.send(:include,
19
+ ::Thredded::Workgroup::RouteDelegator)
20
+ # if we need to use in views, then we add
21
+ # ::Thredded::ApplicationController.helper(::Thredded::Workgroup::RouteDelegator)
22
+ end
23
+ end
24
+ end
25
+ end