conred 0.1 → 0.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.
data/Gemfile CHANGED
@@ -2,4 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in conred.gemspec
4
4
  gemspec
5
- gem 'rake'
5
+ gem 'rake'
6
+ gem 'haml'
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Conred
2
2
 
3
- Conred stands for ConcepticHQ resuable and d in the end is added for awsomness
3
+ In every project we have common things like video
4
+ embeding from url, body formating (Of course we hav Textile, but it is not good for all cases),
5
+ external url protocol adding. And here Conred saves the day.
4
6
 
5
7
  ## Installation
6
8
 
@@ -55,7 +57,7 @@ External link formating
55
57
  ## Contributing
56
58
 
57
59
  1. Fork it
58
- 2. Create your feature branch (`git checkout -b my-new-feature`)
59
- 3. Commit your changes (`git commit -am 'Added some feature'`)
60
- 4. Push to the branch (`git push origin my-new-feature`)
61
- 5. Create new Pull Request
60
+ 2. Write your feature
61
+ 3. Create tests for it (Important!)
62
+ 4. Create new Pull Request
63
+ 5. Be happy
@@ -3,7 +3,10 @@ require "action_view"
3
3
  require "conred/helpers"
4
4
  require "conred/video"
5
5
  require "conred/links"
6
-
6
+ require "haml"
7
7
  module Conred
8
-
8
+ def self.render_file(filename)
9
+ contents = File.read(filename)
10
+ Haml::Engine.new(contents).render
11
+ end
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module Conred
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -20,58 +20,46 @@ module Conred
20
20
  end
21
21
 
22
22
  def youtube_video?
23
- if /^(http:\/\/)*(www\.)*(youtube.com|youtu.be)/ =~ @video_url
24
- true
25
- end
23
+ /^(http:\/\/)*(www\.)*(youtube.com|youtu.be)/ =~ @video_url
26
24
  end
27
25
 
28
26
  def vimeo_video?
29
- if /^(http:\/\/)*(www\.)*(vimeo.com)/ =~ @video_url
30
- true
31
- else
32
- false
33
- end
27
+ /^(http:\/\/)*(www\.)*(vimeo.com)/ =~ @video_url
34
28
  end
35
29
 
36
30
 
37
31
  def video_from_vimeo_url
38
32
  if @video_url[/vimeo\.com\/([0-9]*)/]
39
- vimeo_id = $1
33
+ @vimeo_id = $1
40
34
  end
41
- <<-eos
42
- <iframe
43
- id='vimeo_video'
44
- src='http://player.vimeo.com/video/#{vimeo_id}'
45
- width='#{@width}'
46
- height='#{@height}'
47
- frameborder='0'
48
- webkitAllowFullScreen
49
- mozallowfullscreen
50
- allowFullScreen>
51
- </iframe>
52
- eos
53
- .html_safe
35
+ vimeo_file = File.join(
36
+ File.dirname(__FILE__),
37
+ '..', 'views',
38
+ 'video', 'vimeo_iframe.html.haml'
39
+ )
40
+ render_file(vimeo_file).html_safe
54
41
  end
55
42
 
56
43
  def video_from_youtube_url
57
44
  if @video_url[/youtu\.be\/([^\?]*)/]
58
- youtube_id = $1
45
+ @youtube_id = $1
59
46
  else
60
- @video_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
61
- youtube_id = $5
47
+ @video_url[/(v=([A-Za-z0-9_]*))/]
48
+ @youtube_id = $2
49
+
62
50
  end
63
- <<-eos
64
- <iframe
65
- id='youtube_video'
66
- title='YouTube video player'
67
- width='#{@width}'
68
- height='#{@height}'
69
- src='http://www.youtube.com/embed/#{ youtube_id }?wmode=transparent'
70
- frameborder='0'
71
- allowfullscreen>
72
- </iframe>
73
- eos
74
- .html_safe
51
+ youtube_file = File.join(
52
+ File.dirname(__FILE__),
53
+ '..', 'views',
54
+ 'video', 'youtube_iframe.html.haml'
55
+ )
56
+ render_file(youtube_file).html_safe
75
57
  end
58
+
59
+ def render_file(filename)
60
+ contents = File.read(filename)
61
+ Haml::Engine.new(contents).render
62
+ end
63
+
76
64
  end
