xrb 0.1 → 0.2.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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/bake/xrb/entities.rb +60 -0
  4. data/bake/xrb/parsers.rb +69 -0
  5. data/ext/extconf.rb +21 -0
  6. data/ext/xrb/escape.c +152 -0
  7. data/ext/xrb/escape.h +15 -0
  8. data/ext/xrb/markup.c +1949 -0
  9. data/ext/xrb/markup.h +6 -0
  10. data/ext/xrb/markup.rl +226 -0
  11. data/ext/xrb/query.c +619 -0
  12. data/ext/xrb/query.h +6 -0
  13. data/ext/xrb/query.rl +82 -0
  14. data/ext/xrb/tag.c +204 -0
  15. data/ext/xrb/tag.h +21 -0
  16. data/ext/xrb/template.c +1114 -0
  17. data/ext/xrb/template.h +6 -0
  18. data/ext/xrb/template.rl +77 -0
  19. data/ext/xrb/xrb.c +72 -0
  20. data/ext/xrb/xrb.h +132 -0
  21. data/lib/xrb/buffer.rb +103 -0
  22. data/lib/xrb/builder.rb +222 -0
  23. data/lib/xrb/entities.rb +2137 -0
  24. data/lib/xrb/entities.xrb +30 -0
  25. data/lib/xrb/error.rb +81 -0
  26. data/lib/xrb/fallback/markup.rb +1658 -0
  27. data/lib/xrb/fallback/markup.rl +228 -0
  28. data/lib/xrb/fallback/query.rb +548 -0
  29. data/lib/xrb/fallback/query.rl +88 -0
  30. data/lib/xrb/fallback/template.rb +829 -0
  31. data/lib/xrb/fallback/template.rl +80 -0
  32. data/lib/xrb/markup.rb +56 -0
  33. data/lib/xrb/native.rb +15 -0
  34. data/lib/xrb/parse_delegate.rb +19 -0
  35. data/lib/xrb/parsers.rb +17 -0
  36. data/lib/xrb/query.rb +80 -0
  37. data/lib/xrb/reference.rb +108 -0
  38. data/lib/xrb/strings.rb +47 -0
  39. data/lib/xrb/tag.rb +115 -0
  40. data/lib/xrb/template.rb +164 -0
  41. data/lib/xrb/uri.rb +100 -0
  42. data/lib/xrb/version.rb +8 -0
  43. data/lib/xrb.rb +11 -0
  44. data/license.md +23 -0
  45. data/readme.md +29 -0
  46. data.tar.gz.sig +0 -0
  47. metadata +109 -58
  48. metadata.gz.sig +0 -0
  49. data/README +0 -60
  50. data/app/helpers/ui_helper.rb +0 -80
  51. data/app/models/xrb/element.rb +0 -9
  52. data/lib/xrb/engine.rb +0 -4
  53. data/rails/init.rb +0 -1
  54. data/xrb.gemspec +0 -12
@@ -0,0 +1,30 @@
1
+ # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module XRB
22
+ # We only support a small subset of markup entities.
23
+ module Entities
24
+ HTML5 = {
25
+ <?r self.each do |string, metadata| ?>
26
+ #{string.gsub(/^&|;$/, '').inspect} => #{metadata['characters'].dump}, # #{metadata['characters'].inspect}
27
+ <?r end ?>
28
+ }
29
+ end
30
+ end
data/lib/xrb/error.rb ADDED
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
5
+
6
+ require_relative 'buffer'
7
+
8
+ module XRB
9
+ class Error < StandardError
10
+ end
11
+
12
+ class ParseError < Error
13
+ def initialize(message, buffer, offset)
14
+ super(message)
15
+
16
+ @buffer = buffer
17
+ @offset = offset
18
+ end
19
+
20
+ def location
21
+ @location ||= Location.new(@buffer.read, @offset)
22
+ end
23
+
24
+ attr :buffer
25
+ attr :path
26
+
27
+ def to_s
28
+ "#{buffer.path}#{location}: #{super}\n#{location.line_text}"
29
+ end
30
+ end
31
+
32
+ class Location
33
+ def initialize(input, offset)
34
+ raise ArgumentError.new("Offset #{index} is past end of input #{input.bytesize}") if offset > input.bytesize
35
+
36
+ @offset = offset
37
+ @line_index = 0
38
+ line_offset = next_line_offset = 0
39
+
40
+ input.each_line do |line|
41
+ line_offset = next_line_offset
42
+ next_line_offset += line.bytesize
43
+
44
+ # Is our input offset within this line?
45
+ if next_line_offset >= offset
46
+ @line_text = line.chomp
47
+ @line_range = line_offset...next_line_offset
48
+ break
49
+ else
50
+ @line_index += 1
51
+ end
52
+ end
53
+ end
54
+
55
+ def to_i
56
+ @offset
57
+ end
58
+
59
+ def to_s
60
+ "[#{self.line_number}:#{self.line_offset}]"
61
+ end
62
+
63
+ # The line that contains the @offset (base 0 indexing).
64
+ attr :line_index
65
+
66
+ # The line index, but base-1.
67
+ def line_number
68
+ @line_index + 1
69
+ end
70
+
71
+ # The byte offset to the start of that line.
72
+ attr :line_range
73
+
74
+ # The number of bytes from the start of the line to the given offset in the input.
75
+ def line_offset
76
+ @offset - @line_range.min
77
+ end
78
+
79
+ attr :line_text
80
+ end
81
+ end