draw_uml 0.0.1 → 0.0.2

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: 32353c04331e0f0f460b83fa73745bb54d04354b
4
- data.tar.gz: 989ee3f1245ebd68aebb132158b4764281e57236
3
+ metadata.gz: 6e9e424fce3edd91c448e800ae8e84b4c07fb03f
4
+ data.tar.gz: 8c6525c225b817c8f326b12f37d11f5779d8b72f
5
5
  SHA512:
6
- metadata.gz: bf9a6ac93c4e6b98892b607c7e0e3ec310910894f6a5bbfd61fed060d1c850e95fd123d7ce2f767511be1e6a891b4d07a147689217aa4304527821256326748b
7
- data.tar.gz: 0de6e7790525f79298888089a9019386ceafad2c35760dd8588906f991d3c125d7ef61e65db7d2cc71947d6fe20d63e759e1f42cf84a05b94f159b6a44cdd434
6
+ metadata.gz: 5fd3054cd9cf0d3f35a5ce03c6621d80378ac3e2e596b8fdba0adfdf3a13b75b7c5b8b9c9d893d5ce122f4d267c9891e32b98f532dcf6ad41f597b8d359023db
7
+ data.tar.gz: 3d0dd57faaa43dca9a5eafc6d16ccf4bb0dae9e0510871c661e5f1772f6926dd37c96881f192aa5117bc20bf47ada7fd9e812519dfcdea1bb6f1d7dbf5fdcac2
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .bundle
2
+ doc
2
3
  pkg
3
4
  public
4
5
  tmp
@@ -0,0 +1,12 @@
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,3 +1,25 @@
1
+ require 'pathname'
2
+
1
3
  require_relative 'draw_uml/version'
4
+ require_relative 'draw_uml/configure'
5
+ require_relative 'draw_uml/default'
2
6
  require_relative 'draw_uml/engine'
3
7
  require_relative 'draw_uml/diagram'
8
+
9
+ module DrawUml
10
+ class << self
11
+ def configure
12
+ yield DrawUml::Configure
13
+ end
14
+
15
+ def config
16
+ DrawUml::Configure
17
+ end
18
+
19
+ def root
20
+ @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
21
+ end
22
+ end
23
+ end
24
+
25
+ DrawUml::Configure.setup
@@ -0,0 +1,33 @@
1
+ module DrawUml
2
+ module Configure
3
+ class << self
4
+ attr_accessor :diagram_extension, :diagram_path, :static_path, :image_path
5
+
6
+ def setup
7
+ keys.each do |key|
8
+ instance_variable_set(:"@#{key}", DrawUml::Default.send(key))
9
+ end
10
+ end
11
+
12
+ def keys
13
+ @keys ||= %i[diagram_extension diagram_path static_path image_path]
14
+ end
15
+
16
+ def source_file
17
+ Dir[File.expand_path('**/*.' + self.diagram_extension, self.diagram_path)]
18
+ end
19
+
20
+ def dest_path
21
+ File.expand_path(File.join(self.static_path, self.image_path))
22
+ end
23
+
24
+ def templates_path
25
+ DrawUml.root.join('lib', 'templates').to_s
26
+ end
27
+
28
+ def application_template
29
+ File.read(File.expand_path('application.html.erb', File.join(self.templates_path, 'layouts')))
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ module DrawUml
2
+ module Default
3
+ DIAGRAM_EXTENSION = 'uml'.freeze
4
+ DIAGRAM_PATH = 'doc/diagrams/uml'.freeze
5
+ STATIC_PATH = 'public'.freeze
6
+ IMAGE_PATH = 'images/uml'.freeze
7
+
8
+ class << self
9
+ def options
10
+ Hash[DrawUml::Configure.keys.map{|key| [key, send(key)]}]
11
+ end
12
+
13
+ def diagram_extension
14
+ DIAGRAM_EXTENSION
15
+ end
16
+
17
+ def diagram_path
18
+ DIAGRAM_PATH
19
+ end
20
+
21
+ def static_path
22
+ STATIC_PATH
23
+ end
24
+
25
+ def image_path
26
+ IMAGE_PATH
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,12 +2,16 @@ require 'open3'
2
2
 
