Commit 9530d78c authored by Coraline Ehmke's avatar Coraline Ehmke

HTML report provides line numbers

parent 226e41fb
......@@ -49,13 +49,13 @@ module Snuffle
def cvs_report(summary)
return unless options['format'] == 'csv'
return unless summary.object_candidates.count > 0
return unless summary.cohorts.count > 0
results_files << Snuffle::Formatters::Csv.new(summary).export
end
def html_report(summary, source)
return unless options['format'] == 'html'
return unless summary.object_candidates.count > 0
return unless summary.cohorts.count > 0
results_files << Snuffle::Formatters::Html.new(summary, source).export
end
......
......@@ -3,11 +3,11 @@ module Snuffle
class Cohort
include PoroPlus
attr_accessor :element, :neighbors
attr_accessor :element, :neighbors, :line_numbers
def self.from(nodes)
Element::Hash.materialize(nodes.hashes.to_a).inject([]) do |cohorts, element|
cohort = Cohort.new(element: element)
cohort = Cohort.new(element: element, line_numbers: element.node.line_numbers )
cohorts << cohort if cohort.values.count > 1 && cohort.near_neighbors.count > 0
cohorts
end
......
......@@ -43,9 +43,9 @@
Object Candidates
%tbody
- summaries.each_with_index do |summary, i|
%tr{class: "#{i % 2 == 1 ? 'odd' : 'even'} #{summary.object_candidates.count == 0 ? 'faint' : ''}"}
%tr{class: "#{i % 2 == 1 ? 'odd' : 'even'} #{summary.cohorts.count == 0 ? 'faint' : ''}"}
%td
- if summary.object_candidates.count == 0
- if summary.cohorts.count == 0
= summary.path_to_file
- else
%a{href: "source/#{summary.class_filename}.htm"}
......@@ -57,7 +57,7 @@
- else
= summary.class_name
%td
= summary.object_candidates.count
= summary.cohorts.count
%tfoot
%tr
%td.center{colspan: 3}
......
......@@ -32,10 +32,12 @@
Potential objects:
%ul.indented
- summary.object_candidates.each do |candidate|
- if candidate.length > 0
- summary.cohorts.group_by{|c| c.values.sort }.each do |values, cohorts|
- if cohorts.count > 0
%li
= candidate.map{|c| "##{c}" }.join(", ")
= values.map{|c| "##{c}" }.join(", ")
%br
= "Lines #{cohorts.map(&:line_numbers).join(', ')}"
= source_lines
......
......@@ -5,7 +5,7 @@ module Snuffle
include Ephemeral::Base
include PoroPlus
attr_accessor :id, :name, :type, :child_ids, :parent_id
attr_accessor :id, :name, :type, :child_ids, :parent_id, :line_numbers
scope :by_id, lambda{|id| where(:id => id)}
scope :by_type, lambda{|type| where(:type => type)}
......
......@@ -19,8 +19,8 @@ module Snuffle
@nodes ||= extract_nodes_from(ast)
end
def object_candidates
@object_candidates ||= Cohort.from(self.nodes).map(&:values)
def cohorts
@cohorts ||= Cohort.from(self.nodes)
end
def source
......@@ -30,7 +30,7 @@ module Snuffle
@source = File.readlines(self.path_to_file).each_with_index do |line, index|
start_pos = end_pos + 1
end_pos += line.size
self.lines_of_code << LineOfCode.new(index: index, range: (start_pos..end_pos))
self.lines_of_code << LineOfCode.new(line_number: index + 1, range: (start_pos..end_pos))
line
end.join
end
......@@ -41,7 +41,7 @@ module Snuffle
source: self.source,
class_name: class_name,
path_to_file: self.path_to_file,
object_candidates: object_candidates,
cohorts: cohorts,
source: self.source
)
end
......@@ -71,10 +71,12 @@ module Snuffle
def extract_nodes_from(ast_node, nodes=Ephemeral::Collection.new("Snuffle::Node"), parent_id=:root)
if name = name_from(ast_node)
if ast_node.respond_to?(:type)
lines = LineOfCode.containing(lines_of_code, ast_node.loc.expression.begin_pos, ast_node.loc.expression.end_pos)
extracted_node = Snuffle::Node.new(
type: ast_node.type,
parent_id: parent_id,
name: name_from(ast_node)
name: name_from(ast_node),
line_numbers: lines.map(&:line_number)
)
else
extracted_node = Snuffle::Node.new(
......
......@@ -2,7 +2,7 @@ module Snuffle
class Summary
include PoroPlus
attr_accessor :class_name, :path_to_file, :object_candidates, :source
attr_accessor :class_name, :path_to_file, :cohorts, :source
def class_filename
self.class_name.downcase.gsub(' ', '_')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment