linky 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -11,9 +11,9 @@ A simple gem for safely linking keywords within HTML (i.e., it's more than a `gs
11
11
  Call the `Linky.link` method:
12
12
 
13
13
  require 'linky'
14
- html = "<p>link all occurances of the word "more."</p><div>some more text</div>"
14
+ html = "<p>link the first occurance of the word "more."</p><div>some more text</div>"
15
15
  Linky.link "more", "http://more.com", html, :class => "linky"
16
- # returns "<p>link the word "<a href="http://more.com" class="linky">more</a>."</p><div>some <a href="http://more.com" class="linky">more</a> text</div>"
16
+ # returns "<p>link the first occurance of the word "<a href="http://more.com" class="linky">more</a>."</p><div>some more text</div>"
17
17
 
18
18
  ## Docs
19
19
 
data/lib/linky/linky.rb CHANGED
@@ -28,15 +28,19 @@ class Linky
28
28
 
29
29
  # call the block to determine what we'll replace the needle with
30
30
  new_needle = block.call match[1]
31
+
32
+
31
33
 
32
34
  # break the string into three parts
33
35
  prefix, keyword, postfix = break_on_boundary match[1], haystack.to_s
34
-
36
+
35
37
  haystack.content = prefix
36
38
  haystack.add_next_sibling Nokogiri::HTML::DocumentFragment.parse(new_needle)
37
39
  if !postfix.nil? and !postfix.empty?
38
- haystack.next_sibling.add_next_sibling Nokogiri::HTML::DocumentFragment.parse(postfix)
39
- haystack.next_sibling.next_sibling.content = postfix
40
+ if postfix_content = Nokogiri::HTML::DocumentFragment.parse(postfix)
41
+ postfix_content.content = postfix
42
+ haystack.next_sibling.add_next_sibling postfix_content
43
+ end
40
44
  end
41
45
  true
42
46
  elsif haystack.name != "a" && haystack.respond_to?(:children)
data/spec/linky_spec.rb CHANGED
@@ -24,4 +24,10 @@ describe Linky, "#link" do
24
24
  new_html = Linky.link "he", "#he", html
25
25
  new_html.should == "hi there, <a href=\"#he\">he</a> is funny and he is a he.<div>more he stuff.</div>"
26
26
  end
27
+
28
+ it "should not remove links" do
29
+ html = "<p>California <a href=\"topics/cabernet-sauvignon\">Cabernet Sauvignon</a></p>"
30
+ new_html = Linky.link "California", "topics/california", html
31
+ new_html.should == "<p><a href=\"topics/california\">California</a> <a href=\"topics/cabernet-sauvignon\">Cabernet Sauvignon</a></p>"
32
+ end
27
33
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linky
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-05 00:00:00 -05:00
18
+ date: 2010-12-07 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency