zemus 0.0.7 → 0.0.8

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.
data/.gitignore CHANGED
@@ -1,7 +1,9 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.patch
3
4
  .bundle
4
5
  .config
6
+ .DS_Store
5
7
  .yardoc
6
8
  Gemfile.lock
7
9
  InstalledFiles
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Zemus is a ruby gem that translates URLs into embedable code you can insert on a page. It does its magic by simply inspecting and hacking up the URL itself, it makes no external requests to a webservice.
4
4
 
5
- It currently translates the follow URLs to embedabble HTML:
5
+ It currently translates the following URLs to embedabble HTML in standard mode:
6
6
 
7
7
  * images
8
8
  * mp3s
@@ -12,6 +12,12 @@ It currently translates the follow URLs to embedabble HTML:
12
12
  * kickstarter
13
13
  * soundcloud
14
14
 
15
+ For embeddable elements that require flash, we have implemented a "dirty mode" that will allow these objects for browsers that can display them, and show a message about the lack of compatibility on browsers that don't support flash, such as mobile devices. For flash embeds, there are two hidden div classes, .zemusflashembed and .zemusnoflash, and some lightweight javascript will detect flash capability and display the proper one.
16
+
17
+ In dirty mode, embedding the following URLs is also supported:
18
+
19
+ * twitch
20
+
15
21
  ## Installation
16
22
 
17
23
  Add this line to your application's Gemfile:
@@ -21,6 +27,19 @@ Add this line to your application's Gemfile:
21
27
  And then execute:
22
28
 
23
29
  $ bundle
30
+
31
+ **If you only want to use standard mode and embed HTML5 widgets only, you're done. Skip to usage below.**
32
+
33
+ To enable dirty mode, enter the following command:
34
+
35
+ $ rails g zemus:install
36
+
37
+ This will install the necessary javascript and css files to your project's app/assets directory. At runtime, Zemus will check for the existence of these files to determine whether to embed the supported flash or to fall back to normal mode and return a truncated link.
38
+
39
+ Be sure to precompile your assets before going live to ensure the zemus.js and zemus.css files get included.
40
+
41
+ $ rake assets:precompile
42
+
24
43
 
25
44
  ## Usage
26
45
 
@@ -38,7 +57,11 @@ And then execute:
38
57
 
39
58
  Zemus.embed("https://vine.co/v/bFPjjheVnau/embed/simple")
40
59
 
41
- If Zemus can't automagically transfigure the URL it just returns it as a truncated link.
60
+ If Zemus can't automagically transfigure the URL it just returns it as a truncated link.
61
+
62
+ ## Styling
63
+
64
+ Zemus will output different embedded URLs with different classes, depending on the needs of the particular service. Check the generated HTML output in your project to find what to style.
42
65
 
43
66
  ## TODO / Contributions
44
67
 
@@ -50,6 +73,10 @@ If there is another URL you want to embed, submit the patch. As long as you can
50
73
 
51
74
  Zemus was extracted from and is running in production at http://cheerfulghost.com by Jon Dodson and Mark Tabler.
52
75
 
76
+ Contributions from:
77
+
78
+ Travis Newman @travisnewman
79
+
53
80
  ## Even more
54
81
 
55
82
  Zemus was named after the antagonist of Final Fantasy IV.
@@ -0,0 +1,30 @@
1
+ // Detect whether displaying *.swf is possible
2
+ // https://stackoverflow.com/questions/998245
3
+
4
+ var hasFlash = false;
5
+ try {
6
+ var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
7
+ if (fo) {
8
+ hasFlash = true;
9
+ }
10
+ } catch (e) {
11
+ if (navigator.mimeTypes
12
+ && navigator.mimeTypes['application/x-shockwave-flash'] != undefined
13
+ && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
14
+ hasFlash = true;
15
+ }
16
+ }
17
+
18
+
19
+ // Show the proper div
20
+
21
+ $(document).ready(function(){
22
+
23
+ if (hasFlash == true) {
24
+ $('.zemusflashembed').show();
25
+ }
26
+ else {
27
+ $('.zemusnoflash').show();
28
+ }
29
+
30
+ });
@@ -0,0 +1,7 @@
1
+ div .zemusflashembed {
2
+ display: none;
3
+ }
4
+
5
+ div .zemusnoflash {
6
+ display: none;
7
+ }
@@ -0,0 +1,15 @@
1
+ module Zemus
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ def install_assets
6
+ zemus_js_dir = 'app/assets/javascripts/zemus.js'
7
+ copy_file "zemus.js", zemus_js_dir
8
+
9
+ zemus_css_dir = 'app/assets/stylesheets/zemus.css'
10
+ copy_file "zemus.css", zemus_css_dir
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,7 @@
1
+ div .zemusflashembed {
2
+ display: none;
3
+ }
4
+
5
+ div .zemusnoflash {
6
+ display: none;
7
+ }
@@ -0,0 +1,30 @@
1
+ // Detect whether displaying *.swf is possible
2
+ // https://stackoverflow.com/questions/998245
3
+
4
+ var hasFlash = false;
5
+ try {
6
+ var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
7
+ if (fo) {
8
+ hasFlash = true;
9
+ }
10
+ } catch (e) {
11
+ if (navigator.mimeTypes
12
+ && navigator.mimeTypes['application/x-shockwave-flash'] != undefined
13
+ && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
14
+ hasFlash = true;
15
+ }
16
+ }
17
+
18
+
19
+ // Show the proper div
20
+
21
+ $(document).ready(function(){
22
+
23
+ if (hasFlash == true) {
24
+ $('.zemusflashembed').show();
25
+ }
26
+ else {
27
+ $('.zemusnoflash').show();
28
+ }
29
+
30
+ });
data/lib/zemus/parser.rb CHANGED
@@ -2,8 +2,14 @@ module Zemus
2
2
  class Parser
3
3
 
4
4
  def self.url_classes
5
- [Image, Kickstarter, Sound, Soundcloud, Vimeo,
6
- Vine, Youtube]
5
+ zemus_js_dir = 'app/assets/javascripts/zemus.js'
6
+ if File.exist?(zemus_js_dir)
7
+ [Image, Kickstarter, Sound, Soundcloud, Vimeo,
8
+ Vine, Youtube, Twitch]
9
+ else
10
+ [Image, Kickstarter, Sound, Soundcloud, Vimeo,
11
+ Vine, Youtube]
12
+ end
7
13
  end
8
14
 
9
15
  def self.build_embedder(url)
@@ -15,4 +21,4 @@ module Zemus
15
21
  Generic.new(url)
16
22
  end
17
23
  end
18
- end
24
+ end
@@ -0,0 +1,31 @@
1
+ module Zemus
2
+ class Twitch
3
+
4
+ def self.valid?(url)
5
+ url =~ /www.twitch.tv/
6
+ end
7
+
8
+ def initialize(url)
9
+ @url = url
10
+ end
11
+
12
+ def to_embed
13
+ id = @url.split('/').last
14
+ if @url.split('/')[4] == "b"
15
+ chan = @url.split('/')[3]
16
+ "<div class='zemusflashembed'><object data='http://www.twitch.tv/widgets/archive_embed_player.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' ><param name='movie' value='http://www.twitch.tv/widgets/archive_embed_player.swf'><param name='allowScriptAccess' value='always'><param name='allowNetworking' value='all'><param name='allowFullScreen' value='true'><param name='flashvars' value='channel=#{chan}&amp;auto_play=false&amp;start_volume=25&amp;archive_id=#{id}'></object></div>
17
+ <div class='zemusnoflash'><a href='#{@url}'>Your browser cannot display this embedded Twitch video</a></div>"
18
+
19
+ elsif @url.split('/')[4] == "c"
20
+ chan = @url.split('/')[3]
21
+ "<div class='zemusflashembed'><object data='http://www.twitch.tv/widgets/archive_embed_player.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' ><param name='movie' value='http://www.twitch.tv/widgets/archive_embed_player.swf'><param name='allowScriptAccess' value='always'><param name='allowNetworking' value='all'><param name='allowFullScreen' value='true'><param name='flashvars' value='channel=#{chan}&amp;auto_play=false&amp;start_volume=25&amp;chapter_id=#{id}'></object></div>
22
+ <div class='zemusnoflash'><a href='#{@url}'>Your browser cannot display this embedded Twitch video</a></div>"
23
+ else
24
+ chan = @url.split('/')[3]
25
+ "<div class='zemusflashembed'><object type='application/x-shockwave-flash' height='378' id='live_embed_player_flash' data='http://www.twitch.tv/widgets/live_embed_player.swf?channel=#{chan}'><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /><param name='allowNetworking' value='all' /><param name='movie' value='http://www.twitch.tv/widgets/live_embed_player.swf' /><param name='flashvars' value='hostname=www.twitch.tv&channel=#{chan}&auto_play=true&start_volume=25' /></object></div><div class='zemusnoflash'><a href='#{@url}'>Your browser cannot display this embedded Twitch stream</a></div>"
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
data/lib/zemus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zemus
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/zemus.rb CHANGED
@@ -2,7 +2,7 @@ path = File.expand_path('../zemus', __FILE__)
2
2
  Dir.glob(File.join(path, "/**/*.rb")).each { |f| require f }
