Module: Gliss

Defined in:
lib/gliss.rb

Defined Under Namespace

Classes: App, CommitMsg, Gloss

Constant Summary collapse

GLOSS_TAG_RE =
/(([^\s])\3\3)(-?)(.*?)\2(.*)/
GLOSS_INDENTED_RE =
/^(\s*)#{GLOSS_TAG_RE}/
GLOSS_MIDLINE_RE =
/^(.*?)#{GLOSS_TAG_RE}/
GLOSS_RE =
/^()#{GLOSS_TAG_RE}/
GLOSS_TAG =
5
GLOSS_TEXT =
6
GLOSS_STRIP =
4
GLOSS_BEFORE =
1
BARE_INDENT_RE =
/(\s+)(.*)/
INDENT_AMOUNT =
1
INDENTED_TEXT =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



47
48
49
# File 'lib/gliss.rb', line 47

def filter
  @filter
end

Class Method Details

.begins_gloss(line, sha, allow_indented = false) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/gliss.rb', line 99

def self.begins_gloss(line, sha, allow_indented=false)
  match = line.match(allow_indented ? GLOSS_INDENTED_RE : GLOSS_RE)
  if match
    ws = match[GLOSS_BEFORE]
    tag = match[GLOSS_TAG].strip
    text = match[GLOSS_TEXT].strip
    return [true, nil, ws, Gloss.new(sha, tag, [text])]
  end
  nil
end

.commits_between(repo, older, newer) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/gliss.rb', line 55

def self.commits_between(repo, older, newer)
  if repo.is_a?(String)
    repo = Grit::Repo.new(repo)
  end

  commits = repo.commit_deltas_from(repo, older, newer).sort_by {|c| c.committed_date}
  commits.map do |commit_obj|
    CommitMsg.new(commit_obj.sha, commit_obj.message)
  end
end

.glosses_between(repo, older, newer, allow_indented = false) ⇒ Object



49
50
51
52
53
# File 'lib/gliss.rb', line 49

def self.glosses_between(repo, older, newer, allow_indented=false)
  commits_between(repo, older, newer).inject([]) do |acc, commit|
    acc + glosses_in(commit.log, commit.sha, allow_indented)
  end
end

.glosses_in(message, sha = nil, allow_indented = false) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gliss.rb', line 66

def self.glosses_in(message, sha=nil, allow_indented=false)
  result = []
  continuing = false
  ws = ""
  indent_matcher = nil

  message.each_line do |line|
    line.chomp!
    match = nil
    if continuing
      match = line.match((indent_matcher || /^(?:#{ws})#{BARE_INDENT_RE}$/))
      
      if match
        indent_matcher ||= /^(?:#{ws})(#{match[INDENT_AMOUNT]})(.*)$/
        text = match[INDENTED_TEXT].strip
        result[-1].text << text
        next
      else
        indent_matcher = nil
        continuing = false
      end
    end
    
    match = begins_gloss(line, sha, allow_indented)
    if match
      continuing, indent_matcher, ws, new_gloss = match
      result << new_gloss
    end
  end

  result.each {|g| g.text.reject! {|t| t == ''}; g.text = g.text.join(" ")}
end

.split_glosses(gloss, split_glosses = false) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/gliss.rb', line 110

def self.split_glosses(gloss, split_glosses=false)
  if split_glosses
    result_glosses = [gloss]
    text = gloss.text
    match = text.match(GLOSS_MIDLINE_RE)
    while match
      result_glosses[-1].text = match[GLOSS_BEFORE].strip if result_glosses[-1]
      tag = match[GLOSS_TAG].strip
      text = match[GLOSS_TEXT].strip
      result_glosses << Gloss.new(gloss.sha, tag, text)
      match = text.match(GLOSS_MIDLINE_RE)
    end

    if block_given?
      result_glosses.each do |g|
        yield g
      end
    else
      result_glosses
    end
  else
    if block_given?
      yield gloss
    else
      return [gloss]
    end
  end
end