diff --git a/README.markdown b/README.markdown index aeb31ce..9f67828 100644 --- a/README.markdown +++ b/README.markdown @@ -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 ---- diff --git a/lib/view_inspect.rb b/lib/view_inspect.rb index d651a53..5c8a502 100644 --- a/lib/view_inspect.rb +++ b/lib/view_inspect.rb @@ -6,6 +6,7 @@ module ViewInspect def self.init return unless allow_view_source_location? + @show_line_number = true ServerSideTemplate.handle ClientSideTemplate.handle end @@ -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 diff --git a/lib/view_inspect/handlers/html_template.rb b/lib/view_inspect/handlers/html_template.rb index 01c1845..794fd58 100644 --- a/lib/view_inspect/handlers/html_template.rb +++ b/lib/view_inspect/handlers/html_template.rb @@ -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