Class: Jekyll::UJReadtimeTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::UJReadtimeTag
- Includes:
- Jekyll::UJPowertools::VariableResolver
- Defined in:
- lib/tags/readtime.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ UJReadtimeTag
constructor
A new instance of UJReadtimeTag.
- #render(context) ⇒ Object
Methods included from Jekyll::UJPowertools::VariableResolver
#is_quoted?, #parse_arguments, #parse_options, #resolve_input, #resolve_variable
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ UJReadtimeTag
Returns a new instance of UJReadtimeTag.
9 10 11 12 |
# File 'lib/tags/readtime.rb', line 9 def initialize(tag_name, markup, tokens) super @markup = markup.strip end |
Instance Method Details
#render(context) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tags/readtime.rb', line 14 def render(context) # Get the content to analyze content = resolve_content(context) return '1' unless content # Strip HTML tags stripped_content = strip_html(content) # Count words words = count_words(stripped_content) # Calculate readtime (269 words per minute, minimum 1 minute) readtime = (words / 269.0).ceil readtime = 1 if readtime < 1 readtime.to_s end |