Sha256: 0de4985f5ab8bf69df54722e25c56b7ace3f31d9706ce2424fa500c06f879108

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 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, @pathname.dirname)
    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

2 entries across 2 versions & 1 rubygems

Version Path
rubycritic-0.0.7 lib/rubycritic/report_generators/file_generator.rb
rubycritic-0.0.6 lib/rubycritic/report_generators/file_generator.rb