Class: RubyCritic::Generator::Html::CodeFile

Inherits:
Base
  • Object
show all
Defined in:
lib/rubycritic/generators/html/code_file.rb

Constant Summary collapse

LINE_NUMBER_OFFSET =
1
TEMPLATE =
erb_template('code_file.html.erb')

Constants inherited from Base

Base::LAYOUT_TEMPLATE, Base::TEMPLATES_DIR

Instance Method Summary collapse

Methods inherited from Base

erb_template, #file_href, #file_pathname

Methods included from ViewHelpers

#asset_path, #file_path, #image_path, #javascript_tag, #smell_location_path, #stylesheet_path, #timeago_tag

Constructor Details

#initialize(analysed_module) ⇒ CodeFile


12
13
14
15
# File 'lib/rubycritic/generators/html/code_file.rb', line 12

def initialize(analysed_module)
  @analysed_module = analysed_module
  @pathname = @analysed_module.pathname
end

Instance Method Details

#file_directoryObject


17
18
19
# File 'lib/rubycritic/generators/html/code_file.rb', line 17

def file_directory
  @file_directory ||= root_directory + @pathname.dirname
end

#file_nameObject


21
22
23
# File 'lib/rubycritic/generators/html/code_file.rb', line 21

def file_name
  @pathname.basename.sub_ext('.html')
end

#renderObject


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubycritic/generators/html/code_file.rb', line 25

def render
  file_code = []
  File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
    location = Location.new(@pathname, line_number)
    line_smells = @analysed_module.smells_at_location(location)
    file_code << Line.new(file_directory, line_text, line_smells).render
  end

  file_body = TEMPLATE.result(get_binding { file_code.join })
  LAYOUT_TEMPLATE.result(get_binding { file_body })
end