Class: ProjectController::HtmlDiffVisitor

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/project_controller.rb

Overview

Visitor that adds a method called html_diff to each change

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ HtmlDiffVisitor

Returns a new instance of HtmlDiffVisitor.



116
117
118
# File 'app/controllers/project_controller.rb', line 116

def initialize(project)
  @project = project
end

Instance Method Details

#visit_change(change) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/controllers/project_controller.rb', line 127

def visit_change(change)
  def change.html_diff=(html)
    @html = html
  end

  def change.html_diff
    @html
  end

  html = ""
  dp = DamageControl::DiffParser.new
  diff_file = DamageControl::Directories.diff_file(@project.name, @changeset, change)
  if(File.exist?(diff_file))
    File.open(diff_file) do |diffs_io|
      diffs = dp.parse_diffs(diffs_io)
      dh = DamageControl::DiffHtmlizer.new(html)
      diffs.accept(dh)
      if(html == "")
        html = "Diff was calculated, but was empty. (This may be a bug - new, moved and binary files and are not supported yet)."
      end
    end
  else
    html = "Diff not calculated yet."
  end
  change.html_diff = html
end

#visit_changeset(changeset) ⇒ Object



123
124
125
# File 'app/controllers/project_controller.rb', line 123

def visit_changeset(changeset)
  @changeset = changeset
end

#visit_changesets(changesets) ⇒ Object



120
121
# File 'app/controllers/project_controller.rb', line 120

def visit_changesets(changesets)
end