forked from sylque/dcs-discourse-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.rb
85 lines (74 loc) · 3.59 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# name: docuss
# about: Docuss plugin for Discourse
# version: 1.0.31
# authors: Sylvain Quendez
# url: https://github.com/sylque/dcs-discourse-plugin
# When styles are not working or are not updating, try:
# - stopping server
# - rm -rf discourse/tmp
# - delete discourse/public/uploads/stylesheet-cache
# - restart server
# If styles are still not updating, there is probably a syntax error in the SCSS
# causing a silent failure and causing the file not being processed.
# To be 100% sure you can also enable Chrome Dev Tools -> Settings -> General ->
# Disable cache (while DevTools is open), but note it leads to 30s onload times.
# Load styles
register_asset "stylesheets/docuss.css"
# Register admin settings
enabled_site_setting :docuss_enabled
# Required for Bellhop to run, as it uses Babel regeneratorRuntime. See:
# https://github.com/mozilla/pdf.js/issues/11036
# https://github.com/ianstormtaylor/slate/issues/3242
extend_content_security_policy(script_src: [:unsafe_eval])
# Changes X-Frame-Options so the site can be embedded in an iframe. See:
# https://github.com/BeXcellent/discourse-allowiframe/blob/master/plugin.rb
# https://github.com/TheBunyip/discourse-allow-same-origin/blob/master/plugin.rb
Rails.application.config.action_dispatch.default_headers.merge!({'X-Frame-Options' => 'ALLOWALL'})
# Monkey-ptach the tags:show_latest controller, so that it returns an empty list
# instead of a 404 exception when the tag doesn't exist. Thisserver-side part
# is mandatory to handle loading an initial url pointing to a non-existent tag
# Thefull solution also require to override TagsShowRoute::model() client-side.
# We are overriding this:
# https://github.com/discourse/discourse/blob/385829d7be7cc85b2eb561b7a2640768bc7710de/app/controllers/tags_controller.rb#L70
# Example of controller overriding:
# https://github.com/discourse/discourse-voting/blob/master/plugin.rb#L213
# https://meta.discourse.org/t/overriding-a-method-in-a-controller/92657
# Clean monkey patching in ruby (first metho, with 'prepend()', doesn't work) :
# https://stackoverflow.com/questions/4470108/when-monkey-patching-a-method-can-you-call-the-overridden-method-from-the-new-i
# About handling exceptions:
# http://rubylearning.com/satishtalim/ruby_exceptions.html
#after_initialize do
# require_dependency 'tags_controller'
# class ::TagsController
# old_show_latest = instance_method(:show_latest)
# define_method(:show_latest) do
# begin
# old_show_latest.bind(self).()
# rescue
# list_opts = build_topic_list_options
# @list = TopicQuery.new(current_user, list_opts).public_send("list_latest")
# @list.draft_key = Draft::NEW_TOPIC
# @list.draft_sequence = DraftSequence.current(current_user, Draft::NEW_TOPIC)
# @list.draft = Draft.get(current_user, @list.draft_key, @list.draft_sequence) if current_user
# @list.more_topics_url = construct_url_with(:next, list_opts)
# @list.prev_topics_url = construct_url_with(:prev, list_opts)
# respond_with_list(@list)
# end
# end
# end
#end
after_initialize do
# https://github.com/discourse/discourse-slack-official/blob/master/plugin.rb#L35
require_dependency 'application_controller'
class ::DocussController < ::ApplicationController
def show
# render html: 'Hello'
end
end
Discourse::Application.routes.append do
# https://meta.discourse.org/t/make-forum-available-on-a-subpath-via-additional-route/89453?u=jack2
# https://github.com/discourse/discourse/blob/master/config/routes.rb#L677
#get '/docuss' => 'list#latest'
get '/docuss(/:page)' => 'docuss#show'
end
end