conred 0.0.6 → 0.0.7

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/lib/conred.rb CHANGED
@@ -1,94 +1,9 @@
1
1
  require "conred/version"
2
2
  require "action_view"
3
+ require "conred/helpers"
4
+ require "conred/video"
5
+ require "conred/links"
3
6
 
4
7
  module Conred
5
8
 
6
- module Helpers
7
- extend self
8
- def sanitize_and_trim(text, word_count = nil, omission = '...')
9
- action_view = ActionView::Base.new
10
- text = action_view.strip_tags(text)
11
- if word_count
12
- action_view.truncate(text, :length => word_count, :omission => omission)
13
- else
14
- text
15
- end
16
- end
17
- end
18
-
19
- class Video
20
- def initialize(video_url, width = 670, height = 450, error_message = "Video url you have provided is invalid")
21
- @width = width
22
- @height = height
23
- @video_url = video_url
24
- @error_message = error_message
25
- end
26
-
27
- def code
28
- if youtube_video?
29
- video_from_youtube_url
30
- elsif vimeo_video?
31
- video_from_vimeo_url
32
- else
33
- @error_message
34
- end
35
- end
36
-
37
- def youtube_video?
38
- if /^(http:\/\/)*(www\.)*(youtube.com|youtu.be)/ =~ @video_url
39
- true
40
- end
41
- end
42
-
43
- def vimeo_video?
44
- if /^(http:\/\/)*(www\.)*(vimeo.com)/ =~ @video_url
45
- true
46
- else
47
- false
48
- end
49
- end
50
-
51
-
52
- def video_from_vimeo_url
53
- if @video_url[/vimeo\.com\/([0-9]*)/]
54
- vimeo_id = $1
55
- end
56
- <<-eos
57
- <iframe
58
- id='vimeo_video'
59
- src='http://player.vimeo.com/video/#{vimeo_id}'
60
- width='#{@width}'
61
- height='#{@height}'
62
- frameborder='0'
63
- webkitAllowFullScreen
64
- mozallowfullscreen
65
- allowFullScreen>
66
- </iframe>
67
- eos
68
- end
69
-
70
- def video_from_youtube_url
71
- if @video_url[/youtu\.be\/([^\?]*)/]
72
- youtube_id = $1
73
- else
74
- @video_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
75
- youtube_id = $5
76
- end
77
- <<-eos
78
- <iframe
79
- id='youtube_video'
80
- title='YouTube video player'
81
- width='#{@width}'
82
- height='#{@height}'
83
- src='http://www.youtube.com/embed/#{ youtube_id }'
84
- frameborder='0'
85
- allowfullscreen>
86
- </iframe>
87
- eos
88
- end
89
- end
90
-
91
- class Links
92
-
93
- end
94
9
  end
@@ -0,0 +1,27 @@
1
+ require "conred/version"
2
+ require "action_view"
3
+
4
+ module Conred
5
+
6
+ module Helpers
7
+
8
+ extend self
9
+
10
+ def sanitize_and_trim(text, word_count = nil, omission = '...')
11
+ action_view = ActionView::Base.new
12
+ text = action_view.strip_tags(text)
13
+ if word_count
14
+ action_view.truncate(text, :length => word_count, :omission => omission)
15
+ else
16
+ text
17
+ end
18
+ end
19
+
20
+ def sanitize_body(text)
21
+ text = sanitize(text, :tags => %w(p a strong ul ol li blockquote strike u em), :attributes => %w(href))
22
+ text.html_safe
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,7 @@
1
+ module Conred
2
+
3
+ class Links
4
+
5
+ end
6
+
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Conred
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,75 @@
1
+ require "conred/version"
2
+ require "action_view"
3
+ module Conred
4
+ class Video
5
+ def initialize(video_url, width = 670, height = 450, error_message = "Video url you have provided is invalid")
6
+ @width = width
7
+ @height = height
8
+ @video_url = video_url
9
+ @error_message = error_message
10
+ end
11
+
12
+ def code
13
+ if youtube_video?
14
+ video_from_youtube_url
15
+ elsif vimeo_video?
16
+ video_from_vimeo_url
17
+ else
18
+ @error_message
19
+ end
20
+ end
21
+
22
+ def youtube_video?
23
+ if /^(http:\/\/)*(www\.)*(youtube.com|youtu.be)/ =~ @video_url
24
+ true
25
+ end
26
+ end
27
+
28
+ def vimeo_video?
29
+ if /^(http:\/\/)*(www\.)*(vimeo.com)/ =~ @video_url
30
+ true
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+
37
+ def video_from_vimeo_url
38
+ if @video_url[/vimeo\.com\/([0-9]*)/]
39
+ vimeo_id = $1
40
+ 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
+ end
54
+
55
+ def video_from_youtube_url
56
+ if @video_url[/youtu\.be\/([^\?]*)/]
57
+ youtube_id = $1
58
+ else
59
+ @video_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
60
+ youtube_id = $5
61
+ end
62
+ <<-eos
63
+ <iframe
64
+ id='youtube_video'
65
+ title='YouTube video player'
66
+ width='#{@width}'
67
+ height='#{@height}'
68
+ src='http://www.youtube.com/embed/#{ youtube_id }'
69
+ frameborder='0'
70
+ allowfullscreen>
71
+ </iframe>
72
+ eos
73
+ end
74
+ end
75
+ 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.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -57,7 +57,10 @@ files:
57
57
  - Rakefile
58
58
  - conred.gemspec
59
59
  - lib/conred.rb
60
+ - lib/conred/helpers.rb
61
+ - lib/conred/links.rb
60
62
  - lib/conred/version.rb
63
+ - lib/conred/video.rb
61
64
  - spec/conred_spec.rb
62
65
  homepage: http://github.com/janjiss/conred
63
66
  licenses: []