conred 0.0.8 → 0.0.9
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/README.md +11 -2
- data/lib/conred/helpers.rb +3 -2
- data/lib/conred/version.rb +1 -1
- data/spec/conred_spec/helpers_spec.rb +31 -0
- data/spec/conred_spec/video_spec.rb +0 -0
- metadata +5 -1
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Right now (version 0.0.
|
21
|
+
Right now (version 0.0.8) has several helpers and video class.
|
22
22
|
For video you can use:
|
23
23
|
|
24
24
|
c = Conred::Video.new("http://www.youtube.com/watch?v=Lrj5Kxdzouc")
|
@@ -37,10 +37,19 @@ If you wish to use text helpers then in your application_helper add this include
|
|
37
37
|
|
38
38
|
include Conred::Helpers
|
39
39
|
|
40
|
-
Now you have
|
40
|
+
Now you have these methods available to you:
|
41
|
+
|
42
|
+
Sanitizes all html and trims content if count is provided:
|
41
43
|
|
42
44
|
sanitize_and_trim("<html>string with", 10) => "string ..."
|
45
|
+
|
46
|
+
Sanitizes body, allowed tags are(p a strong ul ol li blockquote strike u em):
|
47
|
+
|
48
|
+
sanitize_body("<html><strong>string</strong> <p>with<p></html>") => "<strong>string</strong> <p>with<p>"
|
49
|
+
|
50
|
+
External link formating
|
43
51
|
|
52
|
+
external_url("www.google.lv") => "http://www.google.lv"
|
44
53
|
|
45
54
|
|
46
55
|
## Contributing
|
data/lib/conred/helpers.rb
CHANGED
@@ -18,12 +18,13 @@ module Conred
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def sanitize_body(text)
|
21
|
-
|
21
|
+
action_view = ActionView::Base.new
|
22
|
+
text = action_view.sanitize(text, :tags => %w(p a strong ul ol li blockquote strike u em), :attributes => %w(href))
|
22
23
|
text.html_safe
|
23
24
|
end
|
24
25
|
|
25
26
|
def external_url(link)
|
26
|
-
/^http/.match(
|
27
|
+
/^http/.match(link) ? link : "http://#{link}"
|
27
28
|
end
|
28
29
|
|
29
30
|
end
|
data/lib/conred/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "conred"
|
2
|
+
|
3
|
+
describe Conred do
|
4
|
+
describe Conred::Helpers do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@html_text = "<html><p>Paragraph text</p> <a href='http://google.com'>Link to some site</a></html>"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return cleaned out text from html" do
|
11
|
+
Conred::Helpers.sanitize_and_trim(@html_text).should == "Paragraph text Link to some site"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should truncate string to fourteen symbols" do
|
15
|
+
Conred::Helpers.sanitize_and_trim(@html_text, 14).should == "Paragraph t..."
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should use different truncate text at the ending of the line" do
|
19
|
+
Conred::Helpers.sanitize_and_trim(@html_text, 11, "").should == "Paragraph t"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should remove unallowed tags" do
|
23
|
+
Conred::Helpers.sanitize_body(@html_text).should == "<p>Paragraph text</p> <a href=\"http://google.com\">Link to some site</a>"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should add protocols in front of urls" do
|
27
|
+
Conred::Helpers.external_url("http://www.google.lv").should == "http://www.google.lv"
|
28
|
+
Conred::Helpers.external_url("www.google.lv").should == "http://www.google.lv"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
File without changes
|
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.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -62,6 +62,8 @@ files:
|
|
62
62
|
- lib/conred/version.rb
|
63
63
|
- lib/conred/video.rb
|
64
64
|
- spec/conred_spec.rb
|
65
|
+
- spec/conred_spec/helpers_spec.rb
|
66
|
+
- spec/conred_spec/video_spec.rb
|
65
67
|
homepage: http://github.com/janjiss/conred
|
66
68
|
licenses: []
|
67
69
|
post_install_message:
|
@@ -88,3 +90,5 @@ specification_version: 3
|
|
88
90
|
summary: ConcepticHQ reusable code
|
89
91
|
test_files:
|
90
92
|
- spec/conred_spec.rb
|
93
|
+
- spec/conred_spec/helpers_spec.rb
|
94
|
+
- spec/conred_spec/video_spec.rb
|