From 9481af265bdc570244624c4a8664044840d237b3 Mon Sep 17 00:00:00 2001 From: Tom-Eric Gerritsen Date: Tue, 19 Jun 2012 18:11:54 +0200 Subject: [PATCH] Add support for multiple paragraphs in descriptions --- lib/kss/section.rb | 31 ++++++++++++++++++++++--------- test/section_test.rb | 6 ++++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/kss/section.rb b/lib/kss/section.rb index f0248eb..b042404 100644 --- a/lib/kss/section.rb +++ b/lib/kss/section.rb @@ -34,12 +34,8 @@ def comment_sections def section return @section unless @section.nil? - comment_sections.each do |text| - if text =~ /Styleguide \d/i - cleaned = text.strip.sub(/\.$/, '') # Kill trailing period - @section = cleaned.match(/Styleguide (.+)/)[1] - end - end + cleaned = section_comment.strip.sub(/\.$/, '') # Kill trailing period + @section = cleaned.match(/Styleguide (.+)/)[1] @section end @@ -48,7 +44,10 @@ def section # # Returns the description String. def description - comment_sections.first + comment_sections.reject do |section| + section == section_comment || + section == modifiers_comment + end.join("\n\n") end # Public: The modifiers section of a styleguide comment block. @@ -57,9 +56,10 @@ def description def modifiers last_indent = nil modifiers = [] - return modifiers unless comment_sections[1] - comment_sections[1].split("\n").each do |line| + return modifiers unless modifiers_comment + + modifiers_comment.split("\n").each do |line| next if line.strip.empty? indent = line.scan(/^\s*/)[0].to_s.size @@ -76,5 +76,18 @@ def modifiers modifiers end + private + + def section_comment + comment_sections.find do |text| + text =~ /Styleguide \d/i + end.to_s + end + + def modifiers_comment + comment_sections[1..-1].reject do |section| + section == section_comment + end.last + end end end diff --git a/test/section_test.rb b/test/section_test.rb index 3c0b533..92b1636 100644 --- a/test/section_test.rb +++ b/test/section_test.rb @@ -4,6 +4,8 @@ class SectionTest < Kss::Test def setup @comment_text = <