Class: Gollum::Filter::CriticMarkup

Inherits:
Gollum::Filter show all
Defined in:
lib/gollum-lib/filter/critic_markup.rb

Overview

CriticMarkup

Render CriticMarkup

Constant Summary collapse

ADDITION_PATTERN =
%r|{\+\+(?<content>.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}|m
DELETION_PATTERN =
%r|{--(?<content>.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}|m
SUBSTITUTION_PATTERN =
%r|{~~(?<oldcontent>.*?)~>(?<newcontent>.*?)~~}|m
HIGHLIGHT_PATTERN =
%r|{\=\=(?<content>.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(?<comment>.*?)<<}|m
COMMENT_PATTERN =
%r|{>>(?<content>.*?)<<}|m

Constants inherited from Gollum::Filter

PLACEHOLDER_PATTERN

Instance Attribute Summary

Attributes inherited from Gollum::Filter

#close_pattern, #open_pattern

Instance Method Summary collapse

Methods inherited from Gollum::Filter

#initialize

Methods included from Helpers

#path_to_link_text, #trim_leading_slashes

Constructor Details

This class inherits a constructor from Gollum::Filter

Instance Method Details

#extract(data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gollum-lib/filter/critic_markup.rb', line 19

def extract(data)
  data.gsub! ADDITION_PATTERN do
    content = $~[:content]
    placeholder = generate_placeholder("#{content}#{@map.size}")
  	# Is there a new paragraph followed by new text
    if content.start_with?("\n\n") && content != "\n\n"
      html = "\n\n<ins class='critic break'>&nbsp;</ins>\n\n<ins>#{content.gsub('\n', ' ')}</ins>"
  	# Is the addition just a single new paragraph
    elsif content == "\n\n"
      html = "\n\n<ins class='critic break'>&nbsp;</ins>\n\n"
  	# Is it added text followed by a new paragraph?
    elsif content.end_with?("\n\n") && content != "\n\n"
	    html = "<ins>#{content.gsub('\n', ' ')}</ins>\n\n<ins class='critic break'>&nbsp;</ins>\n\n"
    else
      html = "<ins>#{content.gsub('\n', ' ')}</ins>"
    end
    @map[placeholder] = html
    placeholder
  end
  
  data.gsub! DELETION_PATTERN do
    content = $~[:content]
    placeholder = generate_placeholder("#{content}#{@map.size}")
    if content == "\n\n"
      html = "<del>&nbsp;</del>"
    else
      html = "<del>#{content.gsub('\n\n', ' ')}</del>"
    end
    @map[placeholder] = html
    placeholder
  end   
  
  data.gsub! SUBSTITUTION_PATTERN do
    oldcontent = $~[:oldcontent]
    newcontent = $~[:newcontent]
    placeholder = generate_placeholder("#{oldcontent}#{newcontent}#{@map.size}")
    html = "<del>#{oldcontent}</del><ins>#{newcontent}</ins>"
    @map[placeholder] = html
    placeholder
  end

  data.gsub! HIGHLIGHT_PATTERN do
    content = $~[:content]
    comment = $~[:comment]
    placeholder = generate_placeholder("#{content}#{@map.size}")
    html = "<mark>#{content}</mark><span class='critic comment'>#{comment}</span>"
    @map[placeholder] = html
    placeholder
  end
  
  data.gsub! COMMENT_PATTERN do
    content = $~[:content]
    placeholder = generate_placeholder("#{content}#{@map.size}")
    html = "<span class='critic comment'>#{content}</span>"
    @map[placeholder] = html
    placeholder
  end
  
  data
end

#process(data) ⇒ Object



80
81
82
83
84
85
# File 'lib/gollum-lib/filter/critic_markup.rb', line 80

def process(data)
  data.gsub! process_pattern do 
    @map[$~[:placeholder]]
  end
  data
end