all repos — markup @ d565a88a743c2624351ce4cd1f027d2bb1cd76ed

The code we use to render README.your_favorite_markup

defer loading of markups gems until they're first used
Charlie Somerville charlie@charliesomerville.com
Wed, 04 Dec 2013 10:09:33 +1100
commit

d565a88a743c2624351ce4cd1f027d2bb1cd76ed

parent

4bef720e5bb10afe26958ba50a9b4f805c597e14

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

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

@@ -8,6 +8,14 @@ module GitHub

module Markup extend self @@markups = {} + @@deferred_markups = [] + + def preload! + @@deferred_markups.each do |loader| + loader.call + end + @@deferred_markups = [] + end def render(filename, content = nil) content ||= File.read(filename)

@@ -20,8 +28,16 @@ end

end def markup(file, pattern, &block) - require file.to_s - add_markup(pattern, &block) + loader = proc do + require file.to_s + add_markup(pattern, &block) + end + @@deferred_markups << loader + add_markup pattern do |*args| + @@deferred_markups.delete(loader) + loader.call + block.call(*args) + end true rescue LoadError false