class TumblrThemer::Post

Constants

POST_TYPES

Attributes

data[R]
html[R]
post_index[R]

Public Class Methods

new(html, data, index=0) click to toggle source
# File lib/tumblr-themer/post.rb, line 5
def initialize html, data, index=0
  @html = TumblrThemer::HtmlSnippet.new(html.dup) if html
  @data = data.dup
  @post_index = index
end
render(html, data, i=0) click to toggle source
# File lib/tumblr-themer/post.rb, line 15
def self.render html, data, i=0
  type = data['type']
  if type == 'photo'
    if data['photos'].size > 1
      klass = TumblrThemer::Post::Photoset
    else
      klass = TumblrThemer::Post::Photo
    end
  else
    klass = TumblrThemer::Post.const_get(type.capitalize)
  end

  klass.new(html,data,i).render
# rescue NameError
  # ''
end

Public Instance Methods

created_at() click to toggle source
# File lib/tumblr-themer/post.rb, line 61
def created_at
  @created_at ||= Time.parse(data['date'])
end
reblogged?() click to toggle source
# File lib/tumblr-themer/post.rb, line 57
def reblogged?
  boolify(data['reblogged_from_id'])
end
render() click to toggle source
# File lib/tumblr-themer/post.rb, line 32
def render
  return '' unless html

  self.class.blocks.each do |name,blk|
    html.block(name,instance_exec(self,&blk))
  end

  self.class.tag_iterators.each do |name,opts|
    vals = instance_exec(self,&opts[:blk])
    html.block(name) do |str|
      strs = []
      vals.each_with_index { |val,i| strs << opts[:klass].new(str,val,i).render }
      strs.join("\n")
    end
  end

  puts html.str

  self.class.tags.each do |name, blk|
    html.tag(name,instance_exec(self,&blk))
  end

  html.str
end
type() click to toggle source
# File lib/tumblr-themer/post.rb, line 11
def type
  self.class.to_s.sub('TumblrThemer::Post::','').downcase
end