Selaa lähdekoodia

[FEATURE] multiple column support

Frank Nägler 11 vuotta sitten
vanhempi
commit
ecd57ee083
4 muutettua tiedostoa jossa 50 lisäystä ja 2 poistoa
  1. 11 1
      content/404.md
  2. 11 0
      content/index.md
  3. 15 1
      lib/pico.php
  4. 13 0
      themes/default/style.css

+ 11 - 1
content/404.md

@@ -1,9 +1,19 @@
 /*
 /*
 Title: Error 404
 Title: Error 404
 Robots: noindex,nofollow
 Robots: noindex,nofollow
+Template: content-sidebar
 */
 */
 
 
+
+{column:content}
+
 Error 404
 Error 404
 =========
 =========
 
 
-Woops. Looks like this page doesn't exist.
+Woops. Looks like this page doesn't exist.
+
+{/column:content}
+
+{column:sidebar}
+<div class="big">404</div>
+{/column:sidebar}

+ 11 - 0
content/index.md

@@ -3,6 +3,7 @@ Title: Welcome
 Description: This description will go in the meta description tag
 Description: This description will go in the meta description tag
 */
 */
 
 
+
 ## Welcome to Pico
 ## Welcome to Pico
 
 
 Congratulations, you have successfully installed [Pico](http://pico.dev7studios.com). Pico is a stupidly simple, blazing fast, flat file CMS.
 Congratulations, you have successfully installed [Pico](http://pico.dev7studios.com). Pico is a stupidly simple, blazing fast, flat file CMS.
@@ -73,6 +74,7 @@ All themes must include an `index.html` file to define the HTML structure of the
 	* `{{ meta.date_formatted }}`
 	* `{{ meta.date_formatted }}`
 	* `{{ meta.robots }}`
 	* `{{ meta.robots }}`
 * `{{ content }}` - The content of the current page (after it has been processed through Markdown)
 * `{{ content }}` - The content of the current page (after it has been processed through Markdown)
+* `{{ column_<name> }}` - The column name of the content of the current page (after it has been processed through Markdown) [more information](#columns)
 * `{{ pages }}` - A collection of all the content in your site
 * `{{ pages }}` - A collection of all the content in your site
 	* `{{ page.title }}`
 	* `{{ page.title }}`
 	* `{{ page.url }}`
 	* `{{ page.url }}`
@@ -94,6 +96,15 @@ Pages can be used like:
 	{% endfor %}
 	{% endfor %}
 &lt;/ul&gt;</pre>
 &lt;/ul&gt;</pre>
 
 
+### <a name="columns"></a> Columns
+
+You can use multiple columns within the templates. A good example is the 404 error page. The basic logic is very simple. In the template you can use twig variables like `{{ column_content }}`.
+To define which content should be displayed in which column, you have to wrap the content (in the *.md files) with markers like this:
+
+<pre>{column:content}
+  my content for column content
+{/column:content}</pre>
+
 ### Plugins
 ### Plugins
 
 
 See [http://pico.dev7studios.com/plugins](http://pico.dev7studios.com/plugins)
 See [http://pico.dev7studios.com/plugins](http://pico.dev7studios.com/plugins)

+ 15 - 1
lib/pico.php

@@ -11,6 +11,7 @@ use \Michelf\MarkdownExtra;
  */
  */
 class Pico {
 class Pico {
 
 
+	protected $columns = array();
 	private $plugins;
 	private $plugins;
 
 
 	/**
 	/**
@@ -101,7 +102,9 @@ class Pico {
 			'next_page' => $next_page,
 			'next_page' => $next_page,
 			'is_front_page' => $url ? false : true,
 			'is_front_page' => $url ? false : true,
 		);
 		);
-
+		foreach ($this->columns as $var => $code) {
+			$twig_vars["column_{$var}"] = $code;
+		}
 		$template = (isset($meta['template']) && $meta['template']) ? $meta['template'] : 'index';
 		$template = (isset($meta['template']) && $meta['template']) ? $meta['template'] : 'index';
 		$this->run_hooks('before_render', array(&$twig_vars, &$twig, &$template));
 		$this->run_hooks('before_render', array(&$twig_vars, &$twig, &$template));
 		$output = $twig->render($template .'.html', $twig_vars);
 		$output = $twig->render($template .'.html', $twig_vars);
@@ -138,6 +141,17 @@ class Pico {
 	{
 	{
 		$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
 		$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
 		$content = str_replace('%base_url%', $this->base_url(), $content);
 		$content = str_replace('%base_url%', $this->base_url(), $content);
+
+		// pattern to find {column:xyz} {/column:xyz} column marker
+		$pattern = '#({column:(.*?)})(.+?)({/column:\\2})#ims';
+		preg_match_all($pattern, $content, $matches);
+
+		$counter = 0;
+		foreach ($matches[2] as $var) {
+			$this->columns[$var] = MarkdownExtra::defaultTransform($matches[3][$counter]);
+			$counter++;
+		}
+
 		$content = MarkdownExtra::defaultTransform($content);
 		$content = MarkdownExtra::defaultTransform($content);
 
 
 		return $content;
 		return $content;

+ 13 - 0
themes/default/style.css

@@ -240,6 +240,19 @@ blockquote {
 #footer a { color: #ddd; }
 #footer a { color: #ddd; }
 #footer a:hover { color: #fff; }
 #footer a:hover { color: #fff; }
 
 
+.col_sidebar {
+    float: left;
+    width: 200px;
+    background: #C0C0C0;
+    margin: 0 10px 10px 0;
+}
+.col_sidebar .big {
+    font-size: 121px;
+    color: #fff;
+    font-weight: bold;
+    margin-left: -3px;
+    line-height: 79px;
+}
 /* Misc Styles
 /* Misc Styles
 /*---------------------------------------------*/
 /*---------------------------------------------*/
 .clearfix:before,
 .clearfix:before,