3
3
 
4
4
  module Zemus
5
-
5
+
6
6
  def self.embed(url)
7
7
  Zemus::Parser.build_embedder(url).to_embed
8
8
  end
@@ -0,0 +1,20 @@
1
+ require_relative('../spec_helper')
2
+
3
+ describe Zemus::Twitch do
4
+ it "embeds twitch stream" do
5
+ Zemus::Twitch.new("http://www.twitch.tv/awesomeguy").to_embed.
6
+ should eq("<div class='zemusflashembed'><object type='application/x-shockwave-flash' height='378' id='live_embed_player_flash' data='http://www.twitch.tv/widgets/live_embed_player.swf?channel=awesomeguy'><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /><param name='allowNetworking' value='all' /><param name='movie' value='http://www.twitch.tv/widgets/live_embed_player.swf' /><param name='flashvars' value='hostname=www.twitch.tv&channel=awesomeguy&auto_play=true&start_volume=25' /></object></div><div class='zemusnoflash'><a href='http://www.twitch.tv/awesomeguy'>Your browser cannot display this embedded Twitch stream</a></div>")
7
+ end
8
+
9
+ it "embeds twitch /b/" do
10
+ Zemus::Twitch.new("http://www.twitch.tv/awesomeguy/b/123456789").to_embed.
11
+ should eq("<div class='zemusflashembed'><object data='http://www.twitch.tv/widgets/archive_embed_player.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' ><param name='movie' value='http://www.twitch.tv/widgets/archive_embed_player.swf'><param name='allowScriptAccess' value='always'><param name='allowNetworking' value='all'><param name='allowFullScreen' value='true'><param name='flashvars' value='channel=awesomeguy&amp;auto_play=false&amp;start_volume=25&amp;archive_id=123456789'></object></div>
12
+ <div class='zemusnoflash'><a href='http://www.twitch.tv/awesomeguy/b/123456789'>Your browser cannot display this embedded Twitch video</a></div>")
13
+ end
14
+
15
+ it "embeds twitch /c/" do
16
+ Zemus::Twitch.new("http://www.twitch.tv/awesomeguy/c/123456789").to_embed.
17
+ should eq("<div class='zemusflashembed'><object data='http://www.twitch.tv/widgets/archive_embed_player.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' ><param name='movie' value='http://www.twitch.tv/widgets/archive_embed_player.swf'><param name='allowScriptAccess' value='always'><param name='allowNetworking' value='all'><param name='allowFullScreen' value='true'><param name='flashvars' value='channel=awesomeguy&amp;auto_play=false&amp;start_volume=25&amp;chapter_id=123456789'></object></div>
18
+ <div class='zemusnoflash'><a href='http://www.twitch.tv/awesomeguy/c/123456789'>Your browser cannot display this embedded Twitch video</a></div>")
19
+ end
20
+ end
data/spec/zemus_spec.rb CHANGED
@@ -57,6 +57,26 @@ describe Zemus do
57
57
 
58
58
  Zemus.embed(url).should eq("<iframe class='vine-embed' src='https://vine.co/v/bFPjjheVnau/embed/simple' width='100%' height='600px' frameborder='0'></iframe><script async src='//platform.vine.co/static/scripts/embed.js' charset='utf-8'></script>")
59
59
  end
60
+
61
+ it "acceptance test for twitch stream" do
62
+ url = "http://www.twitch.tv/awesomeguy"
63
+
64
+ Zemus.embed(url).should eq("<div class='zemusflashembed'><object type='application/x-shockwave-flash' height='378' id='live_embed_player_flash' data='http://www.twitch.tv/widgets/live_embed_player.swf?channel=awesomeguy'><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /><param name='allowNetworking' value='all' /><param name='movie' value='http://www.twitch.tv/widgets/live_embed_player.swf' /><param name='flashvars' value='hostname=www.twitch.tv&channel=awesomeguy&auto_play=true&start_volume=25' /></object></div><div class='zemusnoflash'><a href='http://www.twitch.tv/awesomeguy'>Your browser cannot display this embedded Twitch stream</a></div>")
65
+ end
66
+
67
+ it "acceptance test for twitch /b/" do
68
+ url = "http://www.twitch.tv/awesomeguy/b/123456789"
69
+
70
+ Zemus.embed(url).should eq("<div class='zemusflashembed'><object data='http://www.twitch.tv/widgets/archive_embed_player.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' ><param name='movie' value='http://www.twitch.tv/widgets/archive_embed_player.swf'><param name='allowScriptAccess' value='always'><param name='allowNetworking' value='all'><param name='allowFullScreen' value='true'><param name='flashvars' value='channel=awesomeguy&amp;auto_play=false&amp;start_volume=25&amp;archive_id=123456789'></object></div>
71
+ <div class='zemusnoflash'><a href='http://www.twitch.tv/awesomeguy/b/123456789'>Your browser cannot display this embedded Twitch video</a></div>")
72
+ end
73
+
74
+ it "acceptance test for twitch /c/" do
75
+ url = "http://www.twitch.tv/awesomeguy/c/123456789"
76
+
77
+ Zemus.embed(url).should eq("<div class='zemusflashembed'><object data='http://www.twitch.tv/widgets/archive_embed_player.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' ><param name='movie' value='http://www.twitch.tv/widgets/archive_embed_player.swf'><param name='allowScriptAccess' value='always'><param name='allowNetworking' value='all'><param name='allowFullScreen' value='true'><param name='flashvars' value='channel=awesomeguy&amp;auto_play=false&amp;start_volume=25&amp;chapter_id=123456789'></object></div>
78
+ <div class='zemusnoflash'><a href='http://www.twitch.tv/awesomeguy/c/123456789'>Your browser cannot display this embedded Twitch video</a></div>")
79
+ end
60
80
 
61
81
  it "acceptance test for the generic fallback" do
62
82
  url = "http://google.com/asdfhjklkjsdf/43123123/32124lkjklj123123/foo.html"
data/zemus.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "railties"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
23
25
  spec.add_development_dependency "rspec"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zemus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-27 00:00:00.000000000 Z
13
+ date: 2014-02-07 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: railties
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: bundler
17
33
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +89,11 @@ files:
73
89
  - LICENSE.txt
74
90
  - README.md
75
91
  - Rakefile
92
+ - app/assets/javascripts/zemus.js
93
+ - app/assets/stylesheets/zemus.css
94
+ - lib/generators/zemus/install_generator.rb
95
+ - lib/generators/zemus/templates/zemus.css
96
+ - lib/generators/zemus/templates/zemus.js
76
97
  - lib/zemus.rb
77
98
  - lib/zemus/generic.rb
78
99
  - lib/zemus/image.rb
@@ -80,6 +101,7 @@ files:
80
101
  - lib/zemus/parser.rb
81
102
  - lib/zemus/sound.rb
82
103
  - lib/zemus/soundcloud.rb
104
+ - lib/zemus/twitch.rb
83
105
  - lib/zemus/version.rb
84
106
  - lib/zemus/vimeo.rb
85
107
  - lib/zemus/vine.rb
@@ -89,6 +111,7 @@ files:
89
111
  - spec/zemus/kickstarter_spec.rb
90
112
  - spec/zemus/sound_spec.rb
91
113
  - spec/zemus/soundcloud_spec.rb
114
+ - spec/zemus/twitch_spec.rb
92
115
  - spec/zemus/version_spec.rb
93
116
  - spec/zemus/vimeo_spec.rb
94
117
  - spec/zemus/vine_spec.rb
@@ -126,6 +149,7 @@ test_files:
126
149
  - spec/zemus/kickstarter_spec.rb
127
150
  - spec/zemus/sound_spec.rb
128
151
  - spec/zemus/soundcloud_spec.rb
152
+ - spec/zemus/twitch_spec.rb
129
153
  - spec/zemus/version_spec.rb
130
154
  - spec/zemus/vimeo_spec.rb
131
155
  - spec/zemus/vine_spec.rb