all repos — markup @ 215b7790e83d29821afc43aff8534c840ad9a4f5

The code we use to render README.your_favorite_markup

add `command` to the dsl, for shelling out (when we don't have a class)
Chris Wanstrath chris@ozmm.org
Fri, 30 Oct 2009 22:59:22 -0700
commit

215b7790e83d29821afc43aff8534c840ad9a4f5

parent

eb6d8b0c480d01a78b9e11ebe22581013c3f9046

1 files changed, 31 insertions(+), 2 deletions(-)

jump to
M lib/github/markup.rblib/github/markup.rb

@@ -1,8 +1,18 @@

+begin + require 'open3_detach' +rescue LoadError + require 'open3' +end + module GitHub module Markup extend self @@markups = {} + def render(filename, content) + renderer(filename)[content] || content + end + def markup(file, pattern, &block) require file.to_s add_markup(pattern, &block)

@@ -10,6 +20,17 @@ rescue LoadError

nil end + def command(command, regexp) + command = command.to_s + if !File.exists?(command) && !command.include?('/') + command = File.dirname(__FILE__) + '/commands/' + command.to_s + end + + add_markup(regexp) do |content| + execute(command, content) + end + end + def add_markup(regexp, &block) @@markups[regexp] = block end

@@ -22,8 +43,16 @@ end

end end - def render(filename, content) - renderer(filename)[content] || content + def execute(command, target) + out = '' + Open3.popen3(command) do |stdin, stdout, _| + stdin.puts target + stdin.close + while tmp = stdout.read(1024) + out << tmp + end + end + out end # Define markups