Skip to content

Commit b3351ef

Browse files
author
greg
committed
Initial import
0 parents  commit b3351ef

11 files changed

+2249
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Gregoire Lejeune <[email protected]>

COPYING

+340
Large diffs are not rendered by default.

README.rdoc

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
= Ruby/yUML
2+
3+
Copyright (C) 2009 Gregoire Lejeune
4+
5+
* home : http://github.com/glejeune/ruby-yuml
6+
* doc : http://rdoc.info/projects/glejeune/ruby-yuml
7+
8+
== DESCRIPTION:
9+
10+
Capcode is a web microframework
11+
12+
== FEATURES/PROBLEMS:
13+
14+
=== 0.1.0
15+
* Initial release
16+
17+
== SYNOPSIS:
18+
19+
# file: sample.rb
20+
21+
== REQUIREMENTS:
22+
23+
* An internet acces ;)
24+
25+
== INSTALL:
26+
27+
sudo gem install ruby-yuml
28+
29+
== LICENSE:
30+
31+
Ruby/yUML is freely distributable according to the terms of the
32+
GNU General Public License.
33+
34+
This program is distributed without any warranty. See the file
35+
'COPYING' for details.
36+

Rakefile

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
require 'rake'
2+
require 'rake/clean'
3+
require 'rake/gempackagetask'
4+
require 'rake/rdoctask'
5+
require 'rake/testtask'
6+
require 'fileutils'
7+
require './lib/yuml/version'
8+
include FileUtils
9+
10+
NAME = "Ruby-yUML"
11+
VERS = YUML::VERSION
12+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log']
13+
RDOC_OPTS = ['--quiet', '--title', "Ruby-yUML, the Documentation",
14+
"--opname", "index.html",
15+
"--line-numbers",
16+
"--main", "README.rdoc",
17+
"--inline-source"]
18+
19+
desc "Packages up Ruby-yUML."
20+
task :default => [:package]
21+
task :package => [:clean]
22+
23+
task :doc => [:rdoc, :after_doc]
24+
25+
Rake::RDocTask.new do |rdoc|
26+
rdoc.rdoc_dir = 'doc/rdoc'
27+
rdoc.options += RDOC_OPTS
28+
rdoc.main = "README.rdoc"
29+
rdoc.title = "Ruby/yUML, the Documentation"
30+
rdoc.rdoc_files.add [
31+
'README.rdoc',
32+
'AUTHORS',
33+
'COPYING',
34+
'lib/yuml.rb'
35+
] + Dir.glob( "lib/yuml/*.rb" )
36+
end
37+
38+
task :after_doc do
39+
sh %{scp -r doc/rdoc/* #{ENV['USER']}@rubyforge.org:/var/www/gforge-projects/ruby-yuml/}
40+
end
41+
42+
spec =
43+
Gem::Specification.new do |s|
44+
s.name = NAME
45+
s.version = VERS
46+
s.platform = Gem::Platform::RUBY
47+
s.has_rdoc = true
48+
s.extra_rdoc_files = ["README.rdoc", "AUTHORS", "COPYING",
49+
'lib/yuml.rb'] + Dir.glob( "lib/yuml/*.rb" )
50+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras|test)\/']
51+
s.summary = "Ruby/yUML is a UML diagrams generator via yuml.me"
52+
s.description = s.summary
53+
s.author = "Grégoire Lejeune"
54+
s.email = '[email protected]'
55+
s.homepage = 'http://algorithmique.net'
56+
s.rubyforge_project = 'ruby-yuml'
57+
58+
s.required_ruby_version = ">= 1.8.1"
59+
60+
s.files = %w(COPYING README.rdoc AUTHORS setup.rb) +
61+
Dir.glob("{bin,doc,test,lib,examples}/**/*").delete_if {|item| item.include?("CVS") or item.include?("._")}
62+
63+
s.require_path = "lib"
64+
65+
s.post_install_message = <<EOM
66+
If For more information about Ruby/yUML, see
67+
http://algorithmique.net
68+
69+
EOM
70+
end
71+
72+
Rake::GemPackageTask.new(spec) do |p|
73+
p.need_tar = true
74+
p.gem_spec = spec
75+
end
76+
77+
task :install do
78+
sh %{rake package}
79+
sh %{sudo gem install pkg/#{NAME}-#{VERS}}
80+
end
81+
82+
task :uninstall => [:clean] do
83+
sh %{sudo gem uninstall #{NAME}}
84+
end

examples/use-case-diagram.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$:.unshift( "../lib" )
2+
require 'yuml'
3+
4+
x = YUML::useCaseDiagram( :scruffy, :scale => 75 ) {
5+
actor(:Admin) ^ actor(:User)
6+
actor(:Admin) - note( 'Most privilidged user' )
7+
actor(:User) - useCase(:Login)
8+
actor(:User) - useCase(:Logout)
9+
useCase(:Login) < useCase(:Reminder)
10+
useCase(:Login) > useCase(:Captcha)
11+
}
12+
13+
puts "To String :"
14+
puts x.to_s
15+
16+
puts "URL :"
17+
puts x.to_url( )
18+
19+
puts "Image saved as use-case-diagram.png"
20+
x.to_png( "use-case-diagram.png" )

lib/yuml.rb

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require 'yuml/entities'
2+
require 'yuml/use_case_diagram'
3+
4+
require 'net/http'
5+
6+
module YUML
7+
def self.options_string( options ) #:nodoc:
8+
str = ""
9+
sep = ""
10+
options.each do |k, v|
11+
if v.class == TrueClass
12+
str << sep << k.to_s
13+
else
14+
str << sep << k.to_s << ":" << v.to_s
15+
end
16+
sep = ";"
17+
end
18+
str << "/" if str.size > 0
19+
end
20+
21+
def self.output( options, data, type, file ) #:nodoc:
22+
opts = options.clone
23+
diagram = opts.delete(:diagram)
24+
uri = "/diagram/#{self.options_string(opts)}#{diagram}/#{data}#{type}"
25+
# puts "*** #{uri}"
26+
27+
writer = STDOUT
28+
writer = open(file, "wb") unless file.nil?
29+
res = Net::HTTP.start("yuml.me", 80) {|http|
30+
http.get(URI.escape(uri))
31+
}
32+
writer.write(res.body)
33+
writer.close
34+
end
35+
36+
def self.to_png( options, data, file ) #:nodoc:
37+
self.output( options, data, "", file)
38+
end
39+
40+
def self.to_pdf( options, data, file ) #:nodoc:
41+
self.output( options, data, ".pdf", file)
42+
end
43+
44+
def self.to_jpg( options, data, file ) #:nodoc:
45+
self.output( options, data, ".jpg", file)
46+
end
47+
48+
def self.to_url( options, data, type ) #:nodoc:
49+
opts = options.clone
50+
diagram = opts.delete(:diagram)
51+
if type.nil?
52+
type = ""
53+
else
54+
type = ".#{type}" if type[0].chr != "."
55+
end
56+
"http://yuml.me/diagram/#{self.options_string(opts)}#{diagram}/#{data}#{type}"
57+
end
58+
end

lib/yuml/entities.rb

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module YUML
2+
class Entity #:nodoc:
3+
def initialize( uc, name ) #:nodoc:
4+
@uc = uc
5+
@name = name
6+
end
7+
8+
def -(other)
9+
@uc.link( self, other, "-" )
10+
end
11+
12+
def ^(other)
13+
@uc.link( self, other, "^" )
14+
end
15+
16+
def <(other)
17+
@uc.link( self, other, "<" )
18+
end
19+
20+
def >(other)
21+
@uc.link( self, other, ">" )
22+
end
23+
end
24+
25+
class Actor < Entity
26+
def to_s #:nodoc:
27+
"[#{@name.to_s}]"
28+
end
29+
end
30+
31+
class UseCase < Entity
32+
def to_s #:nodoc:
33+
"(#{@name.to_s})"
34+
end
35+
end
36+
37+
class Note < Entity
38+
def to_s #:nodoc:
39+
"(note: #{@name.to_s})"
40+
end
41+
end
42+
end

lib/yuml/use_case_diagram.rb

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
module YUML
2+
# Create a new Use Case Diagram
3+
def self.useCaseDiagram( *options, &block )
4+
UseCaseDiagram.new( *options, &block )
5+
end
6+
7+
# Create a new Use Case Diagram
8+
class UseCaseDiagram
9+
def initialize( *options, &block )
10+
@options = {
11+
:diagram => "usecase"
12+
}
13+
options.each do |op|
14+
if op.class == Hash
15+
@options = @options.merge( op )
16+
else
17+
@options[op] = true
18+
end
19+
end
20+
21+
@actors = {}
22+
@useCases = {}
23+
@notes = {}
24+
@links = []
25+
26+
instance_eval(&block)
27+
end
28+
29+
# Create a new actor in a Use Case Diagram
30+
def actor(x)
31+
@actors[x] ||= Actor.new( self, x )
32+
end
33+
34+
# Create a new use case in a Use Case Diagram
35+
def useCase(x)
36+
@useCases[x] ||= UseCase.new( self, x )
37+
end
38+
39+
# Create a new note in a Use Case Diagram
40+
def note(x)
41+
@notes[x] ||= Note.new( self, x )
42+
end
43+
44+
def link(one, two, type) #:nodoc:
45+
@links << [one, type, two]
46+
end
47+
48+
# Generate the yUML file
49+
def to_s
50+
output = ""
51+
52+
@links.each do |l|
53+
output << l[0].to_s << l[1].to_s << l[2].to_s << "\n"
54+
end
55+
56+
output
57+
end
58+
59+
# Generate the diagram as a PNG file
60+
def to_png( file = nil )
61+
YUML.to_png( @options, self.to_s.split(/\n/).join( ', ' ), file )
62+
end
63+
64+
# Generate the diagram as a JPEG file
65+
def to_jpg( file = nil )
66+
YUML.to_jpg( @options, self.to_s.split(/\n/).join( ', ' ), file )
67+
end
68+
69+
# Generate the diagram as a PDF file
70+
def to_pdf( file = nil )
71+
YUML.to_pdf( @options, self.to_s.split(/\n/).join( ', ' ), file )
72+
end
73+
74+
# Return the yUML URL
75+
def to_url( type = nil )
76+
YUML.to_url( @options, self.to_s.split(/\n/).join( ', ' ), type )
77+
end
78+
end
79+
end

lib/yuml/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module YUML
2+
VERSION = "0.1.0"
3+
end

0 commit comments

Comments
 (0)