Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
parse multiple json files for links through different templates
Browse files Browse the repository at this point in the history
Issue #10
  • Loading branch information
discipolo authored and rosenstrauch committed Aug 24, 2016
1 parent ff8f838 commit 0376f79
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 18 deletions.
18 changes: 12 additions & 6 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
theme: node_modules/dashpit-foundation-theme
theme: ../node_modules/dashpit-foundation-theme
linklists:
default:
crushpaper:
template: crushpaper
envelope: entries
source: /crushpaper-backup-2016-07-30-18-09-38.json
wallabag:
template: default
source: ./links.yml
other:
template: default
source: ./links.yml
envelope: ''
source: /wallabag-export-3-2016-07-30.json
starthq:
template: starthq
envelope: items
source: /starthq-export.json
26 changes: 15 additions & 11 deletions index.php → public/index.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@

<?php



// Autoload dependencies
// https://getcomposer.org/doc/01-basic-usage.md#autoloading
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

use dashpit\config;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Exception\ParseException;

// load config
$config = new config();
$settings = $config->getConfig('config.yml');
$settings = $config->getConfig('../config.yml');
$theme_directory = $settings['theme'];


// initialize presentation layer
$loader = new Twig_Loader_Filesystem($theme_directory, './templates');
$loader = new Twig_Loader_Filesystem($theme_directory, '../templates');
$loader->addPath($theme_directory);
$loader->addPath('./templates');
$loader->addPath('../templates');
$twig = new Twig_Environment($loader, array(
// 'cache' => 'compilation_cache',
));


$link_lists = $settings['linklists'];
foreach ($link_lists as $listsource => $link_list) {

foreach ($link_lists as $listsource => $link_list_settings) {
// get data
$parsed_linklist = $config->getConfig($link_list['source']);
$linklist = new \dashpit\LinkList($link_list_settings);
$linklist->init($loader);
$parsed_linklist = $linklist->getParsedList();
$linklist->render($parsed_linklist, $listsource);
//$parsed_linklist = $config->getConfig($link_list['source']);
// Debug
//echo 'DEBUG:';
//var_dump($link_list);
echo $twig->render('linklist.html', array(
'sitename' => 'dashpit',
'linklist' => $parsed_linklist,
'listsource' => $listsource
));

}


Expand Down
24 changes: 24 additions & 0 deletions templates/crushpaper_linklist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ sitename }}</title>
</head>
<body>
<h2>{{ listsource }}</h2>


<ul id="linklist">
{% set list = linklist[envelope] %}
{% for item in list if item.url is defined %}
<li>{{ item.title }}
<a href="{{ item.url }}"> {{ item.id }} - {{ item.caption }}</a>
<p>{{ item.note }}</p>
</li>
{% endfor %}
</ul>




</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>{{ listsource }}</h2>

<ul id="linklist">
{% for item in linklist %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
<li>{{ item.title }} {{ item.name }}<a href="{{ item.href }}"> {{ item.id }} - {{ item.caption }}</a></li>
{% endfor %}
</ul>

Expand Down
24 changes: 24 additions & 0 deletions templates/starthq_linklist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ sitename }}</title>
</head>
<body>
<h2>{{ listsource }}</h2>


<ul id="linklist">
{% set list = linklist[envelope][0] %}
{% for item in list %}
<li>{{ item.title }}
<a href="{{ item.url }}"> {{ item.name }} - {{ item.caption }}</a>
<p>{{ item.note }}</p>
</li>
{% endfor %}
</ul>




</body>
</html>

0 comments on commit 0376f79

Please sign in to comment.