whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit d6c7ae9: auto line break
Date Fri, 12 Feb 2016 13:03:25 GMT
Commit d6c7ae9365043cf4b44bd95e3448165e87464fb6:
    auto line break


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
www/board/agenda/views/pages/report.js.rb                    | ++++++++ -
www/board/agenda/views/utils.js.rb                           | + -
------------------------------------------------------------
33 changes: 31 additions, 2 deletions.
------------------------------------------------------------


diff --git a/www/board/agenda/views/pages/report.js.rb b/www/board/agenda/views/pages/report.js.rb
index 045f4a2..f425736 100644
--- a/www/board/agenda/views/pages/report.js.rb
+++ b/www/board/agenda/views/pages/report.js.rb
@@ -58,7 +58,7 @@ def componentWillMount()
 
   def componentWillReceiveProps()
     # determine what text filters to run
-    @filters = [hotlink, self.privates, self.jira]
+    @filters = [hotlink, self.privates, self.jira, self.linebreak]
     @filters << self.localtime if @@item.title == 'Call to order'
     @filters << self.names if @@item.people
     @filters << self.president_attachments if @@item.title == 'President'
@@ -86,6 +86,35 @@ def componentWillReceiveProps()
   ### filters
   #
 
+  # Break long lines
+  def linebreak(text)
+    # find long, breakable lines
+    regex = Regexp.new(/.{80}.*/, 'g')
+    result = nil
+    indicies = [];
+    while result = regex.exec(text)
+      line = result[0]
+      lastspace = /^.*\s\S/.exec(line)[0].length - 1
+      indicies.unshift([line, result.index]) if lastspace > 40
+    end
+
+    # reflow each line found
+    indicies.each do |info|
+      line = info[0]
+      index = info[1]
+      prefix = /^\W*/.exec(line)[0]
+      indent = ' ' * prefix.length
+      replacement = '<span class="hilite" title="reflowed">' + prefix +
+        Flow.text(line[prefix.length..-1], indent).gsub("\n", "\n" + indent) +
+        "</span>"
+
+      text = text.slice(0, index) + replacement + 
+        text.slice(index + line.length)
+    end
+
+    return text
+  end
+
   # Convert start time to local time on Call to order page
   def localtime(text)
     return text.sub /\n(\s+)(Other Time Zones:.*)/ do |match, spaces, text|
diff --git a/www/board/agenda/views/utils.js.rb b/www/board/agenda/views/utils.js.rb
index d2ad843..f1daa1c 100644
--- a/www/board/agenda/views/utils.js.rb
+++ b/www/board/agenda/views/utils.js.rb
@@ -154,7 +154,7 @@ def self.text(text, indent='')
     for i in 0...lines.length
       indent = lines[i].match(/( *)(.?.?)(.*)/m)
 
-      if indent[1] == '' or indent[3] == ''
+      if (indent[1] == '' and indent[2] != '* ') or indent[3] == ''
         # not indented (or short) -> split
         lines[i] = lines[i].
           gsub(/(.{1,#{len}})( +|$\n?)|(.{1,#{len}})/, "$1$3\n").

Mime
View raw message