bergamasco 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/bergamasco/summarize.rb +4 -2
- data/lib/bergamasco/version.rb +1 -1
- data/spec/summarize_spec.rb +3 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2408331adbbd94d3263b46bc845e4ee28b9d25e7
|
4
|
+
data.tar.gz: 31ef99f8504917494f39e7855cba98789bede309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07ed905d2d57fb0d3c5fb86f832346e4ceb9c594b77ca86c0522b6320643babc0a00352bb3c2d54da3fdc108300976626614836f3f074c9de3366ba570d37c42
|
7
|
+
data.tar.gz: 2bdfda5983ab9ab33f365d9fe1c1fb8dd2b503aaa5a22a7a210b88df4e9290f75cf125d3be67210f0dd8b5f99e464b8a514bc8d895fe99001d324a6123a0cbab
|
data/Gemfile.lock
CHANGED
data/lib/bergamasco/summarize.rb
CHANGED
@@ -2,8 +2,10 @@ module Bergamasco
|
|
2
2
|
module Summarize
|
3
3
|
# based on from https://github.com/middleman/middleman-blog/blob/master/lib/middleman-blog/blog_article.rb
|
4
4
|
def self.summary(text, options={})
|
5
|
-
|
6
|
-
|
5
|
+
separator = options[:separator] || "READMORE"
|
6
|
+
|
7
|
+
if !options[:length] && text.include?(separator)
|
8
|
+
truncate_at_separator(text, separator)
|
7
9
|
else
|
8
10
|
max_length = options[:length] || 250
|
9
11
|
ellipsis = options[:ellipsis] || "..."
|
data/lib/bergamasco/version.rb
CHANGED
data/spec/summarize_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Bergamasco::Summarize do
|
|
6
6
|
it 'should truncate after 250 characters' do
|
7
7
|
filepath = fixture_path + 'cool-dois-without-yml.md'
|
8
8
|
file = IO.read(filepath)
|
9
|
-
content = subject.summary(file)
|
9
|
+
content = subject.summary(file, length: 250)
|
10
10
|
expect(content.length).to eq(250)
|
11
11
|
expect(content).to start_with("In 1998 Tim Berners-Lee coined")
|
12
12
|
end
|
@@ -22,8 +22,7 @@ describe Bergamasco::Summarize do
|
|
22
22
|
it 'should truncate at separator' do
|
23
23
|
filepath = fixture_path + 'cool-dois-without-yml.md'
|
24
24
|
file = IO.read(filepath)
|
25
|
-
|
26
|
-
content = subject.summary(file, separator: separator)
|
25
|
+
content = subject.summary(file)
|
27
26
|
expect(content).to start_with("In 1998 Tim Berners-Lee coined")
|
28
27
|
expect(content).to end_with("the referenced resource.")
|
29
28
|
end
|
@@ -31,9 +30,8 @@ describe Bergamasco::Summarize do
|
|
31
30
|
it 'should truncate at separator and convert to html' do
|
32
31
|
filepath = fixture_path + 'cool-dois-without-yml.md'
|
33
32
|
file = IO.read(filepath)
|
34
|
-
separator = "READMORE"
|
35
33
|
html = Bergamasco::Markdown.render_html(file, skip_yaml_header: true, csl: 'spec/fixtures/apa.csl', bibliography: 'spec/fixtures/references.bib')
|
36
|
-
content = subject.summary_from_html(html,
|
34
|
+
content = subject.summary_from_html(html, skip_yaml_header: true, csl: 'spec/fixtures/apa.csl', bibliography: 'spec/fixtures/references.bib')
|
37
35
|
expect(content).to start_with("In 1998 Tim Berners-Lee coined the term cool URIs (1998), that is URIs that don’t change.")
|
38
36
|
expect(content).to end_with("the referenced resource.")
|
39
37
|
end
|