gembed 0.9.0 → 1.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c8826ec97c8ae959db9371776e4886c162c2beac8fa597dbc857db1a187609e
4
- data.tar.gz: 8facf340fcb706fdcd446ce15e18469d9de936eabbb6ff16bc21c56b6d2d4e3d
3
+ metadata.gz: 027b6f23e2cbd5e8ffb8058940de5b53918ab64ffab396c692c37fd04a8ebf23
4
+ data.tar.gz: 456bedb90bdf8669e3acb9217decdb76b1289cec9a16277b7d6ceb820f946a99
5
5
  SHA512:
6
- metadata.gz: 83dd9bb231fa6102311bed3e0a5f2e97b412ff2253403c0a0b451996ab0c16abaf73f26614cec82ef7f8f5618306b64683a9b136dc5dd6a36637d62691d74c17
7
- data.tar.gz: 86bec188e61c4166282ad68c8600cdd9702786f3019c00003a314ebb1ed3cc69e983b8fbfdf22698c8fb13416a1eb59b932c2cdf887b79cfa4aa0e0e6be543c5
6
+ metadata.gz: fa5aa1a6780295c1cd61905ed3d4bd63707e102f82f9a311f723d38de8adbec04f5091e3b18d37a35e7acebb9f3c652df26b849cf2824cf512c571e139559f14
7
+ data.tar.gz: 031507b277ef877253521b184a7c3e5f4073e9b5acd353c29d147e835517a0df3e12c291b3c9776b27ec8a31f038822fbc9d09bb4af05c8ba3953929d3867f4a
@@ -4,17 +4,39 @@ module Gembed
4
4
 
5
5
  # Hash of source classes
6
6
  @sources = Hash[
7
- "loom.com" => Loom
7
+ "loom.com" => Loom,
8
+ "youtube.com" => Youtube,
9
+ "youtu.be" => Youtube,
10
+ "vimeo.com" => Vimeo
8
11
  ]
9
12
 
10
13
  class << self
11
14
  def insert(url)
12
- @sources[find_source(url)].embed(url)
15
+ source = find_source(url)
16
+ if @sources[source].nil?
17
+ return source_error(url)
18
+ else
19
+ @sources[source].embed(url)
20
+ end
21
+ end
22
+
23
+ def get_id(url)
24
+ source = find_source(url)
25
+ if @sources[source].nil?
26
+ return "Source not supported"
27
+ else
28
+ @sources[source].find_id(url)
29
+ end
13
30
  end
14
31
 
15
32
  # Gets domain of the url
16
33
  def find_source(url)
17
- source = url.match(/\/\/[www.]*[a-zA-Z0-9]*\.[a-z]*/).to_s.gsub(/\/\/[www.]*/,'')
34
+ @source = url.match(/\/\/[www.]*[a-zA-Z0-9]*\.[a-z]*/).to_s.gsub(/\/\/[www.]*/,'')
35
+ end
36
+
37
+ def source_error(url)
38
+ result = "<a href='#{url}' target='_blank'>#{url}</a>"
39
+ result.respond_to?(:html_safe) ? result.html_safe : result
18
40
  end
19
41
  end
20
- end
42
+ end
@@ -1,12 +1,12 @@
1
1
  module Gembed
2
2
  class Loom
3
- def self.embed(url)
4
- result = "<div style='position: relative; padding-bottom: 62.5%; height: 0;'><iframe src='#{url.gsub("/share/", "/embed/")}'' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen style='position: absolute; top: 0; left: 0; width: 100%; height: 100%;'></iframe></div>"
5
- if result.respond_to?(:html_safe)
6
- result.html_safe
7
- else
8
- result
9
- end
3
+ def self.embed(url, height: "100%", width: "100%")
4
+ result = "<iframe src='https://www.loom.com/embed/#{find_id(url)}' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen style='position: absolute; top: 0; left: 0; width: #{width}; height: #{height};'></iframe>"
5
+ result.respond_to?(:html_safe) ? result.html_safe : result
6
+ end
7
+
8
+ def self.find_id(url)
9
+ url.split("share/")[1]
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,12 @@
1
+ module Gembed
2
+ class Vimeo
3
+ def self.embed(url, height: "100%", width: "100%")
4
+ result = "<iframe src='https://player.vimeo.com/video/#{find_id(url)}?title=0&byline=0&portrait=0' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen style='position: absolute; top: 0; left: 0; width: #{width}; height: #{height};'></iframe>"
5
+ result.respond_to?(:html_safe) ? result.html_safe : result
6
+ end
7
+
8
+ def self.find_id(url)
9
+ url.split("vimeo.com/")[1]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module Gembed
2
+ class Youtube
3
+ def self.embed(url, height: "100%", width: "100%")
4
+ result = "<iframe src='https://www.youtube.com/embed/#{find_id(url)}' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen style='position: absolute; top: 0; left: 0; width: #{width}; height: #{height};'></iframe>"
5
+ result.respond_to?(:html_safe) ? result.html_safe : result
6
+ end
7
+
8
+ def self.find_id(url)
9
+ id = ''
10
+ url = url.gsub(/(>|<)/i,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/)
11
+ if url[2] != nil
12
+ id = url[2].split(/[^0-9a-z_\-]/i)
13
+ id = id[0];
14
+ else
15
+ id = url;
16
+ end
17
+ id
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gembed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Paul
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Embed media by URL.
13
+ description: Use gembed to embed media in your applications. Give it a url and gembed
14
+ will embed it for you. As simple as that! For a full list of sources see the wiki.
14
15
  email: hello@johnraj.me
15
16
  executables: []
16
17
  extensions: []
@@ -18,13 +19,13 @@ extra_rdoc_files: []
18
19
  files:
19
20
  - lib/gembed.rb
20
21
  - lib/gembed/loom.rb
21
- homepage: https://github.com/iJohnPaul/gembed/
22
+ - lib/gembed/vimeo.rb
23
+ - lib/gembed/youtube.rb
24
+ homepage: https://rubygems.org/gems/gembed
22
25
  licenses:
23
26
  - MIT
24
- metadata:
25
- source_code_uri: https://github.com/iJohnPaul/gembed/
26
- wiki_uri: https://github.com/iJohnPaul/gembed/wiki
27
- post_install_message:
27
+ metadata: {}
28
+ post_install_message:
28
29
  rdoc_options: []
29
30
  require_paths:
30
31
  - lib
@@ -39,8 +40,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  requirements: []
42
- rubygems_version: 3.1.2
43
- signing_key:
43
+ rubygems_version: 3.1.4
44
+ signing_key:
44
45
  specification_version: 4
45
- summary: A gem for embeding media.
46
+ summary: A ruby gem for embedding various media sources by url.
46
47
  test_files: []