gliffynator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2c6e7afdb599662de3762b5e0f0da857de7846b
4
+ data.tar.gz: 72e345378b0510cedbfc651bde8112f752c3b4ad
5
+ SHA512:
6
+ metadata.gz: 5ea2d3261cdd13cfaac4b2aadfea6e0ccd04b80ca0965f50365e783155c0958948188e04e533f9e350362a7c9e5be6c816e1d1abb31bdfbe9f0b297ecee38c3b
7
+ data.tar.gz: 9f154ac1eeb6fb1a9a255ea2334c2aec4c1a34330b7f544ef102345e91f7368a72e0f44ddd772c8f2ed45bad22b5a60a2b274f42d8506a8ca4a5134be6438e4f
data/.editorconfig ADDED
@@ -0,0 +1,14 @@
1
+ # editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ charset = utf-8
7
+ indent_size = 2
8
+ indent_style = space
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
14
+
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .DS_Store
16
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'pry'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2
+ of this software and associated documentation files (the "Software"), to deal
3
+ in the Software without restriction, including without limitation the rights
4
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5
+ copies of the Software, and to permit persons to whom the Software is
6
+ furnished to do so, subject to the following conditions:
7
+
8
+
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Gliffynator
2
+
3
+ [![Build Status](https://travis-ci.org/timothypage/gliffynator.svg)](https://travis-ci.org/timothypage/gliffynator)
4
+
5
+ make gliffy diagrams in ruby!
6
+
7
+
8
+ ## simple DSL
9
+
10
+ diagram = Gliffynator::Diagram.new do
11
+ add_arrow 50, 50, 100, :right, "Some Text"
12
+ end
13
+
14
+ diagram.render
15
+
16
+ or
17
+
18
+ diagram = Gliffynator::Diagram.new
19
+ diagram.add_arrow 50, 50, 100, :right, "Some Text"
20
+
21
+ diagram.render
22
+
23
+ the DSL will keep track of some basic housekeeping, like unique IDs for most objects and their children. If this isn't done, your document may appear correctly until you try and edit it, when moving one thing might cause other side effects!
24
+
25
+ ## Usage
26
+
27
+ you can save a diagram to a file, just make sure it ends in `.gliffy`
28
+
29
+ diagram.render "example.gliffy"
30
+
31
+ or you can get at the raw text (which is just json). this is useful for downloading a file from a Sinatra application, for example
32
+
33
+ get '/example.gliffy' do
34
+ header 'Content-Type', 'text/plain'
35
+ header 'Content-Disposition', 'attachment'
36
+ body diagram.render
37
+ end
38
+
39
+
40
+ ## Contributing
41
+
42
+ tests are in `spec/` and are run with `rake`. Feel free to add some tests :)
43
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: [:spec]
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'gliffynator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'gliffynator'
7
+ spec.version = Gliffynator::VERSION
8
+ spec.authors = ['Tim Zwolak']
9
+ spec.email = ['timothypage@gmail.com']
10
+ spec.summary = "Generate Gliffy diagrams in .gliffy format in Ruby"
11
+ spec.description = <<-eos
12
+ Simple DSL for generating Gliffy diagrams in ruby and exporting in .gliffy format.
13
+ Includes some basic shapes from the UML library
14
+ eos
15
+
16
+ spec.homepage = 'https://github.com/timothypage/gliffynator'
17
+ spec.license = 'MIT'
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.require_paths = ['lib']
20
+ spec.add_development_dependency 'rake', '10.4.2'
21
+ spec.add_development_dependency 'rspec', '3.4.0'
22
+ end
@@ -0,0 +1,96 @@
1
+ class Gliffynator::Arrow < Hash
2
+
3
+ def self.id_usage
4
+ 2
5
+ end
6
+
7
+ def self.create(id, x, y, length, direction, text=false)
8
+
9
+ arrow = {
10
+ x: x.to_f,
11
+ y: y.to_f,
12
+ rotation: 0.0,
13
+ id: id,
14
+ width: 143.5644622626777,
15
+ height: 100.0,
16
+ uid: "com.gliffy.shape.uml.uml_v1.default.message",
17
+ order: id-1000,
18
+ lockAspectRatio: false,
19
+ lockShape: false,
20
+ graphic: {
21
+ type: "Line",
22
+ Line: {
23
+ strokeWidth: 1.0,
24
+ strokeColor: "#000000",
25
+ fillColor: "none",
26
+ dashStyle: nil,
27
+ startArrow: if direction == :left then 2 else 0 end,
28
+ endArrow: if direction == :right then 2 else 0 end,
29
+ startArrowRotation: "auto",
30
+ endArrowRotation: "auto",
31
+ interpolationType: "linear",
32
+ cornerRadius: nil,
33
+ controlPath: [
34
+ [
35
+ 0.0,
36
+ 0.0
37
+ ],
38
+ [
39
+ length,
40
+ 0.0
41
+ ]
42
+ ],
43
+ lockSegments: [],
44
+ ortho: false
45
+ }
46
+ },
47
+ linkMap: [],
48
+ children: [],
49
+ hidden: false,
50
+ layerId: "C3WysuhtocNA"
51
+ }
52
+
53
+ if text
54
+ arrow[:children] << {
55
+ x: 0.0,
56
+ y: 0.0,
57
+ rotation: 0.0,
58
+ id: id+1,
59
+ width: 6.4 * text.length,
60
+ height: 14,
61
+ uid: nil,
62
+ order: "auto",
63
+ lockAspectRatio: false,
64
+ lockShape: false,
65
+ graphic: {
66
+ type: "Text",
67
+ Text: {
68
+ overflow: "both",
69
+ paddingTop: 2,
70
+ paddingright: 2,
71
+ paddingBottom: 2,
72
+ paddingLeft: 2,
73
+ outerPaddingTop: 6,
74
+ outerPaddingRight: 6,
75
+ outerPaddingBottom: 2,
76
+ outerPaddingLeft: 6,
77
+ type: "fixed",
78
+ lineTValue: 0.48267771584556685,
79
+ linePerpValue: 0.0,
80
+ cardinalityType: nil,
81
+ html: "<p style=\"text-align:center;\"><span style=\"font-family:Arial;font-size:12px;\"><span style=\"\">"+text+"</span></p>",
82
+ tid: nil,
83
+ valign: "middle",
84
+ vposition: "none",
85
+ hposition: "none"
86
+ }
87
+ },
88
+ children: [],
89
+ hidden: false,
90
+ layerId: "C3WysuhtocNA"
91
+ }
92
+ end
93
+
94
+ arrow
95
+ end
96
+ end
@@ -0,0 +1,103 @@
1
+ require 'json'
2
+
3
+ class Gliffynator::Diagram
4
+
5
+ include Gliffynator::DSL
6
+
7
+ attr_accessor :diagram
8
+ attr_accessor :objects
9
+
10
+ def initialize(options={}, &block)
11
+
12
+ @objects = Gliffynator::Objects.new
13
+
14
+ @diagram = {
15
+ contentType: "application/gliffy+json",
16
+ version: "1.3",
17
+ stage: {
18
+ background: "#ffffff",
19
+ width: 1248,
20
+ height: 1450,
21
+ nodeIndex: 1661,
22
+ autoFit: true,
23
+ exportBorder: false,
24
+ gridOn: false,
25
+ snapToGrid: false,
26
+ drawingGuidesOn: false,
27
+ pageBreaksOn: false,
28
+ printGridOn: false,
29
+ printPaper: "LETTER",
30
+ maxWidth: 5000,
31
+ maxHeight: 5000,
32
+ themeData: nil,
33
+ viewportType: "default",
34
+ fitBB: {
35
+ min: {
36
+ x: 15,
37
+ y: 14
38
+ },
39
+ max: {
40
+ x: 1247.5,
41
+ y: 1450
42
+ }
43
+ },
44
+ printModel: {
45
+ pageSize: "a4",
46
+ portrait: false,
47
+ fitToOnePage: true,
48
+ displayPageBreaks: false
49
+ },
50
+ objects: @objects,
51
+ layers: [
52
+ {
53
+ guid: "C3WysuhtocNA",
54
+ order: 0,
55
+ name: "Layer 0",
56
+ active: true,
57
+ locked: false,
58
+ visible: true,
59
+ nodeIndex: 185
60
+ }
61
+ ],
62
+ shapeStyles: {},
63
+ lineStyles: {},
64
+ textStyles: {
65
+ global: {
66
+ bold: false,
67
+ underline: false
68
+ }
69
+ }
70
+ },
71
+ metadata: {
72
+ title: "untitled",
73
+ revision: 0,
74
+ exportBorder: false,
75
+ loadPosition: "default",
76
+ libraries: [
77
+ "com.gliffy.libraries.uml.uml_v1.default",
78
+ "com.gliffy.libraries.erd.erd_v1.default",
79
+ "com.gliffy.libraries.basic.basic_v1.default",
80
+ "com.gliffy.libraries.images"
81
+ ],
82
+ lastSerialized: DateTime.now.strftime("%Q"),
83
+ analyticsProduct: "Confluence"
84
+ },
85
+ embeddedResources: {
86
+ index: 0,
87
+ resources: []
88
+ }
89
+ }.merge options
90
+
91
+ self.instance_eval(&block) if block
92
+
93
+ self
94
+ end
95
+
96
+ def render( filename=nil )
97
+ if filename
98
+ return File.write(filename, @diagram.to_json)
99
+ end
100
+
101
+ @diagram.to_json
102
+ end
103
+ end
@@ -0,0 +1,18 @@
1
+ module Gliffynator
2
+ module DSL
3
+ def get_id_and_increment(klass)
4
+ id = self.objects.global_id_counter
5
+ self.objects.global_id_counter = klass.id_usage || 1
6
+
7
+ id
8
+ end
9
+
10
+ def add_arrow(*args)
11
+ id = get_id_and_increment(Arrow)
12
+ self.objects << Gliffynator::Arrow.create(id, *args)
13
+ end
14
+
15
+
16
+
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ class Gliffynator::Objects < Array
2
+
3
+ attr_accessor :global_id_counter
4
+
5
+ def initialize
6
+ @global_id_counter = 1001
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Gliffynator
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'gliffynator/version'
2
+ require 'gliffynator/dsl'
3
+ require 'gliffynator/objects'
4
+ require 'gliffynator/diagram'
5
+ require 'gliffynator/arrow'
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gliffynator::Diagram do
4
+ describe '#initialize' do
5
+ end
6
+
7
+ describe '#add_arrow' do
8
+ let(:diagram) do
9
+ diagram = Gliffynator::Diagram.new
10
+ diagram.add_arrow 50, 50, 100, :right, "Sample Text"
11
+ diagram
12
+ end
13
+
14
+ it "should add the object" do
15
+ expect( diagram.objects.first[:x] ).to eq( 50.to_f )
16
+ end
17
+
18
+ it "should set object order" do
19
+ expect( diagram.objects.first[:order] ).to eq( 1 )
20
+ end
21
+
22
+ it "should set object id" do
23
+ expect( diagram.objects.first[:id] ).to be( 1001 )
24
+ end
25
+ end
26
+
27
+ describe "DSL" do
28
+ it "should allow block syntax" do
29
+ diagram = Gliffynator::Diagram.new do
30
+ add_arrow 50, 50, 100, :right, "Sample Text"
31
+ end
32
+
33
+ expect( diagram.objects.first[:uid] ).to eq( "com.gliffy.shape.uml.uml_v1.default.message" )
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,2 @@
1
+ require 'pry'
2
+ require 'gliffynator'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gliffynator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tim Zwolak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 10.4.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 10.4.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.4.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.4.0
41
+ description: |2
42
+ Simple DSL for generating Gliffy diagrams in ruby and exporting in .gliffy format.
43
+ Includes some basic shapes from the UML library
44
+ email:
45
+ - timothypage@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".editorconfig"
51
+ - ".gitignore"
52
+ - ".rspec"
53
+ - ".travis.yml"
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - gliffynator.gemspec
59
+ - lib/gliffynator.rb
60
+ - lib/gliffynator/arrow.rb
61
+ - lib/gliffynator/diagram.rb
62
+ - lib/gliffynator/dsl.rb
63
+ - lib/gliffynator/objects.rb
64
+ - lib/gliffynator/version.rb
65
+ - spec/diagram_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/timothypage/gliffynator
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.5
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Generate Gliffy diagrams in .gliffy format in Ruby
91
+ test_files: []
92
+ has_rdoc: