rgridblock.rb 1.07 KB
Newer Older
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
module Jekyll
    module Tags
        class RgridblockTag < Liquid::Block
            def initialize(tag_name, block_options, liquid_options)
                super
                @rgridblockID = "rgridblock-#{block_options.strip}"
            end



            def render(context)
                #Pushes a new local scope on the stack, pops it at the end of the block
                #Each new rgridblock  creates a new scope, and contexts have a custom implementation of [] to search up the stack for a matching value.
                context.stack do
                    context["rgridblockID"] = @rgridblockID
                    @content = super
                end
                # The last bit we add is saving the resulting output of our block contents to an instance variable so we can access it outside of the stack scope.
                output= %(<div class="rgridblock" id="#{@rgridblockID}">#{@content}</div>)
                output
              
            end
        end
    end
end

Liquid::Template.register_tag('rgridblock', Jekyll::Tags::RgridblockTag)