liquid_reading_time 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/liquid_reading_time.rb +46 -0
  3. metadata +73 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0d2da442a3f30e53753cd9773025caf1f2676705
4
+ data.tar.gz: 90d795ce61fab8f48279a9c3e6fa4cd097b6196f
5
+ SHA512:
6
+ metadata.gz: 3688bc987f2851975bb2a4a08fb561fc19ab9d5c9a71d6a9b3036e683f3fa3ffd481b474a15243a38d1837d26cd35be762af66d2fdf22e947ef316cecaaf51fa
7
+ data.tar.gz: 52e1b08e2b1381a98cec759d6f890227139a848c9024d753884bdd7a27bd58c22210ecec7b157727b3e5dec87ee32049cdbccf73c7f91a4a91162bdc31b8e483
@@ -0,0 +1,46 @@
1
+ # reading_time
2
+ #
3
+ # A Liquid filter to estimate how long a passage of text will take to read
4
+ #
5
+ # https://github.com/bdesham/reading_time
6
+ #
7
+ # Copyright (c) Benjamin Esham, 2013-2015
8
+ # See README.md for full copyright information.
9
+
10
+ require 'nokogiri'
11
+
12
+ module ReadingTime
13
+
14
+ def count_words(html)
15
+ words(html).length
16
+ end
17
+
18
+ def reading_time(html)
19
+ (count_words(html) / 270.0).ceil
20
+ end
21
+
22
+ private
23
+
24
+ def text_nodes(root)
25
+ ignored_tags = %w[ area audio canvas code embed footer form img
26
+ map math nav object pre script svg table track video ]
27
+
28
+ texts = []
29
+ root.children.each { |node|
30
+ if node.text?
31
+ texts << node.text
32
+ elsif not ignored_tags.include? node.name
33
+ texts.concat text_nodes node
34
+ end
35
+ }
36
+ texts
37
+ end
38
+
39
+ def words(html)
40
+ fragment = Nokogiri::HTML.fragment html
41
+ text_nodes(fragment).map { |text| text.scan(/[[:word:]]+/) }.flatten
42
+ end
43
+
44
+ end
45
+
46
+ Liquid::Template.register_filter(ReadingTime)
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liquid_reading_time
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Esham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: liquid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ description: A Liquid filter that intelligently counts the number of words in a piece
42
+ of HTML and estimates how long the text will take to read.
43
+ email: benjamin@esham.io
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/liquid_reading_time.rb
49
+ homepage: https://github.com/bdesham/reading_time
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: A Liquid filter to count words and estimate reading times.
73
+ test_files: []