Class: Tumblargh::Renderer::Blocks::Posts

Inherits:
Base show all
Defined in:
lib/tumblargh/renderer/blocks/posts.rb

Overview

Posts Loop

block:Posts is executed once for each post. Some post related tags can exist outside of a ‘type` block, such as Title or Permalink, so they should be defined here

Instance Attribute Summary

Attributes inherited from Tumblargh::Renderer::Base

#context, #node, #options

Instance Method Summary collapse

Methods inherited from Base

#should_render?

Methods inherited from Tumblargh::Renderer::Base

#context_post, contextual_tag, #escape_html, #escape_url, #initialize, #method_missing, #strip_html

Constructor Details

This class inherits a constructor from Tumblargh::Renderer::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tumblargh::Renderer::Base

Instance Method Details



16
17
18
19
# File 'lib/tumblargh/renderer/blocks/posts.rb', line 16

def permalink
  url = context.post_url
  url.gsub(/^http:\/\/[^\/]+/, '')
end

#permalink?Boolean

Returns:



21
22
23
# File 'lib/tumblargh/renderer/blocks/posts.rb', line 21

def permalink?
  context.permalink?
end

#post_notes_urlObject



25
26
27
28
# File 'lib/tumblargh/renderer/blocks/posts.rb', line 25

def post_notes_url
  # http://bikiniatoll.tumblr.com/notes/1377511430/vqS0xw8sm
  "/notes/#{context.id}/"
end

#reblog_urlObject



30
31
32
# File 'lib/tumblargh/renderer/blocks/posts.rb', line 30

def reblog_url
  "/reblog/#{context.reblog_key}"
end

#renderObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tumblargh/renderer/blocks/posts.rb', line 50

def render
  if context.is_a? Resource::Post
    super
  else
    posts = permalink? ? [context.posts.first] : context.posts

    posts.map do |post|
      post.context = self
      self.class.new(node, post).render
    end.flatten.join('')
  end
end

#tags_as_classesObject

An HTML class-attribute friendly list of the post’s tags. Example: “humor office new_york_city”

By default, an HTML friendly version of the source domain of imported posts will be included. This may not behave as expected with feeds like Del.icio.us that send their content URLs as their permalinks. Example: “twitter_com”, “digg_com”, etc.

The class-attribute “reblog” will be included automatically if the post was reblogged from another post.



44
45
46
47
48
# File 'lib/tumblargh/renderer/blocks/posts.rb', line 44

def tags_as_classes
  context.tags.map do |tag|
    tag.name.titlecase.gsub(/\s+/, '').underscore.downcase
  end.join " "
end