yUML is an UML scripting tool from yUml.me (crafted by Tobin Harris) that is easy to use. Still it may be too cryptic for non-IT Business Analysts who would prefer to be able to write complete english sentences instead of mathematical-like symbology. Rebol can make it even easier with a custom end-user friendly dialect (Rebol’s parliance for Domain Specific Language). Suppose we want to create this Diagram:

yumlactors

We would write this set of instructions in nearly plain english:


      Blogger is a User
      Admin is a Blogger
      Author is a Blogger
      Subscriber is a User

and our Rebol Dialect Script would translate it to yUML.me dialect:


[Blogger]^[User]
[Admin]^[Blogger]
[Author]^[Blogger]
[Subscriber]^[User]

Other example - if we want to create this diagram:

yumlusecases

We would write this:


      Admin Manage Site
      Manage Site Include Manage Users
      Manage Site Include Manage Themes
      Manage Site Include Manage Plugins

which would be translated into yUML.me dialect as:


[Admin]-(Manage Site)
(Manage Site)>(Manage Users)
(Manage Site)>(Manage Themes)
(Manage Site)>(Manage Plugins)


Extend relation is also supported though I won’t give any example. In this lesson we limit to Use Case Diagrams - we will cope with Class Diagrams in another lesson.

Our whole Rebol script below uses what we learnt previously:

- Automate YUml Diagrams with Rebol
- Creating a Domain Specific Language
- Creating a flexible Robot Worker to automate tasks

So here it is, you should be able to study and understand it after reading the above tutorials (to test it online you can type in rebol console “do http://reboltutorial.com/source/yumldialect.r” and paste the result in your notepad - I advise you to use Notepad2 instead of Notepad because it can highlight Rebol’s brackets and string braces delimiters):



Rebol [
    Name: "Yuml Robot"
    Description: "Generate Yuml Syntax"
    Version: 1.0.0
    Change: ""
]

ROBOT: make object! [

  output: copy ""

  note-rule: [(color: "beige") some [
    'note [
            copy note-string to 'fond thru 'fond copy color to end
            (append output rejoin ["note: " note-string "{" "bg:" color "}"])
            |
            copy note-string to  end  (append output rejoin ["note: " note-string "{" "bg:" color "}"])              

      ]
    ]
    |           copy note-string to 'fond thru 'fond copy color to end
            (append output rejoin ["note: " note-string "{" "bg:" color "}"])
            |
            copy note-string to  end  (append output rejoin ["note: " note-string "{" "bg:" color "}"])
  ]

  actor-rule: [some [ [copy Actor to 'is thru 'is 'a 'Actor (append output rejoin ["[" Actor "]"])]
      | [copy Actor to 'is thru 'is 'a copy Actor2 to end (append output rejoin ["[" Actor "]^[" Actor2 "]"])]
   ]
  ]

  extend-rule: [some [copy UseCase2 to 'Extend thru 'Extend copy UseCase1 to end (append output rejoin ["(" UseCase1 ")<(" UseCase2 ")"])]
  ]

  include-rule: [some [copy UseCase2 to 'Include thru 'Include copy UseCase1 to end (append output rejoin ["(" UseCase2 ")>(" UseCase1 ")"])]
]  

  use-rule: [some [copy Actor to 'Manage thru 'Manage copy UseCase to end (append output rejoin ["[" Actor "]-(" "Manage " UseCase ")"])]
  ]

  yuml-rule: [(Actor: copy [] Actor2: copy []) actor-rule | extend-rule |  include-rule | use-rule | note-rule ]

  ;task1 function
  Generate: func [yuml-orders][

    output: copy ""

    block-orders-draft: parse/all yuml-orders "^/"
    block-orders: copy []
    foreach order block-orders-draft [

      if (length? (order: trim/head/tail order)) > 0 [
          append block-orders  order
      ]
    ]

    foreach order block-orders [
      order-block: to-block order
      parse order-block yuml-rule
      append output newline
    ]
  ]

  ;task2 function
  list: func [][
      foreach Task Tasks-List [
        print Task
      ]
  ]

  ;core engine
  run: func
  [

      Tasks-List: copy [] ; reset the list
      output: copy ""
      do bind code 'self
  ]

]

Worker: Make Robot[]

Yuml-Orders-list: [

  {
      Wordpress Profiles
      Blogger is a User
      Admin is a Blogger
      Author is a Blogger
      Subscriber is a User
  }

  {   Blogger Role
      Blogger Manage Posts
  }

  {
      Admin Roles
      Admin Manage Site
      Manage Site Include Manage Users
      Manage Site Include Manage Themes
      Manage Site Include Manage Plugins
  }

]

Robot-Orders: [
   Yuml-Output-List: copy []

   foreach Yuml-Orders Yuml-Orders-list [
       Print ["Yuml-Orders: " Yuml-Orders " started ..." newline]
       generate Yuml-Orders
       Print output
       Append Yuml-Output-List copy output

       Print ["Yuml-Orders: " Yuml-Orders " done! " newline]
       Print Newline
   ]

   Probe Yuml-Output-List
   write clipboard:// mold Yuml-Output-List
   Print "Copied to clipboard..."
]

Worker/Run Robot-Orders
input

If you paste into Notepad2, this should give you:
yumloutput

You can then go to yUml.me Use Case Diagram to render them:
yuml1yuml2yuml3
yuml

This script is now available on AskCodeGeneration.com.

If you’re looking for Sequence Diagrams look here.

Bookmark and Share

Recent Articles