From bb9b167b13fe0f6fbf6a59547919eed47b9c3476 Mon Sep 17 00:00:00 2001 From: Mike West Date: Sun, 17 Oct 2010 13:16:45 +0200 Subject: [PATCH] Variables for use in Mustache templates. Added: * `docs?`: True if `docs` contains text of any sort, False if it's empty. * `code?`: True if `code` contains text of any sort, False if it's empty. * `empty?`: True if both `code` and `docs` are empty. False otherwise. * `header?`: True if `docs` contains _only_ a HTML header. False otherwise. --- lib/rocco/layout.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/rocco/layout.rb b/lib/rocco/layout.rb index 22d1201..7b790f0 100644 --- a/lib/rocco/layout.rb +++ b/lib/rocco/layout.rb @@ -18,9 +18,15 @@ class Rocco::Layout < Mustache num = 0 @doc.sections.map do |docs,code| { - :docs => docs, - :code => code, - :num => (num += 1) + :docs => docs, + :docs? => !docs.empty?, + :header? => /^.+<\/h.>$/.match( docs ), + + :code => code, + :code? => !code.empty?, + + :empty? => ( code.empty? && docs.empty? ), + :num => (num += 1) } end end