Skip to content

Commit

Permalink
Added files from the jarednova/timber repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jarednova committed Feb 25, 2015
1 parent b4e69af commit f4c796d
Show file tree
Hide file tree
Showing 29 changed files with 448 additions and 19 deletions.
13 changes: 13 additions & 0 deletions 404.php
@@ -0,0 +1,13 @@
<?php
/**
* The template for displaying 404 pages (Not Found)
*
* Methods for TimberHelper can be found in the /functions sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/

$context = Timber::get_context();
Timber::render( '404.twig', $context );
23 changes: 4 additions & 19 deletions LICENSE 100644 → 100755
@@ -1,22 +1,7 @@
The MIT License (MIT)
Copyright (c) 2012-2013 Jared Novack

Copyright (c) 2015 Upstatement
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 changes: 40 additions & 0 deletions archive.php
@@ -0,0 +1,40 @@
<?php
/**
* The template for displaying Archive pages.
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.2
*/

$templates = array( 'archive.twig', 'index.twig' );

$data = Timber::get_context();

$data['title'] = 'Archive';
if ( is_day() ) {
$data['title'] = 'Archive: '.get_the_date( 'D M Y' );
} else if ( is_month() ) {
$data['title'] = 'Archive: '.get_the_date( 'M Y' );
} else if ( is_year() ) {
$data['title'] = 'Archive: '.get_the_date( 'Y' );
} else if ( is_tag() ) {
$data['title'] = single_tag_title( '', false );
} else if ( is_category() ) {
$data['title'] = single_cat_title( '', false );
array_unshift( $templates, 'archive-' . get_query_var( 'cat' ) . '.twig' );
} else if ( is_post_type_archive() ) {
$data['title'] = post_type_archive_title( '', false );
array_unshift( $templates, 'archive-' . get_post_type() . '.twig' );
}

$data['posts'] = Timber::get_posts();

Timber::render( $templates, $data );
20 changes: 20 additions & 0 deletions author.php
@@ -0,0 +1,20 @@
<?php
/**
* The template for displaying Author Archive pages
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
global $wp_query;

$data = Timber::get_context();
$data['posts'] = Timber::get_posts();
if ( isset( $wp_query->query_vars['author'] ) ) {
$author = new TimberUser( $wp_query->query_vars['author'] );
$data['author'] = $author;
$data['title'] = 'Author Archives: ' . $author->name();
}
Timber::render( array( 'author.twig', 'archive.twig' ), $data );
13 changes: 13 additions & 0 deletions footer.php
@@ -0,0 +1,13 @@
<?php
/*
* Third party plugins that hijack the theme will call wp_footer() to get the footer template.
* We use this to end our output buffer (started in header.php) and render into the view/page-plugin.twig template.
*/
$timberContext = $GLOBALS['timberContext'];
if ( ! isset( $timberContext ) ) {
throw new \Exception( 'Timber context not set in footer.' );
}
$timberContext['content'] = ob_get_contents();
ob_end_clean();
$templates = array( 'page-plugin.twig' );
Timber::render( $templates, $timberContext );
54 changes: 54 additions & 0 deletions functions.php
@@ -0,0 +1,54 @@
<?php

if ( ! class_exists( 'Timber' ) ) {
add_action( 'admin_notices', function() {
echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url( admin_url( 'plugins.php#timber' ) ) . '">' . esc_url( admin_url( 'plugins.php' ) ) . '</a></p></div>';
} );
return;
}

