Jump to content

Hanna Code


ryan

Recommended Posts

I just posted version 5 of Hanna Code. The primary additions here are: 

post-2-0-25118000-1371833654_thumb.png

Predefined (default) attribute values

There is a new Attributes field present in the Hanna Code editor. From here you can define what attributes your PHP or Javascript Hanna Code expects. This can also be used to set default values for attributes. Use of this is optional. However, I think it's a good idea to use it as it helps communicate what the options are for a given Hanna Code. It also saves you some code as you can assume your attributes will be defined as variables, ready to access. The main listing page now shows Hanna Codes with their attributes so that they can be copied/pasted into your body text with all attribute options known and ready to fill in. 

Support for Export and Import of Hanna Codes

Now you can export any Hanna code and import it somewhere else using copy/paste. You'll see the Export option when editing a Hanna Code. You'll see the Import option on the main listing page. Below is a predefined Hanna Code you can import if you'd like:

Jumplinks Hanna Code (example for import)

This Hanna code is meant to be used in your body copy. It collects all the headline tags in the text and turns them into anchor jump links while outputting a linked table of contents. It will put the table of contents wherever you type the Hanna code. See the anchor jump links on this page for an example of what this Hanna Code does.
 
Import Data: 
!HannaCode:jumplinks:eyJuYW1lIjoianVtcGxpbmtzIiwidHlwZSI6IjIiLCJjb2RlIjoiXC8qaGNfYXR0clxuZm9yPVwiaDIgaDNcIlxuaGNfYXR0cipcL1xuJGZvciA9IHN0cl9yZXBsYWNlKCcsJywgJyAnLCAkZm9yKTtcclxuJGZvciA9IGV4cGxvZGUoJyAnLCAkZm9yKTtcclxuZm9yZWFjaCgkZm9yIGFzICRrID0+ICR2KSAkZm9yWyRrXSA9IHRyaW0oJHYpO1xyXG5cclxuJGZvciA9IGltcGxvZGUoJ3wnLCAkZm9yKTtcclxuJGFuY2hvcnMgPSBhcnJheSgpOyBcclxuJHZhbHVlID0gJGhhbm5hLT52YWx1ZTsgXHJcblxyXG5pZihwcmVnX21hdGNoX2FsbCgnezwoJyAuICRmb3IgLiAnKVtePl0qPiguKz8pPFwvXFwxPn1pJywgJHZhbHVlLCAkbWF0Y2hlcykpIHtcclxuICBmb3JlYWNoKCRtYXRjaGVzWzFdIGFzICRrZXkgPT4gJHRhZykge1xyXG4gICAgJHRleHQgPSAkbWF0Y2hlc1syXVska2V5XTtcclxuICAgICRhbmNob3IgPSAkc2FuaXRpemVyLT5wYWdlTmFtZSgkdGV4dCwgdHJ1ZSk7XHJcbiAgICAkYW5jaG9yc1skYW5jaG9yXSA9ICR0ZXh0OyBcclxuICAgICRmdWxsID0gJG1hdGNoZXNbMF1bJGtleV07IFxyXG4gICAgJHZhbHVlID0gc3RyX3JlcGxhY2UoJGZ1bGwsIFwiPGEgbmFtZT0nJGFuY2hvcicgaHJlZj0nIyc+PFwvYT4kZnVsbFwiLCAkdmFsdWUpOyBcclxuICB9ICBcclxuICAkaGFubmEtPnZhbHVlID0gJHZhbHVlOyBcclxufVxyXG5cclxuaWYoY291bnQoJGFuY2hvcnMpKSB7XHJcbiAgZWNobyBcIjx1bCBjbGFzcz0nanVtcGxpbmtzJz5cIjtcclxuICBmb3JlYWNoKCRhbmNob3JzIGFzICRhbmNob3IgPT4gJHRleHQpIHtcclxuICAgIGVjaG8gXCI8bGk+PGEgaHJlZj0nJHBhZ2UtPnVybCMkYW5jaG9yJz4kdGV4dDxcL2E+PFwvbGk+XCI7XHJcbiAgfVxyXG4gIGVjaG8gXCI8XC91bD5cIjtcclxufSBlbHNlIHtcclxuICBlY2hvICcnO1xyXG59In0=/!HannaCode

Usage Examples:

 
[[jumplinks]]
Locates all h2 and h3 headlines, turns them into anchors, and generates a table of contents. This is the default behavior with no attributes.
 
[[jumplinks for=h2]]
Here we specify a 'for' attribute. It produces the same behavior as above except only anchors h2 headlines.
 
[[jumplinks for=h2 h4]]
Same as above except only anchors h2 and h4 headlines.
  • Like 7
Link to comment
Share on other sites

  • 2 weeks later...

No no, not TinyMCE. Here's the SS from the modules page:

screen_shot_2013-06-02_at_2_42_47_pm.png