3
3
  module DrawUml
4
4
  class Diagram
5
- def self.create
6
- file = File.read(File.expand_path('sequence.md', './doc/uml'))
7
- path = File.expand_path('sequence.png', './public/images/draw-uml')
5
+ def initialize(path)
6
+ @path = path
7
+ FileUtils.mkdir_p(@path)
8
+ end
8
9
 
9
- cmd = "plantuml -pipe > #{path}"
10
- stdout, status = Open3.capture2(cmd, stdin_data: file)
10
+ def create(file)
11
+ raw = File.read(file)
12
+ filename = File.basename(file, '.*')
13
+ cmd = 'plantuml -pipe > ' + File.join(@path, filename + '.png')
14
+ stdout, status = Open3.capture2(cmd, stdin_data: raw)
11
15
  end
12
16
  end
13
17
  end
@@ -5,16 +5,20 @@ module DrawUml
5
5
  class Engine
6
6
  class << self
7
7
  def call(env)
8
- DrawUml::Diagram.create
8
+ params = Rack::Request.new(env).params
9
+ id = params['id'].to_i ||= 0
9
10
 
10
- status = 200
11
- headers = {'Content-Type' => 'text/html'}
11
+ diagram = DrawUml::Diagram.new(DrawUml::Configure.dest_path)
12
+ diagram.create(DrawUml::Configure.source_file[id])
13
+
14
+ files = DrawUml::Configure.source_file.map { |file| File.basename(file, '.*') }
15
+ path = File.join(DrawUml::Configure.image_path, files[id] + '.png')
12
16
 
13
- file = File.read(File.expand_path('application.html.erb', './lib/templates/layouts'))
14
- path = File.join('images', 'draw-uml', 'sequence.png')
15
- erb = ERB.new(file)
17
+ erb = ERB.new(DrawUml::Configure.application_template)
16
18
  body = erb.result(binding)
17
19
 
20
+ status = 200
21
+ headers = {'Content-Type' => 'text/html'}
18
22
  [status, headers, [body]]
19
23
  end
20
24
  end
@@ -1,3 +1,3 @@
1
1
  module DrawUml
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -5,6 +5,10 @@
5
5
  </head>
6
6
  <body>
7
7
 
8
+ <% files.each_with_index do |item, idx| %>
9
+ <a href="./?id=<%= idx %>"><%= item %></a><br>
10
+ <% end %>
11
+
8
12
  <img src=<%= path %>>
9
13
 
10
14
  </body>
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.1
4
+ version: 0.0.2
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-07 00:00:00.000000000 Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -55,8 +55,7 @@ dependencies:
55
55
  description: Drawing the Unified Modeling Language of Rack.
56
56
  email:
57
57
  - ogom@hotmail.co.jp
58
- executables:
59
- - draw_uml
58
+ executables: []
60
59
  extensions: []
61
60
  extra_rdoc_files: []
62
61
  files:
@@ -66,11 +65,12 @@ files:
66
65
  - LICENSE.txt
67
66
  - README.md
68
67
  - Rakefile
69
- - bin/draw_uml
70
68
  - config.ru
71
- - doc/uml/sequence.md
72
69
  - draw_uml.gemspec
70
+ - example/bin/draw_uml
73
71
  - lib/draw_uml.rb
72
+ - lib/draw_uml/configure.rb
73
+ - lib/draw_uml/default.rb
74
74
  - lib/draw_uml/diagram.rb
75
75
  - lib/draw_uml/engine.rb
76
76
  - lib/draw_uml/version.rb
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require_relative '../lib/draw_uml'
4
-
5
- DrawUml::Diagram.create
@@ -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