Skip to content

Commit

Permalink
init code for the markdown field
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsekaean committed Apr 18, 2015
1 parent 1dfb8ac commit 37408e4
Show file tree
Hide file tree
Showing 9 changed files with 1,713 additions and 0 deletions.
16 changes: 16 additions & 0 deletions _config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Created by Nivanka Fonseka ([email protected]).
* User: nivankafonseka
* Date: 4/18/15
* Time: 11:21 AM
* To change this template use File | Settings | File Templates.
*/

$strMarkDownPath = dirname(__FILE__);
require_once($strMarkDownPath . '/thirdparty/parsedown/Parsedown.php');

if(!defined('MARKDOWN_BASE')){
$strBase = substr(str_replace(BASE_PATH, '', $strMarkDownPath), 1);
define('MARKDOWN_BASE', $strBase);
}
Empty file added _config/config.yml
Empty file.
19 changes: 19 additions & 0 deletions code/Fields/MarkdownEditorField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Created by Nivanka Fonseka ([email protected]).
* User: nivankafonseka
* Date: 4/18/15
* Time: 11:12 AM
* To change this template use File | Settings | File Templates.
*/

class MarkdownEditorField extends TextareaField {

protected $rows = 30;

function Field($properties = array()){
Requirements::css(MARKDOWN_BASE . '/css/MarkdownEditorField.css');
return parent::Field($properties);
}

}
131 changes: 131 additions & 0 deletions code/Model/MarkdownField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
/**
* Created by Nivanka Fonseka ([email protected]).
* User: nivankafonseka
* Date: 4/18/15
* Time: 11:11 AM
* To change this template use File | Settings | File Templates.
*/

class MarkdownField extends Text {

private static $escape_type = 'xml';

private static $casting = array(
"AbsoluteLinks" => "HTMLText",
"BigSummary" => "HTMLText",
"ContextSummary" => "HTMLText",
"FirstParagraph" => "HTMLText",
"FirstSentence" => "HTMLText",
"LimitCharacters" => "HTMLText",
"LimitSentences" => "HTMLText",
"Lower" => "HTMLText",
"LowerCase" => "HTMLText",
"Summary" => "HTMLText",
"Upper" => "HTMLText",
"UpperCase" => "HTMLText",
'EscapeXML' => 'HTMLText',
'LimitWordCount' => 'HTMLText',
'LimitWordCountXML' => 'HTMLText',
'NoHTML' => 'Text',
);

private $parsedContent;


/**
* @return string
* parse contents of the markdown field to tempates
*/
function ParseMarkdown($bCache = true, $strValue = ''){
if($bCache && $this->parsedContent)
return $this->parsedContent;

$shortCodeParser = ShortcodeParser::get_active();
$strParsed = $shortCodeParser->parse(!empty($strValue) ? $strValue : $this->value);

$parseDown = new Parsedown();
$strParsed = $parseDown->text($strParsed);

if($bCache)
$this->parsedContent = $strParsed;

return $strParsed;
}



/**
* @return string
*/
public function forTemplate() {
return $this->ParseMarkdown();
}


/**
* @return string
*/
public function __toString() {
return (string)$this->value;
}

/**
* @param null $title
* @param null $params
* @return FormField|MarkdownEditorField|NullableField|TextareaField
*/
public function scaffoldFormField($title = null, $params = null) {
return new MarkdownEditorField($this->name, $title);
}


/**
* @param null $title
* @param null $params
* @return FormField|TextField
*/
public function scaffoldSearchField($title = null, $params = null) {
return new TextField($this->name, $title);
}


/**
* @return string
*/
public function NoHTML(){
return strip_tags($this->ParseMarkdown());
}

/**
* @return string
*/
public function Upper(){
$strValue = strtoupper($this->__toString());
return $this->ParseMarkdown(false, $strValue);
}

/**
* @return string
*/
public function UpperCase(){
return $this->Upper();
}


/**
* @return string
*/
public function Lower(){
$strValue = strtolower($this->__toString());
return $this->ParseMarkdown(false, $strValue);
}

/**
* @return string
*/
public function LowerCase(){
return $this->Lower();
}

}
1 change: 1 addition & 0 deletions css/MarkdownEditorField.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions css/MarkdownEditorField.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.markdowneditor {


.middleColumn {

margin-left: 0;
clear: both;

textarea {
width: 100%;
max-width: 100%;
}

}


}
1 change: 1 addition & 0 deletions templates/MarkdownEditorField.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<textarea $AttributesHTML>$Value</textarea>
Empty file added thirdparty/_manifest_exclude
Empty file.
Loading

0 comments on commit 37408e4

Please sign in to comment.