| 3 | | # This code is transcribed from "Hacking Movable Type" by Allen, |
| 4 | | # Choate, Hammersley and Haughey, chapter 10: Writing Plugins with |
| 5 | | # slight modifications by Gene Boggs. If you spot an inaccuracy |
| 6 | | # or improvement in the context of The Book or PluginManager |
| 7 | | # requirements, patches are welcome! |
| | 3 | # This code is a modified version of that listed in "Hacking Movable |
| | 4 | # Type" by Allen, Choate, Hammersley and Haughey, chapter 10: Writing |
| | 5 | # Plugins. Gene Boggs added the plugin manager compatiblity files. |
| 19 | | { # Main block of executed code: |
| 20 | | my $name = 'HelloWorld'; |
| 21 | | my $plugin = MT::Plugin->new(); |
| 22 | | $plugin->name($name); |
| 23 | | $plugin->description(__PACKAGE__); |
| 24 | | MT->add_plugin($plugin); |
| 25 | | MT::Template::Context->add_tag($name => \&HelloWorld); |
| 26 | | MT::Template::Context->add_container_tag( |
| 27 | | $name .'Container' => \&HelloWorldContainer, |
| 28 | | ); |
| 29 | | MT::Template::Context->add_conditional_tag( |
| 30 | | $name .'IfNameProvided' => \&HelloWorldIfNameProvided, |
| 31 | | ); |
| 32 | | MT::Template::Context->add_global_filter( |
| 33 | | to_uppercase => \&to_uppercase, |
| 34 | | ); |
| 35 | | } |
| | 17 | use base 'MT::Plugin'; |
| | 18 | |
| | 19 | our $plugin; |
| | 20 | our $VERSION = '0.5'; |
| | 21 | MT->add_plugin($plugin = __PACKAGE__->new({ |
| | 22 | name => "Hello World", |
| | 23 | version => $VERSION, |
| | 24 | description => "Enables friendly greetings.", |
| | 25 | author_name => "Ima Hacker", |
| | 26 | author_link => "http://example.com/", |
| | 27 | template_tags => { |
| | 28 | 'HelloWorld' => \&HelloWorld, |
| | 29 | 'HelloWorldGreeted' => \&HelloWorldGreeted, |
| | 30 | }, |
| | 31 | container_tags => { |
| | 32 | 'HelloWorldContainer' => \&HelloWorldContainer, |
| | 33 | }, |
| | 34 | conditional_tags => { |
| | 35 | 'HelloWorldIfNameProvided' => \&HelloWorldIfNameProvided, |
| | 36 | }, |
| | 37 | global_filters => { |
| | 38 | 'to_uppercase' => \&to_uppercase, |
| | 39 | }, |
| | 40 | })); |
| | 41 | |
| | 144 | =head1 EXAMPLES |
| | 145 | |
| | 146 | ### To all of you |
| | 147 | |
| | 148 | <$MTHelloWorld$> |
| | 149 | |
| | 150 | ### Dirified |
| | 151 | |
| | 152 | <$MTHelloWorld dirify="1"$> |
| | 153 | |
| | 154 | |
| | 155 | ### Showing excitement with a global attribute! |
| | 156 | |
| | 157 | <$MTHelloWorld to_uppercase="1"$> |
| | 158 | |
| | 159 | ### Hi Morty! |
| | 160 | |
| | 161 | <$MTHelloWorld name="Mortimer"$> |
| | 162 | |
| | 163 | ### Containers |
| | 164 | |
| | 165 | <MTHelloWorldContainer name="Byrne, Anil, Byron, Jay, world"> |
| | 166 | Hello <$MTHelloWorldGreeted$>! |
| | 167 | </MTHelloWorldContainer> |
| | 168 | |
| | 169 | ### Containers with a conditional |
| | 170 | |
| | 171 | <MTHelloWorldContainer name="Byrne, Anil, Byron, Jay, world"> |
| | 172 | <MTHelloWorldIfNameProvided> |
| | 173 | Hello <$MTHelloWorldGreeted$>! Nice to see you! |
| | 174 | <MTElse> |
| | 175 | Oh, it's you again, world. Hi. |
| | 176 | </MTElse> |
| | 177 | </MTHelloWorldIfNameProvided> |
| | 178 | </MTHelloWorldContainer> |
| | 179 | |
| | 180 | ### In an entries loop |
| | 181 | |
| | 182 | <MTEntries> |
| | 183 | <$MTHelloWorld$> Thanks for writing this entry. |
| | 184 | </MTEntries> |
| | 185 | |
| | 186 | ### Container inside of entry without tag |
| | 187 | |
| | 188 | <MTEntries> |
| | 189 | <MTHelloWorldContainer> |
| | 190 | Hello <$MTHelloWorldGreeted$>! |
| | 191 | </MTHelloWorldContainer> |
| | 192 | </MTEntries> |
| | 193 | |
| | 194 | ### Container inside of entry with tag as name variable |
| | 195 | |
| | 196 | <MTEntries> |
| | 197 | <MTHelloWorldContainer name="[MTEntryTags glue=','][MTTagName][/MTEntryTags]"> |
| | 198 | This entry is tagged: <$MTHelloWorldGreeted$> |
| | 199 | </MTHelloWorldContainer> |
| | 200 | </MTEntries> |
| | 201 | |