draw_uml 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -13
- data/lib/draw_uml.rb +1 -1
- data/lib/draw_uml/configure.rb +10 -4
- data/lib/draw_uml/diagram.rb +14 -9
- data/lib/draw_uml/engine.rb +60 -36
- data/lib/draw_uml/tree/branch.rb +4 -4
- data/lib/draw_uml/tree/leaf.rb +13 -7
- data/lib/draw_uml/version.rb +1 -1
- data/lib/templates/layouts/application.html.erb +20 -4
- metadata +2 -4
- data/example/bin/draw_uml +0 -12
- data/example/doc/diagrams/uml/sequence.uml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd61f33a91e12c47f1a95e534cdd12c28799df53
|
4
|
+
data.tar.gz: 1ae9588e9720cc9622a7c2595113eb1799e36700
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aab34bc9bd3ef270800cce6e9f4553f470d04f41c92d49dc5dee0ef2913c9972f4c98e211a67ca0f25e101675f9a9f9d01745cd87662a51db8af63f1086c4bbd
|
7
|
+
data.tar.gz: 0f00818298793b7a4c310df033ea0e5289cd7c469d5c6476960c8eba399d82c1e4e5ba2b4d3e9fc733d56f2df8df51ebc12878837893c566e9202f03d9040c35
|
data/README.md
CHANGED
@@ -2,32 +2,40 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/draw_uml.png)](https://rubygems.org/gems/draw_uml) [![Build Status](https://travis-ci.org/ogom/draw_uml.png?branch=master)](https://travis-ci.org/ogom/draw_uml)
|
4
4
|
|
5
|
-
|
5
|
+
Drawing the Unified Modeling Language of Rack.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
```
|
11
|
+
```
|
12
12
|
gem 'draw_uml'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
|
-
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
18
22
|
|
19
|
-
|
23
|
+
### Rails
|
20
24
|
|
21
|
-
|
25
|
+
Add this line to your `config/routes.rb`:
|
22
26
|
|
23
|
-
|
27
|
+
```
|
28
|
+
mount DrawUml::Engine, at: '/rails/draw/uml'
|
29
|
+
```
|
30
|
+
|
31
|
+
Draw by selecting the model:
|
32
|
+
|
33
|
+
![example_uml](http://ogom.github.io/draw_uml/assets/img/example_uml.png)
|
34
|
+
|
35
|
+
## Use
|
24
36
|
|
25
|
-
|
37
|
+
* [PlantUML](http://plantuml.sourceforge.net/)
|
26
38
|
|
27
|
-
##
|
39
|
+
## License
|
28
40
|
|
29
|
-
|
30
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
-
5. Create a new Pull Request
|
41
|
+
* MIT
|
data/lib/draw_uml.rb
CHANGED
data/lib/draw_uml/configure.rb
CHANGED
@@ -7,6 +7,8 @@ module DrawUml
|
|
7
7
|
keys.each do |key|
|
8
8
|
instance_variable_set(:"@#{key}", DrawUml::Default.send(key))
|
9
9
|
end
|
10
|
+
|
11
|
+
FileUtils.mkdir_p(self.source_path)
|
10
12
|
end
|
11
13
|
|
12
14
|
def keys
|
@@ -14,19 +16,23 @@ module DrawUml
|
|
14
16
|
end
|
15
17
|
|
16
18
|
def source_path
|
17
|
-
File.expand_path(self.diagram_path)
|
19
|
+
@source_path ||= File.expand_path(self.diagram_path)
|
18
20
|
end
|
19
21
|
|
20
22
|
def dest_path
|
21
|
-
File.expand_path(File.join(self.static_path, self.image_path))
|
23
|
+
@dest_path ||= File.expand_path(File.join(self.static_path, self.image_path))
|
22
24
|
end
|
23
25
|
|
24
26
|
def templates_path
|
25
|
-
DrawUml.root.join('lib', 'templates').to_s
|
27
|
+
@templates_path ||= DrawUml.root.join('lib', 'templates').to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def application_layout
|
31
|
+
@application_layout ||= File.expand_path('application.html.erb', File.join(self.templates_path, 'layouts'))
|
26
32
|
end
|
27
33
|
|
28
34
|
def application_template
|
29
|
-
File.read(
|
35
|
+
File.read(self.application_layout)
|
30
36
|
end
|
31
37
|
end
|
32
38
|
end
|
data/lib/draw_uml/diagram.rb
CHANGED
@@ -7,17 +7,22 @@ module DrawUml
|
|
7
7
|
FileUtils.mkdir_p(@path)
|
8
8
|
end
|
9
9
|
|
10
|
-
def create(
|
11
|
-
|
12
|
-
|
13
|
-
FileUtils.mkdir_p(File.dirname(file))
|
10
|
+
def create(source_path, dest_path)
|
11
|
+
raw = File.read(source_path)
|
12
|
+
digest = Digest::MD5.hexdigest(raw)
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
tmp_file = File.join(@path, dest_path + ".#{digest}.tmp")
|
15
|
+
unless File.exist?(tmp_file)
|
16
|
+
png_file = File.join(@path, dest_path + '.png')
|
17
|
+
FileUtils.mkdir_p(File.dirname(png_file))
|
18
|
+
|
19
|
+
cmd = 'plantuml -pipe > ' + png_file
|
20
|
+
stdout, status = Open3.capture2(cmd, stdin_data: raw)
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
files = Dir[File.join(@path, dest_path + ".*.tmp")]
|
23
|
+
File.unlink(*files)
|
24
|
+
File.write(tmp_file, nil)
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
data/lib/draw_uml/engine.rb
CHANGED
@@ -3,51 +3,75 @@ require 'erb'
|
|
3
3
|
|
4
4
|
module DrawUml
|
5
5
|
class Engine
|
6
|
-
|
7
|
-
def call(env)
|
8
|
-
@request = Rack::Request.new(env)
|
9
|
-
id = @request.params['id'] ||= nil
|
10
|
-
path = nil
|
6
|
+
attr_accessor :request, :tree
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
path = File.join(DrawUml::Configure.image_path, id + '.png')
|
16
|
-
end
|
8
|
+
def call(env)
|
9
|
+
@request = Rack::Request.new(env)
|
10
|
+
@tree = DrawUml::Tree.create(DrawUml::Configure.source_path)
|
17
11
|
|
18
|
-
|
19
|
-
|
12
|
+
status = 200
|
13
|
+
headers = {'Content-Type' => 'text/html'}
|
14
|
+
body = ERB.new(DrawUml::Configure.application_template).result(binding)
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
[status, headers, [body]]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def image_path
|
21
|
+
path = nil
|
22
|
+
entry = find_entry(request.path_info)
|
23
|
+
unless entry.nil?
|
24
|
+
diagram = DrawUml::Diagram.new(DrawUml::Configure.dest_path)
|
25
|
+
diagram.create(entry.path, entry.id)
|
26
|
+
path = File.join(DrawUml::Configure.image_path, entry.id + '.png')
|
27
|
+
end
|
28
|
+
path
|
24
29
|
end
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
def find_entry(id)
|
32
|
+
raw = nil
|
33
|
+
tree.each do |entry|
|
34
|
+
if entry.id == id
|
35
|
+
raw = entry
|
36
|
+
break
|
37
|
+
end
|
31
38
|
end
|
39
|
+
raw
|
40
|
+
end
|
41
|
+
|
42
|
+
def diagram_tag
|
43
|
+
render_branch(tree)
|
44
|
+
end
|
32
45
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
46
|
+
def render_branch(node)
|
47
|
+
raw = ''
|
48
|
+
raw += "<div style=\"padding-left: #{node.level}0px;\">\n"
|
49
|
+
raw += "<h3 onclick=\"check_branch('#{node.id}')\" >#{node.name}</h3>\n"
|
50
|
+
raw += "<div id=#{node.id}>\n"
|
51
|
+
arr = []
|
52
|
+
node.entries.each do |entry|
|
53
|
+
if entry.leaf?
|
54
|
+
arr << entry
|
55
|
+
else
|
56
|
+
raw += render_branch(entry)
|
43
57
|
end
|
44
|
-
@raw += "<ul>"
|
45
|
-
@raw += arr.map do |entry|
|
46
|
-
"<li><a href=#{@request.path}?id=#{entry.id}>#{entry.name}</a></li>"
|
47
|
-
end.join("\n")
|
48
|
-
@raw += "</ul></div>\n"
|
49
58
|
end
|
50
|
-
|
59
|
+
raw += "<ul>" + arr.map do |entry|
|
60
|
+
"<li><a href=#{request.script_name}#{entry.id}>#{entry.name}</a></li>"
|
61
|
+
end.join("\n")
|
62
|
+
raw += "</ul></div></div>\n"
|
63
|
+
raw
|
64
|
+
end
|
65
|
+
# end private
|
66
|
+
|
67
|
+
class << self
|
68
|
+
def prototype
|
69
|
+
@prototype ||= new
|
70
|
+
end
|
71
|
+
|
72
|
+
def call(env)
|
73
|
+
prototype.call(env)
|
74
|
+
end
|
51
75
|
end
|
52
76
|
end
|
53
77
|
end
|
data/lib/draw_uml/tree/branch.rb
CHANGED
@@ -3,9 +3,9 @@ module DrawUml
|
|
3
3
|
class Branch < DrawUml::Tree::Leaf
|
4
4
|
attr_reader :entries
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@entries = []
|
6
|
+
def initialize(path, level=0, trunk=nil)
|
8
7
|
super
|
8
|
+
@entries = []
|
9
9
|
node
|
10
10
|
end
|
11
11
|
|
@@ -24,9 +24,9 @@ module DrawUml
|
|
24
24
|
def node
|
25
25
|
Dir[File.join(path, '*')].each do |path|
|
26
26
|
if File.directory?(path)
|
27
|
-
entries << DrawUml::Tree::Branch.new(path, level
|
27
|
+
entries << DrawUml::Tree::Branch.new(path, level, trunk)
|
28
28
|
else
|
29
|
-
entries << DrawUml::Tree::Leaf.new(path, level
|
29
|
+
entries << DrawUml::Tree::Leaf.new(path, level, trunk)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/draw_uml/tree/leaf.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
module DrawUml
|
2
2
|
module Tree
|
3
3
|
class Leaf
|
4
|
-
attr_reader :name, :path, :level, :id
|
4
|
+
attr_reader :name, :path, :level, :trunk, :id
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@name = File.basename(
|
8
|
-
@path = File.expand_path(
|
9
|
-
@level = level
|
6
|
+
def initialize(path, level=0, trunk=nil)
|
7
|
+
@name = File.basename(path, '.*')
|
8
|
+
@path = File.expand_path(path)
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
if trunk.nil?
|
11
|
+
@level = level
|
12
|
+
@trunk = path
|
13
|
+
@id = :root
|
14
|
+
else
|
15
|
+
@level = level + 1
|
16
|
+
@trunk = trunk
|
17
|
+
@id = "#{File.dirname(@path)}/#{@name}".sub(trunk, '')
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
def leaf?
|
data/lib/draw_uml/version.rb
CHANGED
@@ -27,23 +27,39 @@
|
|
27
27
|
|
28
28
|
div.diagrams {
|
29
29
|
float:left;
|
30
|
+
padding-right: 30px;
|
31
|
+
padding-bottom: 10px;
|
32
|
+
border-right: solid #eee;
|
30
33
|
}
|
31
34
|
|
32
35
|
div.draw img {
|
33
36
|
padding-top: 40px;
|
34
|
-
padding-left:
|
37
|
+
padding-left: 20px;
|
35
38
|
}
|
36
39
|
</style>
|
40
|
+
|
41
|
+
<script type="text/ecmascript">
|
42
|
+
function check_branch(id) {
|
43
|
+
console.log(id);
|
44
|
+
var element = document.getElementById(id);
|
45
|
+
if (element.style.display == 'none') {
|
46
|
+
element.style.display = 'block';
|
47
|
+
} else {
|
48
|
+
element.style.display = 'none';
|
49
|
+
}
|
50
|
+
}
|
51
|
+
</script>
|
37
52
|
</head>
|
38
53
|
<body>
|
39
|
-
<h2>
|
54
|
+
<h2>Models</h2>
|
55
|
+
<p>Drawing the Unified Modeling Language</p>
|
40
56
|
|
41
57
|
<div class='diagrams'>
|
42
|
-
<%=
|
58
|
+
<%= diagram_tag %>
|
43
59
|
</div>
|
44
60
|
|
45
61
|
<div class='draw'>
|
46
|
-
<img src=<%=
|
62
|
+
<img src=<%= image_path %>>
|
47
63
|
</div>
|
48
64
|
</body>
|
49
65
|
</html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: draw_uml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ogom
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -67,8 +67,6 @@ files:
|
|
67
67
|
- Rakefile
|
68
68
|
- config.ru
|
69
69
|
- draw_uml.gemspec
|
70
|
-
- example/bin/draw_uml
|
71
|
-
- example/doc/diagrams/uml/sequence.uml
|
72
70
|
- lib/draw_uml.rb
|
73
71
|
- lib/draw_uml/configure.rb
|
74
72
|
- lib/draw_uml/default.rb
|
data/example/bin/draw_uml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require_relative '../../lib/draw_uml'
|
4
|
-
|
5
|
-
DrawUml.configure do |config|
|
6
|
-
config.diagram_path = 'example/doc/diagrams/uml'
|
7
|
-
end
|
8
|
-
|
9
|
-
diagram = DrawUml::Diagram.new(DrawUml::Configure.dest_path)
|
10
|
-
DrawUml::Configure.source_file.each do |file|
|
11
|
-
diagram.create(file)
|
12
|
-
end
|