77
65
  end
@@ -0,0 +1 @@
1
+ %iframe{:allowFullScreen => "", :frameborder => "0", :height => @height, :mozallowfullscreen => "", :src => "http://player.vimeo.com/video/\#{@vimeo_id}", :webkitAllowFullScreen => "", :width => @width}
@@ -0,0 +1 @@
1
+ %iframe{:allowfullscreen => "", :frameborder => "0", :height => @height, :src => "http://www.youtube.com/embed/\#{@youtube_id}?wmode=transparent", :title => "YouTube video player", :width => @width}
@@ -3,33 +3,23 @@ require "conred"
3
3
  describe Conred do
4
4
  describe Conred::Video do
5
5
  before do
6
- @vimeo_embed_code = <<-eos
7
- <iframe
8
- id='vimeo_video'
9
- src='http://player.vimeo.com/video/49556689'
10
- width='450'
11
- height='300'
12
- frameborder='0'
13
- webkitAllowFullScreen
14
- mozallowfullscreen
15
- allowFullScreen>
16
- </iframe>
17
- eos
18
-
19
- @youtube_embed_code =
20
- <<-eos
21
- <iframe
22
- id='youtube_video'
23
- title='YouTube video player'
24
- width='450'
25
- height='300'
26
- src='http://www.youtube.com/embed/Lrj5Kxdzouc?wmode=transparent'
27
- frameborder='0'
28
- allowfullscreen>
29
- </iframe>
30
- eos
31
6
 
7
+ @vimeo_code = "49556689"
8
+ vimeo_file = File.join(
9
+ File.dirname(__FILE__),
10
+ '..', '..', 'lib', 'views',
11
+ 'video', 'vimeo_iframe.html.haml'
12
+ )
13
+ @vimeo_embed_code = Conred.render_file(vimeo_file).html_safe
32
14
 
15
+ @youtube_id = "Lrj5Kxdzouc"
16
+ youtube_file = File.join(
17
+ File.dirname(__FILE__),
18
+ '..', '..', 'lib', 'views',
19
+ 'video', 'youtube_iframe.html.haml'
20
+ )
21
+ @youtube_embed_code = Conred.render_file(youtube_file).html_safe
22
+
33
23
  end
34
24
  it "should match youtube video" do
35
25
  Conred::Video.new("http://www.youtube.com/watch?v=SZt5RFzqEfY&feature=g-all-fbc").should be_youtube_video
@@ -49,9 +39,10 @@ describe Conred do
49
39
  Conred::Video.new("eeevil vimeo www.vimeo.com/12311233").youtube_video? == false
50
40
  end
51
41
  it "should return correct embed code" do
52
- Conred::Video.new("http://www.youtube.com/watch?v=Lrj5Kxdzouc", 450, 300).code.should == @youtube_embed_code
53
- Conred::Video.new("http://vimeo.com/49556689", 450, 300).code.should == @vimeo_embed_code
54
- Conred::Video.new("http://google.com/12311233", 450, 300, "Some mistake in url").code.should == "Some mistake in url"
42
+ Conred::Video.new("http://www.youtube.com/watch?NR=1&feature=endscreen&v=Lrj5Kxdzouc", 450, 300).code.should == @youtube_embed_code
43
+ Conred::Video.new("http://www.youtube.com/watch?v=Lrj5Kxdzouc", 450, 300).code.should == @youtube_embed_code
44
+ Conred::Video.new("http://vimeo.com/49556689", 450, 300).code.should == @vimeo_embed_code
45
+ Conred::Video.new("http://google.com/12311233", 450, 300, "Some mistake in url").code.should == "Some mistake in url"
55
46
  end
56
47
  end
57
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conred
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -61,6 +61,8 @@ files:
61
61
  - lib/conred/links.rb
62
62
  - lib/conred/version.rb
63
63
  - lib/conred/video.rb
64
+ - lib/views/video/vimeo_iframe.html.haml
65
+ - lib/views/video/youtube_iframe.html.haml
64
66
  - spec/conred_spec.rb
65
67
  - spec/conred_spec/helpers_spec.rb
66
68
  - spec/conred_spec/video_spec.rb