class Contentful::Social::Template

Attributes

contentful[R]
template[R]
webhook[R]

Public Class Methods

new(contentful_client, webhook, template) click to toggle source
# File lib/contentful/social/template.rb, line 6
def initialize(contentful_client, webhook, template)
  @contentful = contentful_client
  @webhook = webhook
  @template = template
end

Public Instance Methods

render() click to toggle source
# File lib/contentful/social/template.rb, line 12
def render
  template.gsub(/\{\{([\w|\.]+)\}\}/) do |match|
    contentful_find(match.gsub('{{', '').gsub('}}', ''))
  end
end

Protected Instance Methods

contentful_find(field) click to toggle source
# File lib/contentful/social/template.rb, line 20
def contentful_find(field)
  entry = Support.find_entry(contentful, webhook)

  if field.include?('.')
    result = entry
    field.split('.').each do |partial|
      result = result.public_send(partial)
    end

    result
  else
    entry.public_send(field)
  end
end