renamed Asset/Assets to Medium/Media

This commit is contained in:
Andy Miller
2014-08-11 11:07:32 -06:00
parent 6eac0f9131
commit 5fa934c22f
7 changed files with 78 additions and 78 deletions

View File

@@ -1,4 +1,4 @@
title: Assets title: Media
validation: loose validation: loose
form: form:

View File

@@ -1,58 +1,58 @@
jpg: jpg:
type: image type: image
thumb: assets/thumb-jpg.png thumb: thumb-jpg.png
mime: image/jpeg mime: image/jpeg
jpeg: jpeg:
type: image type: image
thumb: assets/thumb-jpeg.png thumb: thumb-jpeg.png
mime: image/jpeg mime: image/jpeg
png: png:
type: image type: image
thumb: assets/thumb-png.png thumb: thumb-png.png
mime: image/png mime: image/png
gif: gif:
type: image type: image
thumb: assets/thumb-gif.png thumb: thumb-gif.png
mime: image/gif mime: image/gif
mp4: mp4:
type: video type: video
thumb: assets/thumb-mp4.png thumb: thumb-mp4.png
mime: video/mp4 mime: video/mp4
mov: mov:
type: video type: video
thumb: assets/thumb-mov.png thumb: thumb-mov.png
mime: video/quicktime mime: video/quicktime
m4v: m4v:
type: video type: video
thumb: assets/thumb-m4v.png thumb: thumb-m4v.png
mime: video/x-m4v mime: video/x-m4v
swf: swf:
type: video type: video
thumb: assets/thumb-swf.png thumb: thumb-swf.png
mime: video/x-flv mime: video/x-flv
txt: txt:
type: file type: file
thumb: assets/thumb-txt.png thumb: thumb-txt.png
mime: text/plain mime: text/plain
doc: doc:
type: file type: file
thumb: assets/thumb-doc.png thumb: thumb-doc.png
mime: application/msword mime: application/msword
html: html:
type: file type: file
thumb: assets/thumb-html.png thumb: thumb-html.png
mime: text/html mime: text/html
pdf: pdf:
type: file type: file
thumb: assets/thumb-pdf.png thumb: thumb-pdf.png
mime: application/pdf mime: application/pdf
zip: zip:
type: file type: file
thumb: assets/thumb-zip.png thumb: thumb-zip.png
mime: application/zip mime: application/zip
gz: gz:
type: file type: file
thumb: assets/thumb-gz.png thumb: thumb-gz.png
mime: application/gzip mime: application/gzip

View File

