discourse_plugin 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +3 -0
- data/lib/discourse_event.rb +24 -0
- data/lib/discourse_plugin.rb +3 -0
- data/lib/discourse_plugin/discourse_plugin.rb +51 -0
- data/lib/discourse_plugin/version.rb +3 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 12b2963648fb3935c7928e6427032c5837577258
|
4
|
+
data.tar.gz: e601f5d516d5aa9b207bdd37a8c13209b7219407
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50ade9beaa0a949a8df7c7c75749aec076caa7715f5f5d7faccba687423e695ca08eb0b8cbb4796191a75a16cc6beac1a1f9e96d58177385fa8e54b0c1e0e2ef
|
7
|
+
data.tar.gz: 7f8c9151c6204eab230f106ac0c776279ac464d1c7d438107638104c3df1d49884ad3e65119c74b0c9bc4275fa31f6e4f5b97b4b4899ff80de282d4cdf92ac26
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Robin Ward
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This is meant to be used by plugins to trigger and listen to events
|
2
|
+
# So we can execute code when things happen.
|
3
|
+
module DiscourseEvent
|
4
|
+
|
5
|
+
# Defaults to a hash where default values are empty sets.
|
6
|
+
def self.events
|
7
|
+
@events ||= Hash.new { |hash, key| hash[key] = Set.new }
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.trigger(event_name, *params)
|
11
|
+
events[event_name].each do |event|
|
12
|
+
event.call(*params)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.on(event_name, &block)
|
17
|
+
events[event_name] << block
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.clear
|
21
|
+
@events = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# A basic plugin for Discourse. Meant to be extended and filled in.
|
2
|
+
# Most work is delegated to a registry.
|
3
|
+
|
4
|
+
class DiscoursePlugin
|
5
|
+
|
6
|
+
attr_reader :registry
|
7
|
+
|
8
|
+
def initialize(registry)
|
9
|
+
@registry = registry
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
# Initialize the plugin here
|
14
|
+
end
|
15
|
+
|
16
|
+
# Loads and mixes in the plugin's mixins into the host app's classes.
|
17
|
+
# A mixin named "UserMixin" will be included into the "User" class.
|
18
|
+
def self.include_mixins
|
19
|
+
mixins.each do |mixin|
|
20
|
+
original_class = mixin.to_s.demodulize.sub("Mixin", "")
|
21
|
+
dependency_file_name = original_class.underscore
|
22
|
+
require_dependency(dependency_file_name)
|
23
|
+
original_class.constantize.send(:include, mixin)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Find the modules defined in the plugin with "Mixin" in their name.
|
28
|
+
def self.mixins
|
29
|
+
constants.map { |const_name| const_get(const_name) }
|
30
|
+
.select { |const| const.class == Module && const.name["Mixin"] }
|
31
|
+
end
|
32
|
+
|
33
|
+
def register_js(file, opts={})
|
34
|
+
@registry.register_js(file, opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def register_css(file)
|
38
|
+
@registry.register_css(file)
|
39
|
+
end
|
40
|
+
|
41
|
+
def register_archetype(name, options={})
|
42
|
+
@registry.register_archetype(name, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def listen_for(event_name)
|
46
|
+
return unless self.respond_to?(event_name)
|
47
|
+
DiscourseEvent.on(event_name, &self.method(event_name))
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: discourse_plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robin Ward
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Toolkit for creating a discourse plugin
|
14
|
+
email:
|
15
|
+
- robin.ward@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- lib/discourse_event.rb
|
23
|
+
- lib/discourse_plugin.rb
|
24
|
+
- lib/discourse_plugin/discourse_plugin.rb
|
25
|
+
- lib/discourse_plugin/version.rb
|
26
|
+
homepage: ''
|
27
|
+
licenses: []
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.2.0
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Toolkit for creating a discourse plugin
|
49
|
+
test_files: []
|
50
|
+
has_rdoc:
|