Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
drakakisgeo committed Feb 6, 2014
0 parents commit 2b9ed37
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
12 changes: 12 additions & 0 deletions .travis.yml
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
20 changes: 20 additions & 0 deletions composer.json
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"
}
18 changes: 18 additions & 0 deletions phpunit.xml
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>
106 changes: 106 additions & 0 deletions src/Lollypopgr/PictureFill/PictureFill.php
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);
}
}
}


38 changes: 38 additions & 0 deletions src/Lollypopgr/PictureFill/PictureFillServiceProvider.php
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();
}

}
14 changes: 14 additions & 0 deletions src/Lollypopgr/config/config.php
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 added tests/.gitkeep
Empty file.

0 comments on commit 2b9ed37

Please sign in to comment.