plantuml_builder 0.1.1 → 0.2.0

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
- SHA256:
3
- metadata.gz: f69f32a774d145c5795ffe8f749ee9c189f9da503ea697a699c328a2e7b1ccff
4
- data.tar.gz: 8f651d9ceadb4ceced50a955b3eba05ead3b8c62d16f1b54ba012b06b2493fc3
2
+ SHA1:
3
+ metadata.gz: adacb6b59b1b94168c9c92b1c941e4e98d711f42
4
+ data.tar.gz: 1e1a51cab501b859d19cf6b70d38f3476903d0da
5
5
  SHA512:
6
- metadata.gz: 1b050f10cde7f32731f8f41e0d9b6b0c680af9559cf3d54421e6ffedd5b412d7f221f0f71cb388a6c84b163b4587ae147feec07b10d090eca7a53070776fe91e
7
- data.tar.gz: 678e8a424b4ef20db9d213a01b2482c27328ac42c8c9541537a8e04cba5c931a1c4231fd73e2e3d91f2ae96cd8d733e5814bbc7b0673ddcca4b5c86c8d595ae1
6
+ metadata.gz: 8a2b6539e65894c0d66f45323b6589996e71c36b3a67abeebc514e6aba57cf26940d7dc0b68105abf71e21534088ab7f1b47b4b4f8a257df0bbdd8f67d24c2e8
7
+ data.tar.gz: 00be3645ea6b221f78b55a0515f7e6cb45dea4eeeb819b181560d1ebb7f5c403365c978ad9696863c324cca41b65ff32477fc181c1f38e840fca0e0f491f6647
data/README.md CHANGED
@@ -40,7 +40,7 @@ For example, [sequence diagram](http://plantuml.com/sequence-diagram):
40
40
 
41
41
  The diagram above will be rendered to:
42
42
 
43
- ![](http://www.plantuml.com/plantuml/png/SoWkIImgAStDuL9GI4mkoIzI22rEBG9oW0Z4Kj2rK_2j34ujAijCJbMmKYX8BKhBByg5gCuiIon9HKXpAG11KMf9QL6UGabHAOYVaef5cKDgNWh8HW00)
43
+ ![](http://www.plantuml.com/plantuml/png/UDfJK70eBaaiAYdDpU5I08B4v9By8eNGujGYC1S8G6m5NJi5tyhWrAAopEHK1Ik5WjIYjFoYN9YEpBB4abI40gZEejIIqg8yXPAYKeX8IYfMfGwfUIaWsm5R-2hl)
44
44
 
45
45
  PlantUML web service expects compression of such diagrams into
46
46
  it's own format. The diagram above should be converted to
@@ -53,6 +53,29 @@ Using `plantuml_builder` you can fetch rendered diagrams from specified server.
53
53
 
54
54
  Diagrams could be fetched as SVG, PNG, and TXT (ASCII-art) format.
55
55
 
56
+
57
+ ### Using as standalone app
58
+
59
+ To build one diagram in SVG format from plantuml.com run:
60
+
61
+ ```bash
62
+ $ plantuml_build png source_file.wsd destination_file.svg
63
+ ```
64
+
65
+ If you need build whole directory, specify `-R` flag before source. To build it into PNG diagrams:
66
+
67
+ ```bash
68
+ $ plantuml_build png -R src dest
69
+ ```
70
+
71
+ If you want to use local server as endpoint, specify it with `--endpoint`:
72
+
73
+ ```bash
74
+ $ plantuml_build txt source_file.wsd destination_file.txt --endpoint=http://localhost:8080
75
+ ```
76
+
77
+ ### Using as library
78
+
56
79
  First, receive diagram text (from WSD or other file format).
57
80
 
58
81
  ```ruby
@@ -68,7 +91,7 @@ wsd = <<-WSD
68
91
  WSD
69
92
  ```
70
93
 
71
- ### SVG
94
+ #### SVG
72
95
 
73
96
  Fetch diagram as SVG:
74
97
 
@@ -82,7 +105,7 @@ to store it in version control system. So, `plantuml_builder` fixes it.
82
105
  Also, XML comment with description would be removed.
83
106
 
84
107
 
85
- ### PNG
108
+ #### PNG
86
109
 
87
110
  Fetch diagram as PNG:
88
111
  ```ruby
@@ -90,7 +113,7 @@ PlantumlBuilder::Formats::PNG.new(wsd).load
90
113
  => # diagram in PNG
91
114
  ```
92
115
 
93
- ### TXT (ASCII-art)
116
+ #### TXT (ASCII-art)
94
117
 
95
118
  ```ruby
96
119
  PlantumlBuilder::Formats::TXT.new(wsd).load
data/bin/console CHANGED
@@ -1,13 +1,9 @@
1
- #!/usr/bin/env ruby
1
+ #! ruby
2
2
 
3
- require "bundler/setup"
4
- require "plantuml_builder"
3
+ require 'bundler/setup'
4
+ require 'plantuml_builder'
5
5
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
6
+ puts "Hello"
8
7
 
9
- require "pry"
8
+ require 'pry'
10
9
  Pry.start
11
-
12
- require "irb"
13
- IRB.start
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'docopt'
6
+
7
+ doc = <<DOCOPT
8
+ plantuml_build allows to build diagrams with PlantUML
9
+
10
+ Usage:
11
+ #{__FILE__} (svg|png|txt) <source> <destination> [--endpoint=<endpoint>]
12
+ #{__FILE__} (svg|png|txt) -R <source_dir> <destination_dir> [--endpoint=<endpoint>]
13
+ #{__FILE__} -h | --help
14
+ #{__FILE__} --version
15
+
16
+
17
+ Options:
18
+ -h --help Show this screen.
19
+ --version Show version.
20
+ -R Recursively build folder.
21
+ --endpoint=<endpoint> URL of PlantUML endpoint
22
+
23
+ DOCOPT
24
+
25
+ CLI = true
26
+ require 'plantuml_builder'
27
+
28
+ begin
29
+ args = PlantumlBuilder::Cli::Args.new(Docopt::docopt(doc))
30
+ PlantumlBuilder::Cli::CliProcessor.new(args).process
31
+ rescue Docopt::Exit => e
32
+ puts e.message
33
+ end
@@ -0,0 +1,53 @@
1
+ module PlantumlBuilder
2
+ module Cli
3
+ class Args
4
+ def initialize(args_hash)
5
+ self.args_hash = args_hash
6
+ end
7
+
8
+ def svg?
9
+ args_hash['svg']
10
+ end
11
+
12
+ def png?
13
+ args_hash['png']
14
+ end
15
+
16
+ def txt?
17
+ args_hash['txt']
18
+ end
19
+
20
+ def source
21
+ args_hash['<source>']
22
+ end
23
+
24
+ def destination
25
+ args_hash['<destination>']
26
+ end
27
+
28
+ def recursive?
29
+ args_hash['-R']
30
+ end
31
+
32
+ def source_dir
33
+ args_hash["<source_dir>"]
34
+ end
35
+
36
+ def destination_dir
37
+ args_hash["<destination_dir>"]
38
+ end
39
+
40
+ def version?
41
+ args_hash['--version']
42
+ end
43
+
44
+ def endpoint
45
+ args_hash['--endpoint']
46
+ end
47
+
48
+ private
49
+
50
+ attr_accessor :args_hash
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,81 @@
1
+ module PlantumlBuilder
2
+ module Cli
3
+ class CliProcessor
4
+ def initialize(args_object)
5
+ self.args_object = args_object
6
+ end
7
+
8
+ def process
9
+ case
10
+ when args_object.version?
11
+ puts_version
12
+ when args_object.recursive?
13
+ process_folder
14
+ else
15
+ process_file(args_object.source, args_object.destination)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def puts_version
22
+ puts PlantumlBuilder::VERSION
23
+ exit(0)
24
+ end
25
+
26
+ def process_folder
27
+ Dir.glob("#{args_object.source_dir}/**/*.*").each do |file|
28
+ r = Regexp.new("^#{args_object.source_dir}")
29
+ dest = file.gsub(r, args_object.destination_dir)
30
+
31
+ destdir = File.dirname(dest)
32
+ FileUtils.mkdir_p(destdir)
33
+
34
+ dest_file = "#{destdir}/#{File.basename(dest, File.extname(dest))}.#{ext}"
35
+
36
+ process_file(file, dest_file)
37
+ end
38
+
39
+ rescue Errno::EEXIST => e
40
+ puts e.message
41
+ exit(1)
42
+ end
43
+
44
+ def process_file(source, dest)
45
+ uml = File.read(source)
46
+ f = args_object.endpoint.nil? ? [uml] : [uml, args_object.endpoint]
47
+
48
+ File.open(dest, 'w') do |file|
49
+ file.write(format.new(*f).load)
50
+ end
51
+ rescue Errno::ENOENT, Errno::EISDIR, SocketError => e
52
+ puts e.message
53
+ exit(1)
54
+ end
55
+
56
+ def format
57
+ case
58
+ when args_object.svg?
59
+ PlantumlBuilder::Formats::SVG
60
+ when args_object.png?
61
+ PlantumlBuilder::Formats::PNG
62
+ when args_object.txt?
63
+ PlantumlBuilder::Formats::TXT
64
+ end
65
+ end
66
+
67
+ def ext
68
+ case
69
+ when args_object.svg?
70
+ 'svg'
71
+ when args_object.png?
72
+ 'png'
73
+ when args_object.txt?
74
+ 'txt'
75
+ end
76
+ end
77
+
78
+ attr_accessor :args_object
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,5 @@
1
+ require 'net/http'
2
+
1
3
  module PlantumlBuilder
2
4
  class DiagramFetcher
3
5
  def initialize(url)
@@ -14,7 +14,9 @@ module PlantumlBuilder
14
14
  end
15
15
 
16
16
  def make_diagram_versionable
17
- self.data = data.split('>').join(">\n").gsub(/<!--.*-->/m, '')
17
+ self.data = data.split('>')
18
+ .join(">\n")
19
+ .gsub(/<!--[\s\S]*?-->/, '') + '>'
18
20
  end
19
21
  end
20
22
 
@@ -1,3 +1,3 @@
1
1
  module PlantumlBuilder
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -7,5 +7,10 @@ require 'plantuml_builder/diagram_fetcher'
7
7
  require 'plantuml_builder/format'
8
8
  require 'plantuml_builder/formats'
9
9
 
10
+ if defined?(CLI)
11
+ require 'plantuml_builder/cli/args'
12
+ require 'plantuml_builder/cli/cli_processor'
13
+ end
14
+
10
15
  module PlantumlBuilder
11
16
  end
@@ -16,10 +16,11 @@ Gem::Specification.new do |spec|
16
16
  spec.license = 'MIT'
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- spec.bindir = 'exe'
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.executables = 'plantuml_build'
21
20
  spec.require_paths = ['lib']
22
21
 
22
+ spec.add_dependency 'docopt', '~> 0.5.0'
23
+
23
24
  spec.add_development_dependency 'bundler', '~> 1.11'
24
25
  spec.add_development_dependency 'pry'
25
26
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plantuml_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Vernidub
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-09 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docopt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -97,7 +111,8 @@ dependencies:
97
111
  description: Gem to build text diagrams with plant uml
98
112
  email:
99
113
  - svernidub@gmail.com
100
- executables: []
114
+ executables:
115
+ - plantuml_build
101
116
  extensions: []
102
117
  extra_rdoc_files: []
103
118
  files:
@@ -109,8 +124,11 @@ files:
109
124
  - README.md
110
125
  - Rakefile
111
126
  - bin/console
127
+ - bin/plantuml_build
112
128
  - bin/setup
113
129
  - lib/plantuml_builder.rb
130
+ - lib/plantuml_builder/cli/args.rb
131
+ - lib/plantuml_builder/cli/cli_processor.rb
114
132
  - lib/plantuml_builder/compressor.rb
115
133
  - lib/plantuml_builder/deflate.rb
116
134
  - lib/plantuml_builder/diagram_fetcher.rb
@@ -139,7 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
157
  - !ruby/object:Gem::Version
140
158
  version: '0'
141
159
  requirements: []
142
- rubygems_version: 3.0.1
160
+ rubyforge_project:
161
+ rubygems_version: 2.4.5.1
143
162
  signing_key:
144
163
  specification_version: 4
145
164
  summary: Gem to build text diagrams with plant uml