Sha256: 6ed4edf34fa5ca2afd514aeb2cadc469ff1c11eb3bdde1440b20ac1ba70b6134

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require "erb"
require "rubycritic/report_generators/base_generator"
require "rubycritic/report_generators/line_generator"

module Rubycritic

  class FileGenerator < BaseGenerator
    LINE_NUMBER_OFFSET = 1
    FILE_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "file.html.erb")))
    LAYOUT_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))

    def initialize(pathname, smells)
      @pathname = pathname
      @smells = smells
    end

    def file_directory
      File.join(REPORT_DIR, File.dirname(@pathname))
    end

    def file_name
      "#{analysed_file_name}.html"
    end

    def analysed_file_name
      @pathname.basename.sub_ext("")
    end

    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 = @smells.select { |smell| smell.located_in?(location) }
        file_code << LineGenerator.new(line_text, line_smells).render
      end

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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubycritic-0.0.5 lib/rubycritic/report_generators/file_generator.rb