Giter VIP home page Giter VIP logo

handlebarss's Introduction

HandlebaRss

A small RSS viewer for displaying remote feeds on static sites.

http://octo-labs.github.io/HandlebaRss/

Requirements

HandlebaRss depends on jquery and handlebars.

Getting started

Installation

First include the dependncies on your page.

<!-- include dependencies -->
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="handlebars-v1.3.0.js"></script>

<!-- include HandlebaRss -->
<script type="text/javascript" src="src/HandlebaRss.js"></script>

Single feeds

<!-- the place where the feed should be rendered -->
<div id="destination"></div>

<!-- the handlebars template for the feed -->
<script id="feed-template" type="text/x-handlebars-template">
  <h1>{{title}}</h1>
  {{#each entries}}
    <h2><a href="{{link}}">{{title}}</a></h2>
    <p>{{contentSnippet}}</p>
  {{/each}}
</script>

<!-- now create a HandlebaRss instance and call init() -->
<script type="text/javascript" charset="utf-8">
  rss = new HandlebaRss("http://www.octolabs.com/blogs/octoblog/feed.xml","#feed-template","#destination");
  rss.init();
</script>

For single feeds the context of the handlebars template is a JSON representation of a feed object.

{
  "author" : "Jeremy Green",
  "description" : "",
  "feedUrl" : "http://www.octolabs.com/blogs/octoblog/feed.xml",
  "link" : "http://www.octolabs.com/blogs/octoblog",
  "title" : "OctoBlog",
  "type" : "atom10",
  "entries" : [{...},{...}]
}

Multiple feeds

For multiple feeds, just pass an array of URLs as the first argument. You can optionally pass an integer as the last argument to limit the number of articles per feed.

<!-- the place where the feed should be rendered -->
<div id="destination"></div>

<!-- the handlebars template for the feed -->
<script id="feed-template" type="text/x-handlebars-template">
  {{#each entries}}
    <h2><a href="{{link}}">{{title}}</a></h2>
    <p>From {{feed.title}}</p>
  {{/each}}
</script>

<!-- now create a HandlebaRss instance and call init() -->
<script type="text/javascript" charset="utf-8">
  rss = new HandlebaRss([
    "http://www.octolabs.com/blogs/octoblog/feed.xml",
    "http://datachomp.com/atom.xml",
    "http://geekindulgence.com/feed/"
  ],"#feed-template","#destination",5);
  rss.init();
</script>

gv For multiple feeds the context of the handlebars template is a JSON object that contains an entries array of the combined and sorted entries from all of the feeds. Each entry has a feed property that contains the data from the top level feed that the entry belongs to (author,description,feedUrl, etc...). In the template you can access these with something like {{feed.author}}.

{
  "entries" : [{...},{...},...]
}

Running the tests

Just load SpecRunner.html in a browser.

Contributing

Please! I'm happy to accept pull requests.

handlebarss's People

Contributors

jagthedrummer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bodik khawkins98

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.