Class: Jekyll::CodeTabs::CodeTabsBlock

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-code-tabs.rb

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-code-tabs.rb', line 8

def render(context)
  environment = context.environments.first
  environment['codetabs'] = {} # reset each time
  super

  uuid = SecureRandom.uuid
				template = ERB.new <<-EOF
<ul class="uk-tab" data-uk-switcher="{connect:'#<%= uuid %>'}">
<% environment['codetabs'].each_with_index do |(key, _), index| %>
	<li<%= index == 0 ? ' class="uk-active"' : ''%>><a href="#"><%= key %></a></li>
<% end %>
</ul>

<ul id="<%= uuid %>" class="uk-switcher uk-margin">
<% environment['codetabs'].each do |_, value| %>
	<li><%= value %></li>
<% end %>
</ul>
EOF
				template.result(binding)
end