Skip to content

Commit

Permalink
Initial File Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fractorr authored May 23, 2017
1 parent d0b3dc6 commit 5abd60e
Show file tree
Hide file tree
Showing 18 changed files with 752 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Svg Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.0 - 2017.05.23
### Added
- Initial release
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017 Trevor Orr

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.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
# svg
# Svg plugin for Craft CMS 3.x

Convert SVG Images

![Screenshot](resources/img/plugin-logo.png)

## Installation

To install Svg, follow these steps:

1. Download & unzip the file and place the `svg` directory into your `craft/plugins` directory
2. -OR- do a `git clone https://github.com/fractorr/svg.git` directly into your `craft/plugins` folder. You can then update it with `git pull`
3. -OR- install with Composer via `composer require fractorr/svg`
4. Install plugin in the Craft Control Panel under Settings > Plugins
5. The plugin folder should be named `svg` for Craft to see it. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads.

Svg works on Craft 3.x.

## Svg Overview

-Insert text here-

## Configuring Svg

-Insert text here-

## Using Svg

-Insert text here-

## Svg Roadmap

Some things to do, and ideas for potential features:

* Release it

Brought to you by [Trevor Orr](http://www.fractorr.com)
50 changes: 50 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "fractorr/svg",
"description": "Convert SVG Images",
"type": "craft-plugin",
"version": "1.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"svg"
],
"support": {
"docs": "https://github.com/fractorr/svg/blob/master/README.md",
"issues": "https://github.com/fractorr/svg/issues"
},
"license": "MIT",
"authors": [
{
"name": "Trevor Orr",
"homepage": "http://www.fractorr.com"
}
],
"require": {
"craftcms/cms": "~3.0.0-beta.1"
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"autoload": {
"psr-4": {
"fractorr\\svg\\": "src/"
}
},
"extra": {
"name": "Svg",
"handle": "svg",
"schemaVersion": "1.0.0",
"hasCpSettings": true,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/fractorr/svg/master/CHANGELOG.md",
"components": {
"svgService": "fractorr\\svg\\services\\SvgService"
},
"class": "fractorr\\svg\\Svg"
}
}
Binary file added resources/img/plugin-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
151 changes: 151 additions & 0 deletions src/Svg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php
/**
* Svg plugin for Craft CMS 3.x
*
* Convert SVG Images
*
* @link http://www.fractorr.com
* @copyright Copyright (c) 2017 Trevor Orr
*/

namespace fractorr\svg;

use fractorr\svg\services\SvgService as SvgServiceService;
use fractorr\svg\variables\SvgVariable;
use fractorr\svg\models\Settings;

use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;

use yii\base\Event;

/**
* Craft plugins are very much like little applications in and of themselves. We’ve made
* it as simple as we can, but the training wheels are off. A little prior knowledge is
* going to be required to write a plugin.
*
* For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL,
* as well as some semi-advanced concepts like object-oriented programming and PHP namespaces.
*
* https://craftcms.com/docs/plugins/introduction
*
* @author Trevor Orr
* @package Svg
* @since 1.0.0
*
* @property SvgServiceService $svgService
*/
class Svg extends Plugin
{
// Static Properties
// =========================================================================

/**
* Static property that is an instance of this plugin class so that it can be accessed via
* Svg::$plugin
*
* @var Svg
*/
public static $plugin;

// Public Methods
// =========================================================================

/**
* Set our $plugin static property to this class so that it can be accessed via
* Svg::$plugin
*
* Called after the plugin class is instantiated; do any one-time initialization
* here such as hooks and events.
*
* If you have a '/vendor/autoload.php' file, it will be loaded for you automatically;
* you do not need to load it in your init() method.
*
*/
public function init()
{
parent::init();
self::$plugin = $this;

// Do something after we're installed
Event::on(
Plugins::className(),
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function (PluginEvent $event) {
if ($event->plugin === $this) {
// We were just installed
}
}
);

/**
* Logging in Craft involves using one of the following methods:
*
* Craft::trace(): record a message to trace how a piece of code runs. This is mainly for development use.
* Craft::info(): record a message that conveys some useful information.
* Craft::warning(): record a warning message that indicates something unexpected has happened.
* Craft::error(): record a fatal error that should be investigated as soon as possible.
*
* Unless `devMode` is on, only Craft::warning() & Craft::error() will log to `craft/storage/logs/web.log`
*
* It's recommended that you pass in the magic constant `__METHOD__` as the second parameter, which sets
* the category to the method (prefixed with the fully qualified class name) where the constant appears.
*
* To enable the Yii debug toolbar, go to your user account in the AdminCP and check the
* [] Show the debug toolbar on the front end & [] Show the debug toolbar on the Control Panel
*
* http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html
*/
Craft::info(
Craft::t(
'svg',
'{name} plugin loaded',
['name' => $this->name]
),
__METHOD__
);
}

/**
* Returns the component definition that should be registered on the
* [[\craft\web\twig\variables\CraftVariable]] instance for this plugin’s handle.
*
* @return mixed|null The component definition to be registered.
* It can be any of the formats supported by [[\yii\di\ServiceLocator::set()]].
*/
public function defineTemplateComponent()
{
return SvgVariable::class;
}

// Protected Methods
// =========================================================================

/**
* Creates and returns the model used to store the plugin’s settings.
*
* @return \craft\base\Model|null
*/
protected function createSettingsModel()
{
return new Settings();
}

/**
* Returns the rendered settings HTML, which will be inserted into the content
* block on the settings page.
*
* @return string The rendered settings HTML
*/
protected function settingsHtml(): string
{
return Craft::$app->view->renderTemplate(
'svg/settings',
[
'settings' => $this->getSettings()
]
);
}
}
65 changes: 65 additions & 0 deletions src/assetbundles/svg/SvgAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Svg plugin for Craft CMS 3.x
*
* Convert SVG Images
*
* @link http://www.fractorr.com
* @copyright Copyright (c) 2017 Trevor Orr
*/

namespace fractorr\svg\assetbundles\Svg;

use Craft;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

/**
* SvgAsset AssetBundle
*
* AssetBundle represents a collection of asset files, such as CSS, JS, images.
*
* Each asset bundle has a unique name that globally identifies it among all asset bundles used in an application.
* The name is the [fully qualified class name](http://php.net/manual/en/language.namespaces.rules.php)
* of the class representing it.
*
* An asset bundle can depend on other asset bundles. When registering an asset bundle
* with a view, all its dependent asset bundles will be automatically registered.
*
* http://www.yiiframework.com/doc-2.0/guide-structure-assets.html
*
* @author Trevor Orr
* @package Svg
* @since 1.0.0
*/
class SvgAsset extends AssetBundle
{
// Public Methods
// =========================================================================

/**
* Initializes the bundle.
*/
public function init()
{
// define the path that your publishable resources live
$this->sourcePath = "@fractorr/svg/assetbundles/svg/dist";

// define the dependencies
$this->depends = [
CpAsset::class,
];

// define the relative path to CSS/JS files that should be registered with the page
// when this asset bundle is registered
$this->js = [
'js/Svg.js',
];

$this->css = [
'css/Svg.css',
];

parent::init();
}
}
11 changes: 11 additions & 0 deletions src/assetbundles/svg/dist/css/Svg.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Svg plugin for Craft CMS
*
* Svg CSS
*
* @author Trevor Orr
* @copyright Copyright (c) 2017 Trevor Orr
* @link http://www.fractorr.com
* @package Svg
* @since 1.0.0
*/
52 changes: 52 additions & 0 deletions src/assetbundles/svg/dist/img/Svg-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5abd60e

Please sign in to comment.