Skip to content

Instantly share code, notes, and snippets.

Last active May 29, 2019 14:20
Show Gist options
  • Save iainjmitchell/5271830 to your computer and use it in GitHub Desktop.
Save iainjmitchell/5271830 to your computer and use it in GitHub Desktop.
BBC News Widget for Dashing

##Description Simple Dashing widget (and associated job) to display BBC News Stories.

##Dependencies nokogiri

Add it to dashing's gemfile:

gem 'nokogiri'

and run bundle install.

##Usage To use this widget, copy news.html,, and news.scss into the /widgets/news directory. Put the news.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="news" data-view="News"></div>
class Dashing.News extends Dashing.Widget
ready: ->
@currentIndex = 0
@headlineElem = $(@node).find('.headline-container')
onData: (data) ->
@currentIndex = 0
startCarousel: ->
setInterval(@nextComment, 8000)
nextComment: =>
headlines = @get('headlines')
if headlines
@headlineElem.fadeOut =>
@currentIndex = (@currentIndex + 1) % headlines.length
@set 'current_headline', headlines[@currentIndex]
<div class="heading">
<image src=""></image>
<span> News</span>
<div class="headline-container">
<h1 data-bind='current_headline.title' class="title"></h1>
<div class="headline">
<p class="description" data-bind='current_headline.description'></p>
class BbcNews
def initialize()
@http ='')
def latest_headlines()
response = @http.request("/news/rss.xml"))
doc = Nokogiri::XML(response.body)
news_headlines = [];
doc.xpath('//channel/item').each do |news_item|
news_headline = NewsHeadlineBuilder.BuildFrom(news_item)
class NewsHeadlineBuilder
def self.BuildFrom(news_item)
title: news_item.xpath('title').text,
description: news_item.xpath('description').text,
@BBC_News =
SCHEDULER.every '15m', :first_in => 0 do |job|
headlines = @BBC_News.latest_headlines
send_event('news', { :headlines => headlines})
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #47bbb3;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);;
$moreinfo-color: rgba(255, 255, 255, 0.7);;
// ----------------------------------------------------------------------------
// Widget-weather styles
// ----------------------------------------------------------------------------
.widget-news {
background-color: $background-color;
vertical-align: baseline !important;
.headline-container {
display: none;
.heading span {
color: black;
.heading img {
margin-top: -5px;
.description {
font-size: 0.8em;
font-size: 1.2em;
padding: 20px;
Copy link

I'm receiving the following error when trying to run this on CentOS (though it worked fine on Ubuntu) with Ruby version 1.9.3-p327:

news.rb:3:in `initialize': uninitialized constant BbcNews::Net (NameError)

Copy link

moollaza commented Nov 3, 2013

@willjohnson it's because news.rb is missing require 'nokogiri' at the top. That will fix it :)

Copy link

jtheoof commented Jan 26, 2014

Also require 'net/http' is missing on top.

Copy link

fjfo commented Jul 21, 2016

bundler: failed to load command: thin (/usr/local/bin/thin)
LoadError: cannot load such file -- nokogiri

Copy link

I'm trying to convert this over to work TechCrunch's RSS feed with mixed success. Their feed includes image links in the descriptions. How can we filter these out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment