Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
marionnewlevant committed Mar 17, 2016
1 parent 3b9d754 commit 3b0d53e
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# MN Eager plugin for Craft CMS

access data that may or may not have been eager-loaded

## Installation

To install MN Eager, follow these steps:

1. Download & unzip the file and place the `mneager` directory into your `craft/plugins` directory
2. Install plugin in the Craft Control Panel under Settings > Plugins

MN Eager works on Craft 2.4.x, Craft 2.5.x., and Craft 2.6.x

## MN Eager Overview

Simplify fetching of fields in an environment where they may have been [Eager Loaded](https://craftcms.com/docs/templating/eager-loading-elements)

## Using MN Eager

`{% set image = craft.mnEager.first(entry.assetsField) %}` will set `image` to the first item in `entry.assetsField` (or `null`) whether or not `assetsField` has been [eager loaded](https://craftcms.com/docs/templating/eager-loading-elements).

`{% set images = craft.mnEager.find(entry.assetsField) %}` will set `images` to an array of items whether or not `assetsField` has been [eager loaded](https://craftcms.com/docs/templating/eager-loading-elements).

You may find this especially useful in writing twig [macros](http://twig.sensiolabs.org/doc/tags/macro.html) which are agnositic as to whether a field has been eager loaded.

## MN Eager Changelog

### 1.0.0 -- 2016.03.16

* Initial release

Brought to you by [Marion Newlevant](http://marion.newlevant.com)
116 changes: 116 additions & 0 deletions mneager/MnEagerPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/**
* MN Eager plugin for Craft CMS
*
* access data that may or may not have been eager-loaded
*
*
* @author Marion Newlevant
* @copyright Copyright (c) 2016 Marion Newlevant
* @link http://marion.newlevant.com
* @package MnEager
* @since 1.0.0
*/

namespace Craft;

class MnEagerPlugin extends BasePlugin
{
/**
* Returns the user-facing name.
*
* @return mixed
*/
public function getName()
{
return Craft::t('MN Eager');
}

/**
* Plugins can have descriptions of themselves displayed on the Plugins page by adding a getDescription() method
* on the primary plugin class:
*
* @return mixed
*/
public function getDescription()
{
return Craft::t('access data that may or may not have been eager-loaded');
}

/**
* Plugins can have links to their documentation on the Plugins page by adding a getDocumentationUrl() method on
* the primary plugin class:
*
* @return string
*/
public function getDocumentationUrl()
{
return 'https://github.com/marionnewlevant/craft-mn_eager/blob/master/README.md';
}

/**
* Plugins can now take part in Craft’s update notifications, and display release notes on the Updates page, by
* providing a JSON feed that describes new releases, and adding a getReleaseFeedUrl() method on the primary
* plugin class.
*
* @return string
*/
public function getReleaseFeedUrl()
{
return 'https://raw.githubusercontent.com/marionnewlevant/craft-mn_eager/master/releases.json';
}

/**
* Returns the version number.
*
* @return string
*/
public function getVersion()
{
return '1.0.0';
}

/**
* As of Craft 2.5, Craft no longer takes the whole site down every time a plugin’s version number changes, in
* case there are any new migrations that need to be run. Instead plugins must explicitly tell Craft that they
* have new migrations by returning a new (higher) schema version number with a getSchemaVersion() method on
* their primary plugin class:
*
* @return string
*/
public function getSchemaVersion()
{
return '1.0.0';
}

/**
* Returns the developer’s name.
*
* @return string
*/
public function getDeveloper()
{
return 'Marion Newlevant';
}

/**
* Returns the developer’s website URL.
*
* @return string
*/
public function getDeveloperUrl()
{
return 'http://marion.newlevant.com';
}

/**
* Returns whether the plugin should get its own tab in the CP header.
*
* @return bool
*/
public function hasCpSection()
{
return false;
}

}
52 changes: 52 additions & 0 deletions mneager/resources/icon-mask.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions mneager/resources/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions mneager/variables/MnEagerVariable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* MN Eager plugin for Craft CMS
*
* MN Eager Variable
*
* @author Marion Newlevant
* @copyright Copyright (c) 2016 Marion Newlevant
* @link http://marion.newlevant.com
* @package MnEagerFetch
* @since 1.0.0
*/

namespace Craft;

class MnEagerVariable
{
public function first($stuff)
{
if (is_array($stuff))
{
return (count($stuff) ? $stuff[0] : null);
} else {
return $stuff->first();
}
}

public function find($stuff)
{
if (is_array($stuff))
{
return ($stuff);
} else {
return $stuff->find();
}
}
}
10 changes: 10 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"version": "1.0.0",
"downloadUrl": "https://github.com/marionnewlevant/craft-mn_eager/mneagerfetch/archive/master.zip",
"date": "2016-03-16T23:45:43.282Z",
"notes": [
"[Added] Initial release"
]
}
]

0 comments on commit 3b0d53e

Please sign in to comment.