rrtf 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -7
- data/documentation/RRTF/CharacterFormatting.html +1002 -0
- data/documentation/RRTF/CharacterStyle.html +1058 -0
- data/documentation/RRTF/Colour.html +813 -0
- data/documentation/RRTF/ColourTable.html +770 -0
- data/documentation/RRTF/CommandNode.html +2372 -0
- data/documentation/RRTF/ContainerNode.html +826 -0
- data/documentation/RRTF/Converters/HTML/Helpers.html +272 -0
- data/documentation/RRTF/Converters/HTML/Node.html +364 -0
- data/documentation/RRTF/Converters/HTML/NodeSet.html +265 -0
- data/documentation/RRTF/Converters/HTML.html +337 -0
- data/documentation/RRTF/Converters.html +117 -0
- data/documentation/RRTF/Document.html +2405 -0
- data/documentation/RRTF/DocumentStyle.html +1367 -0
- data/documentation/RRTF/Font.html +790 -0
- data/documentation/RRTF/FontTable.html +763 -0
- data/documentation/RRTF/FooterNode.html +515 -0
- data/documentation/RRTF/HeaderNode.html +515 -0
- data/documentation/RRTF/ImageNode.html +1374 -0
- data/documentation/RRTF/Information.html +809 -0
- data/documentation/RRTF/LinkNode.html +264 -0
- data/documentation/RRTF/ListLevel.html +799 -0
- data/documentation/RRTF/ListLevelNode.html +612 -0
- data/documentation/RRTF/ListMarker.html +595 -0
- data/documentation/RRTF/ListNode.html +368 -0
- data/documentation/RRTF/ListTable.html +343 -0
- data/documentation/RRTF/ListTemplate.html +433 -0
- data/documentation/RRTF/ListTextNode.html +285 -0
- data/documentation/RRTF/Node.html +616 -0
- data/documentation/RRTF/Paper.html +624 -0
- data/documentation/RRTF/ParagraphFormatting.html +749 -0
- data/documentation/RRTF/ParagraphNode.html +275 -0
- data/documentation/RRTF/ParagraphStyle.html +1319 -0
- data/documentation/RRTF/RTFError.html +295 -0
- data/documentation/RRTF/Style.html +1767 -0
- data/documentation/RRTF/Stylesheet.html +1768 -0
- data/documentation/RRTF/TableCellNode.html +1704 -0
- data/documentation/RRTF/TableNode.html +1025 -0
- data/documentation/RRTF/TableRowNode.html +675 -0
- data/documentation/RRTF/TextNode.html +600 -0
- data/documentation/RRTF/Utilities.html +201 -0
- data/documentation/RRTF.html +129 -0
- data/documentation/_index.html +478 -0
- data/documentation/class_list.html +51 -0
- data/documentation/css/common.css +1 -0
- data/documentation/css/full_list.css +58 -0
- data/documentation/css/style.css +492 -0
- data/documentation/file.README.html +223 -0
- data/documentation/file_list.html +56 -0
- data/documentation/frames.html +17 -0
- data/documentation/index.html +223 -0
- data/documentation/js/app.js +248 -0
- data/documentation/js/full_list.js +216 -0
- data/documentation/js/jquery.js +4 -0
- data/documentation/method_list.html +2203 -0
- data/documentation/top-level-namespace.html +110 -0
- data/examples/01.rtf +14 -17
- data/examples/01_mac_word15_36.png +0 -0
- data/examples/01_styles_and_paragraphs.rb +3 -4
- data/examples/resources/json/redshirt_styles.json +4 -2
- data/lib/rrtf/node.rb +86 -167
- data/lib/rrtf/style/character_style.rb +4 -3
- data/lib/rrtf/style/formatting.rb +55 -11
- data/lib/rrtf/style/paragraph_style.rb +19 -4
- data/lib/rrtf/style/style.rb +15 -15
- data/lib/rrtf/stylesheet.rb +57 -16
- data/lib/rrtf/version.rb +1 -1
- data/rrtf.gemspec +1 -0
- metadata +70 -1
@@ -2,13 +2,19 @@ require 'stringio'
|
|
2
2
|
|
3
3
|
module RRTF
|
4
4
|
# This class represents a styling for a paragraph within an RTF document.
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
5
|
+
# @note paragraphs can be styled with character commands in addition to
|
6
|
+
# paragraph commands, thus this class includes both paragraph & character
|
7
|
+
# formatting modules.
|
8
8
|
class ParagraphStyle < Style
|
9
9
|
include ParagraphFormatting
|
10
10
|
include CharacterFormatting
|
11
11
|
|
12
|
+
# This is the constructor for the CharacterStyle class.
|
13
|
+
#
|
14
|
+
# @param [Hash] options the character style options.
|
15
|
+
# @option options (see Style#initialize)
|
16
|
+
# @option options (see CharacterFormatting#initialize_character_formatting)
|
17
|
+
# @option options (see ParagraphFormatting#initialize_paragraph_formatting)
|
12
18
|
def initialize(options = {})
|
13
19
|
super(options)
|
14
20
|
initialize_paragraph_formatting(options)
|
@@ -50,6 +56,7 @@ module RRTF
|
|
50
56
|
rtf << "\\snext#{@next_style_handle}#{suffix}" unless @next_style_handle.nil?
|
51
57
|
rtf << "\\sqformat#{suffix}" if @primary
|
52
58
|
rtf << "\\spriority#{@priority}#{suffix}" unless @priority.nil?
|
59
|
+
rtf << "\\shidden#{suffix}" if @hidden
|
53
60
|
rtf << "#{name_prefix}#{name};}"
|
54
61
|
|
55
62
|
rtf.string
|
@@ -73,7 +80,15 @@ module RRTF
|
|
73
80
|
end
|
74
81
|
|
75
82
|
def rtf_formatting(document)
|
76
|
-
|
83
|
+
rtf = StringIO.new
|
84
|
+
|
85
|
+
pf = paragraph_formatting_to_rtf(document)
|
86
|
+
cf = character_formatting_to_rtf(document)
|
87
|
+
|
88
|
+
rtf << pf unless pf.nil?
|
89
|
+
rtf << cf unless cf.nil?
|
90
|
+
|
91
|
+
rtf.string
|
77
92
|
end
|
78
93
|
end # End of the ParagraphStyle class.
|
79
94
|
end # module RRTF
|
data/lib/rrtf/style/style.rb
CHANGED
@@ -1,34 +1,33 @@
|
|
1
1
|
# This is a parent class that all style classes will derive from.
|
2
2
|
class RRTF::Style
|
3
3
|
attr_accessor :handle, :name, :priority, :primary, :additive,
|
4
|
-
:next_style_handle, :auto_update, :based_on_style_handle
|
4
|
+
:next_style_handle, :auto_update, :based_on_style_handle,
|
5
|
+
:hidden
|
5
6
|
|
6
7
|
# Constructor for the style class.
|
7
8
|
#
|
8
|
-
#
|
9
|
-
# options
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# additive:: A Boolean indicating whether or not this style is
|
19
|
-
# additive DEFAULT false
|
9
|
+
# @param [Hash] options
|
10
|
+
# @option options [String] "name" (nil) human-readable name for the style.
|
11
|
+
# @option options [Integer] "handle" (nil) 16-bit integer that identifies the style in a document.
|
12
|
+
# @option options [Integer] "next_style_handle" (nil) 16-bit integer that identifies the next style for this style.
|
13
|
+
# @option options [Integer] "based_on_style_handle" (nil) 16-bit integer that identifies the base style for this style.
|
14
|
+
# @option options [Integer] "priority" (nil) 16-bit integer that indicates the ordering of the style among other styles in a document.
|
15
|
+
# @option options [Boolean] "primary" (false) whether or not this style is a primary or "quick" style.
|
16
|
+
# @option options [Boolean] "additive" (false) whether or not this character style is additive to the current paragraph style.
|
17
|
+
# @option options [Boolean] "auto_update" (false) whether or not this style should be updated when any node to which the style is applied is updated.
|
18
|
+
# @option options [Boolean] "hidden" (false) whether or not the style should be hidden.
|
20
19
|
def initialize(options = {})
|
21
20
|
# load default options
|
22
21
|
options = {
|
23
22
|
"name" => nil,
|
24
23
|
"handle" => nil,
|
25
24
|
"priority" => nil,
|
26
|
-
"flow" => 'LEFT_TO_RIGHT',
|
27
25
|
"primary" => false,
|
28
26
|
"additive" => false,
|
29
27
|
"next_style_handle" => nil,
|
30
28
|
"auto_update" => false,
|
31
|
-
"based_on_style_handle" => nil
|
29
|
+
"based_on_style_handle" => nil,
|
30
|
+
"hidden" => false
|
32
31
|
}.merge(options)
|
33
32
|
|
34
33
|
@handle = options.delete("handle")
|
@@ -39,6 +38,7 @@ class RRTF::Style
|
|
39
38
|
@additive = options.delete("additive")
|
40
39
|
@next_style_handle = options.delete("next_style_handle")
|
41
40
|
@auto_update = options.delete("auto_update")
|
41
|
+
@hidden = options.delete("hidden")
|
42
42
|
end
|
43
43
|
|
44
44
|
# Constructs an RTF identifier for the style.
|
data/lib/rrtf/stylesheet.rb
CHANGED
@@ -2,19 +2,33 @@ require 'stringio'
|
|
2
2
|
|
3
3
|
module RRTF
|
4
4
|
|
5
|
-
#
|
5
|
+
# Represents a stylesheet in an RTF document.
|
6
|
+
# @author Wesley Hileman
|
6
7
|
class Stylesheet
|
7
|
-
#
|
8
|
+
# Stores the Style objects associated with the stylesheet, each of which
|
9
|
+
# is keyed by its assigned ID.
|
10
|
+
# @return [Hash<String, Style>] the style hash.
|
8
11
|
attr_reader :styles
|
9
12
|
|
10
|
-
# The document to which the stylesheet belongs
|
13
|
+
# The document to which the stylesheet belongs.
|
14
|
+
# @return [Document] the document object.
|
11
15
|
attr_accessor :document
|
12
16
|
|
17
|
+
# Builds a Stylesheet object.
|
18
|
+
# @see #add_style #add_style for available style options.
|
19
|
+
#
|
20
|
+
# @param [Document] document the document to which the stylesheet belongs.
|
21
|
+
# @param [Hash] options the stylesheet options.
|
22
|
+
# @option options [Array<Hash>] "styles" ([]) a hashmap array specifying the styles to include in the stylesheet.
|
23
|
+
# @option options [Array<Boolean>] "assign_style_handles" (true) whether or not to auto-assign handles to included styles.
|
24
|
+
# @option options [Array<Boolean>] "assign_style_priorities" (true) whether or not to auto-assign priority to included styles.
|
25
|
+
# @option options [Array<Integer>] "base_style_handle" (1) the handle number at which to start indexing styles.
|
26
|
+
# @option options [Array<Integer>] "base_style_handle" (20) the priority number at which to start indexing styles.
|
13
27
|
def initialize(document, options = {})
|
14
28
|
@options = {
|
15
29
|
"styles" => [],
|
16
30
|
"base_style_handle" => 1,
|
17
|
-
"base_style_priority" =>
|
31
|
+
"base_style_priority" => 1,
|
18
32
|
"assign_style_handles" => true,
|
19
33
|
"assign_style_priorities" => true
|
20
34
|
}.merge(options)
|
@@ -25,10 +39,23 @@ module RRTF
|
|
25
39
|
add_styles(@options["styles"])
|
26
40
|
end
|
27
41
|
|
42
|
+
# Adds the specified styles to the stylesheet.
|
43
|
+
# @see #add_style #add_style for available style options.
|
44
|
+
#
|
45
|
+
# @param [Array<Hash>] hash_array a hashmap array specifying the styles to add to the stylesheet.
|
28
46
|
def add_styles(hash_array)
|
29
47
|
hash_array.each { |hash| add_style(hash) }
|
30
48
|
end
|
31
49
|
|
50
|
+
# Adds a single style to the stylesheet.
|
51
|
+
#
|
52
|
+
# @param [Hash] options the options to use in building the style.
|
53
|
+
# @option options [Style] "style" the style object to add to the stylesheet (can be specified directly in place of "type").
|
54
|
+
# @option options [String] "type" the type of style to build ("character" or "paragraph").
|
55
|
+
# @option options (see #extract_add_options)
|
56
|
+
# @option options (see Style#initialize)
|
57
|
+
# @option options (see CharacterFormatting#initialize_character_formatting)
|
58
|
+
# @option options (see ParagraphFormatting#initialize_paragraph_formatting)
|
32
59
|
def add_style(options)
|
33
60
|
style = options.delete("style")
|
34
61
|
type = options.delete("type")
|
@@ -54,9 +81,15 @@ module RRTF
|
|
54
81
|
end # if
|
55
82
|
end # add_style_from_hash()
|
56
83
|
|
57
|
-
# Converts the stylesheet to its RTF representation
|
58
|
-
#
|
59
|
-
# the stylesheet)
|
84
|
+
# Converts the stylesheet to its RTF representation.
|
85
|
+
# @note calling `to_rtf` causes all next and base styles to be updated
|
86
|
+
# (to_rtf "commits" the stylesheet); errors might be raised if next or
|
87
|
+
# base styles are missing (have yet to be added to the stylesheet).
|
88
|
+
#
|
89
|
+
# @param [Hash] options
|
90
|
+
# @option options [Boolean] "uglify" (false) removes most line breaks and spaces from RTF output.
|
91
|
+
# @option options [Integer] "base_indent" (0) the base indent (in spaces) for RTF output (ignored if uglify is true).
|
92
|
+
# @option options [Integer] "child_indent" (0) the amount of spaces by which to indent the component styles (ignored if uglify is true).
|
60
93
|
def to_rtf(options = {})
|
61
94
|
# load default options
|
62
95
|
options = {
|
@@ -68,7 +101,7 @@ module RRTF
|
|
68
101
|
newline_prefix = options["uglify"] ? '' : "\n"
|
69
102
|
base_prefix = options["uglify"] ? '' : " "*options["base_indent"]
|
70
103
|
|
71
|
-
# lookup and set next style handles on component styles
|
104
|
+
# lookup and set next and base style handles on component styles
|
72
105
|
substitute_next_style_handles()
|
73
106
|
substitute_base_style_handles()
|
74
107
|
|
@@ -91,15 +124,23 @@ module RRTF
|
|
91
124
|
private
|
92
125
|
|
93
126
|
# Strips options used in adding a style to a stylesheet from a hash
|
94
|
-
# and returns a subhash containing those options
|
95
|
-
|
127
|
+
# and returns a subhash containing those options.
|
128
|
+
#
|
129
|
+
# @param [Hash] options the subject hash.
|
130
|
+
# @option options [String] "id" the ID for the style (used in generating code only).
|
131
|
+
# @option options [Boolean] "default" (false) whether or not this style is the default style for the document.
|
132
|
+
# @option options [Integer] "next_style" (nil) the ID of the next style (the style to be used in the paragraph created after paragraphs with this style applied).
|
133
|
+
# @option options [Integer] "base_style" (nil) the ID of the base style (the style on which this one is based).
|
134
|
+
# @option options [Boolean] "assign_handle" whether or not a handle should be auto-assigned to this style.
|
135
|
+
# @option options [Boolean] "assign_priority" whether or not a priority should be auto-assigned to this style.
|
136
|
+
def extract_add_options(options)
|
96
137
|
{
|
97
|
-
"id" =>
|
98
|
-
"default" =>
|
99
|
-
"next_style_id" =>
|
100
|
-
"base_style_id" =>
|
101
|
-
"assign_handle" =>
|
102
|
-
"assign_priority" =>
|
138
|
+
"id" => options.delete("id"),
|
139
|
+
"default" => options.delete("default") || false,
|
140
|
+
"next_style_id" => options.delete("next_style") || nil,
|
141
|
+
"base_style_id" => options.delete("base_style") || nil,
|
142
|
+
"assign_handle" => options.delete("assign_handle") || @options["assign_style_handles"],
|
143
|
+
"assign_priority" => options.delete("assign_priority") || @options["assign_style_priorities"]
|
103
144
|
}
|
104
145
|
end # extract_add_options()
|
105
146
|
|
data/lib/rrtf/version.rb
CHANGED
data/rrtf.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.13"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
26
27
|
spec.add_development_dependency "byebug"
|
27
28
|
# Required for HTML converter functionality
|
28
29
|
spec.add_dependency "nokogiri"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrtf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wesley Hileman
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: byebug
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +125,61 @@ files:
|
|
111
125
|
- Rakefile
|
112
126
|
- bin/console
|
113
127
|
- bin/setup
|
128
|
+
- documentation/RRTF.html
|
129
|
+
- documentation/RRTF/CharacterFormatting.html
|
130
|
+
- documentation/RRTF/CharacterStyle.html
|
131
|
+
- documentation/RRTF/Colour.html
|
132
|
+
- documentation/RRTF/ColourTable.html
|
133
|
+
- documentation/RRTF/CommandNode.html
|
134
|
+
- documentation/RRTF/ContainerNode.html
|
135
|
+
- documentation/RRTF/Converters.html
|
136
|
+
- documentation/RRTF/Converters/HTML.html
|
137
|
+
- documentation/RRTF/Converters/HTML/Helpers.html
|
138
|
+
- documentation/RRTF/Converters/HTML/Node.html
|
139
|
+
- documentation/RRTF/Converters/HTML/NodeSet.html
|
140
|
+
- documentation/RRTF/Document.html
|
141
|
+
- documentation/RRTF/DocumentStyle.html
|
142
|
+
- documentation/RRTF/Font.html
|
143
|
+
- documentation/RRTF/FontTable.html
|
144
|
+
- documentation/RRTF/FooterNode.html
|
145
|
+
- documentation/RRTF/HeaderNode.html
|
146
|
+
- documentation/RRTF/ImageNode.html
|
147
|
+
- documentation/RRTF/Information.html
|
148
|
+
- documentation/RRTF/LinkNode.html
|
149
|
+
- documentation/RRTF/ListLevel.html
|
150
|
+
- documentation/RRTF/ListLevelNode.html
|
151
|
+
- documentation/RRTF/ListMarker.html
|
152
|
+
- documentation/RRTF/ListNode.html
|
153
|
+
- documentation/RRTF/ListTable.html
|
154
|
+
- documentation/RRTF/ListTemplate.html
|
155
|
+
- documentation/RRTF/ListTextNode.html
|
156
|
+
- documentation/RRTF/Node.html
|
157
|
+
- documentation/RRTF/Paper.html
|
158
|
+
- documentation/RRTF/ParagraphFormatting.html
|
159
|
+
- documentation/RRTF/ParagraphNode.html
|
160
|
+
- documentation/RRTF/ParagraphStyle.html
|
161
|
+
- documentation/RRTF/RTFError.html
|
162
|
+
- documentation/RRTF/Style.html
|
163
|
+
- documentation/RRTF/Stylesheet.html
|
164
|
+
- documentation/RRTF/TableCellNode.html
|
165
|
+
- documentation/RRTF/TableNode.html
|
166
|
+
- documentation/RRTF/TableRowNode.html
|
167
|
+
- documentation/RRTF/TextNode.html
|
168
|
+
- documentation/RRTF/Utilities.html
|
169
|
+
- documentation/_index.html
|
170
|
+
- documentation/class_list.html
|
171
|
+
- documentation/css/common.css
|
172
|
+
- documentation/css/full_list.css
|
173
|
+
- documentation/css/style.css
|
174
|
+
- documentation/file.README.html
|
175
|
+
- documentation/file_list.html
|
176
|
+
- documentation/frames.html
|
177
|
+
- documentation/index.html
|
178
|
+
- documentation/js/app.js
|
179
|
+
- documentation/js/full_list.js
|
180
|
+
- documentation/js/jquery.js
|
181
|
+
- documentation/method_list.html
|
182
|
+
- documentation/top-level-namespace.html
|
114
183
|
- examples/01.rtf
|
115
184
|
- examples/01_mac_libreoffice5_2_3_3.png
|
116
185
|
- examples/01_mac_pages6_2.png
|