Skip to content

Instantly share code, notes, and snippets.

@paulRbr
Forked from toddq/README.md
Last active August 29, 2015 14:10
Show Gist options
  • Save paulRbr/bdfa3a1bfe77198a78a0 to your computer and use it in GitHub Desktop.
Save paulRbr/bdfa3a1bfe77198a78a0 to your computer and use it in GitHub Desktop.

##Description Simple Dashing widget (and associated job) to display RSS feeds. Based on Iaian Mitchell's News widget.

##Screenshot

##Dependencies nokogiri

htmlentities

Add it to dashing's gemfile:

gem 'nokogiri'
gem 'htmlentities'

and run bundle install.

##Usage To use this widget, copy news.html, news.coffee, 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="seattle-times" data-view="News" data-title="Seattle Times" data-interval="30"></div>
</li>

At the top of the news.rb job file, add any rss feed urls you want fetched to the hash, and the widget id to send data to. In the dashboard layout file, the optional data-interval binding can be used to specify how frequently to rotate the news items.

class Dashing.Rss extends Dashing.Widget
ready: ->
@currentIndex = 0
@headlineElem = $(@node).find('.headline-container')
@nextComment()
@startCarousel()
onData: (data) ->
@currentIndex = 0
startCarousel: ->
interval = $(@node).attr('data-interval')
interval = "30" if not interval
setInterval(@nextComment, parseInt( interval ) * 1000)
nextComment: =>
headlines = @get('headlines')
if headlines
@headlineElem.fadeOut =>
@currentIndex = (@currentIndex + 1) % headlines.length
@set 'current_headline', headlines[@currentIndex]
@headlineElem.fadeIn()
<h3 class="heading" data-bind="title"></h3>
<div class="headline-container">
<h2 class="title" data-bind="current_headline.title"></h2>
<div class="headline description" data-bind="current_headline.description"></div>
</div>
<p class="more-info" data-bind="moreinfo"></p>
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #47bbb3;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);;
$moreinfo-color: rgba(255, 255, 255, 0.8);;
// ----------------------------------------------------------------------------
// Widget-weather styles
// ----------------------------------------------------------------------------
.widget-news {
background-color: $background-color;
vertical-align: baseline !important;
.headline-container {
display: none;
}
.description {
font-size: 0.8em;
color: $moreinfo-color;
}
.heading{
color: black;
}
}
.headline-container {
height: 260px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment