proforma 1.0.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +8 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +11 -0
- data/.ruby-version +1 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +105 -0
- data/Guardfile +16 -0
- data/LICENSE +7 -0
- data/README.md +328 -0
- data/bin/console +11 -0
- data/bin/render +68 -0
- data/lib/proforma.rb +38 -0
- data/lib/proforma/compiling.rb +12 -0
- data/lib/proforma/compiling/aggregation.rb +62 -0
- data/lib/proforma/compiling/compilable.rb +21 -0
- data/lib/proforma/compiling/counter.rb +35 -0
- data/lib/proforma/core_ext/hash.rb +21 -0
- data/lib/proforma/document.rb +38 -0
- data/lib/proforma/hash_evaluator.rb +40 -0
- data/lib/proforma/model_factory.rb +38 -0
- data/lib/proforma/modeling.rb +21 -0
- data/lib/proforma/modeling/banner.rb +64 -0
- data/lib/proforma/modeling/collection.rb +34 -0
- data/lib/proforma/modeling/data_table.rb +117 -0
- data/lib/proforma/modeling/data_table/aggregator.rb +43 -0
- data/lib/proforma/modeling/data_table/column.rb +94 -0
- data/lib/proforma/modeling/generic_container.rb +57 -0
- data/lib/proforma/modeling/grouping.rb +40 -0
- data/lib/proforma/modeling/header.rb +18 -0
- data/lib/proforma/modeling/pane.rb +40 -0
- data/lib/proforma/modeling/pane/column.rb +68 -0
- data/lib/proforma/modeling/pane/line.rb +42 -0
- data/lib/proforma/modeling/separator.rb +19 -0
- data/lib/proforma/modeling/spacer.rb +19 -0
- data/lib/proforma/modeling/table.rb +52 -0
- data/lib/proforma/modeling/table/cell.rb +49 -0
- data/lib/proforma/modeling/table/row.rb +24 -0
- data/lib/proforma/modeling/table/section.rb +23 -0
- data/lib/proforma/modeling/text.rb +37 -0
- data/lib/proforma/modeling/types.rb +10 -0
- data/lib/proforma/modeling/types/align.rb +22 -0
- data/lib/proforma/plain_text_renderer.rb +106 -0
- data/lib/proforma/prototype.rb +28 -0
- data/lib/proforma/template.rb +65 -0
- data/lib/proforma/type_factory.rb +44 -0
- data/lib/proforma/version.rb +12 -0
- data/proforma.gemspec +34 -0
- data/spec/fixtures/snapshots/custom_table.yml +55 -0
- data/spec/fixtures/snapshots/user_details.yml +101 -0
- data/spec/fixtures/snapshots/user_list.yml +143 -0
- data/spec/proforma/hash_evaluator_spec.rb +26 -0
- data/spec/proforma/modeling/table/cell_spec.rb +26 -0
- data/spec/proforma/modeling/table/row_spec.rb +42 -0
- data/spec/proforma_spec.rb +230 -0
- data/spec/spec_helper.rb +25 -0
- metadata +211 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module Proforma
|
11
|
+
# A prototype is a compiled template that has been flattened and ready for rendering.
|
12
|
+
class Prototype
|
13
|
+
attr_writer :children, :title
|
14
|
+
|
15
|
+
def initialize(children: [], title: '')
|
16
|
+
@children = ModelFactory.array(children)
|
17
|
+
@title = title
|
18
|
+
end
|
19
|
+
|
20
|
+
def children
|
21
|
+
Array(@children)
|
22
|
+
end
|
23
|
+
|
24
|
+
def title
|
25
|
+
@title.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module Proforma
|
11
|
+
# A Template instance is a set of modeling objects with directions on how to compile it into
|
12
|
+
# a Prototype object. The prototype instance can then be rendered into an end-result such as
|
13
|
+
# a text, pdf, or spreadsheet file.
|
14
|
+
class Template < Prototype
|
15
|
+
include Compiling::Compilable
|
16
|
+
acts_as_hashable
|
17
|
+
|
18
|
+
attr_writer :split
|
19
|
+
|
20
|
+
def initialize(children: [], split: false, title: '')
|
21
|
+
@split = split
|
22
|
+
|
23
|
+
super(children: children, title: title)
|
24
|
+
end
|
25
|
+
|
26
|
+
def split
|
27
|
+
@split || false
|
28
|
+
end
|
29
|
+
alias split? split
|
30
|
+
|
31
|
+
def compile(data, evaluator)
|
32
|
+
if split?
|
33
|
+
compile_record(data, evaluator)
|
34
|
+
else
|
35
|
+
compile_collection(data, evaluator)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def compile_collection(data, evaluator)
|
42
|
+
compiled_children = Modeling::Collection.new(children: children).compile(data, evaluator)
|
43
|
+
|
44
|
+
[
|
45
|
+
Prototype.new(
|
46
|
+
children: compiled_children,
|
47
|
+
title: evaluator.text({}, title)
|
48
|
+
)
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
def compile_record(data, evaluator)
|
53
|
+
default_grouping = Modeling::Grouping.new(children: children)
|
54
|
+
|
55
|
+
array(data).map do |record|
|
56
|
+
compiled_children = default_grouping.compile(record, evaluator)
|
57
|
+
|
58
|
+
Prototype.new(
|
59
|
+
children: compiled_children,
|
60
|
+
title: evaluator.text(record, title)
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module Proforma
|
11
|
+
# A TypeFactory object understands how to build objects using a special designated '$type' key.
|
12
|
+
class TypeFactory
|
13
|
+
DEFAULT_TYPE_KEY = :type
|
14
|
+
|
15
|
+
attr_reader :registry, :type_key
|
16
|
+
|
17
|
+
def initialize(registry = {}, type_key = DEFAULT_TYPE_KEY)
|
18
|
+
@registry = registry.symbolize_keys
|
19
|
+
@type_key = type_key
|
20
|
+
|
21
|
+
freeze
|
22
|
+
end
|
23
|
+
|
24
|
+
def array(objects = [])
|
25
|
+
objects = objects.is_a?(Hash) ? [objects] : Array(objects)
|
26
|
+
|
27
|
+
objects.map do |object|
|
28
|
+
object.is_a?(Hash) ? make(object) : object
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def make(config = {})
|
33
|
+
config = (config || {}).symbolize_keys
|
34
|
+
type = config[type_key].to_s.to_sym
|
35
|
+
object_class = registry[type]
|
36
|
+
|
37
|
+
raise ArgumentError, "cannot find section from type: #{type}" unless object_class
|
38
|
+
|
39
|
+
config_without_type = config.reject { |k| k == type_key }
|
40
|
+
|
41
|
+
object_class.new(config_without_type)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module Proforma
|
11
|
+
VERSION = '1.0.0-alpha'
|
12
|
+
end
|
data/proforma.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/proforma/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'proforma'
|
7
|
+
s.version = Proforma::VERSION
|
8
|
+
s.summary = 'Configurable and extendable document rendering engine for datasets'
|
9
|
+
|
10
|
+
s.description = <<-DESCRIPTION
|
11
|
+
Provide a simple, configurable, and standardized document generation object model.
|
12
|
+
The basic premise is to pass in a dataset and configuration and this library will return rendered documents.
|
13
|
+
The rendering engines can be plugged in so it leaves this as an extendable/open framework.
|
14
|
+
DESCRIPTION
|
15
|
+
|
16
|
+
s.authors = ['Matthew Ruggio']
|
17
|
+
s.email = ['mruggio@bluemarblepayroll.com']
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
21
|
+
s.homepage = 'https://github.com/bluemarblepayroll/proforma'
|
22
|
+
s.license = 'MIT'
|
23
|
+
|
24
|
+
s.required_ruby_version = '>= 2.3.8'
|
25
|
+
|
26
|
+
s.add_dependency('acts_as_hashable', '~>1')
|
27
|
+
|
28
|
+
s.add_development_dependency('guard-rspec', '~>4.7')
|
29
|
+
s.add_development_dependency('pry', '~>0')
|
30
|
+
s.add_development_dependency('rspec', '~> 3.8')
|
31
|
+
s.add_development_dependency('rubocop', '~>0.63.1')
|
32
|
+
s.add_development_dependency('simplecov', '~>0.16.1')
|
33
|
+
s.add_development_dependency('simplecov-console', '~>0.4.2')
|
34
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
data:
|
2
|
+
- id: 1
|
3
|
+
first: Will
|
4
|
+
last: Smith
|
5
|
+
username: will_smith
|
6
|
+
login_count: 9219
|
7
|
+
phone_numbers:
|
8
|
+
- type: cell
|
9
|
+
number: 555-444-3333
|
10
|
+
- type: fax
|
11
|
+
number: 333-444-2222
|
12
|
+
- id: 2
|
13
|
+
first: Martin
|
14
|
+
last: Lawrence
|
15
|
+
username: mlaw10
|
16
|
+
login_count: 8077
|
17
|
+
phone_numbers:
|
18
|
+
- type: home
|
19
|
+
number: 999-888-7777
|
20
|
+
- id: 3
|
21
|
+
first: Will
|
22
|
+
last: Ferrell
|
23
|
+
username: will.ferrell
|
24
|
+
login_count: 190890
|
25
|
+
phone_numbers:
|
26
|
+
|
27
|
+
template:
|
28
|
+
title: Custom Table
|
29
|
+
children:
|
30
|
+
- type: Grouping
|
31
|
+
children:
|
32
|
+
- type: Table
|
33
|
+
body:
|
34
|
+
rows:
|
35
|
+
- cells:
|
36
|
+
- text: ID Number
|
37
|
+
- text: $:id
|
38
|
+
- text: Username
|
39
|
+
- text: $:username
|
40
|
+
- cells:
|
41
|
+
- text: First Name
|
42
|
+
- text: $:first
|
43
|
+
- text: Last Name
|
44
|
+
- text: $:last
|
45
|
+
|
46
|
+
documents:
|
47
|
+
- title: Custom Table
|
48
|
+
contents: |+
|
49
|
+
ID Number, 1, Username, will_smith
|
50
|
+
First Name, Will, Last Name, Smith
|
51
|
+
ID Number, 2, Username, mlaw10
|
52
|
+
First Name, Martin, Last Name, Lawrence
|
53
|
+
ID Number, 3, Username, will.ferrell
|
54
|
+
First Name, Will, Last Name, Ferrell
|
55
|
+
extension: '.txt'
|
@@ -0,0 +1,101 @@
|
|
1
|
+
data:
|
2
|
+
- id: 1
|
3
|
+
first: Will
|
4
|
+
last: Smith
|
5
|
+
username: will_smith
|
6
|
+
login_count: 9219
|
7
|
+
phone_numbers:
|
8
|
+
- type: cell
|
9
|
+
number: 555-444-3333
|
10
|
+
- type: fax
|
11
|
+
number: 333-444-2222
|
12
|
+
- id: 2
|
13
|
+
first: Martin
|
14
|
+
last: Lawrence
|
15
|
+
username: mlaw10
|
16
|
+
login_count: 8077
|
17
|
+
phone_numbers:
|
18
|
+
- type: home
|
19
|
+
number: 999-888-7777
|
20
|
+
- id: 3
|
21
|
+
first: Will
|
22
|
+
last: Ferrell
|
23
|
+
username: will.ferrell
|
24
|
+
login_count: 190890
|
25
|
+
phone_numbers:
|
26
|
+
|
27
|
+
template:
|
28
|
+
split: true
|
29
|
+
title: User Details
|
30
|
+
children:
|
31
|
+
- type: Header
|
32
|
+
value: User Details
|
33
|
+
- type: Separator
|
34
|
+
- type: Text
|
35
|
+
value: 'The following is user details'
|
36
|
+
- type: Pane
|
37
|
+
columns:
|
38
|
+
- label_width: 25.0
|
39
|
+
lines:
|
40
|
+
- label: ID Number
|
41
|
+
value: $:id
|
42
|
+
- label: First Name
|
43
|
+
value: $:first
|
44
|
+
- label: Last Name
|
45
|
+
value: $:last
|
46
|
+
- type: Spacer
|
47
|
+
- type: Header
|
48
|
+
value: Phone Numbers
|
49
|
+
- type: DataTable
|
50
|
+
property: phone_numbers
|
51
|
+
empty_message: No phone numbers.
|
52
|
+
columns:
|
53
|
+
- header: Type
|
54
|
+
body: $:type
|
55
|
+
- header: Number
|
56
|
+
body: $:number
|
57
|
+
- type: Spacer
|
58
|
+
|
59
|
+
documents:
|
60
|
+
- title: User Details
|
61
|
+
contents: |+
|
62
|
+
USER DETAILS
|
63
|
+
----------------------------------------
|
64
|
+
The following is user details
|
65
|
+
ID Number: 1
|
66
|
+
First Name: Will
|
67
|
+
Last Name: Smith
|
68
|
+
|
69
|
+
PHONE NUMBERS
|
70
|
+
Type, Number
|
71
|
+
cell, 555-444-3333
|
72
|
+
fax, 333-444-2222
|
73
|
+
|
74
|
+
extension: '.txt'
|
75
|
+
- title: User Details
|
76
|
+
contents: |+
|
77
|
+
USER DETAILS
|
78
|
+
----------------------------------------
|
79
|
+
The following is user details
|
80
|
+
ID Number: 2
|
81
|
+
First Name: Martin
|
82
|
+
Last Name: Lawrence
|
83
|
+
|
84
|
+
PHONE NUMBERS
|
85
|
+
Type, Number
|
86
|
+
home, 999-888-7777
|
87
|
+
|
88
|
+
extension: '.txt'
|
89
|
+
- title: User Details
|
90
|
+
contents: |+
|
91
|
+
USER DETAILS
|
92
|
+
----------------------------------------
|
93
|
+
The following is user details
|
94
|
+
ID Number: 3
|
95
|
+
First Name: Will
|
96
|
+
Last Name: Ferrell
|
97
|
+
|
98
|
+
PHONE NUMBERS
|
99
|
+
No phone numbers.
|
100
|
+
|
101
|
+
extension: '.txt'
|
@@ -0,0 +1,143 @@
|
|
1
|
+
data:
|
2
|
+
- id: 1
|
3
|
+
first: Will
|
4
|
+
last: Smith
|
5
|
+
username: will_smith
|
6
|
+
login_count: 9219
|
7
|
+
phone_numbers:
|
8
|
+
- type: cell
|
9
|
+
number: 555-444-3333
|
10
|
+
- type: fax
|
11
|
+
number: 333-444-2222
|
12
|
+
- id: 2
|
13
|
+
first: Martin
|
14
|
+
last: Lawrence
|
15
|
+
username: mlaw10
|
16
|
+
login_count: 8077
|
17
|
+
phone_numbers:
|
18
|
+
- type: home
|
19
|
+
number: 999-888-7777
|
20
|
+
- id: 3
|
21
|
+
first: Will
|
22
|
+
last: Ferrell
|
23
|
+
username: will.ferrell
|
24
|
+
login_count: 190890
|
25
|
+
phone_numbers:
|
26
|
+
|
27
|
+
template:
|
28
|
+
title: User List
|
29
|
+
children:
|
30
|
+
- type: Banner
|
31
|
+
details: "555 N. Michigan Ave.\nChicago, IL 62626\n555-555-5555 ext. 55555"
|
32
|
+
title: Some Random System
|
33
|
+
- type: Spacer
|
34
|
+
- type: Header
|
35
|
+
value: User List
|
36
|
+
- type: Separator
|
37
|
+
- type: Text
|
38
|
+
value: The following is a list of users
|
39
|
+
- type: Spacer
|
40
|
+
- type: DataTable
|
41
|
+
aggregators:
|
42
|
+
- property: login_count
|
43
|
+
function: sum
|
44
|
+
name: login_count_sum
|
45
|
+
- property: login_count
|
46
|
+
function: ave
|
47
|
+
name: login_count_ave
|
48
|
+
columns:
|
49
|
+
- header: ID Number
|
50
|
+
body: $:id
|
51
|
+
footer: Login Count Ave.
|
52
|
+
- header: First Name
|
53
|
+
body: $:first
|
54
|
+
footer: $:login_count_ave
|
55
|
+
- header: Last Name
|
56
|
+
body: $:last
|
57
|
+
- header: Username
|
58
|
+
body: $:username
|
59
|
+
footer: Login Count Sum
|
60
|
+
- header: Login Count
|
61
|
+
footer: $:login_count_sum
|
62
|
+
body: $:login_count
|
63
|
+
- type: Spacer
|
64
|
+
- type: Grouping
|
65
|
+
children:
|
66
|
+
- type: Header
|
67
|
+
value: 'User Details'
|
68
|
+
- type: Separator
|
69
|
+
- type: Pane
|
70
|
+
columns:
|
71
|
+
- label_width: 25.0
|
72
|
+
lines:
|
73
|
+
- label: ID Number
|
74
|
+
value: $:id
|
75
|
+
- label: First Name
|
76
|
+
value: $:first
|
77
|
+
- label: Last Name
|
78
|
+
value: $:last
|
79
|
+
- type: Spacer
|
80
|
+
- type: Header
|
81
|
+
value: Phone Numbers
|
82
|
+
- type: DataTable
|
83
|
+
property: phone_numbers
|
84
|
+
empty_message: No phone numbers.
|
85
|
+
columns:
|
86
|
+
- header: Type
|
87
|
+
body: $:type
|
88
|
+
- header: Number
|
89
|
+
body: $:number
|
90
|
+
- type: Spacer
|
91
|
+
|
92
|
+
documents:
|
93
|
+
- title: User List
|
94
|
+
contents: |+
|
95
|
+
========================================
|
96
|
+
Some Random System
|
97
|
+
========================================
|
98
|
+
555 N. Michigan Ave.
|
99
|
+
Chicago, IL 62626
|
100
|
+
555-555-5555 ext. 55555
|
101
|
+
========================================
|
102
|
+
|
103
|
+
USER LIST
|
104
|
+
----------------------------------------
|
105
|
+
The following is a list of users
|
106
|
+
|
107
|
+
ID Number, First Name, Last Name, Username, Login Count
|
108
|
+
1, Will, Smith, will_smith, 9219
|
109
|
+
2, Martin, Lawrence, mlaw10, 8077
|
110
|
+
3, Will, Ferrell, will.ferrell, 190890
|
111
|
+
Login Count Ave., 69395.333333333333333333, , Login Count Sum, 208186.0
|
112
|
+
|
113
|
+
USER DETAILS
|
114
|
+
----------------------------------------
|
115
|
+
ID Number: 1
|
116
|
+
First Name: Will
|
117
|
+
Last Name: Smith
|
118
|
+
|
119
|
+
PHONE NUMBERS
|
120
|
+
Type, Number
|
121
|
+
cell, 555-444-3333
|
122
|
+
fax, 333-444-2222
|
123
|
+
|
124
|
+
USER DETAILS
|
125
|
+
----------------------------------------
|
126
|
+
ID Number: 2
|
127
|
+
First Name: Martin
|
128
|
+
Last Name: Lawrence
|
129
|
+
|
130
|
+
PHONE NUMBERS
|
131
|
+
Type, Number
|
132
|
+
home, 999-888-7777
|
133
|
+
|
134
|
+
USER DETAILS
|
135
|
+
----------------------------------------
|
136
|
+
ID Number: 3
|
137
|
+
First Name: Will
|
138
|
+
Last Name: Ferrell
|
139
|
+
|
140
|
+
PHONE NUMBERS
|
141
|
+
No phone numbers.
|
142
|
+
|
143
|
+
extension: '.txt'
|