conred 0.3.0 → 0.4.0
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/Gemfile +1 -3
- data/README.md +38 -23
- data/conred.gemspec +5 -3
- data/lib/conred.rb +0 -11
- data/lib/conred/version.rb +1 -1
- data/lib/conred/video.rb +21 -7
- data/spec/conred_spec/video_spec.rb +18 -5
- metadata +47 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a3a8094ee75166da4d706074524ad46797fa8962
|
4
|
+
data.tar.gz: 0da433af7a22fec8d3be07079c88d49bf250d0c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 625290bae1ad5722357cc8c70ac7eba48259a66b123fd0d957310adb0291f505248ba974997a500a76bc5c941e2bbcb0fb786768ade784c8c989d07c75e62984
|
7
|
+
data.tar.gz: 897f9de69ebbdacfdf34f3819aa57662c10302692f432838dc89de8d061dad63fa5d52f2f82dae289d13689d483bc2f025905b62063401571ddf7c3afab6f359
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
[](https://codeclimate.com/github/janjiss/conred)
|
2
|
+
[](https://travis-ci.org/janjiss/conred)
|
3
|
+
|
1
4
|
# Conred
|
2
5
|
|
3
6
|
In every project we have common things like video
|
4
|
-
|
7
|
+
embedding from url, user input displaying, formatting, trimming stripping,
|
5
8
|
external url protocol adding and all that nasty stuff that we write in our apps.
|
6
9
|
These are the cases where Conred saves the day.
|
7
10
|
|
@@ -21,49 +24,63 @@ Or install it yourself as:
|
|
21
24
|
|
22
25
|
## Usage
|
23
26
|
|
24
|
-
### Iframe
|
27
|
+
### Iframe generator for Youtube and Vimeo videos:
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
```ruby
|
30
|
+
c = Conred::Video.new(
|
31
|
+
video_url: "http://www.youtube.com/watch?v=tNtW9pGFPTA&feature=plcp",
|
32
|
+
width: 285,
|
33
|
+
height: 185,
|
34
|
+
error_message: "Video url is invalid"
|
35
|
+
)
|
36
|
+
```
|
34
37
|
|
35
38
|
Then you can get your ready embed code like this (Conred will recognize video provider by itself):
|
36
|
-
|
37
|
-
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
c.code
|
42
|
+
```
|
38
43
|
|
39
44
|
You can also check if it is youtube or vimeo video like this:
|
40
45
|
|
41
|
-
|
42
|
-
|
46
|
+
```ruby
|
47
|
+
c.youtube_video? ==> true
|
48
|
+
c.vimeo_video? ==> false
|
49
|
+
```
|
43
50
|
|
44
51
|
Or if it exists:
|
45
52
|
|
46
|
-
|
53
|
+
```ruby
|
54
|
+
c.exists? ==> true
|
55
|
+
```
|
47
56
|
|
48
57
|
### General helpers for rails app
|
49
58
|
|
50
59
|
If you wish to use text helpers then in your application_helper add this include line:
|
51
60
|
|
52
|
-
|
61
|
+
```ruby
|
62
|
+
include Conred::Helpers
|
63
|
+
```
|
53
64
|
|
54
65
|
Now you have these methods available to you:
|
55
66
|
|
56
67
|
Sanitizes all html and trims content if count is provided:
|
57
68
|
|
58
|
-
|
69
|
+
```ruby
|
70
|
+
sanitize_and_trim("<html>string with", 10) => "string ..."
|
71
|
+
```
|
59
72
|
|
60
73
|
Sanitizes body, allowed tags are(p a strong ul ol li blockquote strike u em):
|
61
74
|
|
62
|
-
|
75
|
+
```ruby
|
76
|
+
sanitize_body("<html><strong>string</strong> <p>with<p></html>") => "<strong>string</strong> <p>with<p>"
|
77
|
+
```
|
63
78
|
|
64
|
-
External link
|
79
|
+
External link formatting
|
65
80
|
|
66
|
-
|
81
|
+
```ruby
|
82
|
+
external_url("www.google.com") => "http://www.google.com"
|
83
|
+
```
|
67
84
|
|
68
85
|
## Contributing
|
69
86
|
|
@@ -75,6 +92,4 @@ External link formating
|
|
75
92
|
|
76
93
|
## Thank you's
|
77
94
|
|
78
|
-
|
79
|
-
@alexcp
|
80
|
-
@barisbalic
|
95
|
+
Please stand up from your chair and applaud to these guys: https://github.com/janjiss/conred/graphs/contributors
|
data/conred.gemspec
CHANGED
@@ -5,11 +5,13 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.authors = ["Janis Miezitis"]
|
6
6
|
gem.email = ["janjiss@gmail.com"]
|
7
7
|
gem.description = %q{Gem to remove repetative tasks}
|
8
|
-
gem.summary = %q{
|
8
|
+
gem.summary = %q{Comrades are for reusable code}
|
9
9
|
gem.homepage = "http://github.com/janjiss/conred"
|
10
10
|
|
11
|
-
gem.
|
12
|
-
gem.
|
11
|
+
gem.add_dependency "haml", '~> 3'
|
12
|
+
gem.add_development_dependency "rspec", '~> 2.0'
|
13
|
+
gem.add_development_dependency "rake", '~> 10.1'
|
14
|
+
gem.add_development_dependency "actionpack", '~> 3'
|
13
15
|
|
14
16
|
gem.files = `git ls-files`.split($\)
|
15
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/conred.rb
CHANGED
@@ -4,14 +4,3 @@ require "conred/helpers"
|
|
4
4
|
require "conred/video"
|
5
5
|
require "conred/links"
|
6
6
|
require "haml"
|
7
|
-
module Conred
|
8
|
-
def Video.new arguments
|
9
|
-
if Video::Youtube.url_format_is_valid? arguments[:video_url]
|
10
|
-
Video::Youtube.new arguments
|
11
|
-
elsif Video::Vimeo.url_format_is_valid? arguments[:video_url]
|
12
|
-
Video::Vimeo.new arguments
|
13
|
-
else
|
14
|
-
Video::Other.new arguments
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/conred/version.rb
CHANGED
data/lib/conred/video.rb
CHANGED
@@ -10,6 +10,16 @@ module Conred
|
|
10
10
|
@video_id = get_video_id_from arguments[:video_url]
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.new arguments
|
14
|
+
if Youtube.url_format_is_valid? arguments[:video_url]
|
15
|
+
Youtube.new arguments
|
16
|
+
elsif Video::Vimeo.url_format_is_valid? arguments[:video_url]
|
17
|
+
Vimeo.new arguments
|
18
|
+
else
|
19
|
+
Other.new arguments
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
def youtube_video?
|
14
24
|
is_a?(Video::Youtube)
|
15
25
|
end
|
@@ -45,15 +55,15 @@ module Conred
|
|
45
55
|
include Video
|
46
56
|
|
47
57
|
def self.url_format_is_valid? url
|
48
|
-
/^(http:\/\/)*(www\.)*(youtube.com|youtu.be)/ =~ url
|
58
|
+
/^(http|https)*(:\/\/)*(www\.)*(youtube.com|youtu.be)/ =~ url
|
49
59
|
end
|
50
60
|
|
51
61
|
def api_uri
|
52
|
-
"
|
62
|
+
"//gdata.youtube.com/feeds/api/videos/#{@video_id}"
|
53
63
|
end
|
54
64
|
|
55
65
|
def video_link
|
56
|
-
"
|
66
|
+
"//www.youtube.com/embed/#{@video_id}?wmode=transparent"
|
57
67
|
end
|
58
68
|
|
59
69
|
private
|
@@ -72,22 +82,22 @@ module Conred
|
|
72
82
|
include Video
|
73
83
|
|
74
84
|
def self.url_format_is_valid? url
|
75
|
-
/^(http:\/\/)*(www\.)*(vimeo.com)/ =~ url
|
85
|
+
/^(http|https)*(:\/\/)*(www\.)*(vimeo.com)/ =~ url
|
76
86
|
end
|
77
87
|
|
78
88
|
def api_uri
|
79
|
-
"
|
89
|
+
"//vimeo.com/api/v2/video/#{@video_id}.json"
|
80
90
|
end
|
81
91
|
|
82
92
|
def video_link
|
83
|
-
"
|
93
|
+
"//player.vimeo.com/video/#{@video_id}"
|
84
94
|
end
|
85
95
|
|
86
96
|
private
|
87
97
|
|
88
98
|
def get_video_id_from url
|
89
99
|
url[/vimeo\.com\/([0-9]*)/]
|
90
|
-
video_id = $1
|
100
|
+
@video_id = $1
|
91
101
|
end
|
92
102
|
end
|
93
103
|
|
@@ -100,6 +110,10 @@ module Conred
|
|
100
110
|
def code
|
101
111
|
@error_message
|
102
112
|
end
|
113
|
+
|
114
|
+
def exist?
|
115
|
+
false
|
116
|
+
end
|
103
117
|
end
|
104
118
|
end
|
105
119
|
end
|
@@ -4,16 +4,24 @@ describe Conred do
|
|
4
4
|
describe Conred::Video do
|
5
5
|
|
6
6
|
let(:short_youtube_url) {Conred::Video.new(:video_url=>"http://youtu.be/SZt5RFzqEfY")}
|
7
|
+
let(:https_youtube_url) {Conred::Video.new(:video_url=>"https://youtu.be/SZt5RFzqEfY")}
|
7
8
|
let(:short_youtube_url_with_www) {Conred::Video.new(:video_url=>"www.youtu.be/SZt5RFzqEfY")}
|
8
9
|
let(:long_youtube_url_with_features) {Conred::Video.new(:video_url=>"http://www.youtube.com/watch?NR=1&feature=endscreen&v=Lrj5Kxdzouc")}
|
9
10
|
let(:short_youtube_url_without_http_and_www) {Conred::Video.new(:video_url=>"youtu.be/SZt5RFzqEfY")}
|
10
11
|
|
11
12
|
let(:vimeo_url) {Conred::Video.new(:video_url=>"http://vimeo.com/12311233")}
|
13
|
+
let(:https_vimeo_url) {Conred::Video.new(:video_url=>"http://vimeo.com/12311233")}
|
12
14
|
let(:evil_vimeo) {Conred::Video.new(:video_url=>"eeevil vimeo www.vimeo.com/12311233")}
|
13
15
|
let(:vimeo_without_http) {Conred::Video.new(:video_url=>"vimeo.com/12311233")}
|
14
|
-
|
16
|
+
|
17
|
+
let(:error_video) { Conred::Video.new(
|
18
|
+
:video_url => "http://google.com/12311233",
|
19
|
+
:error_message => "Some mistake in url")
|
20
|
+
}
|
21
|
+
|
15
22
|
it "should match youtube video" do
|
16
23
|
short_youtube_url.should be_youtube_video
|
24
|
+
https_youtube_url.should be_youtube_video
|
17
25
|
short_youtube_url_with_www.should be_youtube_video
|
18
26
|
long_youtube_url_with_features.should be_youtube_video
|
19
27
|
short_youtube_url_without_http_and_www.should be_youtube_video
|
@@ -27,14 +35,15 @@ describe Conred do
|
|
27
35
|
it "should match vimeo video" do
|
28
36
|
vimeo_url.should_not be_youtube_video
|
29
37
|
vimeo_without_http.should be_vimeo_video
|
38
|
+
https_vimeo_url.should be_vimeo_video
|
30
39
|
vimeo_url.should be_vimeo_video
|
31
|
-
end
|
40
|
+
end
|
32
41
|
|
33
42
|
describe "youtube embed code" do
|
34
43
|
subject {Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzouc", :width=>450,:height=> 300).code }
|
35
44
|
it { should match(/Lrj5Kxdzouc/)}
|
36
45
|
it { should match(/width='450'/)}
|
37
|
-
it {should match(/height='300'/)}
|
46
|
+
it {should match(/height='300'/)}
|
38
47
|
end
|
39
48
|
|
40
49
|
describe "vimeo embed code" do
|
@@ -45,7 +54,7 @@ describe Conred do
|
|
45
54
|
end
|
46
55
|
|
47
56
|
it "should render error message when url is invalid" do
|
48
|
-
|
57
|
+
error_video.code.should == "Some mistake in url"
|
49
58
|
end
|
50
59
|
|
51
60
|
it "should return correct embed code when passing arguments in url" do
|
@@ -61,7 +70,7 @@ describe Conred do
|
|
61
70
|
|
62
71
|
it "should make a request to the proper uri" do
|
63
72
|
non_existing_video = Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzoux")
|
64
|
-
non_existing_video.api_uri.should eq("
|
73
|
+
non_existing_video.api_uri.should eq("//gdata.youtube.com/feeds/api/videos/Lrj5Kxdzoux")
|
65
74
|
end
|
66
75
|
|
67
76
|
it "should be true if response is 200" do
|
@@ -69,6 +78,10 @@ describe Conred do
|
|
69
78
|
Net::HTTP.stub(:get_response=>Net::HTTPOK.new(true,200,"OK"))
|
70
79
|
existing_video.exist?.should be_true
|
71
80
|
end
|
81
|
+
|
82
|
+
it "should be false if uri isn't recognized" do
|
83
|
+
error_video.exist?.should be_false
|
84
|
+
end
|
72
85
|
end
|
73
86
|
end
|
74
87
|
end
|
metadata
CHANGED
@@ -1,48 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Janis Miezitis
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: haml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: rspec
|
16
29
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
30
|
requirements:
|
19
|
-
- -
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
20
46
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
47
|
+
version: '10.1'
|
22
48
|
type: :development
|
23
49
|
prerelease: false
|
24
50
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
51
|
requirements:
|
27
|
-
- -
|
52
|
+
- - "~>"
|
28
53
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
54
|
+
version: '10.1'
|
30
55
|
- !ruby/object:Gem::Dependency
|
31
56
|
name: actionpack
|
32
57
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
58
|
requirements:
|
35
|
-
- -
|
59
|
+
- - "~>"
|
36
60
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
38
|
-
type: :
|
61
|
+
version: '3'
|
62
|
+
type: :development
|
39
63
|
prerelease: false
|
40
64
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
65
|
requirements:
|
43
|
-
- -
|
66
|
+
- - "~>"
|
44
67
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
68
|
+
version: '3'
|
46
69
|
description: Gem to remove repetative tasks
|
47
70
|
email:
|
48
71
|
- janjiss@gmail.com
|
@@ -50,7 +73,7 @@ executables: []
|
|
50
73
|
extensions: []
|
51
74
|
extra_rdoc_files: []
|
52
75
|
files:
|
53
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
54
77
|
- Gemfile
|
55
78
|
- LICENSE
|
56
79
|
- README.md
|
@@ -67,29 +90,29 @@ files:
|
|
67
90
|
- spec/conred_spec/video_spec.rb
|
68
91
|
homepage: http://github.com/janjiss/conred
|
69
92
|
licenses: []
|
93
|
+
metadata: {}
|
70
94
|
post_install_message:
|
71
95
|
rdoc_options: []
|
72
96
|
require_paths:
|
73
97
|
- lib
|
74
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
99
|
requirements:
|
77
|
-
- -
|
100
|
+
- - ">="
|
78
101
|
- !ruby/object:Gem::Version
|
79
102
|
version: '0'
|
80
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
104
|
requirements:
|
83
|
-
- -
|
105
|
+
- - ">="
|
84
106
|
- !ruby/object:Gem::Version
|
85
107
|
version: '0'
|
86
108
|
requirements: []
|
87
109
|
rubyforge_project:
|
88
|
-
rubygems_version:
|
110
|
+
rubygems_version: 2.2.0
|
89
111
|
signing_key:
|
90
|
-
specification_version:
|
91
|
-
summary:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Comrades are for reusable code
|
92
114
|
test_files:
|
93
115
|
- spec/conred_spec.rb
|
94
116
|
- spec/conred_spec/helpers_spec.rb
|
95
117
|
- spec/conred_spec/video_spec.rb
|
118
|
+
has_rdoc:
|