Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for multiple paragraphs in descriptions
  • Loading branch information
tomeric committed Jun 19, 2012
1 parent 4c80c18 commit 9481af2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
31 changes: 22 additions & 9 deletions lib/kss/section.rb
Expand Up @@ -34,12 +34,8 @@ def comment_sections
def section def section
return @section unless @section.nil? return @section unless @section.nil?


comment_sections.each do |text| cleaned = section_comment.strip.sub(/\.$/, '') # Kill trailing period
if text =~ /Styleguide \d/i @section = cleaned.match(/Styleguide (.+)/)[1]
cleaned = text.strip.sub(/\.$/, '') # Kill trailing period
@section = cleaned.match(/Styleguide (.+)/)[1]
end
end


@section @section
end end
Expand All @@ -48,7 +44,10 @@ def section
# #
# Returns the description String. # Returns the description String.
def description def description
comment_sections.first comment_sections.reject do |section|
section == section_comment ||
section == modifiers_comment
end.join("\n\n")
end end


# Public: The modifiers section of a styleguide comment block. # Public: The modifiers section of a styleguide comment block.
Expand All @@ -57,9 +56,10 @@ def description
def modifiers def modifiers
last_indent = nil last_indent = nil
modifiers = [] 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? next if line.strip.empty?
indent = line.scan(/^\s*/)[0].to_s.size indent = line.scan(/^\s*/)[0].to_s.size


Expand All @@ -76,5 +76,18 @@ def modifiers
modifiers modifiers
end 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
end end
6 changes: 4 additions & 2 deletions test/section_test.rb
Expand Up @@ -4,6 +4,8 @@ class SectionTest < Kss::Test


def setup def setup
@comment_text = <<comment @comment_text = <<comment
# Form Button
Your standard form button. Your standard form button.
:hover - Highlights when hovering. :hover - Highlights when hovering.
Expand All @@ -18,7 +20,7 @@ def setup
end end


test "parses the description" do 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 end


test "parses the modifiers" do test "parses the modifiers" do
Expand All @@ -37,4 +39,4 @@ def setup
assert_equal '2.1.1', @section.section assert_equal '2.1.1', @section.section
end end


end end

0 comments on commit 9481af2

Please sign in to comment.