draw_uml 0.0.4 → 0.0.5

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: 16573e1346be07f6a72455846d71b467481650eb
4
- data.tar.gz: 21e1ea5695fa77ca471cfcc291f96ea59b5f2ad1
3
+ metadata.gz: ceb3e8989bb14bc8cf5566082e8141a34f5b27a9
4
+ data.tar.gz: b3b09a7a300aea789dd171453d54d64f62a1ce72
5
5
  SHA512:
6
- metadata.gz: 01061dff6d43219858caf9172bcacde58cb4331f9f34348b8a4a85f4d8c8ec50b50009b7b25cd7b01a549470b2c1a4ab0a390c9d6118be382e4b250f9ee1766e
7
- data.tar.gz: 948eb17cdab82df86a8a75b09f792e1e92aa0989df6cc27140097fcc5c209624d60e53163408a2d278069962b6a0aaf38c2ff8a8f160c493dc94ac783f06e7e4
6
+ metadata.gz: af9528a752388a7dae0584c702968363a5f6ae2b7d616c33eae1bbea014c56fefc6114b5ea0e8fb65efef339e07280c47aad9192ccf3a1b092019c2640ed2d39
7
+ data.tar.gz: 628067ce7c291d5c5c30ba9878fd7f4302dc2af990ccae4d2c4afb162d07f70a1d49d3e4904346ad216e291a0c6c4b055004e393a2607749e030760b18c94719
@@ -17,10 +17,6 @@ module DrawUml
17
17
  File.expand_path(self.diagram_path)
18
18
  end
19
19
 
20
- def parent_path
21
- File.expand_path('..', self.source_path)
22
- end
23
-
24
20
  def dest_path
25
21
  File.expand_path(File.join(self.static_path, self.image_path))
26
22
  end
@@ -1,9 +1,9 @@
1
1
  module DrawUml
2
2
  module Default
3
3
  DIAGRAM_EXTENSION = 'uml'.freeze
4
- DIAGRAM_PATH = 'doc/diagrams/uml'.freeze
4
+ DIAGRAM_PATH = 'doc/diagrams'.freeze
5
5
  STATIC_PATH = 'public'.freeze
6
- IMAGE_PATH = '/images/uml'.freeze
6
+ IMAGE_PATH = '/images/draw_uml'.freeze
7
7
 
8
8
  class << self
9
9
  def options
@@ -7,11 +7,17 @@ module DrawUml
7
7
  FileUtils.mkdir_p(@path)
8
8
  end
9
9
 
10
- def create(file)
11
- raw = File.read(file)
12
- filename = File.basename(file, '.*')
13
- cmd = 'plantuml -pipe > ' + File.join(@path, filename + '.png')
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))
14
+
15
+ cmd = 'plantuml -pipe > ' + file
14
16
  stdout, status = Open3.capture2(cmd, stdin_data: raw)
15
17
  end
18
+
19
+ def config
20
+ DrawUml::Configure
21
+ end
16
22
  end
17
23
  end
@@ -6,14 +6,13 @@ module DrawUml
6
6
  class << self
7
7
  def call(env)
8
8
  @request = Rack::Request.new(env)
9
- file_path = @request.params['path'] ||= nil
10
- image_path = nil
9
+ id = @request.params['id'] ||= nil
10
+ path = nil
11
11
 
12
- unless file_path.nil?
12
+ unless id.nil?
13
13
  diagram = DrawUml::Diagram.new(DrawUml::Configure.dest_path)
14
- diagram.create(expand_path(file_path))
15
- file = File.basename(file_path, '.*')
16
- image_path = File.join(DrawUml::Configure.image_path, file + '.png')
14
+ diagram.create(id)
15
+ path = File.join(DrawUml::Configure.image_path, id + '.png')
17
16
  end
18
17
 
19
18
  erb = ERB.new(DrawUml::Configure.application_template)
@@ -24,46 +23,29 @@ module DrawUml
24
23
  [status, headers, [body]]
25
24
  end
26
25
 
27
- def tree
28
- @raw = ''
29
- branch(DrawUml::Tree.create(DrawUml::Configure.source_path))
30
- @raw
31
- end
32
-
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
43
- end
44
- @raw += "<ul>"
45
- @raw += arr.map do |entry|
46
- link_to(entry)
47
- end.join("\n")
48
- @raw += "</ul></div>\n"
49
- end
50
-
51
26
  private
52
- def link_to(entry)
53
- raw = ''
54
- raw += "<li>"
55
- raw += "<a href=#{@request.path}?path="
56
- raw += "#{contract_path(entry.path)}>#{entry.name}</a>"
57
- raw += "</li>"
58
- raw
59
- end
60
-
61
- def contract_path(path)
62
- path.sub(DrawUml::Configure.parent_path, '')
27
+ def diagrams
28
+ @raw = ''
29
+ branch(DrawUml::Tree.create(DrawUml::Configure.source_path))
30
+ @raw
63
31
  end
64
32
 
65
- def expand_path(path)
66
- File.join(DrawUml::Configure.parent_path, path)
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
43
+ 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"
67
49
  end
68
50
  # end private
69
51
  end
@@ -13,6 +13,13 @@ module DrawUml
13
13
  false
14
14
  end
15
15
 
16
+ def each(&block)
17
+ entries.each do |entry|
18
+ block.call(entry)
19
+ entry.each(&block) if entry.is_a?(DrawUml::Tree::Branch)
20
+ end
21
+ end
22
+
16
23
  private
17
24
  def node
18
25
  Dir[File.join(path, '*')].each do |path|
@@ -1,12 +1,15 @@
1
1
  module DrawUml
2
2
  module Tree
3
3
  class Leaf
4
- attr_reader :name, :path, :level
4
+ attr_reader :name, :path, :level, :id
5
5
 
6
6
  def initialize(name, level=0)
7
7
  @name = File.basename(name, '.*')
8
8
  @path = File.expand_path(name)
9
9
  @level = level
10
+
11
+ raw = path.sub(DrawUml::Configure.source_path, '')
12
+ @id = raw.sub('.' + DrawUml::Configure.diagram_extension, '')
10
13
  end
11
14
 
12
15
  def leaf?
@@ -1,3 +1,3 @@
1
1
  module DrawUml
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -25,7 +25,7 @@
25
25
  h2 { padding-left: 10px; }
26
26
  h3 { padding-left: 10px; }
27
27
 
28
- div.tree {
28
+ div.diagrams {
29
29
  float:left;
30
30
  }
31
31
 
@@ -38,12 +38,12 @@
38
38
  <body>
39
39
  <h2>Unified Modeling Language</h2>
40
40
 
41
- <div class='tree'>
42
- <%= tree %>
41
+ <div class='diagrams'>
42
+ <%= diagrams %>
43
43
  </div>
44
44
 
45
45
  <div class='draw'>
46
- <img src=<%= image_path %>>
46
+ <img src=<%= path %>>
47
47
  </div>
48
48
  </body>
49
49
  </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
4
+ version: 0.0.5
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 00:00:00.000000000 Z
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack