Skip to content

Instantly share code, notes, and snippets.

@camillebaldock
Last active March 16, 2016 20:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camillebaldock/920042990c6f9c121f58 to your computer and use it in GitHub Desktop.
Save camillebaldock/920042990c6f9c121f58 to your computer and use it in GitHub Desktop.
Dashing quotes

Description

A Dashing widget for displaying random quotes from a YAML file.

See a live demo here.

Usage

Install the following gems: mechanize

Expects a quotes.yml YAML file in root directory of your Dashing project.

Its format should be:

---
-
  1:
    author: "Author name 1"
    quotes:
      - "Single line quote"
      - |-
          Multi-line
          Quotes
    title: "Some title"
-
  1:
    author: "Author name 2"
    quotes:
      - "Single line quote"
      - |-
          Multi-line
          Quotes
    title: "Some title 2"
<div class="quote-container">
<h3 data-bind="text"></h3>
</div>
<div class="metadata-container">
<p class="title" data-bind="title"></p>
<p class="author" data-bind="author"></p>
</div>
require 'mechanize'
require 'json'
SCHEDULER.every "1m", :first_in => 0 do
quote_documents = YAML.load(File.open("./quotes.yml"))
quotes = []
quote_documents.each do |quote_document|
entry = quote_document.values.first
entry["quotes"].each do |quote|
quotes << {
author: entry["author"],
title: entry["title"],
text: quote
}
end
end
quote = quotes.sample
send_event("quotes", { text: quote[:text], title: quote[:title], author: quote[:author] } )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment