rblock.rb 1.25 KB
Newer Older
Jacek Lebioda's avatar
Jacek Lebioda committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Jekyll
    module Tags
      class RblockTag < Liquid::Block
       
        def split_params(params)
            params.split("|").map(&:strip)
        end

        def initialize(tag_name, block_options, liquid_options)
            super
            args = split_params(block_options)
            @title = args[0]
            if args.length >1
                @icon = args[1]
            else
                #default icon
                @icon = "fas fa-code"
            end
        end
  
        def render(context)
            rgridblockID = context["rgridblockID"]
           
            #content = super
            site = context.registers[:site]
            converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
            content = converter.convert(super)
         

       
            #Because we’re not changing the context, there’s no need to push the context stack as with the rgridblock. 
            # generate collapsible card HTML
            output = <<~EOS
<div class="rblock">
    <h3>
    <i class="#{@icon}"></i>
    #{@title}
    </h3>
    <hr>
    <p>
    #{content}
    </p>
</div>
    EOS
             output
        end
      end
    end
  end
  
 


Liquid::Template.register_tag('rblock', Jekyll::Tags::RblockTag)