Commit af957011 authored by Sean Madsen's avatar Sean Madsen

home page - show a cleaner book list

If a book has only one language and only one branch then turn the book
title into a link to the book and don't show anything else. Also use
similar logic to present cleaner lists for books that have only one
language and languages that have only one branch.
parent 685c8339
......@@ -5,7 +5,8 @@
<meta charset="UTF-8">
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<title>{% block title %}CiviCRM documentation{% endblock %}</title>
<link rel="stylesheet" href="{{ asset('css/publish.css') }}" /> {% block stylesheets %}{% endblock %}
<link rel="stylesheet" href="{{ asset('css/main.css') }}" />
{% block stylesheets %}{% endblock %}
<link media="all" href="https://civicrm.org/sites/all/themes/civicrm_bootstrap/css/style.css" rel="stylesheet" type="text/css">
</head>
......
......@@ -44,17 +44,12 @@ class ReadController extends Controller
$finder = new Finder();
$yaml = new Parser();
$books = $this->get('book.loader')->find();
$books = $this->get('book.loader')->find();
foreach ($books as $key => $book) {
foreach($book['langs'] as $lang){
if(isset($lang['stable'])){
$stableBooks[$key] = $book;
break;
}
}
}
return $this->render('AppBundle:Read:home.html.twig', array('books'=>$stableBooks, 'locales' => $locales['Names']));
return $this->render('AppBundle:Read:home.html.twig', array(
'books' => $books,
'locales' => $locales['Names'])
);
}
// $k = $this->get('kernel');
......
<ul class="books">
{% for short_name, book in books %}
<li class="book">
<span class="name">
{% if book.is_multi_stable_lang or
book.stable_langs|first.is_multi_version %}
{{ book.name }}
{% else %}
{% set lang = book.langs|keys|first %}
{% set url = "/" ~ short_name ~ "/" ~ lang ~ "/latest" %}
<a href="{{ url }}">{{ book.name }}</a>
{% endif %}
</span>
<span class="separator">&ndash;</span>
<span class="description">{{ book.description }}</span>
{% if book.is_multi_stable_lang %}
{% include 'AppBundle:Read:language_list.html.twig' %}
{% elseif book.stable_langs|first.is_multi_version %}
{% include 'AppBundle:Read:version_list.html.twig'
with {
language: book.stable_langs|first,
lang_code: book.stable_langs|keys|first
} %}
{% endif %}
</li>
{% endfor %}
</ul>
......@@ -23,30 +23,6 @@
<h2>Books</h2>
<ul class="books">
{% for url, book in books %}
<li class="book">
<span class="name"><a href="/{{url}}">{{ book.name }}</a></span> &ndash;
<span class="description">{{ book.description }}</span>
<ul>
{% for lang, language in book.langs if language.stable is defined %}
<li class="lang {{lang}}">
{{ attribute(locales, lang) }}:
<a href="/{{url}}/{{lang}}/stable">Current edition</a>.
Other editions:
{% if language.history is defined %}
{% for version in language.history %}
<a href="/{{url}}/{{lang}}/{{version}}">{{version}}</a>,
{% endfor %}
{% endif %}
<a href="/{{url}}/{{lang}}/latest">latest</a>.
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{% include 'AppBundle:Read:book_list.html.twig' %}
{% endblock %}
<ul class="languages">
{% for lang_code, language in book.stable_langs %}
<li class="language {{ lang_code }}">
{% set language_name = attribute(locales, lang_code) %}
{% spaceless %}
<span class="language-name">
{% if language.is_multi_version %}
{{- language_name -}}
<span class="separator">:</span>
{% else %}
{% set url = "/" ~ short_name ~ "/" ~ lang_code ~ "/latest" %}
<a href="{{ url }}">
{{- language_name -}}
</a>
{% endif %}
</span>
{% endspaceless %}
{% if language.is_multi_version %}
{% include 'AppBundle:Read:version_list.html.twig' %}
{% endif %}
</li>
{% endfor %}
</ul>
{% for version_key, version_branch in language.distinct_versions %}
<ul class="versions">
<li class="version">
{% set url = "/" ~ short_name ~ "/" ~ lang_code ~ "/" ~ version_key %}
<a href="{{ url }}">{{ version_key }} version</a>
</li>
</ul>
{% endfor %}
\ No newline at end of file
......@@ -50,9 +50,102 @@ class BookLoader
uasort($this->cache, [$this, 'compareBooksBySortOrder']);
}
}
/**
* Modifies the book passed in by inserting new elements into the book's
* array structure that provide additional information about the book, such
* as the number of languages, etc.
*
* @param array book
*/
private function addStatsToBook(&$book) {
$this->addToBookDistinctVersions($book);
$this->addToBookIsMultiVersion($book);
$this->addToBookIsMultiLang($book);
$this->addToBookStableLangs($book);
$this->addtoBookIsMultiStableLang($book);
}
/**
* @return array
* Adds 'distinct_versions' element to a book which lists all the distinct
* versions. If 'stable' and 'latest' both point to 'master', then it will
* list only 'stable' in the distinct versions.
*
* @param array book
*
*/
private function addToBookDistinctVersions(&$book) {
foreach ($book['langs'] as &$lang) {
$lang['distinct_versions']['latest'] = $lang['latest'];
if (isset($lang['stable']) && $lang['stable'] != $lang['latest']) {
$lang['distinct_versions']['stable'] = $lang['stable'];
}
if (isset($lang['history'])) {
foreach ($lang['history'] as $version) {
$key = (string) $version;
$lang['distinct_versions'][$key] = $version;
}
}
}
}
/**
* Adds 'is_multi_version' to all language elements of a book to say
* whether the language has multiple versions that are different from one
* another
*
* @param array book
*/
private function addToBookIsMultiVersion(&$book) {
foreach ($book['langs'] as &$lang) {
$lang['is_multi_version'] =
count($lang['distinct_versions']) > 1 ? 1 : 0;
}
}
/**
* Adds 'is_multi_lang' element to a book to say whether the book has
* multiple languages.
*
* @param array book
*/
private function addToBookIsMultiLang(&$book) {
$book['is_multi_lang'] = count($book['langs']) > 1 ? 1 : 0;
}
/**
* Adds 'stable_langs' element to a book -- an array of all the languages
* which have a stable version defined.
*
* @param array book
*/
private function addToBookStableLangs(&$book) {
foreach ($book['langs'] as $lang => $language) {
if(isset($language['stable'])) {
$book['stable_langs'][$lang] = $language;
}
}
}
/**
* Adds 'is_multi_stable_lang' element to a book to say whether the book has
* multiple languages which have stable versions defined.
*
* @param array book
*/
private function addToBookIsMultiStableLang(&$book) {
if(!isset($book['stable_langs'])) {
$this->addToBookStableLangs($book);
}
$book['is_multi_stable_lang'] = count($book['stable_langs']) > 1 ? 1 : 0;
}
/**
* Find all the books
* Fills the private $cache variable with an array of books, as they are
* defined in the yaml config files
*
* @return array all books
*/
public function find()
{
......@@ -64,6 +157,9 @@ class BookLoader
->name("*.yml") as $file) {
$books[basename($file, '.yml')] = $yaml->parse(file_get_contents("$file"));
}
foreach ($books as &$book) {
$this->addStatsToBook($book);
}
$this->cache = $books;
$this->cacheSort();
}
......
/* Home page */
.book {
margin-bottom: 0.8em;
}
.book .name {
font-weight: bold;
}
.book .description {
font-style: italic;
}
/* Publishing messages */
.message {
font-weight: bold;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment