jekyll-hackclub 1.3.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 +12 -20
- data/lib/jekyll-hackclub.rb +3 -1
- 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/tags/file.rb +35 -0
- data/lib/tags/mentions.rb +4 -1
- data/lib/tags/usergroup-tag.rb +27 -0
- metadata +6 -1
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
CHANGED
@@ -1,20 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.downcase(content)
|
7
|
-
content.downcase
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.capitalize(content)
|
11
|
-
content.capitalize
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.size(content)
|
15
|
-
content.size
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require_relative "./pipes/strings"
|
2
|
+
require_relative "./pipes/numbers"
|
3
|
+
require_relative "./pipes/arrays"
|
18
4
|
|
19
5
|
module ArgsParser
|
20
6
|
def self.split_args(content)
|
@@ -23,13 +9,19 @@ module ArgsParser
|
|
23
9
|
|
24
10
|
def self.eval_pipes_with_val(value, pipes)
|
25
11
|
pipes.each do |pipe|
|
12
|
+
args = pipe.split(" ") || []
|
13
|
+
func = args.shift || pipe
|
26
14
|
if (match = pipe.match(/\[(-?\d+):(-?\d+)\]/))
|
27
15
|
start_idx, end_idx = match[1].to_i, match[2].to_i
|
28
16
|
value = value[start_idx..end_idx]
|
29
|
-
elsif StringManipulation.respond_to?(
|
30
|
-
value = StringManipulation.public_send(
|
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)
|
31
23
|
else
|
32
|
-
raise ArgumentError, "Unkown
|
24
|
+
raise ArgumentError, "Unkown function '#{func}'"
|
33
25
|
end
|
34
26
|
end
|
35
27
|
value
|
data/lib/jekyll-hackclub.rb
CHANGED
@@ -2,6 +2,8 @@ require_relative "./tags/emoji"
|
|
2
2
|
require_relative "./tags/mentions"
|
3
3
|
require_relative "./tags/user-tag"
|
4
4
|
require_relative "./tags/channel-tag"
|
5
|
-
require_relative "./tags/
|
5
|
+
require_relative "./tags/usergroup-tag"
|
6
|
+
require_relative "./tags/file"
|
6
7
|
|
8
|
+
require_relative "./tags/parser"
|
7
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)
|
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
|
data/lib/tags/mentions.rb
CHANGED
@@ -16,7 +16,6 @@ module Jekyll
|
|
16
16
|
@pipes = parts[1..-1]
|
17
17
|
|
18
18
|
if @id && @id.start_with?("U")
|
19
|
-
|
20
19
|
display_name = @args[1] || HackclubRequest.resolve_username(@id)
|
21
20
|
display_name = ArgsParser.eval_pipes_with_val(display_name, @pipes)
|
22
21
|
%Q{<a href="https://hackclub.slack.com/team/#{@id}" class="hackclub-mention hackclub-user" target="_blank">@#{display_name}</a>}
|
@@ -24,6 +23,10 @@ module Jekyll
|
|
24
23
|
display_name = @args[1] || HackclubRequest.resolve_channel(@id)
|
25
24
|
display_name = ArgsParser.eval_pipes_with_val(display_name, @pipes)
|
26
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}}
|
27
30
|
end
|
28
31
|
end
|
29
32
|
end
|
@@ -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
|
@@ -43,12 +43,17 @@ extra_rdoc_files: []
|
|
43
43
|
files:
|
44
44
|
- lib/args-parser.rb
|
45
45
|
- lib/jekyll-hackclub.rb
|
46
|
+
- lib/pipes/arrays.rb
|
47
|
+
- lib/pipes/numbers.rb
|
48
|
+
- lib/pipes/strings.rb
|
46
49
|
- lib/server-bridge.rb
|
47
50
|
- lib/tags/channel-tag.rb
|
48
51
|
- lib/tags/emoji.rb
|
52
|
+
- lib/tags/file.rb
|
49
53
|
- lib/tags/mentions.rb
|
50
54
|
- lib/tags/parser.rb
|
51
55
|
- lib/tags/user-tag.rb
|
56
|
+
- lib/tags/usergroup-tag.rb
|
52
57
|
licenses:
|
53
58
|
- MIT
|
54
59
|
metadata: {}
|