OLD | NEW |
(Empty) | |
| 1 |
| 2 module Jekyll |
| 3 |
| 4 # This plugin renders a table with code and a running example side by side. |
| 5 class CodeSampleTag < Liquid::Block |
| 6 |
| 7 def initialize(tag_name, params, tokens) |
| 8 super |
| 9 @percent = params.strip |
| 10 end |
| 11 |
| 12 def render(context) |
| 13 ("\n\n<table sytle='border:0px'><thead>" + |
| 14 "<tr><td><strong>Sample source code</strong>" + |
| 15 "</td><td>" + |
| 16 "</td><td><strong>Sample running</strong></td></tr>" + |
| 17 "</thead><tbody><tr>" + |
| 18 "<td style='width:#{@percent}%;vertical-align:top;'>" + super.strip + |
| 19 "</td><td style='width:100%;'>" + |
| 20 "</td><td style='vertical-align:top;'>" + |
| 21 "<iframe style='border:none;height:#{@height};width:#{@width};'" + |
| 22 " src='#{@url}'></iframe>" + |
| 23 "</td></tr></tbody></table>\n\n") |
| 24 end |
| 25 |
| 26 def unknown_tag(tag, params, tokens) |
| 27 if tag == 'sample' |
| 28 sample_params = params.split(' ') |
| 29 @width = sample_params[0] |
| 30 @height = sample_params[1] |
| 31 @url = sample_params[2] |
| 32 else |
| 33 super |
| 34 end |
| 35 end |
| 36 |
| 37 end |
| 38 end |
| 39 |
| 40 Liquid::Template.register_tag('codesample', Jekyll::CodeSampleTag) |
OLD | NEW |