@@ -20,8 +20,8 @@ abstract class Getters implements \ArrayAccess, \Countable
/** /**
* Magic setter method * Magic setter method
* *
* @param mixed $offset Asset name value * @param mixed $offset Medium name value
* @param mixed $value Asset value * @param mixed $value Medium value
*/ */
public function __set($offset, $value) public function __set($offset, $value)
{ {
@@ -31,8 +31,8 @@ abstract class Getters implements \ArrayAccess, \Countable
/** /**
* Magic getter method * Magic getter method
* *
* @param mixed $offset Asset name value * @param mixed $offset Medium name value
* @return mixed Asset value * @return mixed Medium value
*/ */
public function __get($offset) public function __get($offset)
{ {
@@ -42,7 +42,7 @@ abstract class Getters implements \ArrayAccess, \Countable
/** /**
* Magic method to determine if the attribute is set * Magic method to determine if the attribute is set
* *
* @param mixed $offset Asset name value * @param mixed $offset Medium name value
* @return boolean True if the value is set * @return boolean True if the value is set
*/ */
public function __isset($offset) public function __isset($offset)

View File

@@ -7,13 +7,13 @@ use Grav\Config;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
/** /**
* Assets is a holder object that contains references to the assets of page. This object is created and * Media is a holder object that contains references to the media of page. This object is created and
* populated during the getAssets() method in the Pages object * populated during the getMedia() method in the Pages object
* *
* @author RocketTheme * @author RocketTheme
* @license MIT * @license MIT
*/ */
class Assets extends Getters class Media extends Getters
{ {
protected $gettersVariable = 'instances'; protected $gettersVariable = 'instances';
protected $path; protected $path;
@@ -48,25 +48,25 @@ class Assets extends Getters
$filename = $info->getFilename(); $filename = $info->getFilename();
list($basename, $ext, $meta) = $this->getFileParts($filename); list($basename, $ext, $meta) = $this->getFileParts($filename);
// Get asset instance creating it if it didn't exist. // Get medium instance creating it if it didn't exist.
$asset = $this->get("{$basename}.{$ext}", true); $medium = $this->get("{$basename}.{$ext}", true);
if (!$asset) { if (!$medium) {
continue; continue;
} }
// Assign meta files to the asset. // Assign meta files to the medium.
if ($meta) { if ($meta) {
$asset->addMetaFile($meta); $medium->addMetaFile($meta);
} }
} }
} }
/** /**
* Get asset by basename and extension. * Get medium by basename and extension.
* *
* @param string $filename * @param string $filename
* @param bool $create * @param bool $create
* @return Asset|null * @return Medium|null
*/ */
public function get($filename, $create = false) public function get($filename, $create = false)
{ {
@@ -78,8 +78,8 @@ class Assets extends Getters
/** @var Config $config */ /** @var Config $config */
$config = Registry::get('Config'); $config = Registry::get('Config');
// Check if asset type has been configured. // Check if medium type has been configured.
$params = $config->get("assets.{$ext}"); $params = $config->get("media.{$ext}");
if (!$params) { if (!$params) {
return null; return null;
} }
@@ -87,7 +87,7 @@ class Assets extends Getters
$filePath = $this->path . '/' . $filename; $filePath = $this->path . '/' . $filename;
$params += array( $params += array(
'type' => 'file', 'type' => 'file',
'thumb' => 'assets/thumb.png', 'thumb' => 'media/thumb.png',
'mime' => 'application/octet-stream', 'mime' => 'application/octet-stream',
'name' => $filename, 'name' => $filename,
'filename' => $filename, 'filename' => $filename,
@@ -108,16 +108,16 @@ class Assets extends Getters
} }
} }
$this->add(new Asset($params)); $this->add(new Medium($params));
} }
return isset($this->instances[$filename]) ? $this->instances[$filename] : null; return isset($this->instances[$filename]) ? $this->instances[$filename] : null;
} }
/** /**
* Get a list of all assets. * Get a list of all media.
* *
* @return array|Asset[] * @return array|Medium[]
*/ */
public function all() public function all()
{ {
@@ -125,9 +125,9 @@ class Assets extends Getters
} }
/** /**
* Get a list of all image assets. * Get a list of all image media.
* *
* @return array|Asset[] * @return array|Medium[]
*/ */
public function images() public function images()
{ {
@@ -135,9 +135,9 @@ class Assets extends Getters
} }
/** /**
* Get a list of all video assets. * Get a list of all video media.
* *
* @return array|Asset[] * @return array|Medium[]
*/ */
public function videos() public function videos()
{ {
@@ -145,9 +145,9 @@ class Assets extends Getters
} }
/** /**
* Get a list of all file assets. * Get a list of all file media.
* *
* @return array|Asset[] * @return array|Medium[]
*/ */
public function files() public function files()
{ {

View File

@@ -9,7 +9,7 @@ use Grav\Common\Registry;
use Gregwar\Image\Image as ImageFile; use Gregwar\Image\Image as ImageFile;
/** /**
* The Image asset holds information related to an individual image. These are then stored in the Assets object. * The Image medium holds information related to an individual image. These are then stored in the Media object.
* *
* @author RocketTheme * @author RocketTheme
* @license MIT * @license MIT
@@ -26,13 +26,13 @@ use Gregwar\Image\Image as ImageFile;
* @property string $mime * @property string $mime
* @property int $modified * @property int $modified
* *
* Asset can have up to 3 files: * Medium can have up to 3 files:
* - video.mov Asset file itself. * - video.mov Medium file itself.
* - video.mov.meta.yaml Metadata for the asset. * - video.mov.meta.yaml Metadata for the medium.
* - video.mov.thumb.jpg Thumbnail image for the asset. * - video.mov.thumb.jpg Thumbnail image for the medium.
* *
*/ */
class Asset extends Data class Medium extends Data
{ {
/** /**
* @var string * @var string
@@ -126,7 +126,7 @@ class Asset extends Data
} }
/** /**
* Returns <img> tag from the asset. * Returns <img> tag from the medium.
* *
* @param string $title * @param string $title
* @param string $class * @param string $class
@@ -146,7 +146,7 @@ class Asset extends Data
} }
/** /**
* Return HTML markup from the asset. * Return HTML markup from the medium.
* *
* @param string $title * @param string $title
* @param string $class * @param string $class
@@ -184,7 +184,7 @@ class Asset extends Data
} }
/** /**
* Return lightbox HTML for the asset. * Return lightbox HTML for the medium.
* *
* @param int $width * @param int $width
* @param int $height * @param int $height
@@ -198,7 +198,7 @@ class Asset extends Data
} }
/** /**
* Return link HTML for the asset. * Return link HTML for the medium.
* *
* @param int $width * @param int $width
* @param int $height * @param int $height
@@ -264,7 +264,7 @@ class Asset extends Data
} }
/** /**
* Gets asset image, resets image manipulation operations. * Gets medium image, resets image manipulation operations.
* *
* @param string $variable * @param string $variable
* @return $this * @return $this
@@ -284,7 +284,7 @@ class Asset extends Data
} }
/** /**
* Add meta file for the asset. * Add meta file for the medium.
* *
* @param $type * @param $type
* @return $this * @return $this

View File

@@ -52,7 +52,7 @@ class Page
protected $content; protected $content;
protected $raw_content; protected $raw_content;
protected $pagination; protected $pagination;
protected $assets; protected $media;
protected $title; protected $title;
protected $max_count; protected $max_count;
protected $menu; protected $menu;
@@ -316,7 +316,7 @@ class Page
$this->content = $content; $this->content = $content;
$this->assets(); $this->media();
} }
return $this->content; return $this->content;
@@ -348,17 +348,17 @@ class Page
if ($name == 'type') { if ($name == 'type') {
return basename($this->name(), '.md'); return basename($this->name(), '.md');
} }
if ($name == 'assets') { if ($name == 'media') {
return $this->assets()->all(); return $this->media()->all();
} }
if ($name == 'assets.file') { if ($name == 'media.file') {
return $this->assets()->files(); return $this->media()->files();
} }
if ($name == 'assets.video') { if ($name == 'media.video') {
return $this->assets()->videos(); return $this->media()->videos();
} }
if ($name == 'assets.image') { if ($name == 'media.image') {
return $this->assets()->images(); return $this->media()->images();
} }
$path = explode('.', $name); $path = explode('.', $name);
@@ -536,29 +536,29 @@ class Page
} }
/** /**
* Gets and sets the associated assets as found in the page folder. * Gets and sets the associated media as found in the page folder.
* *
* @param Assets $var Representation of associated assets. * @param Media $var Representation of associated media.
* @return Assets Representation of associated assets. * @return Media Representation of associated media.
*/ */
public function assets($var = null) public function media($var = null)
{ {
/** @var Cache $cache */ /** @var Cache $cache */
$cache = Registry::get('Cache'); $cache = Registry::get('Cache');
if ($var) { if ($var) {
$this->assets = $var; $this->media = $var;
} }
if ($this->assets === null) { if ($this->media === null) {
// Use cached assets if possible. // Use cached media if possible.
$assets_cache_id = md5('assets'.$this->id()); $media_cache_id = md5('media'.$this->id());
if (!$assets = $cache->fetch($assets_cache_id)) { if (!$media = $cache->fetch($media_cache_id)) {
$assets = new Assets($this->path()); $media = new Media($this->path());
$cache->save($assets_cache_id, $assets); $cache->save($media_cache_id, $media);
} }
$this->assets = $assets; $this->media = $media;
} }
return $this->assets; return $this->media;
} }
/** /**

View File

@@ -169,7 +169,7 @@ class Twig
$twig_vars = $this->twig_vars; $twig_vars = $this->twig_vars;
$twig_vars['page'] = $item; $twig_vars['page'] = $item;
$twig_vars['assets'] = $item->assets(); $twig_vars['media'] = $item->media();
$twig_vars['header'] = $item->header(); $twig_vars['header'] = $item->header();
// Get Twig template layout // Get Twig template layout