Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
simoneeconomo committed Jan 1, 2010
1 parent ab9e7fc commit bfca6ea
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 29 deletions.
41 changes: 32 additions & 9 deletions README
@@ -1,12 +1,12 @@
Zen Coding
------------------------------------

Version: 1.0
Version: 1.1
Author: Simone Economo (my.ekoes@gmail.com)
Build Date: 27th Dec 2009
Requirements: Symphony 2.0
Build Date: 1st Jan 2010
Requirements: Symphony 2.0.6+

Allows HTML/XSLT hi-speed coding inside Symphony's page template and utility editors.
Flavours Symphony's textarea fields with an incredibly easy-to-use, CSS-like syntax for writing HTML, XML & XSLT code.

[INSTALLATION]

Expand All @@ -16,14 +16,37 @@ Allows HTML/XSLT hi-speed coding inside Symphony's page template and utility edi

2. Enable it by selecting the "Zen Coding", choose Enable from the with-selected menu, then click Apply.

3. Reach the Nirvana by greeting a highly innovative and time-saving syntax to generate your markup (for more details visit: http://code.google.com/p/zen-coding/)
3. Greet a highly innovative and time-saving syntax to generate your markup at the speed of light (more details can be found here: http://code.google.com/p/zen-coding/)

** Note: Zen Coding is only allowed inside textareas showing a "Zen Coding is enabled" message on the very right. Come on dude, you can't miss it.

4. Go to System > Preferences to enable/disable "Zen Coding".

[FEATURES]

* Zen Coding for <textarea> v0.5 (http://zen-coding.ru/textarea/)
* HTML & XSLT Profiles enabled (http://pepelsbey.net/pro/2008/08/zen-html/)
* Tabs enabled (press [Tab] to indent)
Includes Zen Coding for <textarea> v0.5 (http://zen-coding.ru/textarea/) with:

* XSLT Profile enabled
* Tabs enabled (press [Tab] key to indent)
* Formatted line breaks enabled (auto-indentation of lines when hitting [Enter] key)

[SHORTCUTS]

Meta+E — Expand Abbreviation
Meta+D — Balance Tag Outward
Shift+Meta+D — Balance Tag Inward
Shift+Meta+A — Wrap With Abbreviation
Ctrl+Alt+→ — Next Edit Point
Ctrl+Alt+← — Previous Edit Point
Meta+L — Select Line

[RESOURCES & FURTHER READINGS]

* Zen Coding on Google Code (http://code.google.com/p/zen-coding/)
* Zen HTML elements (http://code.google.com/p/zen-coding/wiki/ZenHTMLElementsEn)
* Zen HTML selectors (http://code.google.com/p/zen-coding/wiki/ZenHTMLSelectorsEn)
* Zen Coding: A Speedy Way To Write HTML/CSS Code (http://www.smashingmagazine.com/2009/11/21/zen-coding-a-new-way-to-write-html-code/)

[CHANGE LOG]

** Note: Zen Coding is only allowed inside textareas showing a "Zen Coding enabled" message on the very right. You can't miss it.
1.1 - New settings in your preferences will let you choose which textarea fields you want Zen Coding enabled in.
66 changes: 66 additions & 0 deletions README.markdown
@@ -0,0 +1,66 @@
# Zen Coding

Flavours Symphony's textarea fields with an incredibly easy-to-use, CSS-like syntax for writing HTML, XML & XSLT code.

- Version: 1.1
- Author: Simone Economo, my.ekoes@gmail.com
- Build Date: 1st January 2010
- Requirements: Symphony CMS 2.0.x

## Installation

_Note_: The latest version can alway be grabbed with `git clone git://github.com/eKoeS/symphony-zencoding.git`

1. Upload the `zencoding` folder in this archive to your Symphony `extensions` folder.
2. Enable it by selecting the "Zen Coding", choose _Enable_ from the _with-selected_ menu, then click _Apply_.
3. Greet a highly innovative and time-saving syntax to generate your markup at the speed of light (for more details see <http://code.google.com/p/zen-coding/>)
_Note_: Zen Coding is only allowed inside textareas showing a "Zen Coding is enabled" message on the very right. Come on dude, you can't miss it.
4. Go to System > Preferences to enable/disable "Zen Coding".

## Features

Includes [Zen Coding for <textarea>](http://zen-coding.ru/textarea/) v0.5 with:

* XSLT Profile enabled
* Tabs enabled (press `[Tab]` key to indent)
* Formatted line breaks enabled (auto-indentation of lines when hitting `[Enter]` key)

## Shortcuts

Meta+E
: Expand Abbreviation

Meta+D
: Balance Tag Outward

Shift+Meta+D
: Balance Tag Inward

Shift+Meta+A
: Wrap With Abbreviation

Ctrl+Alt+→
: Next Edit Point

Ctrl+Alt+←
: Previous Edit Point

Meta+L
: Select Line

## Resources & Further readings

* [Zen Coding on Google Code](http://code.google.com/p/zen-coding/)
* [Zen HTML elements](http://code.google.com/p/zen-coding/wiki/ZenHTMLElementsEn)
* [Zen HTML selectors](http://code.google.com/p/zen-coding/wiki/ZenHTMLSelectorsEn)
* [«Zen Coding: A Speedy Way To Write HTML/CSS Code», on Smashing Magazine](http://www.smashingmagazine.com/2009/11/21/zen-coding-a-new-way-to-write-html-code/)

## Change log

### Version 1.1, 1st January 2010:

- New settings in your preferences will let you choose which textarea fields you want Zen Coding enabled in.

### Version 1.0.0, 27th December 2009:

- Initial release.
2 changes: 1 addition & 1 deletion assets/zenitize.js
@@ -1,4 +1,4 @@
jQuery(document).ready(function(){
jQuery(".primary label:last").append("<i>Zen Coding enabled (<a href=\"http://code.google.com/p/zen-coding/\">?</a>)</i>");
jQuery(".primary label:last").append("<i>Zen Coding is enabled (<a href=\"http://code.google.com/p/zen-coding/\">?</a>)</i>");
jQuery("textarea").addClass("zc-use_tab-true zc-syntax-xsl zc-profile-xml");
});
175 changes: 156 additions & 19 deletions extension.driver.php
@@ -1,25 +1,40 @@
<?php
<?php

require_once(DOCROOT . '/symphony/lib/toolkit/class.sectionmanager.php');

Class extension_ZenCoding extends Extension{
Class extension_ZenCoding extends Extension{

const ALL_FIELDS = 'all';
const NO_FIELDS = 'none';

public function about(){
return array('name' => 'Zen Coding',
'version' => '1.0',
'release-date' => '2009-12-27',
'version' => '1.1',
'release-date' => '2010-01-01',
'author' => array('name' => 'Simone Economo',
'website' => 'http://www.lineheight.net',
'email' => 'my.ekoes@gmail.com'),
'description' => 'Allows HTML/XSLT hi-speed coding inside Symphony\'s page template and utility editors.'
'description' => 'Flavours Symphony\'s textarea fields with an incredibly easy-to-use, CSS-like syntax for writing HTML, XML & XSLT code'
);
}

public function getSubscribedDelegates(){
return array(
// array(
// 'page' => '/backend/',
// 'delegate' => 'ModifyTextareaFieldPublishWidget',
// 'callback' => '__zenitizeTextarea'
// ),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'savePreferences'
),
array(
'page' => '/backend/',
'delegate' => 'ModifyTextareaFieldPublishWidget',
'callback' => '__zenitizeTextarea'
),
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
Expand All @@ -28,20 +43,142 @@ public function getSubscribedDelegates(){
);
}

// public function __zenitizeTextarea($context) {
// $textarea = $context['textarea'];
// $textarea->setAttribute('class', $textarea->getAttribute('class').'zc-use_tab-true zc-syntax-xsl zc-profile-xml');
// }
public function __isAllowedField($id) {
$config = $this->_Parent->Configuration->get('allowed_fields', 'zen_coding');

if ($config == self::ALL_FIELDS)
return true;
else if ($config == self::NO_FIELDS)
return false;
else
return @in_array($id, explode(',', $config));
}

public function __isAllowedSection($id) {
$config = $this->_Parent->Configuration->get('allowed_fields', 'zen_coding');

if ($config == self::ALL_FIELDS)
return @in_array($id, Symphony::Database()->fetchCol('parent_section', "SELECT parent_section FROM tbl_fields WHERE type = 'textarea'"));
else if ($config == self::NO_FIELDS)
return false;
else
return @in_array($id, Symphony::Database()->fetchCol('parent_section', "SELECT parent_section FROM tbl_fields WHERE id IN (" . $config . ")"));
}

public function __zenitizeTextarea($context) {
if ($this->__isAllowedField($context['field']->get('id'))) {
$classes = $context['textarea']->getAttribute('class');
$context['textarea']->setAttribute('class', $classes .' zc-use_tab-true zc-syntax-xsl zc-profile-xml');

$c = $context['label']->getChildren();

if (empty($c)) {
$i = new XMLElement('i');
$context['label']->appendChild($i);
}
else {
$i = $c[0];
$value = ". " . $i->getValue();
}

$i->setValue(__('Zen Coding is enabled (<a href=\'%1$s\' title="%2$s">?</a>)',
array('http://code.google.com/p/zen-coding/', 'More details about Zen Coding and features enabled')
) . $value);
}
}

public function __isTemplateEditor($pageCallback) {
return $pageCallback['driver'] == 'blueprintspages' && $pageCallback['context']['0'] == 'template';
}

public function __isUtilityEditor($pageCallback) {
return $pageCallback['driver'] == 'blueprintsutilities';
}

public function __isEntryEditor($pageCallback) {
return $pageCallback['driver'] == 'publish';
}

public function __appendScripts($context) {
$pageCallback = $context['parent']->getPageCallback();
if (
($pageCallback['driver'] == 'blueprintspages' && $pageCallback['context']['0'] == 'template')
|| ($pageCallback['driver'] == 'blueprintsutilities')
) {
$callback = $context['parent']->getPageCallback();

if ($this->__isTemplateEditor($callback)) {
$context['parent']->Page->addScriptToHead(URL . '/extensions/zencoding/assets/zen_textarea.min.js', 1000, false);
$context['parent']->Page->addScriptToHead(URL . '/extensions/zencoding/assets/zenitize.js', 1000, false);
}
else if ($this->__isUtilityEditor($callback)) {
$context['parent']->Page->addScriptToHead(URL . '/extensions/zencoding/assets/zen_textarea.min.js', 1000, false);
$context['parent']->Page->addScriptToHead(URL . '/extensions/zencoding/assets/zenitize.js', 1000, false);
}
else if ($this->__isEntryEditor($callback)) {
$sectionManager = new SectionManager($context['parent']);
$section_id = $sectionManager->fetchIDFromHandle($callback['context']['section_handle']);

if ($this->__isAllowedSection($section_id))
$context['parent']->Page->addScriptToHead(URL . '/extensions/zencoding/assets/zen_textarea.min.js', 1000, false);
}
}

public function savePreferences($context){
if(!is_array($context['settings']))
$context['settings'] = array('zen_coding' => array('allowed_fields' => self::NO_FIELDS));
elseif(!isset($context['settings']['zen_coding']))
$context['settings']['zen_coding'] = array('allowed_fields' => self::NO_FIELDS);
elseif(is_array($context['settings']['zen_coding']['allowed_fields'])) {
if(@in_array(self::ALL_FIELDS, $context['settings']['zen_coding']['allowed_fields']))
$context['settings']['zen_coding'] = array('allowed_fields' => self::ALL_FIELDS);
else
$context['settings']['zen_coding']['allowed_fields'] = implode(',', $context['settings']['zen_coding']['allowed_fields']);
}
}

public function __buildOptionsArray($context) {
$sectionManager = new SectionManager($context['parent']);
$sections = $sectionManager->fetch(NULL, 'ASC', 'sortorder');

$outline = array();

if(is_array($sections) && !empty($sections)){
foreach($sections as $section)
$outline[$section->get('id')] = array(
'name' => $section->get('name'),
'fields' => $section->fetchFields($type="textarea"),
);
}

$options = array();
$options[] = array(self::ALL_FIELDS, false, __("All fields"));

foreach($outline as $section){
if(!is_array($section['fields'])) continue;

$fields = array();

foreach($section['fields'] as $field)
$fields[] = array($field->get('id'), $this->__isAllowedField($field->get('id')), $field->get('label'));

if(is_array($fields) && !empty($fields))
$options[] = array('label' => $section['name'], 'options' => $fields);
}

return $options;

}

public function appendPreferences($context){
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Zen Coding')));

$label = Widget::Label(__('Allowed fields'));
$options = $this->__buildOptionsArray($context);
$select = Widget::Select('settings[zen_coding][allowed_fields][]', $options, array('multiple' => 'multiple'));
$label->appendChild($select);

$group->appendChild($label);
$group->appendChild(new XMLElement('p', __('This will let you use Zen Coding in Textarea-based fields of your sections.'), array('class' => 'help')));

$context['wrapper']->appendChild($group);
}

}
Expand Down

0 comments on commit bfca6ea

Please sign in to comment.