Permalink
Browse files

Allow asset data to be stored within the page .txt

So, if the page data contains a key which matches the filename of the asset, then merge the corresponding data into the Asset->data object.
  • Loading branch information...
1 parent b2651aa commit 2e6729a25c52515af0c0e19b4eeba7acfa268b29 @kolber committed Mar 9, 2012
Showing with 21 additions and 4 deletions.
  1. +15 −1 app/asset-types/asset-factory.inc.php
  2. +6 −3 content/1.projects/1.project-1/project.yml
@@ -5,6 +5,17 @@
static $store;
static $asset_subclasses = array();
+ static function extract_page_data($asset_path) {
+ # separate the filename and the parent page path
+ $path = explode('/', $asset_path);
+ $file_name = array_pop($path);
+ $page_path = implode('/', $path);
+
+ # return any page data scoped against the asset filename
+ $page_data = self::$store[$page_path];
+ return isset($page_data[$file_name]) ? $page_data[$file_name] : array();
+ }
+
static function &create($file_path) {
#
# a little bit of magic here to find any classes which extend 'Asset'
@@ -27,9 +38,12 @@ static function &create($file_path) {
if(in_array(strtolower($split_path[1]), $identifiers)) $asset = $asset_type;
}
+ # extract any page data scoped against the asset filename
+ $page_data = self::extract_page_data($file_path);
+
# create a new asset and return its data
$asset = new $asset($file_path);
- return $asset->data;
+ return array_merge($asset->data, $page_data);
} else {
# new page
@@ -1,7 +1,10 @@
title: The Test Project 1
+
date: March 10, 2002
+
content: |
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
- et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
- ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+
+01.jpg:
+ description: CAPTION

2 comments on commit 2e6729a

@bumpux
bumpux commented on 2e6729a Mar 27, 2012

I love this! It opens a lot of possibilites for storing asset-related data centrally with the power of yaml text objects. Right now this only works in the yaml branch. I see it's doc'ed already in the wiki -- will it be folded into master soon?

@kolber
Owner
kolber commented on 2e6729a Apr 12, 2012

This was pushed up to the master branch, so should be usable off HEAD.

Please sign in to comment.