draw_uml 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86908c27699847e4e49ecd3e0f4f76c25bc9d929
4
- data.tar.gz: 98c770b3c7a3a49698f775b693033c3503e2a2e1
3
+ metadata.gz: 16573e1346be07f6a72455846d71b467481650eb
4
+ data.tar.gz: 21e1ea5695fa77ca471cfcc291f96ea59b5f2ad1
5
5
  SHA512:
6
- metadata.gz: 8342d7334734b458e48e566614b1a78c94928b723cd3b3a1f8dfaaee46bf433d125d7c10e6f1e574c743517b53762e8f7e4772cf12b076c9b72e5ac41efcf21e
7
- data.tar.gz: 459c443e3e93b395e3268cd107868a848d04f12691f9ccf646126129f105f033603f01a0f21a4f8f1708f379d1eb60a2c34b8c549c7e98c3349eeb82efd9c504
6
+ metadata.gz: 01061dff6d43219858caf9172bcacde58cb4331f9f34348b8a4a85f4d8c8ec50b50009b7b25cd7b01a549470b2c1a4ab0a390c9d6118be382e4b250f9ee1766e
7
+ data.tar.gz: 948eb17cdab82df86a8a75b09f792e1e92aa0989df6cc27140097fcc5c209624d60e53163408a2d278069962b6a0aaf38c2ff8a8f160c493dc94ac783f06e7e4
@@ -17,8 +17,8 @@ module DrawUml
17
17
  File.expand_path(self.diagram_path)
18
18
  end
19
19
 
20
- def source_file
21
- Dir[File.join(self.source_path, '**/*.' + self.diagram_extension)]
20
+ def parent_path
21
+ File.expand_path('..', self.source_path)
22
22
  end
23
23
 
24
24
  def dest_path
@@ -1,23 +1,20 @@
1
1
  require 'rack'
2
2
  require 'erb'
3
- require 'pp'
4
3
 
5
4
  module DrawUml
6
5
  class Engine
7
6
  class << self
8
7
  def call(env)
9
- request = Rack::Request.new(env)
10
- id = request.params['id'].to_i ||= 0
8
+ @request = Rack::Request.new(env)
9
+ file_path = @request.params['path'] ||= nil
10
+ image_path = nil
11
11
 
12
- # root = DrawUml::Tree.create(DrawUml::Configure.source_path)
13
- # root.each do |node|
14
- # end
15
-
16
- diagram = DrawUml::Diagram.new(DrawUml::Configure.dest_path)
17
- diagram.create(DrawUml::Configure.source_file[id])
18
-
19
- files = DrawUml::Configure.source_file.map { |file| File.basename(file, '.*') }
20
- image_path = File.join(DrawUml::Configure.image_path, files[id] + '.png')
12
+ unless file_path.nil?
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')
17
+ end
21
18
 
22
19
  erb = ERB.new(DrawUml::Configure.application_template)
23
20
  body = erb.result(binding)
@@ -26,6 +23,49 @@ module DrawUml
26
23
  headers = {'Content-Type' => 'text/html'}
27
24
  [status, headers, [body]]
28
25
  end
26
+
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
+ 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, '')
63
+ end
64
+
65
+ def expand_path(path)
66
+ File.join(DrawUml::Configure.parent_path, path)
67
+ end
68
+ # end private
29
69
  end
30
70
  end
31
71
  end
@@ -3,26 +3,23 @@ module DrawUml
3
3
  class Branch < DrawUml::Tree::Leaf
4
4
  attr_reader :entries
5
5
 
6
- def initialize(name)
6
+ def initialize(name, level=0)
7
7
  @entries = []
8
8
  super
9
9
  node
10
10
  end
11
11
 
12
- def each(&block)
13
- entries.each do |entry|
14
- block.call(entry)
15
- entry.each(&block) if entry.is_a?(DrawUml::Tree::Branch)
16
- end
12
+ def leaf?
13
+ false
17
14
  end
18
15
 
19
16
  private
20
17
  def node
21
18
  Dir[File.join(path, '*')].each do |path|
22
19
  if File.directory?(path)
23
- entries << DrawUml::Tree::Branch.new(path)
20
+ entries << DrawUml::Tree::Branch.new(path, level+1)
24
21
  else
25
- entries << DrawUml::Tree::Leaf.new(path)
22
+ entries << DrawUml::Tree::Leaf.new(path, level+1)
26
23
  end
27
24
  end
28
25
  end
@@ -1,11 +1,16 @@
1
1
  module DrawUml
2
2
  module Tree
3
3
  class Leaf
4
- attr_reader :name, :path
4
+ attr_reader :name, :path, :level
5
5
 
6
- def initialize(name)
6
+ def initialize(name, level=0)
7
7
  @name = File.basename(name, '.*')
8
8
  @path = File.expand_path(name)
9
+ @level = level
10
+ end
11
+
12
+ def leaf?
13
+ true
9
14
  end
10
15
  end
11
16
  end
@@ -1,3 +1,3 @@
1
1
  module DrawUml
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -2,28 +2,48 @@
2
2
  <html>
3
3
  <head><title>Diagrams</title>
4
4
  <style type="text/css">
5
- div.diagrams {
6
- padding-top: 20px;
5
+
6
+ body { background-color: #fff; color: #333; }
7
+
8
+ body, p, ol, ul, td {
9
+ font-family: helvetica, verdana, arial, sans-serif;
10
+ font-size: 13px;
11
+ line-height: 18px;
12
+ }
13
+
14
+ pre {
15
+ background-color: #eee;
16
+ padding: 10px;
17
+ font-size: 11px;
18
+ white-space: pre-wrap;
19
+ }
20
+
21
+ a { color: #000; }
22
+ a:visited { color: #666; }
23
+ a:hover { color: #fff; background-color:#000; }
24
+
25
+ h2 { padding-left: 10px; }
26
+ h3 { padding-left: 10px; }
27
+
28
+ div.tree {
7
29
  float:left;
8
30
  }
9
31
 
10
32
  div.draw img {
11
33
  padding-top: 40px;
12
- padding-left: 80px;
34
+ padding-left: 60px;
13
35
  }
14
36
  </style>
15
37
  </head>
16
38
  <body>
39
+ <h2>Unified Modeling Language</h2>
17
40
 
18
- <div class='diagrams'>
19
- <% files.each_with_index do |item, idx| %>
20
- <a href="<%= request.path %>?id=<%= idx %>"><%= item %></a><br>
21
- <% end %>
22
- </div>
23
-
24
- <div class='draw'>
25
- <img src=<%= image_path %>>
26
- </div>
41
+ <div class='tree'>
42
+ <%= tree %>
43
+ </div>
27
44
 
45
+ <div class='draw'>
46
+ <img src=<%= image_path %>>
47
+ </div>
28
48
  </body>
29
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.3
4
+ version: 0.0.4
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-09 00:00:00.000000000 Z
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack