Module: Dyndoc::Linter

Defined in:
lib/dyndoc-linter.rb

Class Method Summary collapse

Class Method Details

.check_content(txt) ⇒ Object



40
41
42
# File 'lib/dyndoc-linter.rb', line 40

def Linter.check_content(txt)
  Dyndoc::Linter.simplify_dyndoc_tags(Dyndoc::Linter.selected_tags(txt))
end

.check_file(file_to_lint) ⇒ Object



44
45
46
47
# File 'lib/dyndoc-linter.rb', line 44

def Linter.check_file(file_to_lint)
  txt=File.read(file_to_lint)
  Dyndoc::Linter.check_content(txt) + Dyndoc::Linter.guess_bad_opentags(txt)
end

.guess_bad_opentags(txt) ⇒ Object



36
37
38
# File 'lib/dyndoc-linter.rb', line 36

def Linter.guess_bad_opentags(txt)
  selected_opentags=txt.scan(/(?:\{[\#\@](?:[\w\:\|-]*[<>]?[=?!><]?(?:\.\w*)?)\})/).each_with_index.map{|e,i| [i+1,e] }
end

.guess_bad_tags(tags) ⇒ Object



32
33
34
# File 'lib/dyndoc-linter.rb', line 32

def Linter.guess_bad_tags(tags)

end

.selected_tags(txt) ⇒ Object



10
11
12
13
14
# File 'lib/dyndoc-linter.rb', line 10

def Linter.selected_tags(txt)
  selected_tags=txt.scan(/(?:\{[\#\@](?:[\w\:\|-]*[<>]?[=?!><]?(?:\.\w*)?)\]|\[[\#\@](?:[\w\:\|-]*[<>]?[=?!><]?)\})/).each_with_index.map{|e,i| [i+1,e] }
  ## p selected_tags
  selected_tags
end

.simplify_dyndoc_tags(tags) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dyndoc-linter.rb', line 16

def Linter.simplify_dyndoc_tags(tags)
  (0..(tags.length-2)).each do |i|
    if (tags[i][1] == "{#"+tags[i+1][1][2..-2]+"]" and tags[i+1][1] == "[#"+tags[i][1][2..-2]+"}") or (tags[i][1][0]=="{" and tags[i+1][1]=="[#}")
      tags.delete_at i+1;tags.delete_at i
      Dyndoc::Linter.simplify_dyndoc_tags(tags)
      break
    end
    if (tags[i][1] == "{@"+tags[i+1][1][2..-2]+"]" and tags[i+1][1] == "[@"+tags[i][1][2..-2]+"}") or (tags[i][1][0]=="{" and tags[i+1][1]=="[@}")
      tags.delete_at i+1;tags.delete_at i
      Dyndoc::Linter.simplify_dyndoc_tags(tags)
      break
    end
  end
  return tags
end