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.



91
92
93
# File 'app/controllers/project_controller.rb', line 91

def initialize(project)
  @project = project
end

Instance Method Details

#visit_change(change) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/controllers/project_controller.rb', line 99

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



95
96
97
# File 'app/controllers/project_controller.rb', line 95

def visit_changeset(changeset)
  @changeset = changeset
end