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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/xrb/buffer.rb +2 -0
- data/lib/xrb/builder.rb +20 -0
- data/lib/xrb/error.rb +19 -0
- data/lib/xrb/fallback/markup.rb +1220 -1217
- data/lib/xrb/fallback/markup.rl +1 -0
- data/lib/xrb/fallback/query.rb +313 -311
- data/lib/xrb/fallback/template.rb +541 -536
- data/lib/xrb/markup.rb +23 -3
- data/lib/xrb/query.rb +25 -0
- data/lib/xrb/strings.rb +19 -2
- data/lib/xrb/tag.rb +46 -0
- data/lib/xrb/template.rb +11 -1
- data/lib/xrb/version.rb +3 -2
- data/lib/xrb.rb +0 -2
- data/readme.md +27 -3
- data/releases.md +26 -0
- data.tar.gz.sig +0 -0
- metadata +7 -7
- metadata.gz.sig +0 -0
- data/lib/xrb/reference.rb +0 -108
- data/lib/xrb/uri.rb +0 -100
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c405671464f8c345c353f1b8613e7f92c5aa7ce16ece92879a5430564130a1dc
|
|
4
|
+
data.tar.gz: d5408318e1f6d65ffd77380104e8b38e47cc38a54cf5333869fbfcb704191df8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f958390f0dca1de58d1181ad9e01c29fc5f8a49da8260e63082d2df1bd319d8e0c05ec207a4a8c01699c5e6afd1f69c92a42df747573693f220bd40daa1b1ed1
|
|
7
|
+
data.tar.gz: 54db6f9744055840a9153e4145eb6fb10a85d2ba28b836c7c629a556c817f8343e1e15004faf361fb2d493477f6ea145b10b72f4764b5937d925072dabde8510
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/lib/xrb/buffer.rb
CHANGED
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
|