Class: Jekyll::HackclubFileTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/tags/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(tagName, content, tokens) ⇒ HackclubFileTag



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tags/file.rb', line 6

def initialize(tagName, content, tokens)
    super
    content = content.strip()
    @id, keys, pipes = ArgsParser.split_args(content)
    pipes = pipes || ""
    keys = keys || ""
    keys = keys.split(".")

    if keys == []
        rawfile = HackclubRequest.raw_file(@id).dig("file")
        permalink = rawfile.dig("permalink")
        name = rawfile.dig("name")
        @data = '<a href="'+permalink+'" class="hackclub-file" target="_blank">'+name+'</a>'
    else
        @data = HackclubRequest.raw_file(@id).dig("file").dig(*keys)
        @data = ArgsParser.eval_pipes_with_val(@data, pipes.split(" | ").map(&:strip))
    end
end

Instance Method Details

#render(context) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/tags/file.rb', line 25

def render(context)
    if @data == nil
        %Q{null}
    else
        %Q{#{@data}}
    end
end