Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for multiple paragraphs in descriptions

  • Loading branch information...
commit 9481af265bdc570244624c4a8664044840d237b3 1 parent 4c80c18
@tomeric tomeric authored
Showing with 26 additions and 11 deletions.
  1. +22 −9 lib/kss/section.rb
  2. +4 −2 test/section_test.rb
View
31 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
View
6 test/section_test.rb
@@ -4,6 +4,8 @@ class SectionTest < Kss::Test
def setup
@comment_text = <<comment
+# Form Button
+
Your standard form button.
:hover - Highlights when hovering.
@@ -18,7 +20,7 @@ def setup
end
test "parses the description" do
- assert_equal "Your standard form button.", @section.description
+ assert_equal "# Form Button\n\nYour standard form button.", @section.description
end
test "parses the modifiers" do
@@ -37,4 +39,4 @@ def setup
assert_equal '2.1.1', @section.section
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.