Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
More robust (but slower) optional clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
Casey Kuhlman committed Jul 15, 2013
1 parent 08cfb89 commit 6880d17
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/legal_markdown/legal_to_markdown/mixins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,30 @@ def clauses_mixins

clauses_to_delete.each { |m| @headers.delete(m) }
clauses_to_mixin.each { |m| @headers.delete(m) }
clauses_deleted = clauses_to_delete.dup
clauses_added = clauses_to_mixin.dup

until clauses_to_delete.size == 0
clauses_to_delete.each do | mixin |
until clauses_added.size == 0 && clauses_deleted.size == 0
clauses_to_mixin.each do | mixin |
pattern = /(\[\{\{#{mixin}\}\}\s*?)(.*?\n*?)(\])/m
sub_pattern = /\[\{\{(\S+?)\}\}\s*?/
@content[pattern]
get_it_all = $& || ""
sub_clause = $2 || ""
if sub_clause[sub_pattern] && clauses_to_delete.include?($1)
next
elsif sub_clause[sub_pattern]
pattern = /\[\{\{#{mixin}\}\}\s*?.*?\n*?\].*?\n*?\]/m
@content[pattern]; get_it_all = $& || ""
end
@content = @content.gsub( get_it_all, "" )
clauses_to_delete.delete( mixin ) unless @content[pattern]
next if sub_clause[sub_pattern] && ( clauses_to_mixin.include?($1) || clauses_to_delete.include?($1) )
@content = @content.gsub( get_it_all, sub_clause.lstrip )
clauses_added.delete( mixin ) unless @content[pattern]
end
end

until clauses_to_mixin.size == 0
clauses_to_mixin.each do | mixin |
clauses_to_delete.each do | mixin |
pattern = /(\[\{\{#{mixin}\}\}\s*?)(.*?\n*?)(\])/m
sub_pattern = /\[\{\{(\S+?)\}\}\s*?/
@content[pattern]
get_it_all = $& || ""
sub_clause = $2 || ""
next if sub_clause[sub_pattern] && clauses_to_mixin.include?($1)
@content = @content.gsub( get_it_all, sub_clause.lstrip )
clauses_to_mixin.delete( mixin ) unless @content[pattern]
next if sub_clause[sub_pattern] && ( clauses_to_mixin.include?($1) || clauses_to_delete.include?($1) )
@content = @content.gsub( get_it_all, "" )
clauses_deleted.delete( mixin ) unless @content[pattern]
end
end
end
Expand Down

0 comments on commit 6880d17

Please sign in to comment.