Class: ActionView::TemplateError

Inherits:
ActionViewError
  • Object
show all
Defined in:
lib/masterview/rails_ext/action_view_erb_direct.rb,
lib/masterview/rails_ext/action_view_erb_direct.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#source_extract(indention = 0) ⇒ Object

:nodoc:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/masterview/rails_ext/action_view_erb_direct.rb', line 149

def source_extract(indentation = 0)
  return unless num = line_number
  num = num.to_i

  #MasterView::Log.debug { "source_extract12 tpath=#{@file_path}  base=#{@base_path}"}

  # template is relative to Rails root

  #added/modified the following two lines to support reading from MasterView with fallback to file system
  filedata = MasterView::RailsExt::ShortPathCalculator.calc_short_path_and_retrieve(MasterView::ConfigSettings.rails_root_path, @file_path,
                                                                                    MasterView::IOMgr.erb)
  source_code = (filedata) ? StringIO.new(filedata).readlines : IO.readlines(@file_path) # mio.exists? use it, else original file read
  # source_code = IO.readlines(@file_path) # original rails 1.2 source

  start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
  end_on_line   = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min

  indent = ' ' * indentation
  line_counter = start_on_line

  source_code[start_on_line..end_on_line].sum do |line|
    line_counter += 1
    "#{indent}#{line_counter}: #{line}"
  end
end