jekyll-hackclub 1.2.0 → 1.4.0
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 +4 -4
- data/lib/args-parser.rb +39 -0
- data/lib/jekyll-hackclub.rb +9 -5
- data/lib/pipes/arrays.rb +17 -0
- data/lib/pipes/numbers.rb +17 -0
- data/lib/pipes/strings.rb +17 -0
- data/lib/server-bridge.rb +29 -0
- data/lib/{channel-tag.rb → tags/channel-tag.rb} +6 -3
- data/lib/{emoji.rb → tags/emoji.rb} +1 -1
- data/lib/tags/file.rb +35 -0
- data/lib/{mentions.rb → tags/mentions.rb} +12 -1
- data/lib/tags/parser.rb +18 -0
- data/lib/{user-tag.rb → tags/user-tag.rb} +7 -3
- data/lib/tags/usergroup-tag.rb +27 -0
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1de71437907ec6e92d5b674b42dc745763ffb1f0b4010345df2bd38ae614960f
|
4
|
+
data.tar.gz: 0c04f981eaed4fb3b09f4aef40ed183ea64a95019977f8f407fa97e0f750a432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab656eaeb6afcd5810732d0ca95bf0feb9be3165c6b50101f2f1eac981842fcd9e4ccca73575edab704e50513dad6ee53ef6af8d657d3ab6664453035550f2b6
|
7
|
+
data.tar.gz: 0a7ba5e07b1c95719ee6f407302bd571488e2033b4ccdd6211f6d9ac06d73cb5c927dbd677a57011fac09e2d7620f8bd37e809b67650fc909c1c165aff726016
|
data/lib/args-parser.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative "./pipes/strings"
|
2
|
+
require_relative "./pipes/numbers"
|
3
|
+
require_relative "./pipes/arrays"
|
4
|
+
|
5
|
+
module ArgsParser
|
6
|
+
def self.split_args(content)
|
7
|
+
content.split(" ; ").map(&:strip)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.eval_pipes_with_val(value, pipes)
|
11
|
+
pipes.each do |pipe|
|
12
|
+
args = pipe.split(" ") || []
|
13
|
+
func = args.shift || pipe
|
14
|
+
if (match = pipe.match(/\[(-?\d+):(-?\d+)\]/))
|
15
|
+
start_idx, end_idx = match[1].to_i, match[2].to_i
|
16
|
+
value = value[start_idx..end_idx]
|
17
|
+
elsif StringManipulation.respond_to?(func)
|
18
|
+
value = StringManipulation.public_send(func, value, args)
|
19
|
+
elsif NumbersManipulation.respond_to?(func)
|
20
|
+
value = NumbersManipulation.public_send(func, value, args)
|
21
|
+
elsif ArraysManipulation.respond_to?(func)
|
22
|
+
value = ArraysManipulation.public_send(func, value, args)
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Unkown function '#{func}'"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
value
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.eval_pipes(arg)
|
31
|
+
parts = arg.split(" | ").map(&:strip)
|
32
|
+
value = parts.shift
|
33
|
+
eval_pipes_with_val(value, parts)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.parse(content)
|
37
|
+
split_args(content).map { |arg| eval_pipes(arg) }
|
38
|
+
end
|
39
|
+
end
|
data/lib/jekyll-hackclub.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
require_relative "./emoji"
|
2
|
-
require_relative "./mentions"
|
3
|
-
require_relative "./
|
4
|
-
require_relative "./
|
5
|
-
require_relative "./
|
1
|
+
require_relative "./tags/emoji"
|
2
|
+
require_relative "./tags/mentions"
|
3
|
+
require_relative "./tags/user-tag"
|
4
|
+
require_relative "./tags/channel-tag"
|
5
|
+
require_relative "./tags/usergroup-tag"
|
6
|
+
require_relative "./tags/file"
|
7
|
+
|
8
|
+
require_relative "./tags/parser"
|
9
|
+
require_relative "./server-bridge"
|
data/lib/pipes/arrays.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module ArraysManipulation
|
2
|
+
def self.first(content, args)
|
3
|
+
content = content.first
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.last(content, args)
|
7
|
+
content = content.last
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get(content, args)
|
11
|
+
content = content[args[0]]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.cut(content, args)
|
15
|
+
content = content[args[0]..args[1]]
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NumbersManipulation
|
2
|
+
def self.to_int(content, args)
|
3
|
+
content.to_i
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.multiply(content, args)
|
7
|
+
content * args[0].to_i
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.add(content, args)
|
11
|
+
content + args[0].to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.substract(content, args)
|
15
|
+
content - args[0].to_i
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module StringManipulation
|
2
|
+
def self.uppercase(content, args)
|
3
|
+
content.upcase
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.downcase(content, args)
|
7
|
+
content.downcase
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.capitalize(content, args)
|
11
|
+
content.capitalize
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.size(content, args)
|
15
|
+
content.size
|
16
|
+
end
|
17
|
+
end
|
data/lib/server-bridge.rb
CHANGED
@@ -21,6 +21,18 @@ module HackclubRequest
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
def self.raw_file(fileid)
|
25
|
+
uri = URI("#{host}/files.info/#{fileid}")
|
26
|
+
res = Net::HTTP.get_response(uri)
|
27
|
+
|
28
|
+
data = JSON.parse(res.body)
|
29
|
+
if res.is_a?(Net::HTTPSuccess)
|
30
|
+
data
|
31
|
+
else
|
32
|
+
{}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
24
36
|
def self.raw_user(userid)
|
25
37
|
uri = URI("#{host}/users.info/#{userid}")
|
26
38
|
res = Net::HTTP.get_response(uri)
|
@@ -33,6 +45,23 @@ module HackclubRequest
|
|
33
45
|
end
|
34
46
|
end
|
35
47
|
|
48
|
+
def self.raw_usergroup(groupid)
|
49
|
+
uri = URI("#{host}/usergroup/#{groupid}")
|
50
|
+
res = Net::HTTP.get_response(uri)
|
51
|
+
|
52
|
+
data = JSON.parse(res.body)
|
53
|
+
if res.is_a?(Net::HTTPSuccess)
|
54
|
+
data
|
55
|
+
else
|
56
|
+
{}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.resolve_usergroup(groupid)
|
61
|
+
data = raw_usergroup(groupid)
|
62
|
+
return data.dig("handle") || "unknown"
|
63
|
+
end
|
64
|
+
|
36
65
|
def self.resolve_username(userid)
|
37
66
|
uri = URI("#{host}/users.info/#{userid}")
|
38
67
|
res = Net::HTTP.get_response(uri)
|
@@ -1,14 +1,17 @@
|
|
1
1
|
require "jekyll"
|
2
|
-
require_relative "
|
2
|
+
require_relative "../server-bridge"
|
3
3
|
|
4
4
|
module Jekyll
|
5
5
|
class HackclubChannelTag < Liquid::Tag
|
6
6
|
def initialize(tagName, content, tokens)
|
7
7
|
super
|
8
8
|
content = content.strip()
|
9
|
-
@id,
|
10
|
-
|
9
|
+
@id, keys, pipes = ArgsParser.split_args(content)
|
10
|
+
pipes = pipes || ""
|
11
|
+
keys = keys.split(".")
|
12
|
+
|
11
13
|
@data = HackclubRequest.raw_channel(@id).dig("channel").dig(*keys)
|
14
|
+
@data = ArgsParser.eval_pipes_with_val(@data, pipes.split(" | ").map(&:strip))
|
12
15
|
end
|
13
16
|
|
14
17
|
def render(context)
|
data/lib/tags/file.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "../server-bridge"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class HackclubFileTag < Liquid::Tag
|
6
|
+
def initialize(tagName, content, tokens)
|
7
|
+
super
|
8
|
+
content = content.strip()
|
9
|
+
@id, keys, pipes = ArgsParser.split_args(content)
|
10
|
+
pipes = pipes || ""
|
11
|
+
keys = keys || ""
|
12
|
+
keys = keys.split(".")
|
13
|
+
|
14
|
+
if keys == []
|
15
|
+
rawfile = HackclubRequest.raw_file(@id).dig("file")
|
16
|
+
permalink = rawfile.dig("permalink")
|
17
|
+
name = rawfile.dig("name")
|
18
|
+
@data = '<a href="'+permalink+'" class="hackclub-file" target="_blank">'+name+'</a>'
|
19
|
+
else
|
20
|
+
@data = HackclubRequest.raw_file(@id).dig("file").dig(*keys)
|
21
|
+
@data = ArgsParser.eval_pipes_with_val(@data, pipes.split(" | ").map(&:strip))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def render(context)
|
26
|
+
if @data == nil
|
27
|
+
%Q{null}
|
28
|
+
else
|
29
|
+
%Q{#{@data}}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Liquid::Template.register_tag "file", HackclubFileTag
|
35
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "jekyll"
|
2
|
-
require_relative "
|
2
|
+
require_relative "../args-parser"
|
3
|
+
require_relative "../server-bridge"
|
3
4
|
|
4
5
|
module Jekyll
|
5
6
|
class HackclubMention < Liquid::Tag
|
@@ -10,12 +11,22 @@ module Jekyll
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def render(context)
|
14
|
+
parts = @id.split(" | ")
|
15
|
+
@id = parts[0]
|
16
|
+
@pipes = parts[1..-1]
|
17
|
+
|
13
18
|
if @id && @id.start_with?("U")
|
14
19
|
display_name = @args[1] || HackclubRequest.resolve_username(@id)
|
20
|
+
display_name = ArgsParser.eval_pipes_with_val(display_name, @pipes)
|
15
21
|
%Q{<a href="https://hackclub.slack.com/team/#{@id}" class="hackclub-mention hackclub-user" target="_blank">@#{display_name}</a>}
|
16
22
|
elsif @id && @id.start_with?("C")
|
17
23
|
display_name = @args[1] || HackclubRequest.resolve_channel(@id)
|
24
|
+
display_name = ArgsParser.eval_pipes_with_val(display_name, @pipes)
|
18
25
|
%Q{<a href="https://hackclub.slack.com/archives/#{@id}" class="hackclub-mention hackclub-channel" target="_blank">##{display_name}</a>}
|
26
|
+
elsif @id && @id.start_with?("S")
|
27
|
+
display_name = @args[1] || HackclubRequest.resolve_usergroup(@id)
|
28
|
+
display_name = ArgsParser.eval_pipes_with_val(display_name, @pipes)
|
29
|
+
%Q{@#{display_name}}
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
data/lib/tags/parser.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "../server-bridge"
|
3
|
+
require_relative "../args-parser"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class HackclubParser < Liquid::Tag
|
7
|
+
def initialize(tagName, content, tokens)
|
8
|
+
super
|
9
|
+
@content = content
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(context)
|
13
|
+
%Q{#{ArgsParser.parse(@content)}}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Liquid::Template.register_tag "_parser", HackclubParser
|
18
|
+
end
|
@@ -1,14 +1,18 @@
|
|
1
1
|
require "jekyll"
|
2
|
-
require_relative "
|
2
|
+
require_relative "../args-parser"
|
3
|
+
require_relative "../server-bridge"
|
3
4
|
|
4
5
|
module Jekyll
|
5
6
|
class HackclubUserTag < Liquid::Tag
|
6
7
|
def initialize(tagName, content, tokens)
|
7
8
|
super
|
8
9
|
content = content.strip()
|
9
|
-
@id,
|
10
|
-
|
10
|
+
@id, keys, pipes = ArgsParser.split_args(content)
|
11
|
+
pipes = pipes || ""
|
12
|
+
keys = keys.split(".")
|
13
|
+
|
11
14
|
@data = HackclubRequest.raw_user(@id).dig("user").dig(*keys)
|
15
|
+
@data = ArgsParser.eval_pipes_with_val(@data, pipes.split(" | ").map(&:strip))
|
12
16
|
end
|
13
17
|
|
14
18
|
def render(context)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "../server-bridge"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class HackclubUsergroupTag < Liquid::Tag
|
6
|
+
def initialize(tagName, content, tokens)
|
7
|
+
super
|
8
|
+
content = content.strip()
|
9
|
+
@id, keys, pipes = ArgsParser.split_args(content)
|
10
|
+
pipes = pipes || ""
|
11
|
+
keys = keys.split(".")
|
12
|
+
|
13
|
+
@data = HackclubRequest.raw_usergroup(@id).dig(*keys)
|
14
|
+
@data = ArgsParser.eval_pipes_with_val(@data, pipes.split(" | ").map(&:strip))
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(context)
|
18
|
+
if @data == nil
|
19
|
+
%Q{null}
|
20
|
+
else
|
21
|
+
%Q{#{@data}}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Liquid::Template.register_tag "usergroup", HackclubUsergroupTag
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-hackclub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MathiasDPX
|
@@ -41,12 +41,19 @@ executables: []
|
|
41
41
|
extensions: []
|
42
42
|
extra_rdoc_files: []
|
43
43
|
files:
|
44
|
-
- lib/
|
45
|
-
- lib/emoji.rb
|
44
|
+
- lib/args-parser.rb
|
46
45
|
- lib/jekyll-hackclub.rb
|
47
|
-
- lib/
|
46
|
+
- lib/pipes/arrays.rb
|
47
|
+
- lib/pipes/numbers.rb
|
48
|
+
- lib/pipes/strings.rb
|
48
49
|
- lib/server-bridge.rb
|
49
|
-
- lib/
|
50
|
+
- lib/tags/channel-tag.rb
|
51
|
+
- lib/tags/emoji.rb
|
52
|
+
- lib/tags/file.rb
|
53
|
+
- lib/tags/mentions.rb
|
54
|
+
- lib/tags/parser.rb
|
55
|
+
- lib/tags/user-tag.rb
|
56
|
+
- lib/tags/usergroup-tag.rb
|
50
57
|
licenses:
|
51
58
|
- MIT
|
52
59
|
metadata: {}
|