From ae9b8ef1645c160c02913ad441a6bbc60981e006 Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Mon, 9 Jan 2012 13:07:09 -0600 Subject: [PATCH 1/5] Dropping ternary if statement for single line expression Conflicts: lib/rocco.rb --- lib/rocco.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rocco.rb b/lib/rocco.rb index 92c2c23..624e1d2 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -349,9 +349,9 @@ def split(sections) docs_blocks, code_blocks = [], [] sections.each do |docs,code| docs_blocks << docs.join("\n") - code_blocks << code.map do |line| - tabs = line.match(/^(\t+)/) - tabs ? line.sub(/^\t+/, ' ' * tabs.captures[0].length) : line + code_blocks << code.map do |l| + tabs = l.match /^(\t+)/ + if tabs then l.sub(/^\t+/, ' ' * tabs.captures[0].length) else l end end.join("\n") end [docs_blocks, code_blocks] From f64e94620ebfaa2ac7440ff983524ed49ae7dd2f Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Mon, 9 Jan 2012 13:07:23 -0600 Subject: [PATCH 2/5] Dropping ternary if expression for single line --- lib/rocco.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rocco.rb b/lib/rocco.rb index 624e1d2..d733166 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -361,9 +361,9 @@ def split(sections) # Markdown syntax. def docblock(docs) docs.map do |doc| - doc.split("\n").map do |line| - line.match(/^@\w+/) ? line.sub(/^@(\w+)\s+/, '> **\1** ')+" " : line - end.join("\n") + doc.split("\n").map do |l| + if l.match(/^@\w+/) then l.sub(/^@(\w+)\s+/, '> **\1** ') + " " else l end + end.join "\n" end end From 5d6718f42541cd4a107c82b3eb53921157232182 Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Mon, 9 Jan 2012 13:06:41 -0600 Subject: [PATCH 3/5] Moving to single line if expression Conflicts: lib/rocco.rb --- lib/rocco.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rocco.rb b/lib/rocco.rb index d733166..2f39a88 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -334,9 +334,10 @@ def normalize_leading_spaces(sections) if section.any? && section[0].any? leading_space = section[0][0].match("^\s+") if leading_space - section[0] = - section[0].map{ |line| line.sub(/^#{leading_space.to_s}/, '') } end + if section.any? && section.first.any? + leading_space = section.first.first.match("^\s+") + section[0] = section.first.map{ |l| l.sub(/^#{leading_space}/, '') } if leading_space end section end From eef02ba61c00d3d881d65b582ea2128da05e7042 Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Mon, 9 Jan 2012 13:04:36 -0600 Subject: [PATCH 4/5] Droping the if block, using or statement --- lib/rocco.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/rocco.rb b/lib/rocco.rb index 2f39a88..e8deede 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -204,12 +204,9 @@ def detect_language include CommentStyles def generate_comment_chars + comment_hash = { :single => @options[:comment_chars], :multi => nil, :heredoc => nil } @_commentchar ||= - if COMMENT_STYLES[@options[:language]] - COMMENT_STYLES[@options[:language]] - else - { :single => @options[:comment_chars], :multi => nil, :heredoc => nil } - end + COMMENT_STYLES[@options[:language]] or comment_hash end # Internal Parsing and Highlighting From 505f85bd9d1ad5b4935431fa2b55e2692ab05c94 Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Mon, 9 Jan 2012 21:34:17 -0600 Subject: [PATCH 5/5] Removing extra crud logic. --- lib/rocco.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/rocco.rb b/lib/rocco.rb index e8deede..8f626b8 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -328,10 +328,6 @@ def parse(data) # `def func():\n print "omg!"` def normalize_leading_spaces(sections) sections.map do |section| - if section.any? && section[0].any? - leading_space = section[0][0].match("^\s+") - if leading_space - end if section.any? && section.first.any? leading_space = section.first.first.match("^\s+") section[0] = section.first.map{ |l| l.sub(/^#{leading_space}/, '') } if leading_space