Class: TwitterJekyll::TwitterTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-twitter-plugin.rb

Overview

Class to respond to Jekyll tag; entry point to library

Direct Known Subclasses

TwitterTagNoCache

Constant Summary collapse

ERROR_BODY_TEXT =
"<p>Tweet could not be processed</p>".freeze
OEMBED_ARG =
"oembed".freeze
URL_OR_STRING_PARAM =
/^("|')?(http|https):\/\//i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_name, params, _tokens) ⇒ TwitterTag

Returns a new instance of TwitterTag.



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/jekyll-twitter-plugin.rb', line 150

def initialize(_name, params, _tokens)
  super

  # Test if first arg is a URL or starts with oembed,
  # otherwise its a Jekyll variable. TODO: remove oembed after deprecation cycle
  if params =~ URL_OR_STRING_PARAM || params.to_s.start_with?(OEMBED_ARG)
    @fetch_from_context = false
    @api_request = parse_params_from_string(params)
  else
    @fetch_from_context = true
    @variable_params = normalize_string_params(params)
  end
end

Instance Attribute Details

#cache=(value) ⇒ Object

for testing



148
149
150
# File 'lib/jekyll-twitter-plugin.rb', line 148

def cache=(value)
  @cache = value
end

Class Method Details

.cache_klassObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Class that implements caching strategy



166
167
168
# File 'lib/jekyll-twitter-plugin.rb', line 166

def self.cache_klass
  FileCache
end

Instance Method Details

#render(context) ⇒ Object

Return html string for Jekyll engine



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/jekyll-twitter-plugin.rb', line 172

def render(context)
  if fetch_from_context?
    variable_name, *params = @variable_params
    tweet_url = context[variable_name]
    @api_request = parse_params_from_array [tweet_url, *params]
  end

  api_secrets_deprecation_warning(context) # TODO: remove after deprecation cycle
  response = cached_response || live_response
  html_output_for(response)
end