This repository has been archived by the owner on Jul 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Darren Belding
committed
Feb 10, 2017
0 parents
commit d7637cb
Showing
13 changed files
with
302 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 @@ | ||
COMPOSE_PROJECT_NAME=m2_meanbee_svghelper |
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 @@ | ||
/magento |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Meanbee | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,37 @@ | ||
# Magento 2 SVG Helper | ||
|
||
Simple module that provides a block level helper for reading in an SVG files source from a theme in Magento 2. | ||
|
||
## Installation | ||
|
||
Install this extension via Composer: | ||
|
||
``` | ||
composer config repositories.meanbee_svghelper vcs https://github.com/meanbee/magento2-svghelper | ||
composer require meanbee/magento2-svghelper | ||
``` | ||
|
||
## Development | ||
|
||
### Setting up a development environment | ||
|
||
A Docker development environment is included with the project: | ||
|
||
``` | ||
mkdir magento | ||
docker-compose up -d db # Allow a few seconds for the db to initalise | ||
docker-compose run --rm cli bash /src/setup.sh | ||
docker-compose up -d | ||
``` | ||
|
||
## Usage | ||
|
||
The SVGHelper is set as data on every block. This means that in your template you can call: | ||
|
||
```<?php echo $block->getData('svgHelper')->getViewSvg('pathtofile.svg') ?>``` | ||
|
||
or | ||
|
||
```<?php echo $block->getData('svgHelper')->getViewSvg('Magento_Module::pathtofile.svg') ?>``` | ||
|
||
This will output the raw contents of the svg file. |
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,33 @@ | ||
{ | ||
"name": "meanbee/magento2-svghelper", | ||
"description": "Magento 2 module that provides a block level helper for reading in an SVG files source from a theme", | ||
"type": "magento2-module", | ||
"version": "1.0.0", | ||
"license": [ | ||
"Commercial" | ||
], | ||
"repositories": { | ||
"magento": { | ||
"type": "composer", | ||
"url": "https://repo.magento.com/" | ||
} | ||
}, | ||
"require": { | ||
"magento/framework": "100.1.*", | ||
"psr/log": "~1.0" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Darren Belding", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"files": [ | ||
"src/registration.php" | ||
], | ||
"psr-4": { | ||
"Meanbee\\SVGHelper\\": "/src" | ||
} | ||
} | ||
} |
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,115 @@ | ||
version: "2" | ||
services: | ||
varnish: | ||
image: meanbee/magento2-varnish:latest | ||
hostname: m2-meanbee-svghelper.docker | ||
ports: | ||
- 80 | ||
environment: | ||
- VIRTUAL_HOST=m2-meanbee-svghelper.docker | ||
- VIRTUAL_PORT=80 | ||
- HTTPS_METHOD=noredirect | ||
- CERT_NAME=default | ||
links: | ||
- web | ||
|
||
web: | ||
image: meanbee/magento2-nginx:1.9 | ||
hostname: web.m2-meanbee-svghelper.docker | ||
ports: | ||
- 80 | ||
volumes_from: | ||
- appdata | ||
env_file: | ||
- ./magento.env | ||
links: | ||
- fpm | ||
|
||
fpm: | ||
image: meanbee/magento2-php:7.0-fpm | ||
hostname: fpm.m2-meanbee-svghelper.docker | ||
ports: | ||
- 9000 | ||
volumes_from: | ||
- appdata | ||
env_file: | ||
- ./magento.env | ||
environment: | ||
- ENABLE_SENDMAIL=true | ||
- PHP_ENABLE_XDEBUG | ||
links: | ||
- db | ||
|
||
cron: | ||
image: meanbee/magento2-php:7.0-cli | ||
hostname: cron.m2-meanbee-svghelper.docker | ||
command: run-cron | ||
volumes_from: | ||
- appdata | ||
env_file: | ||
- ./magento.env | ||
environment: | ||
- ENABLE_SENDMAIL=true | ||
links: | ||
- db | ||
|
||
cli: | ||
image: meanbee/magento2-php:7.0-cli | ||
volumes_from: | ||
- appdata | ||
volumes: | ||
- ~/.composer:/root/.composer | ||
env_file: | ||
- ./magento.env | ||
environment: | ||
- COMPOSER_HOME=/root/.composer | ||
- COMPOSER_ALLOW_SUPERUSER=1 | ||
- M2SETUP_INSTALL_DB=true | ||
- M2SETUP_VERSION=2.1.* | ||
- M2SETUP_USE_SAMPLE_DATA=true | ||
- M2SETUP_DB_HOST=db | ||
- M2SETUP_DB_NAME=magento2 | ||
- M2SETUP_DB_USER=magento2 | ||
- M2SETUP_DB_PASSWORD=magento2 | ||
- M2SETUP_BASE_URL=https://m2-meanbee-svghelper.docker/ | ||
- M2SETUP_BACKEND_FRONTNAME=admin | ||
- M2SETUP_ADMIN_FIRSTNAME=Admin | ||
- M2SETUP_ADMIN_LASTNAME=User | ||
- [email protected] | ||
- M2SETUP_ADMIN_USER=admin | ||
- M2SETUP_ADMIN_PASSWORD=password123 | ||
links: | ||
- db | ||
|
||
db: | ||
image: mariadb:10 | ||
ports: | ||
- 3306 | ||
volumes_from: | ||
- dbdata | ||
env_file: | ||
- ./magento.env | ||
environment: | ||
- MYSQL_ROOT_PASSWORD=magento2 | ||
- MYSQL_USER=magento2 | ||
- MYSQL_PASSWORD=magento2 | ||
- MYSQL_DATABASE=magento2 | ||
- TERM=dumb | ||
|
||
appdata: | ||
image: cweagans/bg-sync | ||
volumes: | ||
- /var/www/magento | ||
- .:/src | ||
environment: | ||
- SYNC_SOURCE=/var/www/magento | ||
- SYNC_DESTINATION=/src/magento | ||
- SYNC_VERBOSE=1 | ||
- SYNC_MAX_INOTIFY_WATCHES=64000 | ||
privileged: true | ||
restart: always | ||
|
||
dbdata: | ||
image: tianon/true | ||
volumes: | ||
- /var/lib/mysql |
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,2 @@ | ||
MAGENTO_RUN_MODE=developer | ||
PHP_MEMORY_LIMIT=2G |
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,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e # Exit on error | ||
|
||
# Install Magento 2 if necessary | ||
magento-installer | ||
|
||
cd $MAGENTO_ROOT | ||
|
||
# Add the extension via Composer | ||
composer config repositories.meanbee_svghelper '{"type": "path", "url": "/src", "options": {"symlink": true}}' | ||
|
||
composer require "meanbee/magento2-svghelper" "@dev" | ||
|
||
# Workaround for Magento only allowing template paths within the install root | ||
ln -s /src $MAGENTO_ROOT/src | ||
|
||
# Enable the extension and run migrations | ||
magento-command module:enable Meanbee_SVGHelper | ||
magento-command setup:upgrade | ||
magento-command setup:static-content:deploy | ||
magento-command cache:flush |
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,35 @@ | ||
<?php | ||
|
||
namespace Meanbee\SVGHelper\Helper; | ||
|
||
use \Magento\Framework\App\Helper\AbstractHelper; | ||
|
||
class Data extends AbstractHelper | ||
{ | ||
protected $_assetSource; | ||
protected $_assetRepository; | ||
|
||
public function __construct( | ||
\Magento\Framework\App\Helper\Context $context, | ||
\Magento\Framework\View\Asset\Source $assetSource, | ||
\Magento\Framework\View\Asset\Repository $assetRepository | ||
) | ||
{ | ||
$this->_assetSource = $assetSource; | ||
$this->_assetRepository = $assetRepository; | ||
|
||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* @param $path | ||
* | ||
* @return bool|string | ||
*/ | ||
public function getViewSvg($path) | ||
{ | ||
$file = $this->_assetRepository->createAsset($path); | ||
return $this->_assetSource->getContent($file); | ||
} | ||
|
||
} |
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 @@ | ||
<?php | ||
|
||
namespace Meanbee\SVGHelper\Plugin; | ||
|
||
class BlockPlugin | ||
{ | ||
protected $_svgHelper; | ||
|
||
public function __construct( | ||
\Meanbee\SVGHelper\Helper\Data $svgHelper | ||
) | ||
{ | ||
$this->_svgHelper = $svgHelper; | ||
} | ||
|
||
public function afterCreateBlock($subject, $result) | ||
{ | ||
return $result->setData('svgHelper', $this->_svgHelper); | ||
} | ||
} |
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,5 @@ | ||
<config> | ||
<type name="Magento\Framework\View\Element\BlockFactory"> | ||
<plugin name="set_svg_helper" type="Meanbee\SVGHelper\Plugin\BlockPlugin" sortOrder="1" /> | ||
</type> | ||
</config> |
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 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Meanbee_SVGHelper" setup_version="1.0.0"/> | ||
</config> |
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,7 @@ | ||
<?php | ||
|
||
\Magento\Framework\Component\ComponentRegistrar::register( | ||
\Magento\Framework\Component\ComponentRegistrar::MODULE, | ||
'Meanbee_SVGHelper', | ||
__DIR__ | ||
); |