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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ceb3e8989bb14bc8cf5566082e8141a34f5b27a9
4
- data.tar.gz: b3b09a7a300aea789dd171453d54d64f62a1ce72
3
+ metadata.gz: dd61f33a91e12c47f1a95e534cdd12c28799df53
4
+ data.tar.gz: 1ae9588e9720cc9622a7c2595113eb1799e36700
5
5
  SHA512:
6
- metadata.gz: af9528a752388a7dae0584c702968363a5f6ae2b7d616c33eae1bbea014c56fefc6114b5ea0e8fb65efef339e07280c47aad9192ccf3a1b092019c2640ed2d39
7
- data.tar.gz: 628067ce7c291d5c5c30ba9878fd7f4302dc2af990ccae4d2c4afb162d07f70a1d49d3e4904346ad216e291a0c6c4b055004e393a2607749e030760b18c94719
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
- TODO: Write a gem description
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
- ```ruby
11
+ ```
12
12
  gem 'draw_uml'
13
13
  ```
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle
17
+ ```
18
+ $ bundle
19
+ ```
20
+
21
+ ## Usage
18
22
 
19
- Or install it yourself as:
23
+ ### Rails
20
24
 
21
- $ gem install draw_uml
25
+ Add this line to your `config/routes.rb`:
22
26
 
23
- ## Usage
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
- TODO: Write usage instructions here
37
+ * [PlantUML](http://plantuml.sourceforge.net/)
26
38
 
27
- ## Contributing
39
+ ## License
28
40
 
29
- 1. Fork it ( https://github.com/[my-github-username]/draw_uml/fork )
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
@@ -18,7 +18,7 @@ module DrawUml
18
18
  end
19
19
 
20
20
  def root
21
- @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
21
+ @root ||= Pathname.new(File.expand_path('..', File.dirname(__FILE__)))
22
22
  end
23
23
  end
24
24
  end
@@ -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(File.expand_path('application.html.erb', File.join(self.templates_path, 'layouts')))
35
+ File.read(self.application_layout)
30
36
  end
31
37
  end
32
38
  end
@@ -7,17 +7,22 @@ module DrawUml
7
7
  FileUtils.mkdir_p(@path)
8
8
  end
9
9
 
10
- def create(path)
11
- file = File.join(@path, path + '.png')
12
- raw = File.read(File.join(config.source_path, path + '.' + config.diagram_extension))
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
- cmd = 'plantuml -pipe > ' + file
16
- stdout, status = Open3.capture2(cmd, stdin_data: raw)
17
- end
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
- def config
20
- DrawUml::Configure
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
@@ -3,51 +3,75 @@ require 'erb'
3
3
 
4
4
  module DrawUml
5
5
  class Engine
6
- class << self
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
- unless id.nil?
13
- diagram = DrawUml::Diagram.new(DrawUml::Configure.dest_path)
14
- diagram.create(id)
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
- erb = ERB.new(DrawUml::Configure.application_template)
19
- body = erb.result(binding)
12
+ status = 200
13
+ headers = {'Content-Type' => 'text/html'}
14
+ body = ERB.new(DrawUml::Configure.application_template).result(binding)
20
15
 
21
- status = 200
22
- headers = {'Content-Type' => 'text/html'}
23
- [status, headers, [body]]
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
- private
27
- def diagrams
28
- @raw = ''
29
- branch(DrawUml::Tree.create(DrawUml::Configure.source_path))
30
- @raw
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
- def branch(node)
34
- @raw += "<div style=\"padding-left: #{node.level}0px;\">\n"
35
- @raw += "<h3>#{node.name}</h3>\n"
36
- arr = []
37
- node.entries.each do |entry|
38
- if entry.leaf?
39
- arr << entry
40
- else
41
- branch(entry)
42
- end
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
- # end private
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
@@ -3,9 +3,9 @@ module DrawUml
3
3
  class Branch < DrawUml::Tree::Leaf
4
4
  attr_reader :entries
5
5
 
6
- def initialize(name, level=0)
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+1)
27
+ entries << DrawUml::Tree::Branch.new(path, level, trunk)
28
28
  else
29
- entries << DrawUml::Tree::Leaf.new(path, level+1)
29
+ entries << DrawUml::Tree::Leaf.new(path, level, trunk)
30
30
  end
31
31
  end
32
32
  end
@@ -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(name, level=0)
7
- @name = File.basename(name, '.*')
8
- @path = File.expand_path(name)
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
- raw = path.sub(DrawUml::Configure.source_path, '')
12
- @id = raw.sub('.' + DrawUml::Configure.diagram_extension, '')
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?
@@ -1,3 +1,3 @@
1
1
  module DrawUml
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -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: 60px;
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>Unified Modeling Language</h2>
54
+ <h2>Models</h2>
55
+ <p>Drawing the Unified Modeling Language</p>
40
56
 
41
57
  <div class='diagrams'>
42
- <%= diagrams %>
58
+ <%= diagram_tag %>
43
59
  </div>
44
60
 
45
61
  <div class='draw'>
46
- <img src=<%= path %>>
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.5
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-12 00:00:00.000000000 Z
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
@@ -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
@@ -1,7 +0,0 @@
1
- @startuml
2
- Alice -> Bob: Authentication Request
3
- Bob --> Alice: Authentication Response
4
-
5
- Alice -> Bob: Another authentication Request
6
- Alice <-- Bob: another authentication Response
7
- @enduml