berkeley_library-tind 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +18 -0
- data/.gitignore +388 -0
- data/.idea/inspectionProfiles/Project_Default.xml +20 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/tind.iml +138 -0
- data/.idea/vcs.xml +6 -0
- data/.rubocop.yml +334 -0
- data/.ruby-version +1 -0
- data/.simplecov +8 -0
- data/.yardopts +1 -0
- data/CHANGES.md +58 -0
- data/Dockerfile +57 -0
- data/Gemfile +3 -0
- data/Jenkinsfile +18 -0
- data/LICENSE.md +21 -0
- data/README.md +73 -0
- data/Rakefile +20 -0
- data/berkeley_library-tind.gemspec +50 -0
- data/bin/tind-export +14 -0
- data/docker-compose.yml +15 -0
- data/lib/berkeley_library/tind.rb +3 -0
- data/lib/berkeley_library/tind/api.rb +1 -0
- data/lib/berkeley_library/tind/api/api.rb +132 -0
- data/lib/berkeley_library/tind/api/api_exception.rb +131 -0
- data/lib/berkeley_library/tind/api/collection.rb +82 -0
- data/lib/berkeley_library/tind/api/date_range.rb +67 -0
- data/lib/berkeley_library/tind/api/format.rb +32 -0
- data/lib/berkeley_library/tind/api/search.rb +100 -0
- data/lib/berkeley_library/tind/config.rb +103 -0
- data/lib/berkeley_library/tind/export.rb +1 -0
- data/lib/berkeley_library/tind/export/column.rb +54 -0
- data/lib/berkeley_library/tind/export/column_group.rb +144 -0
- data/lib/berkeley_library/tind/export/column_group_list.rb +131 -0
- data/lib/berkeley_library/tind/export/column_width_calculator.rb +76 -0
- data/lib/berkeley_library/tind/export/config.rb +154 -0
- data/lib/berkeley_library/tind/export/csv_exporter.rb +29 -0
- data/lib/berkeley_library/tind/export/export.rb +47 -0
- data/lib/berkeley_library/tind/export/export_command.rb +168 -0
- data/lib/berkeley_library/tind/export/export_exception.rb +8 -0
- data/lib/berkeley_library/tind/export/export_format.rb +67 -0
- data/lib/berkeley_library/tind/export/exporter.rb +105 -0
- data/lib/berkeley_library/tind/export/filter.rb +52 -0
- data/lib/berkeley_library/tind/export/no_results_error.rb +7 -0
- data/lib/berkeley_library/tind/export/ods_exporter.rb +138 -0
- data/lib/berkeley_library/tind/export/row.rb +24 -0
- data/lib/berkeley_library/tind/export/row_metrics.rb +18 -0
- data/lib/berkeley_library/tind/export/table.rb +175 -0
- data/lib/berkeley_library/tind/export/table_metrics.rb +116 -0
- data/lib/berkeley_library/tind/marc.rb +1 -0
- data/lib/berkeley_library/tind/marc/xml_reader.rb +144 -0
- data/lib/berkeley_library/tind/module_info.rb +14 -0
- data/lib/berkeley_library/util/arrays.rb +178 -0
- data/lib/berkeley_library/util/logging.rb +1 -0
- data/lib/berkeley_library/util/ods/spreadsheet.rb +170 -0
- data/lib/berkeley_library/util/ods/xml/content_doc.rb +26 -0
- data/lib/berkeley_library/util/ods/xml/document_node.rb +57 -0
- data/lib/berkeley_library/util/ods/xml/element_node.rb +106 -0
- data/lib/berkeley_library/util/ods/xml/loext/table_protection.rb +26 -0
- data/lib/berkeley_library/util/ods/xml/manifest/file_entry.rb +42 -0
- data/lib/berkeley_library/util/ods/xml/manifest/manifest.rb +73 -0
- data/lib/berkeley_library/util/ods/xml/manifest_doc.rb +26 -0
- data/lib/berkeley_library/util/ods/xml/namespace.rb +46 -0
- data/lib/berkeley_library/util/ods/xml/office/automatic_styles.rb +181 -0
- data/lib/berkeley_library/util/ods/xml/office/body.rb +17 -0
- data/lib/berkeley_library/util/ods/xml/office/document_content.rb +98 -0
- data/lib/berkeley_library/util/ods/xml/office/document_styles.rb +39 -0
- data/lib/berkeley_library/util/ods/xml/office/font_face_decls.rb +30 -0
- data/lib/berkeley_library/util/ods/xml/office/scripts.rb +17 -0
- data/lib/berkeley_library/util/ods/xml/office/spreadsheet.rb +37 -0
- data/lib/berkeley_library/util/ods/xml/office/styles.rb +39 -0
- data/lib/berkeley_library/util/ods/xml/style/cell_style.rb +58 -0
- data/lib/berkeley_library/util/ods/xml/style/column_style.rb +36 -0
- data/lib/berkeley_library/util/ods/xml/style/default_style.rb +31 -0
- data/lib/berkeley_library/util/ods/xml/style/family.rb +85 -0
- data/lib/berkeley_library/util/ods/xml/style/font_face.rb +46 -0
- data/lib/berkeley_library/util/ods/xml/style/paragraph_properties.rb +30 -0
- data/lib/berkeley_library/util/ods/xml/style/row_style.rb +37 -0
- data/lib/berkeley_library/util/ods/xml/style/style.rb +44 -0
- data/lib/berkeley_library/util/ods/xml/style/table_cell_properties.rb +40 -0
- data/lib/berkeley_library/util/ods/xml/style/table_column_properties.rb +30 -0
- data/lib/berkeley_library/util/ods/xml/style/table_properties.rb +25 -0
- data/lib/berkeley_library/util/ods/xml/style/table_row_properties.rb +28 -0
- data/lib/berkeley_library/util/ods/xml/style/table_style.rb +27 -0
- data/lib/berkeley_library/util/ods/xml/style/text_properties.rb +52 -0
- data/lib/berkeley_library/util/ods/xml/styles_doc.rb +26 -0
- data/lib/berkeley_library/util/ods/xml/table/named_expressions.rb +17 -0
- data/lib/berkeley_library/util/ods/xml/table/repeatable.rb +38 -0
- data/lib/berkeley_library/util/ods/xml/table/table.rb +193 -0
- data/lib/berkeley_library/util/ods/xml/table/table_cell.rb +46 -0
- data/lib/berkeley_library/util/ods/xml/table/table_column.rb +43 -0
- data/lib/berkeley_library/util/ods/xml/table/table_row.rb +136 -0
- data/lib/berkeley_library/util/ods/xml/text/p.rb +118 -0
- data/lib/berkeley_library/util/paths.rb +111 -0
- data/lib/berkeley_library/util/stringios.rb +30 -0
- data/lib/berkeley_library/util/strings.rb +42 -0
- data/lib/berkeley_library/util/sys_exits.rb +15 -0
- data/lib/berkeley_library/util/times.rb +22 -0
- data/lib/berkeley_library/util/uris.rb +44 -0
- data/lib/berkeley_library/util/uris/appender.rb +162 -0
- data/lib/berkeley_library/util/uris/requester.rb +62 -0
- data/lib/berkeley_library/util/uris/validator.rb +32 -0
- data/rakelib/bundle.rake +8 -0
- data/rakelib/coverage.rake +11 -0
- data/rakelib/gem.rake +54 -0
- data/rakelib/rubocop.rake +18 -0
- data/rakelib/spec.rake +2 -0
- data/spec/.rubocop.yml +40 -0
- data/spec/berkeley_library/tind/api/api_exception_spec.rb +91 -0
- data/spec/berkeley_library/tind/api/api_spec.rb +143 -0
- data/spec/berkeley_library/tind/api/collection_spec.rb +74 -0
- data/spec/berkeley_library/tind/api/date_range_spec.rb +110 -0
- data/spec/berkeley_library/tind/api/format_spec.rb +54 -0
- data/spec/berkeley_library/tind/api/search_spec.rb +364 -0
- data/spec/berkeley_library/tind/config_spec.rb +86 -0
- data/spec/berkeley_library/tind/export/column_group_spec.rb +29 -0
- data/spec/berkeley_library/tind/export/column_spec.rb +43 -0
- data/spec/berkeley_library/tind/export/config_spec.rb +206 -0
- data/spec/berkeley_library/tind/export/export_command_spec.rb +169 -0
- data/spec/berkeley_library/tind/export/export_format_spec.rb +59 -0
- data/spec/berkeley_library/tind/export/export_matcher.rb +112 -0
- data/spec/berkeley_library/tind/export/export_spec.rb +150 -0
- data/spec/berkeley_library/tind/export/exporter_spec.rb +125 -0
- data/spec/berkeley_library/tind/export/row_spec.rb +118 -0
- data/spec/berkeley_library/tind/export/table_spec.rb +322 -0
- data/spec/berkeley_library/tind/marc/xml_reader_spec.rb +93 -0
- data/spec/berkeley_library/util/arrays_spec.rb +340 -0
- data/spec/berkeley_library/util/ods/spreadsheet_spec.rb +124 -0
- data/spec/berkeley_library/util/ods/xml/content_doc_spec.rb +121 -0
- data/spec/berkeley_library/util/ods/xml/manifest/file_entry_spec.rb +27 -0
- data/spec/berkeley_library/util/ods/xml/manifest/manifest_spec.rb +33 -0
- data/spec/berkeley_library/util/ods/xml/office/document_content_spec.rb +60 -0
- data/spec/berkeley_library/util/ods/xml/style/automatic_styles_spec.rb +37 -0
- data/spec/berkeley_library/util/ods/xml/style/family_spec.rb +57 -0
- data/spec/berkeley_library/util/ods/xml/table/table_row_spec.rb +179 -0
- data/spec/berkeley_library/util/ods/xml/table/table_spec.rb +218 -0
- data/spec/berkeley_library/util/paths_spec.rb +90 -0
- data/spec/berkeley_library/util/stringios_spec.rb +34 -0
- data/spec/berkeley_library/util/strings_spec.rb +27 -0
- data/spec/berkeley_library/util/times_spec.rb +39 -0
- data/spec/berkeley_library/util/uris_spec.rb +118 -0
- data/spec/data/collection-names.txt +438 -0
- data/spec/data/collections.json +4827 -0
- data/spec/data/disjoint-records.xml +187 -0
- data/spec/data/record-184453.xml +58 -0
- data/spec/data/record-184458.xml +63 -0
- data/spec/data/record-187888.xml +78 -0
- data/spec/data/records-api-search-cjk-p1.xml +6381 -0
- data/spec/data/records-api-search-cjk-p2.xml +5 -0
- data/spec/data/records-api-search-p1.xml +4506 -0
- data/spec/data/records-api-search-p2.xml +4509 -0
- data/spec/data/records-api-search-p3.xml +4506 -0
- data/spec/data/records-api-search-p4.xml +4509 -0
- data/spec/data/records-api-search-p5.xml +4506 -0
- data/spec/data/records-api-search-p6.xml +2436 -0
- data/spec/data/records-api-search-p7.xml +5 -0
- data/spec/data/records-api-search.xml +234 -0
- data/spec/data/records-manual-search.xml +547 -0
- data/spec/spec_helper.rb +30 -0
- data/test/profile/table_from_records_profile.rb +46 -0
- metadata +585 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/element_node'
|
2
|
+
|
3
|
+
module BerkeleyLibrary
|
4
|
+
module Util
|
5
|
+
module ODS
|
6
|
+
module XML
|
7
|
+
module Office
|
8
|
+
class Body < XML::ElementNode
|
9
|
+
def initialize(doc:)
|
10
|
+
super(:office, 'body', doc: doc)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/namespace'
|
2
|
+
require 'berkeley_library/util/ods/xml/element_node'
|
3
|
+
require 'berkeley_library/util/ods/xml/table/table'
|
4
|
+
require 'berkeley_library/util/ods/xml/office/scripts'
|
5
|
+
require 'berkeley_library/util/ods/xml/office/font_face_decls'
|
6
|
+
require 'berkeley_library/util/ods/xml/office/automatic_styles'
|
7
|
+
require 'berkeley_library/util/ods/xml/office/body'
|
8
|
+
require 'berkeley_library/util/ods/xml/office/spreadsheet'
|
9
|
+
|
10
|
+
module BerkeleyLibrary
|
11
|
+
module Util
|
12
|
+
module ODS
|
13
|
+
module XML
|
14
|
+
module Office
|
15
|
+
class DocumentContent < XML::ElementNode
|
16
|
+
|
17
|
+
# ------------------------------------------------------------
|
18
|
+
# Constants
|
19
|
+
|
20
|
+
OFFICE_VERSION = '1.2'.freeze
|
21
|
+
REQUIRED_NAMESPACES = Namespace.reject { |ns| ns == Namespace::MANIFEST }
|
22
|
+
|
23
|
+
# ------------------------------------------------------------
|
24
|
+
# Initializer
|
25
|
+
|
26
|
+
def initialize(doc:)
|
27
|
+
super(:office, 'document-content', doc: doc)
|
28
|
+
|
29
|
+
set_default_attributes!
|
30
|
+
add_default_children!
|
31
|
+
end
|
32
|
+
|
33
|
+
# ------------------------------------------------------------
|
34
|
+
# Accessors and utility methods
|
35
|
+
|
36
|
+
def scripts
|
37
|
+
@scripts ||= Scripts.new(doc: doc)
|
38
|
+
end
|
39
|
+
|
40
|
+
def font_face_decls
|
41
|
+
@font_face_decls ||= Office::FontFaceDecls.new(doc: doc)
|
42
|
+
end
|
43
|
+
|
44
|
+
def automatic_styles
|
45
|
+
@automatic_styles ||= Office::AutomaticStyles.new(doc: doc)
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_table(name, table_style = nil, protected: true)
|
49
|
+
new_table = XML::Table::Table.new(name, table_style, styles: automatic_styles, protected: protected)
|
50
|
+
new_table.tap { |table| spreadsheet.add_child(table) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def spreadsheet
|
54
|
+
@spreadsheet ||= Office::Spreadsheet.new(doc: doc)
|
55
|
+
end
|
56
|
+
|
57
|
+
def body
|
58
|
+
@body ||= Body.new(doc: doc).tap { |body| body.add_child(spreadsheet) }
|
59
|
+
end
|
60
|
+
|
61
|
+
# ------------------------------------------------------------
|
62
|
+
# Protected methods
|
63
|
+
|
64
|
+
# ----------------------------------------
|
65
|
+
# Protected ElementNode overrides
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def create_element
|
70
|
+
# Make sure any styles, font faces, etc. needed for the body get created
|
71
|
+
# *before* we try to write them to XML
|
72
|
+
children.reverse_each(&:ensure_element!)
|
73
|
+
|
74
|
+
super
|
75
|
+
end
|
76
|
+
|
77
|
+
# ------------------------------------------------------------
|
78
|
+
# Private methods
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def set_default_attributes!
|
83
|
+
REQUIRED_NAMESPACES.each { |ns| set_attribute(:xmlns, ns.prefix, ns.uri) }
|
84
|
+
set_attribute('version', OFFICE_VERSION)
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_default_children!
|
88
|
+
children << scripts
|
89
|
+
children << font_face_decls
|
90
|
+
children << automatic_styles
|
91
|
+
children << body
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/element_node'
|
2
|
+
require 'berkeley_library/util/ods/xml/office/font_face_decls'
|
3
|
+
require 'berkeley_library/util/ods/xml/office/styles'
|
4
|
+
|
5
|
+
module BerkeleyLibrary
|
6
|
+
module Util
|
7
|
+
module ODS
|
8
|
+
module XML
|
9
|
+
module Office
|
10
|
+
class DocumentStyles < XML::ElementNode
|
11
|
+
REQUIRED_NAMESPACES = %i[office style fo].freeze
|
12
|
+
|
13
|
+
def initialize(doc:)
|
14
|
+
super(:office, 'document-styles', doc: doc)
|
15
|
+
|
16
|
+
set_default_attributes!
|
17
|
+
add_default_children!
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def required_namespaces
|
23
|
+
@required_namespaces ||= REQUIRED_NAMESPACES.map { |p| Namespace.for_prefix(p) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_default_attributes!
|
27
|
+
required_namespaces.each { |ns| set_attribute(:xmlns, ns.prefix, ns.uri) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_default_children!
|
31
|
+
add_child(FontFaceDecls.new(doc: doc))
|
32
|
+
add_child(Styles.new(doc: doc))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/element_node'
|
2
|
+
require 'berkeley_library/util/ods/xml/style/font_face'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module Util
|
6
|
+
module ODS
|
7
|
+
module XML
|
8
|
+
module Office
|
9
|
+
class FontFaceDecls < XML::ElementNode
|
10
|
+
def initialize(doc:)
|
11
|
+
super(:office, 'font-face-decls', doc: doc)
|
12
|
+
|
13
|
+
add_font_face(default_face)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_font_face(font_face)
|
17
|
+
children << font_face
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def default_face
|
23
|
+
Style::FontFace.default_face(doc: doc)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/element_node'
|
2
|
+
|
3
|
+
module BerkeleyLibrary
|
4
|
+
module Util
|
5
|
+
module ODS
|
6
|
+
module XML
|
7
|
+
module Office
|
8
|
+
class Scripts < XML::ElementNode
|
9
|
+
def initialize(doc:)
|
10
|
+
super(:office, 'scripts', doc: doc)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/element_node'
|
2
|
+
require 'berkeley_library/util/ods/xml/table/named_expressions'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module Util
|
6
|
+
module ODS
|
7
|
+
module XML
|
8
|
+
module Office
|
9
|
+
class Spreadsheet < XML::ElementNode
|
10
|
+
def initialize(doc:)
|
11
|
+
super(:office, 'spreadsheet', doc: doc)
|
12
|
+
end
|
13
|
+
|
14
|
+
def named_expressions
|
15
|
+
@named_expressions ||= Table::NamedExpressions.new(doc: doc)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_child(child)
|
19
|
+
other_children << child
|
20
|
+
end
|
21
|
+
|
22
|
+
def children
|
23
|
+
other_children.dup.tap { |cc| cc << named_expressions }
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def other_children
|
29
|
+
@other_children ||= []
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/element_node'
|
2
|
+
require 'berkeley_library/util/ods/xml/style/style'
|
3
|
+
require 'berkeley_library/util/ods/xml/style/default_style'
|
4
|
+
require 'berkeley_library/util/ods/xml/style/paragraph_properties'
|
5
|
+
|
6
|
+
module BerkeleyLibrary
|
7
|
+
module Util
|
8
|
+
module ODS
|
9
|
+
module XML
|
10
|
+
module Office
|
11
|
+
class Styles < XML::ElementNode
|
12
|
+
def initialize(doc:)
|
13
|
+
super(:office, 'styles', doc: doc)
|
14
|
+
|
15
|
+
add_default_children!
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def add_default_children!
|
21
|
+
add_child(table_cell_default_style)
|
22
|
+
add_child(Style::Style.new('Default', 'table-cell', doc: doc))
|
23
|
+
end
|
24
|
+
|
25
|
+
def table_cell_default_style
|
26
|
+
style_children = [
|
27
|
+
Style::ParagraphProperties.new(doc: doc),
|
28
|
+
Style::TextProperties.new(font_name: Style::FontFace::DEFAULT_FONT_FACE, doc: doc)
|
29
|
+
]
|
30
|
+
Style::DefaultStyle.new('table-cell', doc: doc).tap do |ds|
|
31
|
+
style_children.each { |c| ds.add_child(c) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/style/style'
|
2
|
+
require 'berkeley_library/util/ods/xml/style/table_cell_properties'
|
3
|
+
require 'berkeley_library/util/ods/xml/style/text_properties'
|
4
|
+
|
5
|
+
module BerkeleyLibrary
|
6
|
+
module Util
|
7
|
+
module ODS
|
8
|
+
module XML
|
9
|
+
module Style
|
10
|
+
class CellStyle < Style
|
11
|
+
|
12
|
+
attr_reader :color, :font_weight
|
13
|
+
|
14
|
+
# Initializes a new cell style. Note that this should not be called
|
15
|
+
# directly, but only from {XML::Office::AutomaticStyles#add_cell_style}.
|
16
|
+
#
|
17
|
+
# @param name [String] the style name
|
18
|
+
# @param color [String, nil] a hex color (e.g. `#fdb515`)
|
19
|
+
# @param font_weight [String, nil] the font weight, if other than normal
|
20
|
+
# @param wrap [Boolean] whether to allow text wrapping
|
21
|
+
# @param styles [XML::Office::AutomaticStyles] the document styles
|
22
|
+
# rubocop:disable Metrics/ParameterLists, Style/OptionalBooleanParameter
|
23
|
+
def initialize(name, protected = false, color = nil, styles:, font_weight: nil, wrap: false)
|
24
|
+
super(name, :table_cell, doc: styles.doc)
|
25
|
+
@protected = protected
|
26
|
+
@color = color
|
27
|
+
@font_weight = font_weight
|
28
|
+
@wrap = wrap
|
29
|
+
|
30
|
+
set_attribute('parent-style-name', 'Default')
|
31
|
+
add_default_children!
|
32
|
+
end
|
33
|
+
# rubocop:enable Metrics/ParameterLists, Style/OptionalBooleanParameter
|
34
|
+
|
35
|
+
def protected?
|
36
|
+
@protected
|
37
|
+
end
|
38
|
+
|
39
|
+
def wrap?
|
40
|
+
@wrap
|
41
|
+
end
|
42
|
+
|
43
|
+
def custom_text_properties?
|
44
|
+
[color, font_weight].any? { |p| !p.nil? }
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def add_default_children!
|
50
|
+
children << TableCellProperties.new(protected?, wrap: wrap?, doc: doc)
|
51
|
+
children << TextProperties.new(color: color, font_weight: font_weight, doc: doc) if custom_text_properties?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/style/style'
|
2
|
+
require 'berkeley_library/util/ods/xml/style/table_column_properties'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module Util
|
6
|
+
module ODS
|
7
|
+
module XML
|
8
|
+
module Style
|
9
|
+
class ColumnStyle < Style
|
10
|
+
DEFAULT_WIDTH = '1in'.freeze
|
11
|
+
|
12
|
+
attr_reader :width
|
13
|
+
|
14
|
+
# Initializes a new column style. Note that this should not be called
|
15
|
+
# directly, but only from {XML::Office::AutomaticStyles#add_column_style}.
|
16
|
+
#
|
17
|
+
# @param style_name [String] the name of the style
|
18
|
+
# @param width [String] the column width
|
19
|
+
# @param styles [XML::Office::AutomaticStyles] the document styles
|
20
|
+
def initialize(style_name, width = nil, styles:)
|
21
|
+
super(style_name, :table_column, doc: styles.doc)
|
22
|
+
@width = width || DEFAULT_WIDTH
|
23
|
+
add_default_children!
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def add_default_children!
|
29
|
+
children << TableColumnProperties.new(width, doc: doc)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'berkeley_library/util/ods/xml/element_node'
|
2
|
+
require 'berkeley_library/util/ods/xml/style/family'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module Util
|
6
|
+
module ODS
|
7
|
+
module XML
|
8
|
+
module Style
|
9
|
+
class DefaultStyle < XML::ElementNode
|
10
|
+
|
11
|
+
attr_reader :family
|
12
|
+
|
13
|
+
def initialize(family, doc:)
|
14
|
+
super(:style, 'default-style', doc: doc)
|
15
|
+
|
16
|
+
@family = Family.ensure_family(family)
|
17
|
+
|
18
|
+
set_default_attributes!
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def set_default_attributes!
|
24
|
+
set_attribute('family', family)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'typesafe_enum'
|
2
|
+
|
3
|
+
module BerkeleyLibrary
|
4
|
+
module Util
|
5
|
+
module ODS
|
6
|
+
module XML
|
7
|
+
module Style
|
8
|
+
class Family < TypesafeEnum::Base
|
9
|
+
# ------------------------------------------------------------
|
10
|
+
# Enum instances
|
11
|
+
|
12
|
+
# NOTE: declaration order is as they appear in spreadsheets saved from LibreOffice
|
13
|
+
|
14
|
+
new(:TABLE_COLUMN, 'table-column') do
|
15
|
+
def prefix
|
16
|
+
'co'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
new(:TABLE_ROW, 'table-row') do
|
21
|
+
def prefix
|
22
|
+
'ro'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
new(:TABLE, 'table') do
|
27
|
+
def prefix
|
28
|
+
'ta'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
new(:TABLE_CELL, 'table-cell') do
|
33
|
+
def prefix
|
34
|
+
'ce'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# ------------------------------------------------------------
|
39
|
+
# Class methods
|
40
|
+
|
41
|
+
class << self
|
42
|
+
def from_string(str)
|
43
|
+
find_by_key(str.to_s.upcase.to_sym) ||
|
44
|
+
find_by_value_str(str.to_s.downcase)
|
45
|
+
end
|
46
|
+
|
47
|
+
def ensure_family(f)
|
48
|
+
family = f.is_a?(Family) ? f : Family.from_string(f)
|
49
|
+
return family if family
|
50
|
+
|
51
|
+
raise ArgumentError, "Not a style family: #{f.inspect}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# ------------------------------------------------------------
|
56
|
+
# Public instance methods
|
57
|
+
|
58
|
+
def split_name(style_name)
|
59
|
+
return [nil, style_name] unless style_name.start_with?(prefix)
|
60
|
+
|
61
|
+
[prefix, style_name[prefix.size..]]
|
62
|
+
end
|
63
|
+
|
64
|
+
def index_part(style_name)
|
65
|
+
prefix, suffix = split_name(style_name)
|
66
|
+
return unless prefix == self.prefix
|
67
|
+
return unless (suffix_i = suffix.to_i).to_s == suffix
|
68
|
+
|
69
|
+
suffix_i
|
70
|
+
end
|
71
|
+
|
72
|
+
# ------------------------------------------------------------
|
73
|
+
# TypesafeEnum overrides
|
74
|
+
|
75
|
+
def to_s
|
76
|
+
# noinspection RubyYardReturnMatch
|
77
|
+
value
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|