class StarterSite extends TimberSite {

function __construct() {
add_theme_support( 'post-formats' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_filter( 'timber_context', array( $this, 'add_to_context' ) );
add_filter( 'get_twig', array( $this, 'add_to_twig' ) );
add_action( 'init', array( $this, 'register_post_types' ) );
add_action( 'init', array( $this, 'register_taxonomies' ) );
parent::__construct();
}

function register_post_types() {
//this is where you can register custom post types
}

function register_taxonomies() {
//this is where you can register custom taxonomies
}

function add_to_context( $context ) {
$context['foo'] = 'bar';
$context['stuff'] = 'I am a value set in your functions.php file';
$context['notes'] = 'These values are available everytime you call Timber::get_context();';
$context['menu'] = new TimberMenu();
$context['site'] = $this;
return $context;
}

function add_to_twig( $twig ) {
/* this is where you can add your own fuctions to twig */
$twig->addExtension( new Twig_Extension_StringLoader() );
$twig->addFilter( 'myfoo', new Twig_Filter_Function( 'myfoo' ) );
return $twig;
}

}

new StarterSite();

function myfoo( $text ) {
$text .= ' bar!';
return $text;
}
7 changes: 7 additions & 0 deletions header.php
@@ -0,0 +1,7 @@
<?php
/*
* Third party plugins that hijack the theme will call wp_head() to get the header template.
* We use this to start our output buffer and render into the view/page-plugin.twig template in footer.php
*/
$GLOBALS['timberContext'] = Timber::get_context();
ob_start();
27 changes: 27 additions & 0 deletions index.php
@@ -0,0 +1,27 @@
<?php
/**
* The main template file
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/

if ( ! class_exists( 'Timber' ) ) {
echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
return;
}
$context = Timber::get_context();
$context['posts'] = Timber::get_posts();
$context['foo'] = 'bar';
$templates = array( 'index.twig' );
if ( is_home() ) {
array_unshift( $templates, 'home.twig' );
}
Timber::render( $templates, $context );
5 changes: 5 additions & 0 deletions js/site.js
@@ -0,0 +1,5 @@
jQuery( document ).ready( function( $ ) {

// Your JavaScript goes here

});
27 changes: 27 additions & 0 deletions page.php
@@ -0,0 +1,27 @@
<?php
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* To generate specific templates for your pages you can use:
* /mytheme/views/page-mypage.twig
* (which will still route through this PHP file)
* OR
* /mytheme/page-mypage.php
* (in which case you'll want to duplicate this file and save to the above path)
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/

$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
Timber::render( array( 'page-' . $post->post_name . '.twig', 'page.twig' ), $context );
Binary file added screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions search.php
@@ -0,0 +1,18 @@
<?php
/**
* Search results page
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/

$templates = array( 'search.twig', 'archive.twig', 'index.twig' );
$context = Timber::get_context();

$context['title'] = 'Search results for '. get_search_query();
$context['posts'] = Timber::get_posts();

Timber::render( $templates, $context );
10 changes: 10 additions & 0 deletions sidebar.php
@@ -0,0 +1,10 @@
<?php
/**
* The Template for displaying all single posts
*
*
* @package WordPress
* @subpackage Timber
*/

Timber::render( array( 'sidebar.twig' ), $data );
22 changes: 22 additions & 0 deletions single.php
@@ -0,0 +1,22 @@
<?php
/**
* The Template for displaying all single posts
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/

$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post;
$context['wp_title'] .= ' - ' . $post->title();
$context['comment_form'] = TimberHelper::get_comment_form();

if ( post_password_required( $post->ID ) ) {
Timber::render( 'single-password.twig', $context );
} else {
Timber::render( array( 'single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single.twig' ), $context );
}
5 changes: 5 additions & 0 deletions style.css
@@ -0,0 +1,5 @@
/*
* Theme Name: My Timber Starter Theme
* Description: Starter Theme to use with Timber
* Author: Upstatement and YOU!
*/
5 changes: 5 additions & 0 deletions views/404.twig
@@ -0,0 +1,5 @@
{% extends "base.twig" %}

{% block content %}
Sorry, we couldn't find what you're looking for.
{% endblock %}
7 changes: 7 additions & 0 deletions views/author.twig
@@ -0,0 +1,7 @@
{% extends "base.twig" %}

{% block content %}
{% for post in posts %}
{% include ["tease-"~post.post_type~".twig", "tease.twig"] %}
{% endfor %}
{% endblock %}
59 changes: 59 additions & 0 deletions views/base.twig
@@ -0,0 +1,59 @@
{% block html_head_container %}

{% include 'html-header.twig' %}
{% block head %}
{% endblock %}
</head>
{% endblock %}

<body class="{{body_class}}" data-template="base.twig">
<header class="header" >
{% block header %}
<div class="wrapper">
<h1 class="hdr-logo" role="banner">
<a class="hdr-logo-link" href="/" rel="home">{{site.name}}</a>
</h1>
<nav id="nav-main" class="nav-main" role="navigation">
<ul class="nav">
{% for item in menu.get_items %}
<li class="nav-item {{item.classes | join(' ')}}">
<a class="nav-link" href="{{item.get_link}}">{{item.title}}</a>
{% if item.get_children %}
<ul class="nav nav-drop">
{% for child in item.get_children %}
<li class="nav-drop-item">
<a class="nav-link" href="{{child.get_link}}">{{child.title}}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</nav><!-- #nav -->
</div>
{% endblock %}
</header>

<section id="content" role="main" class="content-wrapper">
{% if title %}<h1>{{title}}</h1>{% endif %}
<div class="wrapper {{sidebar_class}}">
{% block content %}
Sorry, no content
{% endblock %}
</div>
{% if sidebar %}
<aside class="layout-sidebar">
{{sidebar}}
</aside>
{% endif %}
</section>

{% block footer %}
<footer id="footer">
{% include 'footer.twig' %}
</footer>
{{ function('wp_footer') }}
{% endblock %}
</body>
</html>
4 changes: 4 additions & 0 deletions views/comment.twig
@@ -0,0 +1,4 @@
<div class="blog-comment {{comment.comment_type}}" id="blog-comment-{{comment.ID}}">
<h5 class="comment-author">{{comment.author.name}} says</h5>
<div class="comment-content">{{comment.comment_content|wpautop}}</div>
</div>
1 change: 1 addition & 0 deletions views/footer.twig
@@ -0,0 +1 @@
Copyright {{"now"|date('Y')}}

0 comments on commit f4c796d

Please sign in to comment.