Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ Installation
gem "view_inspect"
end

Configuration
----
# config/environments/development.rb
ViewInspect.show_line_number = true # default value true

ViewInspect.max_path_depth = 3
# default value 0, 0 means show full path, when a positive number is given
# and the positive number is less than absolute path depth of the view file,
# then the in view, the path will be display in relative:
# Example if a view path is /foo/bar/project/app/views/users/index.html.erb,
# if you set max_path_depth to 3 then the output will be
# views/users/index.html.erb, so you can easily copy
# the search input of your editor by double click select it


Warning
----

Expand Down
17 changes: 17 additions & 0 deletions lib/view_inspect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module ViewInspect
def self.init
return unless allow_view_source_location?

@show_line_number = true
ServerSideTemplate.handle
ClientSideTemplate.handle
end
Expand All @@ -18,6 +19,22 @@ def self.disable=(bool)
@disable = bool
end

def self.max_path_depth=(depth)
@max_path_depth = depth
end

def self.max_path_depth
@max_path_depth && @max_path_depth >= 0 ? @max_path_depth : 0
end

def self.show_line_number?
@show_line_number
end

def self.show_line_number=(bool)
@show_line_number = bool
end

def self.show_html_syntax_error?
@show_html_syntax_error
end
Expand Down
5 changes: 3 additions & 2 deletions lib/view_inspect/handlers/html_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def add_file_line(source, filepath)

doc.traverse do |node|
if node.is_a?(::Nokogiri::XML::Element)
file_line = [filepath, node.line].join(":")
node.set_attribute "data-orig-file-line", file_line
file_line = [filepath.split(File::SEPARATOR)[-ViewInspect.max_path_depth..-1].join(File::SEPARATOR)]
file_line << node.line if ViewInspect.show_line_number?
node.set_attribute "data-orig-file-line".freeze, file_line.join(':'.freeze)
end
end

Expand Down