Loading ...
Sorry, an error occurred while loading the content.
 

How to develop and run my own plugin

Expand Messages
  • Stefan Krauth
    Hello All, I m new to this group, so just correct me, if I m doing something wrong. A little bit of history: I started with something around NB 3.2 and was
    Message 1 of 3 , Oct 17, 2011
      Hello All,

      I'm new to this group, so just correct me, if I'm doing something
      wrong.

      A little bit of history:
      I started with something around NB 3.2 and was pretty happy with it for
      some years. Then I switched to S9Y for performance reasons. I got free
      webspace on a cheap and slow linux machine with just a few megabytes of
      ram. No fun to play with NB there. Meanwhile I'm hosting at a FreeBSD
      Jail of the local Unix User Group. Still not a fast machine, but fast
      enough to kick S9Y away again. I'm running NB 3.5-RC1.

      Plugin: What do It should do!
      -----------------------------
      I've written a custom plugin working on NB_MetaBody which parses some
      bbcode like statements which makes it easy to place images in the blog.
      The images are handled by javascripts, so it's not just a <img
      src="...">

      My workstation at home is a mac. I've automator scripts for "transmit"
      to get images resized and online. So if I put an image named "image.jpg"
      at it, it will upload 3 images with different sizes.

      - image.jpg (on my workstation, dropped to the automator script)
      becomes:
      - image_s.jpg (small version displayed in the article)
      - image_m.jpg (medium version for mouseover via css)
      - image_o.jpg (original version when clicked)

      In NB, I enter the code [blogimage="image.jpg"] and my plugin will
      assemble the HTML code like this:

      <div class="pic">
      <a class="p1" target="_new" href="./images/blog/image_o.png">
      <img alt="Picture image small" border="0"
      src="./images/blog/image_s.png"/>
      <img class="large" alt="image medium" border="0"
      src="./images/blog/image_m.png"/>
      </a>
      </div>

      Note: only one such statement per line is allowed.

      My Problem Number 1:
      --------------------
      The currently biggest problem is not really a nanoblogger issue. It's
      my bash knowledge. At the end of this mail, there is a link to my
      shortcode.sh script. It kills all newlines and tabs etc. inside
      NB_MetaBody. This is a huge problem when it comes to code inside of
      <pre> tags. I have built in a workaround for newlines but I want to do
      it right.

      Short question:
      ---------------
      What is the difference between NB_EntryBody and NB_MetaBody? At first I
      tried to modify NB_EntryBody which worked sometimes. But It seems mostly
      to be overwritten by NB_MetaBody.

      My Problem Number 2:
      ---------------------
      How can I influence the order of the plugins and where is a good place
      to run it?
      Currenty I've put it into plugins/custom and run it from the
      markdown.sh after markdown has finished via "load_plugins custom". I
      need to run it after markdown because markdown does not work if all
      newlines are killed by my script beforehand. So this is not a issue when
      I'd be able to fix my first issue.

      * For reference:
      My development page: http:/beta.xxzz.de (tidy is turned off)
      My Plugin: http://sh.xxzz.de/shortcode.sh.html (remove .html to
      download)

      * Other stuff (not related to the above)
      If you're interested. Some time ago, I've written a bash interface for
      nanoblogger. Feel free to use it:
      http://sh.xxzz.de/nbi.html (remove .html to download)
      Pictures: http://beta.xxzz.de/archives/2011/10/15/T19_49_09/ (when it
      shows 404, NB is updating, try again later :-)

      By checking my code (of nbi and shortcode.sh) you get an Idea of my
      (limited) Bash knowledge. I'd be happy to get any kind of help, ideas or
      performance improvements.

      Thanks and best Regards,
      Stefan
    • Stefan Krauth
      Hello All, I ve solved my main problem. ... Here is the updated code. http://sh.xxzz.de/shortcode2.sh.html I simply set IFS to r . It leaves the white spaces
      Message 2 of 3 , Oct 19, 2011
        Hello All,

        I've solved my main problem.

        > My Problem Number 1:
        > --------------------
        > The currently biggest problem is not really a nanoblogger issue.
        > It's
        >
        > my bash knowledge. At the end of this mail, there is a link to my
        > shortcode.sh script. It kills all newlines and tabs etc. inside
        > NB_MetaBody. This is a huge problem when it comes to code inside of
        > tags. I have built in a workaround for newlines but I want to do it
        > right.

        Here is the updated code. http://sh.xxzz.de/shortcode2.sh.html
        I simply set IFS to "\r". It leaves the white spaces intact now and
        my workaround to reassemble the newlines is still in place. It's
        working for me now - better solutions are still appreciated.

        > My Problem Number 2:
        > ---------------------
        > How can I influence the order of the plugins and where is a good
        > place to run it?
        > Currenty I've put it into plugins/custom and run it from the
        > markdown.sh after markdown has finished via "load_plugins custom". I
        > need to run it after markdown because markdown does not work if all
        > newlines are killed by my script beforehand. So this is not a issue
        > when I'd be able to fix my first issue.

        I still don't know the logic behind the different plugin locations. I
        stopped
        to call the custom plugin from the markdown.sh. I placed the plugin to
        the shortcode folder. It seems to work so far. It's called before
        markdown
        but because whitespaces and newlines are still (or again) there, it
        works
        fine now.

        Best Regards,
        Stefan
      • Kevin W.
        Hi Stefan, Please see my response below. ... That s exactly the kind of scenario the shortcode plugins are designed for! Sounds well thought out. Also, there s
        Message 3 of 3 , Oct 23, 2011
          Hi Stefan,

          Please see my response below.

          >________________________________
          >
          >
          >Plugin: What do It should do!
          >-----------------------------
          >I've written a custom plugin working on NB_MetaBody which parses some
          >bbcode like statements which makes it easy to place images in the blog.
          >The images are handled by javascripts, so it's not just a <img
          >src="...">
          >
          >My workstation at home is a mac. I've automator scripts for "transmit"
          >to get images resized and online. So if I put an image named "image.jpg"
          >at it, it will upload 3 images with different sizes.
          >
          >- image.jpg (on my workstation, dropped to the automator script)
          >becomes
          >- image_s.jpg (small version displayed in the article)
          >- image_m.jpg (medium version for mouseover via css)
          >- image_o.jpg (original version when clicked)
          >
          >In NB, I enter the code [blogimage="image.jpg"] and my plugin will
          >assemble the HTML code like this:
          >
          ><div class="pic">
          ><a class="p1" target="_new" href="./images/blog/image_o.png">
          ><img alt="Picture image small" border="0"
          >src="./images/blog/image_s.png"/>
          ><img class="large" alt="image medium" border="0"
          >src="./images/blog/image_m.png"/>
          ></a>
          ></div>
          >
          >Note: only one such statement per line is allowed.
          >

          That's exactly the kind of scenario the shortcode plugins are designed for! Sounds well thought out.

          Also, there's a way to parse the the lines so that you can allow multiple statements per line. More about that soon.

          I have a good example of a similar shortcode plugin here:
          http://nanoblogger.svn.sourceforge.net/viewvc/nanoblogger/trunk/experimental/plugins/shortcode/youtube.sh?revision=678&content-type=text%2Fplain

          Some quick notes about the example plugin:
          * It uses shell parameter expansion to quickly detect instances of shortcode which will be looped through later (this is important for performance reasons)
          * Looks for three variations of shortcode: open, enclosed, and enclosed with attributes
          * Isolates instances of shortcode variations using sed's inverted delete and substitution commands
          * Assembles sed scripts on the fly and only executes on lines where shortcode occurs (see use of sc_lines)
          * Subsequently modifies NB_MetaBody upon each iteration of loop

          >My Problem Number 1:
          >--------------------
          >The currently biggest problem is not really a nanoblogger issue. It's
          >my bash knowledge. At the end of this mail, there is a link to my
          >shortcode.sh script. It kills all newlines and tabs etc. inside
          >NB_MetaBody. This is a huge problem when it comes to code inside of
          ><pre> tags. I have built in a workaround for newlines but I want to do
          >it right.


          Use sed instead?


          >Short question:
          >---------------
          >What is the difference between NB_EntryBody and NB_MetaBody? At first I
          >tried to modify NB_EntryBody which worked sometimes. But It seems mostly
          >to be overwritten by NB_MetaBody.


          NB_EntryBody is antiquated and is now largely just a copy of NB_MetaBody.

          >My Problem Number 2:
          >---------------------
          >How can I influence the order of the plugins and where is a good place
          >to run it?
          >Currenty I've put it into plugins/custom and run it from the
          >markdown.sh after markdown has finished via "load_plugins custom". I
          >need to run it after markdown because markdown does not work if all
          >newlines are killed by my script beforehand. So this is not a issue when
          >I'd be able to fix my first issue.

          Probably best if you can preserve newlines.

          To answer your question though, plugins can be influenced in a variety of ways:
          * User plugins (e.g. [blog_dir]/plugins)
            * Have to manually create structure (e.g. mkdir [blog_dir]/plugins/shortcode)

            * Can override plugins (e.g. [blog_dir]/plugins/entry/format/markdown.sh)
            * Can disable plugins (e.g. [blog_dir]/plugins/entry/format/markdown.off)
          * Rename plugin file. Plugins are loaded alphanumerically. So, placing a number in front in most cases will be enough to load first.

          * Not recommended, but you can change order of plugin type by setting ENTRY_PLUGINSLOOP in blog.conf
            * interestingly enough, there's no such thing for pages right now, and format plugins are currently being called after shortcode ones.


          >* For reference:
          >My development page: http:/beta.xxzz.de (tidy is turned off)
          >My Plugin: http://sh.xxzz.de/shortcode.sh.html (remove .html to
          >download)
          >
          >* Other stuff (not related to the above)
          >If you're interested. Some time ago, I've written a bash interface for
          >nanoblogger. Feel free to use it:
          >http://sh.xxzz.de/nbi.html (remove .html to download)
          >Pictures: http://beta.xxzz.de/archives/2011/10/15/T19_49_09/ (when it
          >shows 404, NB is updating, try again later :-)


          nbi looks nice!


          >By checking my code (of nbi and shortcode.sh) you get an Idea of my
          >(limited) Bash knowledge. I'd be happy to get any kind of help, ideas or
          >performance improvements.
          >
          >Thanks and best Regards,
          >Stefan

          Hope that helps. Glad you like it.


          Kevin
        Your message has been successfully submitted and would be delivered to recipients shortly.