Sha256: b2140d70a14152796728cada8075ae36be5d73d92733f5224ebba7004ecd7a47

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

require "rubycritic/generators/html/base"
require "rubycritic/generators/html/line"

module Rubycritic
  module Generator
    module Html

      class CodeFile < Base
        LINE_NUMBER_OFFSET = 1
        TEMPLATE = erb_template("code_file.html.erb")

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

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

        def file_name
          @pathname.basename.sub_ext(".html")
        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 = @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
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubycritic-2.6.0 lib/rubycritic/generators/html/code_file.rb
rubycritic-2.5.0 lib/rubycritic/generators/html/code_file.rb
rubycritic-2.4.1 lib/rubycritic/generators/html/code_file.rb
rubycritic-2.4.0 lib/rubycritic/generators/html/code_file.rb
rubycritic-2.3.0 lib/rubycritic/generators/html/code_file.rb
rubycritic-2.2.0 lib/rubycritic/generators/html/code_file.rb
rubycritic-2.1.0 lib/rubycritic/generators/html/code_file.rb
rubycritic-2.0.0 lib/rubycritic/generators/html/code_file.rb
rubycritic-1.4.0 lib/rubycritic/generators/html/code_file.rb