Class: Jekyll::CodeExampleTags::AllPageCodeExamplesTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/pulsar-jekyll-code-example.rb

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/pulsar-jekyll-code-example.rb', line 106

def render(context)
  examples = {}
  context['page']['content'].scan(/\{%\s*code_example (\S+)\s*%\}/) do |name|
    context_path, example_name = Jekyll::CodeExampleTags::get_example_name_and_context(name[0])
    more_examples = Jekyll::CodeExampleTags::code_examples(context_path, example_name, context['site'])
    examples.merge!(more_examples){|key, pre_example, new_example| "#{pre_example}\n#{new_example}"}
  end

  # Build the code example elements
  output = Jekyll::CodeExampleTags::buttons_markup(examples, context)
  examples.each do |lang, paths|
    example_content = ""
    for path in paths.split("\n")
      example_content << File.read(path)
    end
    output << Jekyll::CodeExampleTags::example_markup(lang, example_content)
  end

  output = Jekyll::CodeExampleTags::wrap_examples_div(output)
end