aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2014-06-22 13:40:55 +0200
committerVictor Häggqvist <[email protected]>2014-06-22 13:40:55 +0200
commit61a021a728e3dfa7b452b1884188780e6dcae01e (patch)
tree63e1a1d6dc15228e9e1cf346811881f8e32c08f4
init
-rw-r--r--.gitignore6
-rw-r--r--_build/build.config.php18
-rw-r--r--_build/build.transport.php106
-rw-r--r--_build/data/transport.snippets.php23
-rw-r--r--composer.json17
-rw-r--r--composer.lock65
-rw-r--r--core/components/parsedown/docs/changelog.txt5
-rw-r--r--core/components/parsedown/docs/license.txt21
-rw-r--r--core/components/parsedown/docs/readme.txt18
-rw-r--r--core/components/parsedown/elements/snippets/snippet.parsedown.php50
-rw-r--r--core/components/parsedown/model/parsedown/parsedownmodx.class.php81
11 files changed, 410 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3a693c9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+composer.phar
+vendor/
+
+# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
+# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
+# composer.lock
diff --git a/_build/build.config.php b/_build/build.config.php
new file mode 100644
index 0000000..45b3cef
--- /dev/null
+++ b/_build/build.config.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * parse it
+ *
+ * @package parsedown
+ * @subpackage build
+ */
+define('MODX_BASE_PATH', '/vagrant/modx/');
+define('MODX_CORE_PATH', MODX_BASE_PATH . 'core/');
+define('MODX_MANAGER_PATH', MODX_BASE_PATH . 'manager/');
+define('MODX_CONNECTORS_PATH', MODX_BASE_PATH . 'connectors/');
+define('MODX_ASSETS_PATH', MODX_BASE_PATH . 'assets/');
+
+define('MODX_BASE_URL','/modx/');
+/* define('MODX_CORE_URL', MODX_BASE_URL . 'core/'); */ /* There isn't a core URL!! */
+define('MODX_MANAGER_URL', MODX_BASE_URL . 'manager/');
+define('MODX_CONNECTORS_URL', MODX_BASE_URL . 'connectors/');
+define('MODX_ASSETS_URL', MODX_BASE_URL . 'assets/');
diff --git a/_build/build.transport.php b/_build/build.transport.php
new file mode 100644
index 0000000..837b18b
--- /dev/null
+++ b/_build/build.transport.php
@@ -0,0 +1,106 @@
+<?php
+/**
+ * Parsedown build script
+ *
+ * @author Victor Häggqvist <[email protected]>
+ * @copyright Copyright 2014, Victor Häggqvist
+ * @package parsedown
+ * @subpackage build
+ */
+$tstart = explode(' ', microtime());
+$tstart = $tstart[1] + $tstart[0];
+set_time_limit(0);
+
+/* define package names */
+define('PKG_NAME','Parsedown');
+define('PKG_NAME_LOWER','parsedown');
+define('PKG_VERSION','0.1.0');
+define('PKG_RELEASE','beta');
+
+/* define build paths */
+$root = dirname(dirname(__FILE__)).'/';
+$sources = array(
+ 'root' => $root,
+ 'build' => $root . '_build/',
+ 'data' => $root . '_build/data/',
+ //'resolvers' => $root . '_build/resolvers/',
+ 'elements' => $root.'core/components/'.PKG_NAME_LOWER.'/elements/',
+
+ 'source_core' => $root.'core/components/'.PKG_NAME_LOWER,
+ 'docs' => $root.'core/components/'.PKG_NAME_LOWER.'/docs/',
+ // 'lexicon' => $root . 'core/components/'.PKG_NAME_LOWER.'/lexicon/',
+);
+unset($root);
+
+/* override with your own defines here (see build.config.sample.php) */
+require_once $sources['build'] . 'build.config.php';
+require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
+
+$modx= new modX();
+$modx->initialize('mgr');
+$modx->setLogLevel(modX::LOG_LEVEL_INFO);
+$modx->setLogTarget('ECHO');
+
+$modx->loadClass('transport.modPackageBuilder','',false, true);
+$builder = new modPackageBuilder($modx);
+$builder->createPackage(PKG_NAME_LOWER,PKG_VERSION,PKG_RELEASE);
+$builder->registerNamespace(PKG_NAME_LOWER,false,true,'{core_path}components/'.PKG_NAME_LOWER.'/');
+
+/* create category */
+$category= $modx->newObject('modCategory');
+$category->set('id',1);
+$category->set('category',PKG_NAME);
+
+/* add snippets */
+$modx->log(modX::LOG_LEVEL_INFO,'Packaging in snippets...');
+$snippets = include $sources['data'].'transport.snippets.php';
+if (empty($snippets)) $modx->log(modX::LOG_LEVEL_ERROR,'Could not package in snippets.');
+$category->addMany($snippets);
+
+
+/* create category vehicle */
+$attr = array(
+ xPDOTransport::UNIQUE_KEY => 'category',
+ xPDOTransport::PRESERVE_KEYS => false,
+ xPDOTransport::UPDATE_OBJECT => true,
+ xPDOTransport::RELATED_OBJECTS => true,
+ xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
+ 'Snippets' => array(
+ xPDOTransport::PRESERVE_KEYS => false,
+ xPDOTransport::UPDATE_OBJECT => true,
+ xPDOTransport::UNIQUE_KEY => 'name',
+ ),
+ ),
+);
+$vehicle = $builder->createVehicle($category,$attr);
+
+$modx->log(modX::LOG_LEVEL_INFO,'Adding file resolvers to category...');
+
+$vehicle->resolve('file',array(
+ 'source' => $sources['source_core'],
+ 'target' => "return MODX_CORE_PATH . 'components/';",
+));
+$builder->putVehicle($vehicle);
+
+
+
+/* now pack in the license file, readme and setup options */
+$modx->log(modX::LOG_LEVEL_INFO,'Adding package attributes and setup options...');
+$builder->setPackageAttributes(array(
+ 'license' => file_get_contents($sources['docs'] . 'license.txt'),
+ 'readme' => file_get_contents($sources['docs'] . 'readme.txt'),
+ 'changelog' => file_get_contents($sources['docs'] . 'changelog.txt'),
+ /*'setup-options' => array(
+ 'source' => $sources['build'].'setup.options.php',
+ ),*/
+));
+
+/* zip up package */
+$modx->log(modX::LOG_LEVEL_INFO,'Packing up transport package zip...');
+$builder->pack();
+
+$tend= explode(" ", microtime());
+$tend= $tend[1] + $tend[0];
+$totalTime= sprintf("%2.4f s",($tend - $tstart));
+$modx->log(modX::LOG_LEVEL_INFO,"\nPackage Built.\nExecution time: {$totalTime}\n");
+exit ();
diff --git a/_build/data/transport.snippets.php b/_build/data/transport.snippets.php
new file mode 100644
index 0000000..b9548d6
--- /dev/null
+++ b/_build/data/transport.snippets.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * @package parsedown
+ * @subpackage build
+ */
+function getSnippetContent($filename) {
+ $o = file_get_contents($filename);
+ $o = trim(str_replace(array('<?php','?>'),'',$o));
+ return $o;
+}
+
+$snippets = array();
+
+$snippets[1] = $modx->newObject('modSnippet');
+$snippets[1]->fromArray(array(
+ 'id' => 1,
+ 'name' => 'Parsedown',
+ 'description' => 'A markdown parser with GFM support',
+ 'snippet' => getSnippetContent($sources['elements'].'snippets/snippet.parsedown.php'),
+),'',true,true);
+
+return $snippets;
+
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..dd61198
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,17 @@
+{
+ "name": "snilius/mod-parsedown",
+ "description": "Parsedown packaged for MODx",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Victor Häggqvist",
+ "email": "[email protected]"
+ }
+ ],
+ "require": {
+ "erusev/parsedown": "1.0.1"
+ },
+ "config": {
+ "vendor-dir": "core/components/parsedown/model/vendor"
+ }
+}
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..efeb5e2
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,65 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
+ ],
+ "hash": "a1134e325c5b6ff60517022018d9cf69",
+ "packages": [
+ {
+ "name": "erusev/parsedown",
+ "version": "1.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/erusev/parsedown.git",
+ "reference": "d24439ada0704948deef0d3eda2ea20fd8db1747"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/erusev/parsedown/zipball/d24439ada0704948deef0d3eda2ea20fd8db1747",
+ "reference": "d24439ada0704948deef0d3eda2ea20fd8db1747",
+ "shasum": ""
+ },
+ "type": "library",
+ "autoload": {
+ "psr-0": {
+ "Parsedown": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Emanuil Rusev",
+ "email": "[email protected]",
+ "homepage": "http://erusev.com"
+ }
+ ],
+ "description": "Parser for Markdown.",
+ "homepage": "http://parsedown.org",
+ "keywords": [
+ "markdown",
+ "parser"
+ ],
+ "time": "2014-05-21 20:20:46"
+ }
+ ],
+ "packages-dev": [
+
+ ],
+ "aliases": [
+
+ ],
+ "minimum-stability": "stable",
+ "stability-flags": [
+
+ ],
+ "platform": [
+
+ ],
+ "platform-dev": [
+
+ ]
+}
diff --git a/core/components/parsedown/docs/changelog.txt b/core/components/parsedown/docs/changelog.txt
new file mode 100644
index 0000000..baea53b
--- /dev/null
+++ b/core/components/parsedown/docs/changelog.txt
@@ -0,0 +1,5 @@
+Changelog for Parsedown integration into MODx Revolution.
+
+Parsedown 0.1.0
+====================================
+- MODx snippet wrapper for Parsedown
diff --git a/core/components/parsedown/docs/license.txt b/core/components/parsedown/docs/license.txt
new file mode 100644
index 0000000..5e0fc21
--- /dev/null
+++ b/core/components/parsedown/docs/license.txt
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Victor Häggqvist
+
+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.
diff --git a/core/components/parsedown/docs/readme.txt b/core/components/parsedown/docs/readme.txt
new file mode 100644
index 0000000..cacddd1
--- /dev/null
+++ b/core/components/parsedown/docs/readme.txt
@@ -0,0 +1,18 @@
+--------------------
+Extra: Parsedown
+--------------------
+Version: 0.1.0
+Created: 2014-06-21
+Since: 2014-06-21
+Author: Victor Häggqvist <[email protected]>
+Source: https://github.com/victorhaggqvist/parsedown-modx
+License: MIT
+Creadits: Emanuil Rusev (https://github.com/erusev) Creator of Parsedown (https://github.com/erusev/parsedown)
+
+This Extra provides a snippet [[Parsedown]] which is a wrapper for Parsedown (https://github.com/erusev/parsedown) packaged for easy use in MODx.
+
+Parsedown (PHP lib) is a parser for Markdown with support for GFM (GitHub Flavored Markdown)
+
+USAGE
+
+[[*content:Parsedown]]
diff --git a/core/components/parsedown/elements/snippets/snippet.parsedown.php b/core/components/parsedown/elements/snippets/snippet.parsedown.php
new file mode 100644
index 0000000..7c363bb
--- /dev/null
+++ b/core/components/parsedown/elements/snippets/snippet.parsedown.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Parsedown
+ *
+ * @author Victor Häggqvist <[email protected]>
+ * @copyright Copyright 2014, Victor Häggqvist
+ *
+ * DESCRIPTION
+ *
+ * This snippet is Parsedown (https://github.com/erusev/parsedown) packaged for easy use in MODx.
+ * Parsedown is a parser for Markdown in PHP with support for GFM (GitHub Flavored Markdown)
+ *
+ * USAGE
+ *
+ * [[*content:Parsedown]]
+ *
+ * PHP version 5
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014 Victor Häggqvist
+ *
+ * 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.
+ */
+$corePath = $modx->getOption('parsedown.core_path', null, $modx->getOption('core_path').'components/parsedown/');
+
+require $corePath.'model/vendor/erusev/parsedown/Parsedown.php';
+
+$parsedownmodx = $modx->getService('parsedownmodx', 'ParsedownMODx', $corePath.'model/parsedown/', $scriptProperties);
+if (!($parsedownmodx instanceof ParsedownMODx)) return '';
+
+$html = $parsedownmodx->parseText($input);
+
+return $html;
diff --git a/core/components/parsedown/model/parsedown/parsedownmodx.class.php b/core/components/parsedown/model/parsedown/parsedownmodx.class.php
new file mode 100644
index 0000000..2c04b1c
--- /dev/null
+++ b/core/components/parsedown/model/parsedown/parsedownmodx.class.php
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * ParsedownMODx - A MODx Parsedown wrapper
+ *
+ * PHP version 5
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014 Victor Häggqvist
+ *
+ * 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.
+ *
+ * @author Victor Häggqvist <[email protected]>
+ * @copyright Copyright 2014, Victor Häggqvist
+ * @package parsedown
+ * @subpackage core
+ */
+
+class ParsedownMODx {
+
+ /**
+ * A modX instance
+ * @var modX (Object)
+ */
+ public $modx;
+
+ /**
+ * Array of config stuff
+ * @var array
+ */
+ public $config = array();
+
+ /**
+ * Parsedown instance
+ * @var Parsedown (Object)
+ */
+ private $parsedown;
+
+ function __construct(modX &$modx,array $config = array()) {
+ $this->modx = &$modx;
+
+ $basePath = $this->modx->getOption('parsedownmodx.core_path', $config,$this->modx->getOption('core_path').'components/parsedownmodx/');
+ $assetsUrl = $this->modx->getOption('parsedownmodx.assets_url', $config,$this->modx->getOption('assets_url').'components/parsedownmodx/');
+ $this->config = array_merge(array(
+ 'basePath' => $basePath,
+ 'corePath' => $basePath,
+ 'modelPath' => $basePath.'model/',
+ 'processorsPath' => $basePath.'processors/',
+ 'templatesPath' => $basePath.'templates/',
+ 'chunksPath' => $basePath.'elements/chunks/',
+ 'jsUrl' => $assetsUrl.'js/',
+ 'cssUrl' => $assetsUrl.'css/',
+ 'assetsUrl' => $assetsUrl,
+ 'connectorUrl' => $assetsUrl.'connector.php',
+ ), $config);
+
+ $this->parsedown = new Parsedown();
+ }
+
+ public function parseText($text) {
+ return $this->parsedown->text($text);
+ }
+}
+?>