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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de886c16f8e0135c5cf61d9918210a0ea31905bb51f5292d539fcd1ff27aaf4c
4
- data.tar.gz: 6649112e691948cb83a94829364d5a4c0b22b617c4c3e5d600aeccab79973200
3
+ metadata.gz: '0495d9b427da78fb0c05e06159bebbd4c8b345398450d2962274fc0acd8e1bc4'
4
+ data.tar.gz: 81c1e2d3ac7e91326cd00c26a96eb353af2c1b141239aa449005e89d2801545c
5
5
  SHA512:
6
- metadata.gz: 9fef2b54b058eba122b6ef06cf801d271fdefc4d00e71b9a5c554f09a6fe03272f194a5f0d629c45f8a812ba1a1ec0091f0f0795df31cf9df4f99bcbfe0ef6af
7
- data.tar.gz: f39585ba8cc849022224092743768f83c8d2864942523526aade46a4326b6de4efcb2603ca1ec81d89572c97c840c808bdc7c581799026d78de2b5d1b4dc63fe
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,5 +1,7 @@
1
- require_relative "./emoji"
2
- require_relative "./mentions"
3
- require_relative "./server-bridge"
4
- require_relative "./user-tag"
5
- require_relative "./channel-tag"
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 "./server-bridge"
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, *rest = content.split(" ", 2)
10
- keys = rest.join.split(".")
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,5 @@
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
@@ -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
@@ -1,14 +1,18 @@
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 HackclubUserTag < Liquid::Tag
6
7
  def initialize(tagName, content, tokens)
7
8
  super
8
9
  content = content.strip()
9
- @id, *rest = content.split(" ", 2)
10
- keys = rest.join.split(".")
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.2.0
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/channel-tag.rb
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/user-tag.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
50
52
  licenses:
51
53
  - MIT
52
54
  metadata: {}