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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0495d9b427da78fb0c05e06159bebbd4c8b345398450d2962274fc0acd8e1bc4'
4
- data.tar.gz: 81c1e2d3ac7e91326cd00c26a96eb353af2c1b141239aa449005e89d2801545c
3
+ metadata.gz: 1de71437907ec6e92d5b674b42dc745763ffb1f0b4010345df2bd38ae614960f
4
+ data.tar.gz: 0c04f981eaed4fb3b09f4aef40ed183ea64a95019977f8f407fa97e0f750a432
5
5
  SHA512:
6
- metadata.gz: 766b2fdcd3e220a8d75bc500f8232f4dad39bcb3f800c10006c5e2735a1a2acb40ab8f4169b5e1933ae4240d6ffec87d711bbbc4568e2499774cbe8f9c22e049
7
- data.tar.gz: 6cff13dae2e12a3a47aad22d598d53dd6a6f88181621c9a385f3793b2d25253861688b41810ad31498d9513fd90f9460e681c8824d42f27fbcc67701e5e7d34f
6
+ metadata.gz: ab656eaeb6afcd5810732d0ca95bf0feb9be3165c6b50101f2f1eac981842fcd9e4ccca73575edab704e50513dad6ee53ef6af8d657d3ab6664453035550f2b6
7
+ data.tar.gz: 0a7ba5e07b1c95719ee6f407302bd571488e2033b4ccdd6211f6d9ac06d73cb5c927dbd677a57011fac09e2d7620f8bd37e809b67650fc909c1c165aff726016
data/lib/args-parser.rb CHANGED
@@ -1,20 +1,6 @@
1
- module StringManipulation
2
- def self.uppercase(content)
3
- content.upcase
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?(pipe)
30
- value = StringManipulation.public_send(pipe, value)
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 pipe '#{pipe}'"
24
+ raise ArgumentError, "Unkown function '#{func}'"
33
25
  end
34
26
  end
35
27
  value
@@ -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/parser"
5
+ require_relative "./tags/usergroup-tag"
6
+ require_relative "./tags/file"
6
7
 
8
+ require_relative "./tags/parser"
7
9
  require_relative "./server-bridge"
@@ -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.3.0
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: {}