-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2b9ed37
Showing
8 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
|
||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar install --dev | ||
|
||
script: phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "lollypopgr/picture-fill", | ||
"description": "", | ||
"authors": [ | ||
{ | ||
"name": "George Drakakis", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0", | ||
"illuminate/support": "4.1.*" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Lollypopgr\\PictureFill": "src/" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php namespace Lollypopgr\PictureFill; | ||
|
||
use Config; | ||
|
||
class PictureFill { | ||
|
||
private $ruleSet; | ||
private $imageFolder; | ||
protected static $instance; | ||
|
||
public function __construct(array $ruleSetName=null,$imageFolder=null){ | ||
|
||
$this->ruleSet = !is_null($ruleSetName) ?: Config::get('picture-fill::default') ; | ||
$this->imageFolder = $imageFolder; | ||
} | ||
|
||
|
||
/** | ||
* Create the boilerplate markup for | ||
* scottjehl/picturefill | ||
* | ||
* @param string $image | ||
* @param string $altText | ||
* @param array $ruleSet | ||
* @return string | ||
*/ | ||
public function responsiveImage($image,$altText,array $ruleSet=null){ | ||
|
||
$image = is_null($this->imageFolder) ? $image : $this->imageFolder.$image; | ||
|
||
$ruleSet = is_null($ruleSet) ? $this->ruleSet : $ruleSet; | ||
|
||
$output = '<span data-picture data-alt="'.$altText.'">'; | ||
$output .= '<span data-src="'.$image.'"></span>'; | ||
|
||
|
||
|
||
foreach($ruleSet as $rule){ | ||
|
||
$output .= '<span data-src="'.$this->buildSuffix($image,$rule[0]).'" data-media="'.$rule[1].'"></span>'; | ||
} | ||
|
||
$output .= '<noscript> | ||
<img src="'.$image.'" alt="'.$altText.'"> | ||
</noscript> | ||
</span>'; | ||
|
||
return $output; | ||
|
||
} | ||
|
||
|
||
/** | ||
* Build name by adding the suffix | ||
* @param string $image [original name] | ||
* @param string $extraname [extra name] | ||
* @return string [generated original+extra+extension] | ||
*/ | ||
private function buildSuffix($image,$extraname){ | ||
$extension_pos = strrpos($image, '.'); | ||
return substr($image, 0, $extension_pos) . $extraname . substr($image, $extension_pos); | ||
} | ||
|
||
/** | ||
* Set Rules | ||
* @param array $rules | ||
*/ | ||
public function set_ruleSet(array $rules){ | ||
$this->ruleSet = $rules; | ||
} | ||
|
||
/** | ||
* Get Rules | ||
* @return [type] | ||
*/ | ||
public function get_ruleSet(){ | ||
return $this->ruleSet; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Handle dynamic method calls | ||
* | ||
* @param string $name | ||
* @param array $args | ||
*/ | ||
public static function __callStatic($name,$args) | ||
{ | ||
$instance = static::$instance; | ||
if ( ! $instance) $instance = static::$instance = new static; | ||
if($name=="make"){ | ||
if(sizeof($args)>2){ | ||
|
||
$sizes = is_array($args[2]) ? $args[2] :null; | ||
|
||
}else{ | ||
$sizes = null; | ||
} | ||
|
||
return $instance->responsiveImage($args[0],$args[1],$sizes); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php namespace Lollypopgr\PictureFill; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class PictureFillServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
|
||
public function boot(){ | ||
$this->package('lollypopgr/picture-fill'); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
// Set default image names and media query rules | ||
|
||
return [ | ||
'default'=>[ | ||
["_small","(max-width: 640px)"], | ||
["_medium","(min-width: 641px)"], | ||
["_large","(min-width: 1025px)"], | ||
["_xlarge","(min-width: 1441px)"] | ||
|
||
] | ||
|
||
]; |
Empty file.