html-pipeline-trix-video 0.0.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 +7 -0
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/README.md +50 -0
- data/Rakefile +14 -0
- data/bin/console +16 -0
- data/bin/setup +7 -0
- data/html-pipeline-trix-video.gemspec +26 -0
- data/lib/html/pipeline/trix_video.rb +5 -0
- data/lib/html/pipeline/trix_video/trix_video_filter.rb +52 -0
- data/lib/html/pipeline/trix_video/version.rb +7 -0
- data/license.txt +21 -0
- data/test/test_helper.rb +18 -0
- data/test/trix_video_filter_test.rb +32 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5c9bc4198c6a825f0b13fb9d64df6537f196c59
|
4
|
+
data.tar.gz: d98e8a6208525d0d01086d18c28d672368ddaa5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90c2ecb24521555459eef81fe8ae3ced693d6c31bb9c38a53898110017026933bb167ef3e06a6dd0253032a41063b242b59b684ab880eb278c2051cce4a32beb
|
7
|
+
data.tar.gz: 6eacde5c12ae604f69f08dd98b53699bcbd6ee97da91c6e1b6d0dcfe6fcd6d251b03b4a8cc20eb1cf584065128cabb76bd32fa112e00be53df14717e64d1fd29
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
## HTML::Pipeline Trix Video
|
2
|
+
|
3
|
+
This project is intended to provide a filter that will take
|
4
|
+
[Trix](https://github.com/basecamp/trix)-produced content as input, find
|
5
|
+
`<figure>` tags that hold onto image previews taken from YouTube or Vimeo
|
6
|
+
videos, and convert those into raw YouTube or Vimeo video URLs.
|
7
|
+
|
8
|
+
The intention is that this returned URL can then be filtered through
|
9
|
+
[html-pipeline-vimeo](https://github.com/dlackty/html-pipeline-vimeo) and
|
10
|
+
[html-pipeline-youtube](https://github.com/st0012/html-pipeline-youtube) in
|
11
|
+
order to display embedded videos in Trix-produced content.
|
12
|
+
|
13
|
+
This is based off of the work-flow suggested in Trix's [Issue
|
14
|
+
206](https://github.com/basecamp/trix/issues/206).
|
15
|
+
|
16
|
+
### Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'html-pipeline'
|
22
|
+
gem 'html-pipeline-trix-video'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
$ bundle
|
29
|
+
```
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
$ gem install html-pipeline-trix-video
|
35
|
+
```
|
36
|
+
|
37
|
+
### Usage
|
38
|
+
|
39
|
+
You can add `HTML::Pipeline::TrixVideoFilter` into your pipeline like this:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
pipeline = HTML::Pipeline.new [
|
43
|
+
HTML::Pipeline::TrixVideoFilter,
|
44
|
+
HTML::Pipeline::VimeoFilter
|
45
|
+
]
|
46
|
+
|
47
|
+
result = pipeline.call(text)
|
48
|
+
```
|
49
|
+
|
50
|
+
See [html-pipeline](https://github.com/jch/html-pipeline).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "rubygems"
|
3
|
+
require "bundler/setup"
|
4
|
+
|
5
|
+
require "bundler/gem_tasks"
|
6
|
+
require "rake/testtask"
|
7
|
+
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << "test"
|
10
|
+
t.test_files = FileList['test/**/*_test.rb']
|
11
|
+
t.verbose = true
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "html/pipeline/trix_video"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
require "awesome_print"
|
15
|
+
|
16
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'html/pipeline/trix_video/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "html-pipeline-trix-video"
|
8
|
+
spec.version = HTML::Pipeline::TrixVideo::VERSION
|
9
|
+
spec.authors = ["Wendy Randquist"]
|
10
|
+
spec.email = ["wendybeth010@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{An HTML::Pipeline filter converting Trix-compliant YouTube or Vimeo preview figures into URLs}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/wendybeth/html-pipeline-trix-video"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test/features)/}) }
|
18
|
+
|
19
|
+
spec.add_dependency "html-pipeline", "~> 2.0"
|
20
|
+
|
21
|
+
spec.add_development_dependency "awesome_print"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest"
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "html/pipeline"
|
2
|
+
|
3
|
+
module HTML
|
4
|
+
class Pipeline
|
5
|
+
# HTML Filter for Trix-compliant video preview filters
|
6
|
+
#
|
7
|
+
class TrixVideoFilter < TextFilter
|
8
|
+
def call
|
9
|
+
text_fragment.css("figure").each do |figure|
|
10
|
+
service, id = video_information(figure)
|
11
|
+
|
12
|
+
case service
|
13
|
+
when "youtube"
|
14
|
+
figure.replace "https://youtube.com/watch?v=#{id}"
|
15
|
+
when "vimeo"
|
16
|
+
figure.replace "https://vimeo.com/#{id}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
text_fragment.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def video_information(figure)
|
24
|
+
url = figure.css("img").first ? figure.css("img").first["src"] : nil
|
25
|
+
|
26
|
+
if match = valid_id(url, youtube_regex)
|
27
|
+
[ "youtube", match[1] ]
|
28
|
+
elsif match = valid_id(url, vimeo_regex)
|
29
|
+
[ "vimeo", match[1] ]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def valid_id(url, regex)
|
34
|
+
return unless url
|
35
|
+
url.match(regex)
|
36
|
+
end
|
37
|
+
|
38
|
+
def text_fragment
|
39
|
+
@fragment ||= Nokogiri::HTML::DocumentFragment.parse(@text)
|
40
|
+
end
|
41
|
+
|
42
|
+
def youtube_regex
|
43
|
+
/img.youtube.com\/vi\/(\S*)\/\d.jpg/
|
44
|
+
end
|
45
|
+
|
46
|
+
def vimeo_regex
|
47
|
+
/i.vimeocdn.com\/video\/[0-9]*_[0-9]{3}x[0-9]{3}.jpg\?r=pad\?id=([0-9]*)/
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/license.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Wendy Randquist
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "minitest/autorun"
|
3
|
+
|
4
|
+
require "./lib/html/pipeline/trix_video"
|
5
|
+
|
6
|
+
module TestHelpers
|
7
|
+
|
8
|
+
def assert_equal_html(expected, actual)
|
9
|
+
assert_equal equalized_html(expected), equalized_html(actual)
|
10
|
+
end
|
11
|
+
|
12
|
+
def equalized_html(html)
|
13
|
+
Nokogiri::HTML::DocumentFragment.parse(html).to_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
Minitest::Test.send(:include, TestHelpers)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class HTML::Pipeline::TrixVideoFilterTest < Minitest::Test
|
4
|
+
TrixVideoFilter = HTML::Pipeline::TrixVideoFilter
|
5
|
+
|
6
|
+
def test_it_converts_youtube_figures_into_youtube_urls
|
7
|
+
assert_equal_html "https://youtube.com/watch?v=FTfrKOQFPNA", TrixVideoFilter.call(youtube_figure)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_it_converts_vimeo_figures_into_vimeo_urls
|
11
|
+
assert_equal_html "https://vimeo.com/187229876", TrixVideoFilter.call(vimeo_figure)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_it_leaves_other_figures_alone
|
15
|
+
assert_equal_html image_figure, TrixVideoFilter.call(image_figure)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def youtube_figure
|
21
|
+
"<figure class=\"attachment attachment-preview\" data-trix-attachment=\"{"contentType":"image","height":360,"url":"https://img.youtube.com/vi/FTfrKOQFPNA/0.jpg","width":480}\" data-trix-content-type=\"image\"><img src=\"https://img.youtube.com/vi/FTfrKOQFPNA/0.jpg\" width=\"480\" height=\"360\"><figcaption class=\"caption\"></figcaption></figure>"
|
22
|
+
end
|
23
|
+
|
24
|
+
def vimeo_figure
|
25
|
+
"<figure class=\"attachment attachment-preview\" data-trix-attachment=\"{"contentType":"image","height":150,"url":"https://i.vimeocdn.com/video/597074452_200x150.jpg?r=pad?id=187229876","width":200}\" data-trix-content-type=\"image\"><img src=\"https://i.vimeocdn.com/video/597074452_200x150.jpg?r=pad?id=187229876\" width=\"200\" height=\"150\"><figcaption class=\"caption\"></figcaption></figure>"
|
26
|
+
end
|
27
|
+
|
28
|
+
def image_figure
|
29
|
+
"<figure class=\"attachment attachment-preview png\" data-trix-attachment=\"{"contentType":"image/png","filename":"zw.png","filesize":923,"height":11,"url":"/uploads/image/filename/113/zw.png","width":16}\" data-trix-content-type=\"image/png\" data-trix-attributes=\"{"caption":"with a caption!"}\"><img src=\"/uploads/image/filename/113/zw.png\" width=\"16\" height=\"11\"><figcaption class=\"caption caption-edited\">with a caption!</figcaption></figure>"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html-pipeline-trix-video
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wendy Randquist
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: html-pipeline
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: awesome_print
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: An HTML::Pipeline filter converting Trix-compliant YouTube or Vimeo preview
|
98
|
+
figures into URLs
|
99
|
+
email:
|
100
|
+
- wendybeth010@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- bin/console
|
110
|
+
- bin/setup
|
111
|
+
- html-pipeline-trix-video.gemspec
|
112
|
+
- lib/html/pipeline/trix_video.rb
|
113
|
+
- lib/html/pipeline/trix_video/trix_video_filter.rb
|
114
|
+
- lib/html/pipeline/trix_video/version.rb
|
115
|
+
- license.txt
|
116
|
+
- test/test_helper.rb
|
117
|
+
- test/trix_video_filter_test.rb
|
118
|
+
homepage: https://github.com/wendybeth/html-pipeline-trix-video
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.4.5
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: An HTML::Pipeline filter converting Trix-compliant YouTube or Vimeo preview
|
142
|
+
figures into URLs
|
143
|
+
test_files: []
|
144
|
+
has_rdoc:
|