Skip to content

Instantly share code, notes, and snippets.

@spilth
Created January 31, 2013 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spilth/4683737 to your computer and use it in GitHub Desktop.
Save spilth/4683737 to your computer and use it in GitHub Desktop.
module Liquid
class RubyBlock < Liquid::Block
def initialize(name, markup, tokens)
super
@code = @nodelist[0].to_s.gsub(/^$\n/, '')
File.open('/tmp/ruby-foo.rb', 'w') {|f| f.write("#{@code}")}
@result = `ruby /tmp/ruby-foo.rb`
end
def render(context)
%Q[<h6>Code:</h6><pre><code>#{@code}</code></pre><h6>Output:</h6><pre class="output"><code>#{@result}</code></pre>]
end
end
end
Liquid::Template.register_tag('ruby', Liquid::RubyBlock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment