Dropdown

Code Climate Build Status Coverage Status

Blog engine that parses Markdown files stored in Dropbox for a static blog engine.

Installation

Add this line to your application's Gemfile:

gem 'dropdown'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dropdown

Getting Started with Dropbox storage

  1. Create an application on Dropbox

    1. Sign into Dropbox
    2. Visit https://www.dropbox.com/developers/apps/create
    3. Choose 'Dropbox API app' for 'What type of app do you want to create?'
    4. Choose 'Files and datastores' for 'What type of data does your app need to store on Dropbox?'
    5. Choose 'No -- My app needs access to files already on Dropbox' for 'Can your app be limited to its own, private folder?'
    6. Choose 'All file types -- My app needs access to a user's full Dropbox' for 'What type of files does your app need access to?'
    7. Name your application. We suggest something like ' Dropdown blog'

    Here is a screenshot of an example of a Dropbox app creation page filled out:

  2. Enter your Dropbox APP KEY and APP SECRET in environment variables

    Once your create a Dropbox application, you will be assigned an App key and an App secret. You will want to put these values in environment variables so you can use these in your Dropdown configuration settings. We highly suggest you do not put these values straight into your configuration because you do not want them checked into your source control.

    For development, we recommend using dotenv.

    1. For Rails, add this line to your application's Gemfile

      gem 'dotenv-rails', :groups => [:development, :test]
      
    2. Create a .env file to the root of your project

    3. Add the .env file to your .gitignore

    4. Add the following content to your .env file

      DROPBOX_APP_KEY=<your app key>
      DROPBOX_APP_SECRET=<your app secret>
      DROPBOX_ACCESS_TOKEN=<your access token>
      

    For production, if you application lives on Heroku, you can run the following:

    heroku config:set DROPBOX_APP_KEY=<your app key>
    heroku config:set DROPBOX_APP_SECRET=<your app secret>
    heroku config:set DROPBOX_ACCESS_TOKEN=<your access token>
    
  3. Update your Dropdown configuration

    For Rails, create config/initializers/dropdown.rb with the following content:

    Dropdown.configure do |c|
      c.dropbox_app_key: ENV['DROPBOX_APP_KEY']
      c.dropdown_app_secret: ENV['DROPBOX_APP_SECRET']
      c.dropdown_access_token: ENV['DROPBOX_ACCESS_TOKEN']
    end
    

    We will be retrieving the DROPBOX_ACCESS_TOKEN with the next step.

  4. Run rake setup:dropbox:access_token

    This will instruct you to go to a Dropbox url to authorize your Dropbox application.

    Copy the authorization code and enter it the console.

    Your access token will be displayed and you can copy it to an environment variable: DROPBOX_ACCESS_TOKEN.

Potential Implementation

Dropbox directory structure


  - blog-posts
  |-- markdown
      |-- random-post-1.md
      |-- random-post-2.md
  |-- html
      |-- random-post-1.html
      |-- random-post-2.html
  |-- templates
      |-- honeysuckle.handlebars
  |-- .index

Parsing

A rake task will be used to process a directory with Markdown files. The process will read each Markdown file and create an accompanying static file in HTML. This process will use RedCarpet to parse the markdown files and generate HTML files.

  # task to process the Markdown directory
  require 'dropdown/processor'

  task :process [:source, :destination] do |t, args|
    DropDown::Processor.new(args.source, args.destination).process
  end

Additional functionality

  DropDown::Processor.new.process(:all)   # same as calling DropDown::Processor.new.process
  DropDown::Processor.new.process         # uses the source and destination directories specified in the configuration

Format of the generated output

Each file will have meta data stored as comments in the MarkDown:

Title: Deep Throat Exposed!
Author: Bob Woodward
Post: 4/4/1974

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut volutpat molestie condimentum. Vestibulum malesuada, 
lorem sit amet euismod pellentesque, tellus felis varius enim, id tincidunt leo odio aliquet ante. Maecenas metus 
lorem, pretium vitae auctor sed, blandit id quam.

This will generate the following html:

<!-- Title: Deep Throat Exposed! -->
<!-- Author: Bob Woodward -->
<!-- Post: 4/4/1974 -->
<div class='post'>
  <div class='title'>Deep Throat Exposed!</div>
  <div class='author'>Bob Woodward</div>
  <div class='post'>19740404T....</div>
  <div class='content'>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut volutpat molestie condimentum. Vestibulum malesuada, 
    lorem sit amet euismod pellentesque, tellus felis varius enim, id tincidunt leo odio aliquet ante. Maecenas metus 
    lorem, pretium vitae auctor sed, blandit id quam.
  </div>
</div>

This will also create the following row in the .index file:

title: Deep Throat Exposed! author: Bob Woodward post: 19740404T.... slug: deep-throat-exposed checksum: 384749403

Retreiving

Displaying

Configuration

  DropDown.configure do |c|
    c.base_path: 'blog_posts'
    c.source_directory: 'markdown'
    c.destination_directory: 'html'
    c.template: 'honeysuckle'
    c.dropbox_app_key: '<insert dropbox app key>'
    c.dropbox_app_secret: '<insert dropbox app secret key>'
  end