Class: SirTrevorRails::Blocks::TweetBlock

Inherits:
SirTrevorRails::Block show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
lib/sir_trevor_rails/blocks/tweet_block.rb

Constant Summary

Constants inherited from SirTrevorRails::Block

SirTrevorRails::Block::DEFAULT_FORMAT

Instance Attribute Summary

Attributes inherited from SirTrevorRails::Block

#parent, #type

Instance Method Summary collapse

Methods inherited from SirTrevorRails::Block

#as_json, custom_block_types, #format, from_hash, #initialize, #to_partial_path

Constructor Details

This class inherits a constructor from SirTrevorRails::Block

Instance Method Details

#at_nameObject



24
25
26
# File 'lib/sir_trevor_rails/blocks/tweet_block.rb', line 24

def at_name
  "@" << screen_name
end

#profile_image_urlObject



28
29
30
31
32
33
# File 'lib/sir_trevor_rails/blocks/tweet_block.rb', line 28

def profile_image_url
  # TODO: add support for different size images: https://dev.twitter.com/overview/general/user-profile-images-and-banners

  # Split the URL to omit the protocol and let the browser define the context (note: assumes asset is available over both HTTP and HTTPS) 
  "//" << self.user[:profile_image_url].split("://")[1]
end

#profile_urlObject



16
17
18
# File 'lib/sir_trevor_rails/blocks/tweet_block.rb', line 16

def profile_url
  "//twitter.com/" << self.user[:screen_name]
end

#render_tweet_bodyObject



9
10
11
12
13
14
# File 'lib/sir_trevor_rails/blocks/tweet_block.rb', line 9

def render_tweet_body
  sanitize Twitter::Autolink.auto_link(
        self.text,
        url_entities: (self.entities.values_at(:urls, :media).flatten.compact.uniq rescue nil)
      ), tags: %w{a span}, attributes: %w{class href rel target}
end

#screen_nameObject



20
21
22
# File 'lib/sir_trevor_rails/blocks/tweet_block.rb', line 20

def screen_name
  self.user[:screen_name]
end