Class: Jekyll::ExampleEmbedTag

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

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ ExampleEmbedTag

Returns a new instance of ExampleEmbedTag.



3
4
5
6
# File 'lib/jekyll_example_embed.rb', line 3

def initialize(tag_name, text, tokens)
  @example = text.strip
  super
end

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
29
30
31
32
33
34
35
# File 'lib/jekyll_example_embed.rb', line 8

def render(context)
  @context = context

  lang, name = @example.split('/')

  coerce_documents!

  document = collection.docs.detect do |document|
    document.relative_path == "_examples/#{@example}"
  end

  if document.nil?
    puts "** ERROR: Could not find example #{@example}\n"
    return
  end

  highlight = context.stack do
    wrapped_content = "{% highlight #{lang} %}#{document.content}{% endhighlight %}"
    Liquid::Template.parse(wrapped_content).render!(context)
  end

  [ "<h4>#{name}</h4>",
    '<h5>Source</h5>',
    highlight,
    '<h5>Result</h5>',
    %{<iframe src="#{document.url}" frameBorder="0" onload="#{auto_resize}"></iframe>}
  ].join("\n")
end