jekyll-hackclub 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6983799f7f157799ee42dc525700706a97d24a4c6e67da64baeb9b91520b411
4
- data.tar.gz: 83032a1f6dc44f6da7e1b8698a2ee05543fb6d581a4c7d45008fb8ae7d55c587
3
+ metadata.gz: '0495d9b427da78fb0c05e06159bebbd4c8b345398450d2962274fc0acd8e1bc4'
4
+ data.tar.gz: 81c1e2d3ac7e91326cd00c26a96eb353af2c1b141239aa449005e89d2801545c
5
5
  SHA512:
6
- metadata.gz: 5338d85198e7446012bc68eeecc3d740bb9d99b9c577693074e973450b23e97e7e70fd5ad102931875a02ad9dfaa60130c93d2bb55a50e5017731c6a01797d1c
7
- data.tar.gz: cdce15077066008b97d13a0328b1b68c0023d12ff350f9a13541bf3133f850247c227a4a00cda414e4a7209b83b8b818dd69aa2733ae0197e0fa33447a57171f
6
+ metadata.gz: 766b2fdcd3e220a8d75bc500f8232f4dad39bcb3f800c10006c5e2735a1a2acb40ab8f4169b5e1933ae4240d6ffec87d711bbbc4568e2499774cbe8f9c22e049
7
+ data.tar.gz: 6cff13dae2e12a3a47aad22d598d53dd6a6f88181621c9a385f3793b2d25253861688b41810ad31498d9513fd90f9460e681c8824d42f27fbcc67701e5e7d34f
@@ -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
@@ -1,3 +1,7 @@
1
- require_relative "./emoji"
2
- require_relative "./mentions"
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
+
3
7
  require_relative "./server-bridge"
data/lib/server-bridge.rb CHANGED
@@ -21,6 +21,18 @@ module HackclubRequest
21
21
  end
22
22
  end
23
23
 
24
+ def self.raw_user(userid)
25
+ uri = URI("#{host}/users.info/#{userid}")
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.resolve_username(userid)
25
37
  uri = URI("#{host}/users.info/#{userid}")
26
38
  res = Net::HTTP.get_response(uri)
@@ -37,6 +49,18 @@ module HackclubRequest
37
49
  end
38
50
  end
39
51
 
52
+ def self.raw_channel(channelid)
53
+ uri = URI("#{host}/conversations.info/#{channelid}")
54
+ res = Net::HTTP.get_response(uri)
55
+
56
+ data = JSON.parse(res.body)
57
+ if res.is_a?(Net::HTTPSuccess)
58
+ data
59
+ else
60
+ {}
61
+ end
62
+ end
63
+
40
64
  def self.resolve_channel(channelid)
41
65
  uri = URI("#{host}/conversations.info/#{channelid}")
42
66
  res = Net::HTTP.get_response(uri)
@@ -0,0 +1,27 @@
1
+ require "jekyll"
2
+ require_relative "../server-bridge"
3
+
4
+ module Jekyll
5
+ class HackclubChannelTag < 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_channel(@id).dig("channel").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 "channel", HackclubChannelTag
27
+ end
@@ -1,11 +1,11 @@
1
1
  require "jekyll"
2
- require_relative "./server-bridge"
2
+ require_relative "../server-bridge"
3
3
 
4
4
  module Jekyll
5
5
  class HackclubEmoji < Liquid::Tag
6
6
  def initialize(tagName, content, tokens)
7
7
  super
8
- @id = content.gsub(/\A:+|:+\z/, '')
8
+ @id = content.gsub(/\A:+|:+\z/, '').strip
9
9
  @img_url = HackclubRequest.resolve_emoji(@id)
10
10
  end
11
11
 
@@ -1,5 +1,6 @@
1
1
  require "jekyll"
2
- require_relative "./server-bridge"
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
@@ -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
@@ -0,0 +1,28 @@
1
+ require "jekyll"
2
+ require_relative "../args-parser"
3
+ require_relative "../server-bridge"
4
+
5
+ module Jekyll
6
+ class HackclubUserTag < Liquid::Tag
7
+ def initialize(tagName, content, tokens)
8
+ super
9
+ content = content.strip()
10
+ @id, keys, pipes = ArgsParser.split_args(content)
11
+ pipes = pipes || ""
12
+ keys = keys.split(".")
13
+
14
+ @data = HackclubRequest.raw_user(@id).dig("user").dig(*keys)
15
+ @data = ArgsParser.eval_pipes_with_val(@data, pipes.split(" | ").map(&:strip))
16
+ end
17
+
18
+ def render(context)
19
+ if @data == nil
20
+ %Q{null}
21
+ else
22
+ %Q{#{@data}}
23
+ end
24
+ end
25
+ end
26
+
27
+ Liquid::Template.register_tag "user", HackclubUserTag
28
+ 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.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MathiasDPX
@@ -41,10 +41,14 @@ executables: []
41
41
  extensions: []
42
42
  extra_rdoc_files: []
43
43
  files:
44
- - lib/emoji.rb
44
+ - lib/args-parser.rb
45
45
  - lib/jekyll-hackclub.rb
46
- - lib/mentions.rb
47
46
  - lib/server-bridge.rb
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
48
52
  licenses:
49
53
  - MIT
50
54
  metadata: {}