alephant

Static publishing to S3 on push notification from SQS

Code Climate

Build Status

Dependency Status

Gem Version

Dependencies

  • JRuby 1.7.8
  • An AWS account (you'll need to create):
    • An S3 bucket
    • An SQS Queue
    • A Dynamo DB table (optional, will attempt to create if can't be found)

Setup

Ensure you have a config/aws.yml in the format:

access_key_id: ACCESS_KEY_ID
secret_access_key: SECRET_ACCESS_KEY

Install the gem:

gem install alephant

In your application:

require 'alephant'
opts = {
  :s3_bucket_id => 'bucket-id',
  :s3_object_path => 'path/to/object',
  :s3_object_id => 'object_id',
  :table_name => 'your_dynamo_db_table',
  :sqs_queue_id => 'https://your_amazon_sqs_queue_url',
  :view_id => 'my_view_id',
  :sequential_proc => Proc.new { |last_seen_id, data|
    last_seen_id < data["sequence_id"].to_i
  },
  :set_last_seen_proc => Proc.new { |data|
    data["sequence_id"].to_i
  }
}

logger = Logger.new

thread = Alephant::Alephant.new(opts, logger).run!
thread.join

logger is optional, and must confirm to the Ruby standard logger interface

Provide a view in a folder (fixtures are optional):

SQS Message Format

{
  "content": "hello world",
  "sequential_id": 1
}

foo.rb

module MyApp
  module Views
    class Foo < Alephant::Views::Base
      def content
        @data['content']
      end
    end
  end
end

foo.mustache

{{content}}

S3 Output

hello world

Preview Server

alephant preview

The included preview server allows you to see the html generated by your templates, both standalone and in the context of a page.

Standalone

/component/:id/?:fixture?

Full page preview

When viewing the component in the context of a page, you'll need to retrieve a mustache template to provide the page context.

When performing an update a regex is applied to replace the static hostnames in the retrieved html.

Environment Variables

STATIC_HOST_REGEX="static.(sandbox.dev|int|test|stage|live).yourapp(i)?.com\/"
PREVIEW_TEMPLATE_URL="http://yourapp.com/template"

Example Remote Template

http://m.int.bbc.co.uk/news/layout/template

alephant update

In page /preview/:id/:region/?:fixture?