Skip to content

Commit

Permalink
Doxter 0.6.1
Browse files Browse the repository at this point in the history
* Fixes an issue caused by iconv() not being defined in some environments
* Fixes some deprecation issues and spacing
* Improves header parsing by generating slugs the craft way
* Improves dependency management
  • Loading branch information
selvinortiz committed Apr 6, 2014
1 parent 21d615f commit d0254c3
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 124 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
build
vendor
tests/report
tests/unstable.sh
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Lovingly crafted by [Selvin Ortiz][developer] for [Craft CMS][craft]

## Changes

### 0.6.1
* Fixes an issue caused by `iconv()` not being defined in some environments
* Fixes some deprecation issues and spacing
* Improves **header parsing** by generating slugs the _craft way_
* Improves dependency management

### 0.6.0
* Adds the `HeaderParser` class
* Adds the `ReferenceTagParser` class
Expand Down Expand Up @@ -71,4 +77,4 @@ Initial preview release
[readme]:https://github.com/selvinortiz/craft.doxter/blob/master/README.md "The Readme"
[refTags]:http://buildwithcraft.com/docs/reference-tags "Reference Tags"
[gfm]: https://help.github.com/articles/github-flavored-markdown "Github Flavored Markdown"
[zit]:https://github.com/selvinortiz/zit "Zit"
[zit]:https://github.com/selvinortiz/zit "Zit"
20 changes: 10 additions & 10 deletions DoxterPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace Craft;

/**
* Doxter @v0.6.0
* Doxter @v0.6.1
*
* Doxter is a markdown plugin designed to improve the way you write documentation
*
Expand Down Expand Up @@ -47,7 +47,7 @@ public function getName($real=false)

public function getVersion()
{
return '0.6.0';
return '0.6.1';
}

public function getDeveloper()
Expand Down Expand Up @@ -103,40 +103,40 @@ public function hasCpSection()
public function defineSettings()
{
return array(
/**
/*
* Whether recursive parsing should be enabled in parsers that support it
*/
'parseRecursively' => array(AttributeType::Bool, 'default' => true),

/**
/*
* Whether headers should be parsed and anchored
*/
'addHeaderAnchors' => array(AttributeType::Bool, 'default' => true),

/**
/*
* The headers that should be parsed and anchored if header parsing is enabled
*/
'addHeaderAnchorsTo' => array(AttributeType::String, 'default' => 'h1, h2, h3'),

/**
/*
* The snippet used to wrap fenced code blocks in {languageClass} {sourceCode}
*/
'codeBlockSnippet' => array(AttributeType::String,
'default' => '<pre><code data-language="language-{languageClass}">{sourceCode}</code></pre>',
'column' => ColumnType::Text
),

/**
/*
* Whether reference tags should be parsed {type:reference:property}
*/
'parseReferenceTags' => array(AttributeType::Bool, 'default' => true),

/**
/*
* Whether a tab with the name/alias should be shown in the CP nav
*/
'enableCpTab' => array(AttributeType::Bool, 'default' => false),

/**
/*
* The plugin alias to use in place of the name in the CP tab, plugin settings, etc.
*/
'pluginAlias' => array(AttributeType::String, 'default' => 'Doxter')
Expand Down Expand Up @@ -175,6 +175,6 @@ public function getCpSettingsUrl($append='')
{
function doxter()
{
return \SelvinOrtiz\Doxter\Di::getInstance();
return \SelvinOrtiz\Doxter\Doxter::getInstance();
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
![Doxter](resources/img/doxter.png)

# Doxter 0.6.0
# Doxter 0.6.1
Lovingly crafted by [Selvin Ortiz][developer] for [Craft CMS][craft]

**Doxter** is a markdown plugin designed to improve the way you write documentation.
It provides a minimalist textarea **fieldtype** with [editor behavior][behave], a toolbar for [reference tags][refTags], and [live preview][preview] support.
It also provides a **markdown parser** that supports [github flavor markdown][gfm], [reference tags][parseRefs] with _recursive parsing_ and _linkable headers_.
It provides a simple textarea **fieldtype** with [editor behavior][behave], a toolbar for [reference tags][refTags], and [live preview][preview] support.
It also provides a **markdown parser** that supports [github flavor markdown][gfm], [reference tags][parseRefs] with _recursive parsing_ and **linkable headers**.

## Installation
1. Download the [Official Release][release]
Expand Down Expand Up @@ -97,7 +97,7 @@ Doxter is open source software licensed under the [MIT license][license]

[craft]:http://buildwithcraft.com "Craft CMS"
[developer]:http://twitter.com/selvinortiz "@selvinortiz"
[release]:https://github.com/selvinortiz/craft.doxter/releases/download/v0.6.0/doxter.v0.6.0.zip "Official Release"
[release]:https://github.com/selvinortiz/craft.doxter/releases/download/v0.6.1/doxter.v0.6.1.zip "Official Release"
[refTags]:http://buildwithcraft.com/docs/reference-tags "Reference Tags"
[parseRefs]:http://buildwithcraft.com/docs/templating/filters#parseRefs "Reference Tag Filter"
[preview]:http://buildwithcraft.com/features/live-preview "Live Preview"
Expand Down
32 changes: 0 additions & 32 deletions library/src/SelvinOrtiz/Doxter/Di.php

This file was deleted.

46 changes: 27 additions & 19 deletions library/src/SelvinOrtiz/Doxter/Doxter.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
<?php
namespace SelvinOrtiz\Doxter;

use SelvinOrtiz\Zit\IZit;
use SelvinOrtiz\Zit\Zit;

class Doxter
class Doxter extends Zit
{
public function parse($source, array $params = array())
public function init()
{
$codeBlockSnippet = null;
$addHeaderAnchors = true;
$addHeaderAnchorsTo = array('h1', 'h2', 'h3');
$parseReferenceTags = true;
$parseReferenceTagsRecursively = true;

extract($params);
// Define parser dependencies
doxter()->stash('parser', new DoxterParser);
doxter()->stash('parsedown', \Parsedown::instance());
doxter()->stash('headerParser', new HeaderParser);
doxter()->stash('markdownParser', new MarkdownParser);
doxter()->stash('referenceTagParser', new ReferenceTagParser);
}

// By parsing reference tags first, we have a chance to parse md within them
if ($parseReferenceTags)
protected function pop($id, $args=array() )
{
try
{
$source = Di::getInstance()->referenceTagParser->parse($source, compact('parseReferenceTagsRecursively'));
return parent::pop($id, $args);
}

$source = Di::getInstance()->markdownParser->parse($source, compact('codeBlockSnippet'));

if ($addHeaderAnchors)
catch (\Exception $e)
{
$source = Di::getInstance()->headerParser->parse($source, compact('addHeaderAnchorsTo'));
throw new Exception\MissingDependencyException($id);
}
}
}


return $source;
/**
* A way to grab the dependency container within the Doxter namespace
*/
if (!function_exists('\\SelvinOrtiz\\Doxter\\doxter'))
{
function doxter()
{
return \SelvinOrtiz\Doxter\Doxter::getInstance();
}
}
31 changes: 31 additions & 0 deletions library/src/SelvinOrtiz/Doxter/DoxterParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace SelvinOrtiz\Doxter;

class DoxterParser extends Parser
{
public function parse($source, array $params = array())
{
$codeBlockSnippet = null;
$addHeaderAnchors = true;
$addHeaderAnchorsTo = array('h1', 'h2', 'h3');
$parseReferenceTags = true;
$parseReferenceTagsRecursively = true;

extract($params);

// By parsing reference tags first, we have a chance to parse md within them
if ($parseReferenceTags)
{
$source = doxter()->referenceTagParser->parse($source, compact('parseReferenceTagsRecursively'));
}

$source = doxter()->markdownParser->parse($source, compact('codeBlockSnippet'));

if ($addHeaderAnchors)
{
$source = doxter()->headerParser->parse($source, compact('addHeaderAnchorsTo'));
}

return $source;
}
}

This file was deleted.

20 changes: 5 additions & 15 deletions library/src/SelvinOrtiz/Doxter/HeaderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
/**
* Doxter Header Parser
*
* @package SelvinOrtiz
* @package SelvinOrtiz\Doxter
*/
class HeaderParser extends BaseParser
class HeaderParser extends Parser
{
/**
* Parses headers and adds anchors
*
* @param string $source
* @param array $params
*
* @return string
*/
public function parse($source=null, array $params=array())
Expand Down Expand Up @@ -48,18 +50,6 @@ protected function getHeaderExpression($headers)

protected function createSlug($title)
{
$slug = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
$locale = @setlocale(LC_CTYPE, 0);

@setlocale(LC_CTYPE, 'en_US.UTF-8');

$slug = iconv('UTF-8', 'ASCII//TRANSLIT', $slug);

$slug = preg_replace('/[^a-z0-9 ]+/i', '', $slug);
$slug = preg_replace('/\s+/', '-', $slug);

@setlocale(LC_CTYPE, $locale);

return strtolower($slug);
return \Craft\ElementHelper::createSlug($title);
}
}
4 changes: 2 additions & 2 deletions library/src/SelvinOrtiz/Doxter/MarkdownParser.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace SelvinOrtiz\Doxter;

class MarkdownParser extends BaseParser
class MarkdownParser extends Parser
{
protected $codeBlockSnippet;

Expand All @@ -11,7 +11,7 @@ public function parse($source=null, array $params=array())

extract($params);

$source = Di::getInstance()->parsedown->parse($source);
$source = doxter()->parsedown->parse($source);

if (empty($codeBlockSnippet))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php
namespace SelvinOrtiz\Doxter;

use SelvinOrtiz\Zit\IZit;

abstract class BaseParser implements ParserInterface
abstract class Parser
{
public function isValidString($subject)
{
Expand Down
7 changes: 0 additions & 7 deletions library/src/SelvinOrtiz/Doxter/ParserInterface.php

This file was deleted.

Loading

0 comments on commit d0254c3

Please sign in to comment.