Module: Utils
- Included in:
- Htmlize
- Defined in:
- lib/smart_diff/utils.rb
Class Method Summary collapse
-
.get_install_path ⇒ Pathname
Where in the file-system is smart_diff installed?.
-
.inside_anchor?(tags, nd_start, nd_end) ⇒ TrueClass, FalseClass
Determines if the node beginning with nd_start and ending with nd_end falls inside an anchor.
-
.node_end(node) ⇒ Fixnum
Get a node’s end position.
-
.node_start(node) ⇒ Fixnum
Get a node’s start position,.
Class Method Details
.get_install_path ⇒ Pathname
Where in the file-system is smart_diff installed?
11 12 13 14 15 |
# File 'lib/smart_diff/utils.rb', line 11 def get_install_path utils_path = Pathname.new(__FILE__).dirname # There should be a more elegant way to do this install_path = utils_path.parent.parent end |
.inside_anchor?(tags, nd_start, nd_end) ⇒ TrueClass, FalseClass
Determines if the node beginning with nd_start and ending with nd_end falls inside an anchor. In other words, is the current node inside another node _which also changed_ and has a match in the other file. (If it is an insertion or deletion it gets wrapped in a span so we aren’t concerned with those.)
In a pair of tags, the opening tag only has some of the position information, so they are marked with a meaningless -1. But the closing tags have the information needed- start and end offsets.
Subnodes were added to the array after the outer nodes, so we check them here, once, against each tag, and decide how to process them as we generate the HTML.
60 61 62 63 64 65 66 67 |
# File 'lib/smart_diff/utils.rb', line 60 def inside_anchor?(, nd_start, nd_end) .each do |t| if nd_end < t.idx && nd_start > t.start && t.start != -1 return true end end return false end |
.node_end(node) ⇒ Fixnum
Get a node’s end position.
35 36 37 |
# File 'lib/smart_diff/utils.rb', line 35 def node_end(node) node.position.end_offset end |
.node_start(node) ⇒ Fixnum
Get a node’s start position,
24 25 26 |
# File 'lib/smart_diff/utils.rb', line 24 def node_start(node) node.position.start_offset end |