rrtf 0.1.1 → 0.1.2

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -7
  3. data/documentation/RRTF/CharacterFormatting.html +1002 -0
  4. data/documentation/RRTF/CharacterStyle.html +1058 -0
  5. data/documentation/RRTF/Colour.html +813 -0
  6. data/documentation/RRTF/ColourTable.html +770 -0
  7. data/documentation/RRTF/CommandNode.html +2372 -0
  8. data/documentation/RRTF/ContainerNode.html +826 -0
  9. data/documentation/RRTF/Converters/HTML/Helpers.html +272 -0
  10. data/documentation/RRTF/Converters/HTML/Node.html +364 -0
  11. data/documentation/RRTF/Converters/HTML/NodeSet.html +265 -0
  12. data/documentation/RRTF/Converters/HTML.html +337 -0
  13. data/documentation/RRTF/Converters.html +117 -0
  14. data/documentation/RRTF/Document.html +2405 -0
  15. data/documentation/RRTF/DocumentStyle.html +1367 -0
  16. data/documentation/RRTF/Font.html +790 -0
  17. data/documentation/RRTF/FontTable.html +763 -0
  18. data/documentation/RRTF/FooterNode.html +515 -0
  19. data/documentation/RRTF/HeaderNode.html +515 -0
  20. data/documentation/RRTF/ImageNode.html +1374 -0
  21. data/documentation/RRTF/Information.html +809 -0
  22. data/documentation/RRTF/LinkNode.html +264 -0
  23. data/documentation/RRTF/ListLevel.html +799 -0
  24. data/documentation/RRTF/ListLevelNode.html +612 -0
  25. data/documentation/RRTF/ListMarker.html +595 -0
  26. data/documentation/RRTF/ListNode.html +368 -0
  27. data/documentation/RRTF/ListTable.html +343 -0
  28. data/documentation/RRTF/ListTemplate.html +433 -0
  29. data/documentation/RRTF/ListTextNode.html +285 -0
  30. data/documentation/RRTF/Node.html +616 -0
  31. data/documentation/RRTF/Paper.html +624 -0
  32. data/documentation/RRTF/ParagraphFormatting.html +749 -0
  33. data/documentation/RRTF/ParagraphNode.html +275 -0
  34. data/documentation/RRTF/ParagraphStyle.html +1319 -0
  35. data/documentation/RRTF/RTFError.html +295 -0
  36. data/documentation/RRTF/Style.html +1767 -0
  37. data/documentation/RRTF/Stylesheet.html +1768 -0
  38. data/documentation/RRTF/TableCellNode.html +1704 -0
  39. data/documentation/RRTF/TableNode.html +1025 -0
  40. data/documentation/RRTF/TableRowNode.html +675 -0
  41. data/documentation/RRTF/TextNode.html +600 -0
  42. data/documentation/RRTF/Utilities.html +201 -0
  43. data/documentation/RRTF.html +129 -0
  44. data/documentation/_index.html +478 -0
  45. data/documentation/class_list.html +51 -0
  46. data/documentation/css/common.css +1 -0
  47. data/documentation/css/full_list.css +58 -0
  48. data/documentation/css/style.css +492 -0
  49. data/documentation/file.README.html +223 -0
  50. data/documentation/file_list.html +56 -0
  51. data/documentation/frames.html +17 -0
  52. data/documentation/index.html +223 -0
  53. data/documentation/js/app.js +248 -0
  54. data/documentation/js/full_list.js +216 -0
  55. data/documentation/js/jquery.js +4 -0
  56. data/documentation/method_list.html +2203 -0
  57. data/documentation/top-level-namespace.html +110 -0
  58. data/examples/01.rtf +14 -17
  59. data/examples/01_mac_word15_36.png +0 -0
  60. data/examples/01_styles_and_paragraphs.rb +3 -4
  61. data/examples/resources/json/redshirt_styles.json +4 -2
  62. data/lib/rrtf/node.rb +86 -167
  63. data/lib/rrtf/style/character_style.rb +4 -3
  64. data/lib/rrtf/style/formatting.rb +55 -11
  65. data/lib/rrtf/style/paragraph_style.rb +19 -4
  66. data/lib/rrtf/style/style.rb +15 -15
  67. data/lib/rrtf/stylesheet.rb +57 -16
  68. data/lib/rrtf/version.rb +1 -1
  69. data/rrtf.gemspec +1 -0
  70. 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
- # NOTE: Paragraphs can be styled with character commands in addition to
6
- # paragraph commands, thus this class includes both paragraph & character
7
- # formatting modules
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
- "#{paragraph_formatting_to_rtf(document)} #{character_formatting_to_rtf(document)}"
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
@@ -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
- # ===== Parameters
9
- # options:: A hashmap of options for the style. Used only in stylesheet.
10
- # name:: Human-readable name for the style DEFAULT nil
11
- # id:: ID for the style (for use in code) DEFAULT nil
12
- # handle:: A 16-bit integer that identifies the style in a document
13
- # DEFAULT nil
14
- # flow:: The character flow (Style::LEFT_TO_RIGHT or Style::RIGHT_TO_LEFT)
15
- # DEFAULT LEFT_TO_RIGHT
16
- # primary:: A Boolean indicating whether or not this style is a
17
- # primary or "quick" style
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.
@@ -2,19 +2,33 @@ require 'stringio'
2
2
 
3
3
  module RRTF
4
4
 
5
- # Class that represents a stylesheet in an RTF document
5
+ # Represents a stylesheet in an RTF document.
6
+ # @author Wesley Hileman
6
7
  class Stylesheet
7
- # An array of styles associated with the stylesheet
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" => 100,
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
- # NOTE calling to_rtf causes all next styles to be updated (to_rtf "commits"
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
- def extract_add_options(hash)
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" => hash.delete("id"),
98
- "default" => hash.delete("default") || false,
99
- "next_style_id" => hash.delete("next_style") || nil,
100
- "base_style_id" => hash.delete("base_style") || nil,
101
- "assign_handle" => hash.delete("assign_handle") || @options["assign_style_handles"],
102
- "assign_priority" => hash.delete("assign_priority") || @options["assign_style_priorities"]
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
@@ -1,3 +1,3 @@
1
1
  module RRTF
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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