This script (see usage) will generate multiple yUML Use Case Scripts at once using an english-natural-like syntax copied to clipboard as input (see sample input) and output will also be copied to clipboard (see sample output).



Rebol [
Title: "yUML Use Case"
Author-Url: http://askuml.com
Script-Url: http://askuml.com/blog/yuml-use-case
Version: 1.2
Date: 3-Jul-2010
Purpose: {
Generate yUML Use Case Diagram
}
]
do code-block/2; business rules parsing
do code-block/3; yUML function
do code-block/4; Robot Maker
print "Copy UML Script to clipboard ..."
input
Yuml-Orders-list: to-block read clipboard://
Create-Use-Case Yuml-Orders-list
clipboard: copy ""
foreach element Yuml-Output-List [
append clipboard element
append clipboard newline
append clipboard newline
]
Print mold/only Yuml-Output-List
write clipboard:// mold/only Yuml-Output-List
;write clipboard:// clipboard
ans: "Copied to clipboard... do you want to go to yUml.me (Y/N): "
if ans = "Y" [
browse http://yuml.me/diagram/scruffy/usecase/draw
]
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 'Connect thru 'Connect 'to copy UseCase to end (append output rejoin ["[" Actor "]-(" "Connect to " UseCase ")"])]
|
[copy Actor to 'Use thru 'Use copy UseCase to end (append output rejoin ["[" Actor "]-(" "Use " UseCase ")"])]
|
[copy Actor to 'List thru 'List copy UseCase to end (append output rejoin ["[" Actor "]-(" "List " UseCase ")"])]
|
[copy Actor to 'Show thru 'Show copy UseCase to end (append output rejoin ["[" Actor "]-(" "Show " UseCase ")"])]
|
[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 ]
Create-Use-Case: func[Yuml-Orders-list][
Worker: Make Robot[]
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
]
]
Worker/Run Robot-Orders
Yuml-Output-List
]
ROBOT: make object! [
;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 [code][
Tasks-List: copy [] ; reset the list
output: copy ""
do bind code 'self
]
]
Sample UML Inputs (3 blocks scripts, first line of each block is an UML note):
{
Wordpress Profiles
Blogger is a User
Admin is a Blogger
Author is a Blogger
Subscriber is a User
}
{
Blogger Role
Blogger Manage Posts
Manage Posts Include Create Post
Manage Posts Include Edit Post
Manage Posts Include Delete Post
Categorize Post Extend Create Post
Categorize Post Extend Edit Post
}
{
Admin Roles
Admin Manage Site
Manage Site Include Manage Users
Manage Site Include Manage Themes
Manage Site Include Manage Plugins
}
Sample yUML Outputs (3 blocks scripts):
{
note: Wordpress Profiles{bg:beige}
[Blogger]^[User]
[Admin]^[Blogger]
[Author]^[Blogger]
[Subscriber]^[User]
}
{
[Blogger]-(Manage Posts)
(Manage Posts)>(Create Post)
(Manage Posts)>(Edit Post)
(Manage Posts)>(Delete Post)
(Create Post)(Manage Themes)
(Manage Site)>(Manage Plugins)
}
Copy a block script output ...

and copy it to http://yuml.me/diagram/scruffy/usecase/draw
