desirae-datamap-ruhoh.js/datamapper-ruhoh.js

115 lines
4.3 KiB
JavaScript
Raw Normal View History

2015-01-16 04:29:44 +00:00
/*jshint -W054 */
;(function (exports) {
'use strict';
var Mustache = exports.Mustache || require('mustache')
;
function map(view) {
var newview
2015-01-16 05:35:29 +00:00
, analytics
, comments
;
comments = view.site.disqus_shortname &&
Mustache.render(view.desi.partials.disqus, { disqus: {
shortname: view.site.disqus_shortname
, identifier: view.entity.disqus_identifier || undefined
, url: !view.entity.disqus_identifier && view.entity.disqus_url || undefined
}})
;
analytics = view.site.google_analytics_tracking_id &&
Mustache.render(view.desi.partials.google_analytics, { google_analytics: {
tracking_id: view.site.google_analytics_tracking_id
}})
2015-01-16 04:29:44 +00:00
;
newview = {
content: view.contents
, page: {
title: view.entity.yml.title || view.site.title // in rt
, tagline: view.entity.yml.tagline // in rt
, description: view.entity.yml.description // in rt
, content: view.contents
, youtube: view.entity.yml.youtube
, tags: view.entity.yml.tags
, categories: view.entity.yml.categories
, player_width: view.entity.yml.player_width
, player_height: view.entity.yml.player_height
, next: view.entities[view.entity_index + 1]
, previous: view.entities[view.entity_index - 1]
, date: view.entity.year + '-' + view.entity.month + '-' + view.entity.day
// TODO , url: view.entities.
}
, 'page?previous': view.entities[view.entity_index - 1] // ruhoh-twitter only
// should contain { url: ..., title: ... }
, 'page?next': view.entities[view.entity_index + 1] // ruhoh-twitter only
, 'page.categories?to_categories': [] // ruhoh-twitter only
, 'page.tags?to_tags': [] // ruhoh-twitter only
, posts: { collated: view.desi.collated }
, urls: {
base_url: view.env.base_url
2015-01-23 11:11:11 +00:00
// /something/ -> good (leading and trailing slash)
// / -> bad good (leading and trailing slash)
, base_path: (view.env.base_path + '/').replace('//', '/')
2015-01-16 04:29:44 +00:00
}
, data: {
author: {
name: view.author.name
, twitter: view.author.twitter
}
, title: view.site.title
}
2015-01-23 22:15:10 +00:00
, stylesheets: { 'load': function () {
2015-01-23 10:54:04 +00:00
return function (text, render) {
// TODO pay attention to text of which styles to load?
// this is unescaped, right?
2015-01-23 22:15:10 +00:00
console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ magicstache');
return render(view.desi.styles.join('\n'));
2015-01-23 10:54:04 +00:00
};
2015-01-23 22:15:10 +00:00
}}
2015-01-16 04:29:44 +00:00
, styles: view.desi.styles.join('\n')
2015-01-16 05:35:29 +00:00
, assets: view.desi.styles.join('\n') // ruhoh-twitter only
, comments: comments // ruhoh-twitter only
, analytics: analytics // ruhoh-twitter only
2015-01-16 04:29:44 +00:00
, widgets: {
2015-01-16 05:35:29 +00:00
comments: comments
, analytics: analytics
2015-01-16 04:29:44 +00:00
, facebook_connect: view.desi.partials.facebook_connect
, twitter: view.desi.partials.twitter
, google_plusone: view.desi.partials.google_plusone
, amazon_link_enhancer: view.site.amazon_affiliate_id &&
Mustache.render(view.desi.partials.amazon_link_enhancer, {
amazon_affiliate_id: view.site.amazon_affiliate_id
})
}
, site: {
navigation: view.navigation
, title: view.site.title // ruhoh-twitter only
, author: { // ruhoh-twitter only
name: view.author.name // ruhoh-twitter only
}
}
};
// backwards compat
newview.site['navigation?to_pages'] = newview.site.navigation; // ruhoh-twitter only
newview.site['navigation?to__root'] = newview.site.navigation;
newview.data.navigation = view.site.navigation;
newview.data['navigation?to_pages'] = newview.site.navigation;
newview.data['navigation?to__root'] = newview.site.navigation;
newview.page.content = view.contents;
return newview;
}
2015-01-16 05:35:29 +00:00
// shoulda made this an object at the start... oops
map.ruhoh = map;
map['ruhoh@1.0'] = map;
map['ruhoh@2.6'] = map;
2015-01-16 04:29:44 +00:00
exports.DesiraeDatamapRuhoh = map.DesiraeDatamapRuhoh = map;
}('undefined' !== typeof exports && exports || window));