link_url 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/link_url.rb +35 -4
  3. metadata +10 -12
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzBlYzg3NTBmYmZiYzc0NGFiYjZjYjkxYjhlN2M0YTE5YWQyNmI4NA==
5
+ data.tar.gz: !binary |-
6
+ M2Q5MTk3ZWRmZTNmZWMzODBiMGRkZTliNGViNTZlOWE2ZTRiNzQ2MA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDEzOTkxZDRhMWE5NTIyZDhjMDFjMzJhZDg4NDc3NTI4YjNlMTNhNjJjZDdk
10
+ ODI1MmY3ZGU3NDE4MDAzZDU2MDMzYTllZTAzMzU1NWRlMzNmNjNjODU4NmI5
11
+ ZTNjYmVjZmViYzliNDVhZTc2OWZjYTQ3N2U4MjhiMzYyNmZiNWE=
12
+ data.tar.gz: !binary |-
13
+ ZWM5MzZlODRmMjQyMjU0ZWM1MjRjMzg3YmY0ODc3YmMyYzJkZWM3MTVmN2Vh
14
+ NWUxZDc0MjA4ZjlkNTRhNjc5OTcyNGU0M2IxNTViYjAyZjE4Y2MxMzFiMmIw
15
+ YzkzZjc5MDFlOGZlZjMwNWE1NWI1NjlhODczNTU4MzAwNDMxZjk=
data/lib/link_url.rb CHANGED
@@ -1,14 +1,19 @@
1
1
  # The main LinkUrl driver
2
2
  class LinkUrl
3
- # Convert any url from the string or text into the links
4
- #
3
+ # Convert any image url into the image tag sepratedly and remain other url normal by using convert_image("www.clecotech.in http://www.ashishprajapati.com/new.png").
4
+ # Convert image url into image tag and normal url into link by using convert_all("www.ashishprajapati.com/new.png").
5
+ # Convert any url from the string or text into the links by using convert("www.ashishprajapati.com").
6
+ #
5
7
  # Example:
6
8
  # >> LinkUrl.convert("Hi my new website http://www.bookofskills.com ! Please come at us to reward me.")
7
9
  # => Hi my new website <a href='http://www.bookofskills.com'>http://www.bookofskills.com</a> ! Please come at us to reward me.
8
- #
10
+ # >> LinkUrl.convert_image("Hi I have updated the code. my website is www.ashishprajapati.com you can see my pic using www.ashishprajapati.com/ashish.png")
11
+ # => Hi I have updated the code. my website is www.ashishprajapati.com you can see my pic using <img src='www.ashishprajapati.com/ashish.png' />
12
+ # >> LinkUrl.convert_all("Hi I have updated the code. my website is www.ashishprajapati.com you can see my pic using www.ashishprajapati.com/ashish.png")
13
+ # => Hi I have updated the code. my website is <a href='www.ashishprajapati.com'>www.ashishprajapati.com</a> you can see my pic using <img src='www.ashishprajapati.com/ashish.png' />
9
14
  # Arguments:
10
15
  # content: (String)
11
-
16
+ # Convert all url into links.
12
17
  def self.convert(content)
13
18
  if(content)
14
19
  exp =/\b((?:mailto:\S+|(?:https?|ftp|file):\/\/|www.)[^\s<]+)\b/
@@ -17,4 +22,30 @@ class LinkUrl
17
22
  return content
18
23
  end
19
24
  end
25
+ # Convert Image Url into image tag and other url remain normal.
26
+ def self.convert_image(content)
27
+ if(content)
28
+ exp =/\b(((?:https?|ftp|file):\/\/|www.)[^\s<]+)\b/
29
+ content = content.gsub(exp) do |url|
30
+ if url[/(?:png|jpe?g|gif|svg|bmp)$/]
31
+ "<img src='#{url}' />"
32
+ else
33
+ "#{url}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ # Convert Image Url into image tag and normal url into link.
39
+ def self.convert_all(content)
40
+ if(content)
41
+ exp =/\b(((?:https?|ftp|file):\/\/|www.)[^\s<]+)\b/
42
+ content = content.gsub(exp) do |url|
43
+ if url[/(?:png|jpe?g|gif|svg|bmp)$/]
44
+ "<img src='#{url}' />"
45
+ else
46
+ "<a href='#{url}'>#{url}</a>"
47
+ end
48
+ end
49
+ end
50
+ end
20
51
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ashish Prajapati
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-31 00:00:00.000000000 Z
11
+ date: 2014-01-01 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: Convert all the url from the string or text into the links as <a href="...">...</a>
15
- Need to install this gem and use LinkUrl.convert("Guys come at www.ashishprajapati.com
16
- and http://www.bookofskills.com")
13
+ description: Convert any image url into the image tag sepratedly and remain other
14
+ url normal by using LinkUrl.convert_image("www.clecotech.in http://www.ashishprajapati.com/new.png").
15
+ Convert image url into image tag and normal url into link by using LinkUrl.convert_all("www.ashishprajapati.com/new.png").
16
+ Convert any url from the string or text into the links by using LinkUrl.convert("www.ashishprajapati.com").
17
17
  email: mail@ashishprajapati.com
18
18
  executables: []
19
19
  extensions: []
@@ -22,27 +22,25 @@ files:
22
22
  - lib/link_url.rb
23
23
  homepage: http://rubygems.org/gems/link_url
24
24
  licenses: []
25
+ metadata: {}
25
26
  post_install_message:
26
27
  rdoc_options: []
27
28
  require_paths:
28
29
  - lib
29
30
  required_ruby_version: !ruby/object:Gem::Requirement
30
- none: false
31
31
  requirements:
32
32
  - - ! '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  required_rubygems_version: !ruby/object:Gem::Requirement
36
- none: false
37
36
  requirements:
38
37
  - - ! '>='
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
40
  requirements: []
42
41
  rubyforge_project:
43
- rubygems_version: 1.8.25
42
+ rubygems_version: 2.0.4
44
43
  signing_key:
45
- specification_version: 3
46
- summary: Convert all url into link
44
+ specification_version: 4
45
+ summary: Convert all images into image tag and url into link or as per your choice
47
46
  test_files: []
48
- has_rdoc: