xrb 0.11.2 → 0.12.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 191b9d8b1c76135932e4b95c00603c31e9d8528bea772b8dcdb8f6a9c697e898
4
- data.tar.gz: b05ffe7752fb49104e1a056ed96bc235676c19d06e2a4aa751c3e13a39e75637
3
+ metadata.gz: c405671464f8c345c353f1b8613e7f92c5aa7ce16ece92879a5430564130a1dc
4
+ data.tar.gz: d5408318e1f6d65ffd77380104e8b38e47cc38a54cf5333869fbfcb704191df8
5
5
  SHA512:
6
- metadata.gz: 112685f3e991db8bcfcff7777e907111b2aae8621435bb9d176cff8359d0167627d1cb2d79f12e16adc0530458796317602a2b7700d2dee1f75e5d52fdab7ab4
7
- data.tar.gz: 3e4ed11828e217d07459c7fb2ced92af58029392de6d3b49510336c3dfd9ab44777fbaf61b7de1124138b9e4d09183395e4148d6942e738f3ea311aeec4c61db
6
+ metadata.gz: f958390f0dca1de58d1181ad9e01c29fc5f8a49da8260e63082d2df1bd319d8e0c05ec207a4a8c01699c5e6afd1f69c92a42df747573693f220bd40daa1b1ed1
7
+ data.tar.gz: 54db6f9744055840a9153e4145eb6fb10a85d2ba28b836c7c629a556c817f8343e1e15004faf361fb2d493477f6ea145b10b72f4764b5937d925072dabde8510
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/xrb/buffer.rb CHANGED
@@ -17,6 +17,8 @@ module XRB
17
17
  # @attribute [String] the path name of the buffer.
18
18
  attr :path
19
19
 
20
+ # Freeze the buffer and its contents.
21
+ # @returns [Buffer] The frozen buffer.
20
22
  def freeze
21
23
  return self if frozen?
22
24
 
data/lib/xrb/builder.rb CHANGED
@@ -75,6 +75,11 @@ module XRB
75
75
  return nil
76
76
  end
77
77
 
78
+ # Create a markup fragment containing a single inline tag.
79
+ # @parameter name [String | Symbol] The tag name.
80
+ # @parameter content [Object] The tag content, which will be escaped as required.
81
+ # @parameter attributes [Hash] The tag attributes.
82
+ # @returns [Fragment] The generated markup fragment.
78
83
  def self.tag(name, content, **attributes)
79
84
  self.fragment do |builder|
80
85
  builder.inline(name, attributes) do
@@ -83,6 +88,10 @@ module XRB
83
88
  end
84
89
  end
85
90
 
91
+ # Initialize a builder which appends markup to the given output buffer.
92
+ # @parameter output [String | Nil] The output buffer, or `nil` to create a new markup string.
93
+ # @parameter indent [Boolean] Whether generated markup should be indented.
94
+ # @parameter encoding [Encoding] The encoding for a newly created output buffer.
86
95
  def initialize(output = nil, indent: true, encoding: Encoding::UTF_8)
87
96
  # This field gets togged in #inline so we keep track of it separately from @indentation.
88
97
  @indent = indent
@@ -114,10 +123,15 @@ module XRB
114
123
 
115
124
  alias to_s to_str
116
125
 
126
+ # Compare the generated output with another string-like object.
127
+ # @parameter other [Object] The object to compare with the output.
128
+ # @returns [Boolean] Whether the generated output is equal to the other object as a string.
117
129
  def == other
118
130
  @output == String(other)
119
131
  end
120
132
 
133
+ # Compute the indentation for the current nesting level.
134
+ # @returns [String] The current indentation, or an empty string when indentation is disabled.
121
135
  def indentation
122
136
  if @indent
123
137
  INDENT * (@level.size - 1)
@@ -150,6 +164,9 @@ module XRB
150
164
 
151
165
  alias inline inline_tag
152
166
 
167
+ # Temporarily disable indentation while yielding to the block.
168
+ # @yields {} The block which generates inline content.
169
+ # @returns [Object] The value returned by the block.
153
170
  def inline!
154
171
  original_indent = @indent
155
172
  @indent = false
@@ -175,6 +192,9 @@ module XRB
175
192
  end
176
193
  end
177
194
 
195
+ # Append unescaped content directly to the output buffer.
196
+ # @parameter content [String] The raw markup to append.
197
+ # @returns [String] The output buffer.
178
198
  def raw(content)
179
199
  @output << content
180
200
  end
data/lib/xrb/error.rb CHANGED
@@ -6,10 +6,16 @@
6
6
  require_relative "buffer"
7
7
 
8
8
  module XRB
9
+ # The base class for XRB errors.
9
10
  class Error < StandardError
10
11
  end
11
12
 
13
+ # Raised when an XRB parser encounters invalid input.
12
14
  class ParseError < Error
15
+ # Initialize a parse error at a specific byte offset within a buffer.
16
+ # @parameter message [String] The error message.
17
+ # @parameter buffer [Buffer] The input buffer being parsed.
18
+ # @parameter offset [Integer] The byte offset where parsing failed.
13
19
  def initialize(message, buffer, offset)
14
20
  super(message)
15
21
 
@@ -17,6 +23,8 @@ module XRB
17
23
  @offset = offset
18
24
  end
19
25
 
26
+ # Compute the location of the parse error within the input buffer.
27
+ # @returns [Location] The line and byte location of the error.
20
28
  def location
21
29
  @location ||= Location.new(@buffer.read, @offset)
22
30
  end
@@ -24,12 +32,19 @@ module XRB
24
32
  attr :buffer
25
33
  attr :path
26
34
 
35
+ # Format the error with its path, location, message, and source line.
36
+ # @returns [String] The formatted parse error.
27
37
  def to_s
28
38
  "#{buffer.path}#{location}: #{super}\n#{location.line_text}"
29
39
  end
30
40
  end
31
41
 
42
+ # A byte offset resolved to a line within an input string.
32
43
  class Location
44
+ # Initialize a location for a byte offset within an input string.
45
+ # @parameter input [String] The complete input string.
46
+ # @parameter offset [Integer] The byte offset within the input string.
47
+ # @raises [ArgumentError] If the offset is past the end of the input.
33
48
  def initialize(input, offset)
34
49
  raise ArgumentError.new("Offset #{index} is past end of input #{input.bytesize}") if offset > input.bytesize
35
50
 
@@ -52,10 +67,14 @@ module XRB
52
67
  end
53
68
  end
54
69
 
70
+ # Convert the location to its absolute byte offset.
71
+ # @returns [Integer] The byte offset within the input string.
55
72
  def to_i
56
73
  @offset
57
74
  end
58
75
 
76
+ # Format the location as a one-based line number and zero-based line offset.
77
+ # @returns [String] The formatted location.
59
78
  def to_s
60
79
  "[#{self.line_number}:#{self.line_offset}]"
61
80
  end