class FrenchPress::Post::Generic

Represents a generic post (i.e. a text post)

Attributes

file_name[R]
parent_blog[W]

Public Class Methods

new(content, file_type = nil) click to toggle source
# File lib/frenchpress/post/generic.rb, line 10
def initialize(content, file_type = nil)
  title = (rand(36**9) + rand(36**10)).to_s(36) # Random title
  assign_variables(:@content => content,
                   :@blog => FrenchPress.working,
                   :@date => Time.now,
                   :@title => title,
                   :@file_type => file_type)
  derive_variables
end

Public Instance Methods

assign_variables(args) click to toggle source
# File lib/frenchpress/post/generic.rb, line 20
def assign_variables(args)
  args.each(&method(:instance_variable_set)) # Thanks, SO
end
derive_variables() click to toggle source
# File lib/frenchpress/post/generic.rb, line 24
def derive_variables
  @file_name = @date.strftime '%Y-%m-%d' + '-' + @title
  @file_suffix = 'jpeg' if @file_suffix == 'jpg'
  @file_suffix ||= 'html'
end
render() click to toggle source
# File lib/frenchpress/post/generic.rb, line 41
def render
  @content
end
render_as_quote() click to toggle source
# File lib/frenchpress/post/generic.rb, line 45
def render_as_quote
  "<a href=\"#{@parent_blog[:url]}\" class=\"quote-attr\">" \
    "#{@parent_blog[:host]}</a>\n" \
    "<blockquote>#{render}</blockquote>"
end
render_with_tags() click to toggle source
# File lib/frenchpress/post/generic.rb, line 51
def render_with_tags
  (tags << render).join("\n")
end
tags() click to toggle source
# File lib/frenchpress/post/generic.rb, line 30
def tags
  [
    '---',
    "type: #{@type}",
    "date: #{@date.strftime '%Y-%m-%d %H:%M:%S'}",
    'layout: post',
    "title: #{@title}",
    '---'
  ]
end