Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

AUBBC2 alpha development

by Anonymous Monk
on Oct 19, 2011 at 10:22 UTC ( #932345=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I pushed out a consept code for a new BBcode engine. Its main function gives the developer controle over many parts of the BBcode tags through its placeholders with HTML template design. AUBBC2

One main reason why I posted this is to ask: Does this look easy to use?

Note: The add_tag() in alpha 3 doesnt work and Im sure a few other things.

Adding Tags
$aubbc->add_tag( 'tag' => 'Tag', # Tag name: 'type' => '#', # Type number: tag style 'function' => '', # Function: subroutine to expa +nd methods 'message' => 'any', # Message: of tag 'extra' => '', # Extra: of tag 'markup' => '', # Template: output );

Type number: Tag style
1 [tag]
2 [tag]message[/tag] or [tag=extra]message[/tag] or [tag attr=x...]message[/tag] or [tag=x attr=x...]message[/tag]
3 [tag://message] or [tag://message|extra]
4 replace or remove

Tag name:
This allows a single tag added to change many tags and supports more complex regex:

# This is an example of bold and italic in the same add_tag() # Tags: [b]message[/b] or [i]message[/i] # Output: <b>message</b> or <i>message</i> $aubbc->add_tag( 'tag' => 'b|i', # b or i 'type' => '2', 'function' => '', 'message' => 'any', 'extra' => '', 'markup' => '<%{tag}>%{message}</%{tag}>', );

The name gets check to make sure its a defined subroutine then gets passed these variables of the tag.

sub new_function { # $tag, $message, $attrs are the captured group of its place my ($type, $tag, $message, $markup, $extra, $attrs) = @_; # expand functions.... # A) if there is a $message and blank $markup the $message wi +ll replace the tag. # B) if there is both $message and $markup, then $message can + be inserted # into $markup if $markup has %{message} or any "Markup Templ +ate Tags", # then markup will replace the tag. # C) if both are blank the tag doesnt change. return ($message, $markup); # May have to return more so we have better/more controle }

Allows regex or fast regex for 'any', 'href', 'src'
href-> protocal://location/web/path/or/file
src-> protocal://location/web/path/or/file
or /local/web/path/or/file

Extra: supports -> any href src
Allows regex after tag= and message| or if negative pipe is in front will switch to the attribute syntax for attribute range matching.

Attributes syntax and rules:
-1) -| must be at the beginning of 'extra'
-2) All attributes listed in 'extra' must be used atleast one time for the tag to convert.
-3) The tag will not convert if an attribute is out of range
-4) Do not use extra delimiters like / and , in 'extra', use as needed.

Attribute syntax:


n{0-0000} = Number range n{1-10} means any number from 1 to 10
w{0000} = Word range character pre-set limit is '\w,.!?- ' w{5} means text 5 in length or less
w{xx|xx} = Word match w{This|That} will match 'This' or 'That' and supports regex in w{regex}
l{x-y} = Letter range with no length check l{a-c} means any letters from a to c
l{0000} = Length check l{5} means text 5 in length or less

note: usage of X{attribute_name} in the markup will be replaced with the value if everything is correct.
# tag: [dd=Stuff 7 attr=33]stuff[/dd] # output: <dd attr="33" alt="Stuff 7">stuff</dd> $aubbc->add_tag( 'tag' => 'dd', 'type' => '2', 'function' => '', 'message' => 'any', 'extra' => '-|attr/n{20-100},dd/w{7}', 'markup' => '<%{tag} attr="X{attr}" alt="X{dd}">%{message}</ +%{tag}>', ); # tag: [video height=90 width=115] +p4[/video] # output: <video width="115" height="90" controls="controls"> #<source src="" type="video/mp4" + /> #Your browser does not support the video tag. #</video> $aubbc->add_tag( 'tag' => 'video', 'type' => '2', 'function' => '', 'message' => 'src', 'extra' => '-|width/n{90-120},height/n{60-90}', 'markup' => '<video width="X{width}" height="X{height}" cont +rols="controls"> <source src="%{message}" type="video/mp4" /> Your browser does not support the video tag. </video>', );
This is the template of the tag and has tags of its own giving you more controle

Markup Template Tags:

Tag Info
%setting% Any setting name in AUBBC2's main setting hash %AUBBC
%{tag} Tag value
%{message} Message value
%{extra} Extra value for non-attribute syntax
X{attribute} Attribute names for values of attribute syntax

Replies are listed 'Best First'.
Re: AUBBC2 alpha development
by Anonymous Monk on Oct 19, 2011 at 10:58 UTC

    Does this look easy to use?

    Looks easy enough, albeit low-level (WORDY)

    I don't like magic numbers :) Instead of 'type' => '#' use names like

    1. lonetag, tagonly, tago, tag
    2. tagpair, tagbal, balancedtag, tagb, tag_balanced
    3. linktag, tagalt
    4. striptag

    Better yet, instead of (or in addition to) add_tag, provide strip_tag, link_tag, balanced_tag, ...

    I also don't like do_all_ubbc, as do_all isn't as informative as process , render, translate or transform,

    Also, there is no clear and concise example of usage, either in demo , docs, or test suite

      Is it (WORDY) in a good way?

      Im changing the numbers of type to names: single, balanced, link, strip and renaming do_all_ubbc to render I was thinking of name parse_bbcode, but its just names.. at some point that sub could have been called crap and working like a champ...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://932345]
Approved by salva
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2018-03-18 08:27 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (229 votes). Check out past polls.