Commit 288a1454 authored by Sean Madsen's avatar Sean Madsen

Book categorization to close #30

parent 16e2d7fc
name: Developer guide name: Developer guide
weight: 10 weight: 10
description: For CiviCRM developers description: For CiviCRM developers
category: Core
langs: langs:
en: en:
repo: 'https://github.com/civicrm/civicrm-dev-docs' repo: 'https://github.com/civicrm/civicrm-dev-docs'
......
name: User guide name: User guide
weight: -100 weight: -100
description: Aimed at day to day users of CiviCRM. description: Aimed at day to day users of CiviCRM.
category: Core
langs: langs:
en: en:
repo: 'https://github.com/civicrm/civicrm-user-guide' repo: 'https://github.com/civicrm/civicrm-user-guide'
......
...@@ -11,9 +11,14 @@ class ReadController extends Controller { ...@@ -11,9 +11,14 @@ class ReadController extends Controller {
* @Route("/") * @Route("/")
*/ */
public function HomeAction() { public function HomeAction() {
/** @var \AppBundle\Model\Library $library */
$library = $this->get('library');
return $this->render( return $this->render(
'AppBundle:Read:home.html.twig', 'AppBundle:Read:home.html.twig', array(
array('library' => $this->get('library')) 'core_books' => $library->getBooksByCategory('Core'),
'extensions_books' => $library->getBooksByCategory('Extensions'),
)
); );
} }
......
...@@ -33,6 +33,12 @@ class Book { ...@@ -33,6 +33,12 @@ class Book {
*/ */
public $weight; public $weight;
/**
*
* @var string (e.g. "Core", "Extensions") Should be in sentence case
*/
public $category;
/** /**
* Creates a book based on a yaml conf file * Creates a book based on a yaml conf file
* *
...@@ -49,6 +55,8 @@ class Book { ...@@ -49,6 +55,8 @@ class Book {
foreach ($yaml['langs'] as $code => $languageData) { foreach ($yaml['langs'] as $code => $languageData) {
$this->languages[] = new Language($code, $languageData); $this->languages[] = new Language($code, $languageData);
} }
$category = isset($yaml['category']) ? $yaml['category'] : "Extensions";
$this->category = ucwords($category);
} }
/** /**
......
...@@ -99,6 +99,23 @@ class Library { ...@@ -99,6 +99,23 @@ class Library {
return $chosen; return $chosen;
} }
/**
* Gives an array of book objects which match a given category
*
* @param string $category
*
* @return array of Book objects
*/
public function getBooksByCategory($category) {
$books = array();
foreach ($this->books as $book) {
if ($book->category == $category) {
$books[] = $book;
}
}
return $books;
}
/** /**
* See which books/languages are using a given repository. * See which books/languages are using a given repository.
* *
......
<ul class="books"> <ul class="books">
{% for book in library.books %} {% for book in books %}
<li class="book"> <li class="book">
<span class="name"> <span class="name">
{% if book.isMultiLanguage or book.languages|first.isMultiVersion %} {% if book.isMultiLanguage or book.languages|first.isMultiVersion %}
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
{% if book.isMultiLanguage %} {% if book.isMultiLanguage %}
{% include 'AppBundle:Read:language_list.html.twig' %} {% include 'AppBundle:Read:language_list.html.twig' %}
{% elseif book.languages|first.isMultiVersion %} {% elseif book.languages|first.isMultiVersion %}
{% include 'AppBundle:Read:version_list.html.twig' {% include 'AppBundle:Read:version_list.html.twig'
with {language: book.languages|first} %} with {language: book.languages|first} %}
{% endif %} {% endif %}
</li> </li>
......
...@@ -3,26 +3,30 @@ ...@@ -3,26 +3,30 @@
{% block title %}CiviCRM Documentation{% endblock %} {% block title %}CiviCRM Documentation{% endblock %}
{% block body %} {% block body %}
<a href="https://civicrm.org">CiviCRM home</a> <a href="https://civicrm.org">CiviCRM home</a>
<h1>CiviCRM Documentation</h1> <h1>CiviCRM Documentation</h1>
<p>CiviCRM offers community contributed documentation in the form of digital <p>CiviCRM offers community contributed documentation in the form of digital
<em>books</em>, listed below. We encourage everyone to <em>books</em>, listed below. We encourage everyone to
<a href="https://docs.civicrm.org/dev/en/latest/documentation/"> <a href="https://docs.civicrm.org/dev/en/latest/documentation/">
help contribute to documentation</a>.</p> help contribute to documentation</a>.</p>
<p><em>Note: some documentation has not yet been moved into book format and <p><em>Note: some documentation has not yet been moved into book format and
can still be found on our can still be found on our
<a href="https://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Documentation">wiki</a> <a href="https://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Documentation">wiki</a>
while it awaits migration. In particular, information about while it awaits migration. In particular, information about
<a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Installation+and+Upgrades"> <a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Installation+and+Upgrades">
installation and upgrades</a> installation and upgrades</a>
is still on the wiki.</em></p> is still on the wiki.</em></p>
<h2>Books</h2> <h2>Core Books</h2>
{% include 'AppBundle:Read:book_list.html.twig' with {books: core_books} %}
<h2>Extensions Books</h2>
{% include 'AppBundle:Read:book_list.html.twig' %} {% include 'AppBundle:Read:book_list.html.twig' with {books: extensions_books} %}
{% endblock %} {% endblock %}
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