Class: RubyCritic::Generator::Html::CodeFile
- 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
- #file_directory ⇒ Object
- #file_name ⇒ Object
-
#initialize(analysed_module) ⇒ CodeFile
constructor
A new instance of CodeFile.
- #render ⇒ Object
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
Returns a new instance of 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_directory ⇒ Object
17 18 19 |
# File 'lib/rubycritic/generators/html/code_file.rb', line 17 def file_directory @file_directory ||= root_directory + @pathname.dirname end |
#file_name ⇒ Object
21 22 23 |
# File 'lib/rubycritic/generators/html/code_file.rb', line 21 def file_name @pathname.basename.sub_ext('.html') end |
#render ⇒ Object
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 |