In the 'Code' box, there's no syntax highlighting for the code that is in the textarea. I'm just suggesting that the code in the textarea has syntax highlighting as you type to help prevent users from making an error when writing their code in that box.

  • Like 1
Link to comment
Share on other sites

Makes sense to me. The only thing is that PW core doesn't come with an Inputfield that does this, so it would be an external 3rd party dependency... something I'd like to avoid. So what I'll probably do is make the Inputfield type configurable so that you could tell it to use some future code-editing Inputfield instead of InputfieldTextarea.

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...

I just downloaded 0.0.7 from the modules page.  On install, I get:

  • Module Install - TextformatterHannaCode

  • Created Page: /processwire/setup/hanna-code/

  • Module Auto Install: ProcessHannaCode

  • BLOB/TEXT column 'code' can't have a default value

If I got to setup/Hanna, I get:

Table 'pwire.hanna_code' doesn't exist

I also get the same error message when trying to uninstall.

EDIT:

line 436 of TextformatterHannaCode, I removed "default '' " and it installed fine.  I don't think will cause any unexpected issues...

i'm using mysql, if that matters (567 I think)

  • Like 1
Link to comment
Share on other sites

It sounds like your version of MySQL won't accept default values for a text field. I've not heard of that before. Perhaps it is some MySQL setting that I've not seen before. Seems like if it won't accept a default value (which we specify a blank string) then it could only be null as a default. Not that it matters much, but I'd prefer the blank string since there is no use for a null here.  I agree that removing the default that you did shouldn't cause any issues. I'm curious to see if this issue turns up for anyone else. 

Link to comment
Share on other sites

It sounds like your version of MySQL won't accept default values for a text field. I've not heard of that before. Perhaps it is some MySQL setting that I've not seen before. Seems like if it won't accept a default value (which we specify a blank string) then it could only be null as a default. Not that it matters much, but I'd prefer the blank string since there is no use for a null here.  I agree that removing the default that you did shouldn't cause any issues. I'm curious to see if this issue turns up for anyone else. 

According to http://dev.mysql.com/doc/refman/5.6/en/blob.html, BLOB and TEXT fields cannot have a default value.

  • Like 1
Link to comment
Share on other sites

Sometimes when I say text I actually mean varchar (since it is also a type of text field). But in this case, I think I must have just forgotten when writing the schema. My version of mysql (and apparently most people's) doesn't complain about a default value in a "text" field, for whatever reason. But I will correct this, as it's sure to come up again. 

Link to comment
Share on other sites

Sometimes when I say text I actually mean varchar (since it is also a type of text field). But in this case, I think I must have just forgotten when writing the schema. My version of mysql (and apparently most people's) doesn't complain about a default value in a "text" field, for whatever reason. But I will correct this, as it's sure to come up again. 

Which version are you running?

EDIT:

  I did notice in the comments that this is an error on windows systems (which is my dev area), but more of a warning on others.  This may be our differences.

Link to comment
Share on other sites

I'm not at my desktop computer, but think it is MySQL 5.5.25 (under MAMP) that I'm running. But you are right that assigning the default value to the text field in this module's schema wasn't right, so I pushed a fix for it a couple days ago. 

Link to comment
Share on other sites

  • 2 weeks later...

Is it possible to use Hanna Code directly in my template file or in PHP without using a field for it? For example

Use directly:

<?php include("./head.inc"); ?>
<div class="container content">
<div class="row-fluid">
    <a name="content"></a>
[[newsdetails]]

</div>
</div>
<?php include("./foot.inc"); ?>
 

or with PHP:

<?php include("./head.inc"); ?>
<div class="container content">
<div class="row-fluid">
    <a name="content"></a>
<?php
$hanna = $modules->get('TextformatterHannaCode');
$page->body = $hanna->render('[[newsdetails]]');
echo $page->body;
?>
</div>
</div>
<?php include("./foot.inc"); ?>
 
Link to comment
Share on other sites

From the README file (given this, I think your example would work): 

Using Hanna Code from the API

If you want to populate Hanna Code from the API, you can do so using the render() method, like this:

$hanna = $modules->get('TextformatterHannaCode');
$page->body = $hanna->render($page->body); 
  • Like 1
Link to comment
Share on other sites

I've tried both the Hanna Code docs example and jmartsch PHP example but no dice. They both don't work for me. Nothing gets written or output. No errors, nothing. What exactly are they meant to do? Write to Hanna or output from Hanna? I am interpreting "populate" as creating a Hanna Code block. I think I am wrong ;)

Link to comment
Share on other sites

I also tried, and it doesn't work. Further investigation is that the formatValue doesn't return but set $this->value;

So get it fixed I need to comment out #178:

        //$this->value = '';

and change in render() method to instead return $this->value:

    public function render($value) {
        $this->formatValue(new NullPage(), new Field(), $value);
        return $this->value;
    }

Don't know what Ryan smoked :P but I didn't first spotted it as it's really wierd wired.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...