jekyll-hackclub 1.2.0 → 1.3.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 +47 -0
- data/lib/jekyll-hackclub.rb +7 -5
- data/lib/{channel-tag.rb → tags/channel-tag.rb} +6 -3
- data/lib/{emoji.rb → tags/emoji.rb} +1 -1
- data/lib/{mentions.rb → tags/mentions.rb} +9 -1
- data/lib/tags/parser.rb +18 -0
- data/lib/{user-tag.rb → tags/user-tag.rb} +7 -3
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0495d9b427da78fb0c05e06159bebbd4c8b345398450d2962274fc0acd8e1bc4'
|
4
|
+
data.tar.gz: 81c1e2d3ac7e91326cd00c26a96eb353af2c1b141239aa449005e89d2801545c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 766b2fdcd3e220a8d75bc500f8232f4dad39bcb3f800c10006c5e2735a1a2acb40ab8f4169b5e1933ae4240d6ffec87d711bbbc4568e2499774cbe8f9c22e049
|
7
|
+
data.tar.gz: 6cff13dae2e12a3a47aad22d598d53dd6a6f88181621c9a385f3793b2d25253861688b41810ad31498d9513fd90f9460e681c8824d42f27fbcc67701e5e7d34f
|
data/lib/args-parser.rb
ADDED
@@ -0,0 +1,47 @@
|
|
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
|
18
|
+
|
19
|
+
module ArgsParser
|
20
|
+
def self.split_args(content)
|
21
|
+
content.split(" ; ").map(&:strip)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.eval_pipes_with_val(value, pipes)
|
25
|
+
pipes.each do |pipe|
|
26
|
+
if (match = pipe.match(/\[(-?\d+):(-?\d+)\]/))
|
27
|
+
start_idx, end_idx = match[1].to_i, match[2].to_i
|
28
|
+
value = value[start_idx..end_idx]
|
29
|
+
elsif StringManipulation.respond_to?(pipe)
|
30
|
+
value = StringManipulation.public_send(pipe, value)
|
31
|
+
else
|
32
|
+
raise ArgumentError, "Unkown pipe '#{pipe}'"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
value
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.eval_pipes(arg)
|
39
|
+
parts = arg.split(" | ").map(&:strip)
|
40
|
+
value = parts.shift
|
41
|
+
eval_pipes_with_val(value, parts)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.parse(content)
|
45
|
+
split_args(content).map { |arg| eval_pipes(arg) }
|
46
|
+
end
|
47
|
+
end
|
data/lib/jekyll-hackclub.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
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/parser"
|
6
|
+
|
7
|
+
require_relative "./server-bridge"
|
@@ -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)
|
@@ -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,11 +11,18 @@ 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")
|
19
|
+
|
14
20
|
display_name = @args[1] || HackclubRequest.resolve_username(@id)
|
21
|
+
display_name = ArgsParser.eval_pipes_with_val(display_name, @pipes)
|
15
22
|
%Q{<a href="https://hackclub.slack.com/team/#{@id}" class="hackclub-mention hackclub-user" target="_blank">@#{display_name}</a>}
|
16
23
|
elsif @id && @id.start_with?("C")
|
17
24
|
display_name = @args[1] || HackclubRequest.resolve_channel(@id)
|
25
|
+
display_name = ArgsParser.eval_pipes_with_val(display_name, @pipes)
|
18
26
|
%Q{<a href="https://hackclub.slack.com/archives/#{@id}" class="hackclub-mention hackclub-channel" target="_blank">##{display_name}</a>}
|
19
27
|
end
|
20
28
|
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)
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MathiasDPX
|
@@ -41,12 +41,14 @@ 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/mentions.rb
|
48
46
|
- lib/server-bridge.rb
|
49
|
-
- lib/
|
47
|
+
- lib/tags/channel-tag.rb
|
48
|
+
- lib/tags/emoji.rb
|
49
|
+
- lib/tags/mentions.rb
|
50
|
+
- lib/tags/parser.rb
|
51
|
+
- lib/tags/user-tag.rb
|
50
52
|
licenses:
|
51
53
|
- MIT
|
52
54
|
metadata: {}
|