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, #javascript_tag, #smell_location_path, #stylesheet_path, #timeago_tag

Constructor Details

#initialize(analysed_module) ⇒ CodeFile

Returns a new instance of CodeFile.



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

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

Instance Method Details

#file_directoryObject



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

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

#file_nameObject



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

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

#renderObject



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

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 })
  LAYOUT_TEMPLATE.result(get_binding { file_body })
end