belletrist 1.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d59cf0de5fc3b77ee612b1bec7fc8a41db26bf7475e1f4943967871f41f024d
4
+ data.tar.gz: 62755a4c1c86779d64f29857cfce47fecb3740562ce53105cb35b6666cfaabd5
5
+ SHA512:
6
+ metadata.gz: a7a9d2b6c69834b2054f364271abff3362ccf37fbdcc789c482c6d2243225cf041cbc388b4bf9f7185501be7a12848152fdb15840dc8254faa1239c1833cc0a3
7
+ data.tar.gz: 2918a2a44daa4495d1955378e6d8962d312d635fb99ba600a7a81480525b1a9340b08f9ac59768c2a89df310477525562ed49d2c5f6de5a0a361473b5d3d618e
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Scribe Changelog
2
+ This file contains general, high level explanations of the differences between versions. Please check the commmit
3
+ history for further details.
4
+
5
+ ## 1.0.3
6
+ * Actually added the LICENSE file to the gem.
7
+
8
+ ## 1.0.1 & 1.0.2
9
+ * Dumb fixes to correct errors in me getting all of this laid out. No functional change.
10
+
11
+ ## 1.0.0
12
+ * Created the initial DSL for HTML generation, includes sanitizing and array mapping capabilities.
13
+ * HTML DSL also supports sub-elements by subclassing HTML::Element, and using the `with` method.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2023
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 all
11
+ 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 THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Belletrist
2
+ Belletrist is a collection of Ruby DSLs for generation of different data file types. Currently, HTML is supported, but
3
+ that will grow as my needs do, or if other people want or contribute any other DSLs, which would be pretty cool I think.
4
+
5
+ Important to note is that Belletrist has a focus on performance, not correctness. Belletrist ascribes to the rule of
6
+ "what goes in, must come out". Belletrist DSLs must output well-formed documents so long as the developer provides
7
+ Belletrist valid input, if that contract is broken the result is undefined.
8
+
9
+ ## Requirements of a Belletrist DSL
10
+ * All input must be sanitized, and sanitization is not optional.
11
+ * Correctness of input is not a concern of the DSL, but of the developer.
12
+
13
+ ## Using
14
+ Below are some examples of how you can use the different DSLs provided by Belletrist.
15
+
16
+ ### HTML
17
+ ```ruby
18
+ require 'belletrist'
19
+
20
+ da_rulez = ['Be hip!', 'Be cool!', 'Don\'t be square!']
21
+
22
+ document = Belletrist::HTML::Document.new
23
+ document.head do
24
+ title 'Some Kind of Web Page'
25
+ meta name: 'description', content: 'Example'
26
+ end
27
+ document.body do
28
+ h1 'My Very Cool Website'
29
+ p 'Please follow the rules:'
30
+ ol.map da_rulez do |rule|
31
+ li rule
32
+ end
33
+ end
34
+
35
+ # String conversation is serialization of the input.
36
+ print document.to_s
37
+ ```
@@ -0,0 +1,22 @@
1
+ require_relative './lib/belletrist/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'belletrist'
5
+ s.version = Belletrist::VERSION
6
+ s.licenses = ['MIT']
7
+ s.summary = 'A collection of Ruby DSLs for data file generation.'
8
+ s.description = <<-EOF
9
+ Belletrist is a collection of Ruby DSLs for generation of different data file types. Currently, HTML is supported, but
10
+ that will grow as my needs do, or if other people want or contribute any other DSLs, which would be pretty cool I think.
11
+
12
+ Important to note is that Belletrist has a focus on performance, not correctness. Belletrist ascribes to the rule of
13
+ "what goes in, must come out". Belletrist DSLs must output well-formed documents so long as the developer provides
14
+ Belletrist valid input, if that contract is broken the result is undefined.
15
+ EOF
16
+ s.authors = ['Juniper']
17
+ s.email = 'me@junisoft.org'
18
+ s.files = Dir['lib/**/*.rb'] + %w[README.md CHANGELOG.md belletrist.gemspec LICENSE]
19
+ s.homepage = 'https://codeberg.org/juniper/Belletrist'
20
+ s.metadata = { "source_code_uri" => "https://codeberg.org/juniper/Belletrist" }
21
+ s.required_ruby_version = '>= 2.7.0'
22
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Belletrist
4
+ class BaseCollector
5
+ attr_reader :elements
6
+
7
+ def initialize
8
+ @elements = []
9
+ end
10
+
11
+ def to_s
12
+ @elements.map {|e| e.to_s}.join('')
13
+ end
14
+
15
+ private def method_missing(symbol, *args, &block)
16
+ with new_element(symbol.to_s, args), &block
17
+ end
18
+
19
+ private def new_element(ele, args)
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def p(*args, &block)
24
+ method_missing(:p, *args, &block)
25
+ end
26
+
27
+ def with(ele, &block)
28
+ @elements.push ele
29
+ ele.children.instance_eval(&block) if block
30
+ ele
31
+ end
32
+
33
+ def map(arr, &block)
34
+ arr.each do |item|
35
+ instance_exec item, &block
36
+ end
37
+ end
38
+
39
+ def responds_to?(method)
40
+ true
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './abstract'
4
+
5
+ module Belletrist::HTML
6
+ class Base
7
+ attr_reader :children
8
+
9
+ def initialize
10
+ @children = Collector.new
11
+ end
12
+
13
+ def inspect
14
+ self.to_s
15
+ end
16
+ end
17
+
18
+ class Element < Base
19
+ ESCAPE_HTML = {
20
+ "&" => "&amp;",
21
+ "<" => "&lt;",
22
+ ">" => "&gt;",
23
+ "'" => "&#x27;",
24
+ '"' => "&quot;",
25
+ "/" => "&#x2F;"
26
+ }
27
+ ESCAPE_HTML_PATTERN = Regexp.union(ESCAPE_HTML.keys)
28
+
29
+ attr_accessor :text
30
+ attr_reader :name
31
+
32
+ def initialize(name, args)
33
+ super()
34
+ @name = name.to_s
35
+ @attr = []
36
+ @text = ""
37
+
38
+ args.each do |arg|
39
+ if arg.is_a?(Hash)
40
+ import_attribute(arg)
41
+ else
42
+ @text += arg.to_s
43
+ end
44
+ end
45
+
46
+ component(@children)
47
+ end
48
+
49
+ def component(c)
50
+ end
51
+
52
+ private def import_attribute(hash)
53
+ hash.each do |entry|
54
+ k, v = entry
55
+ @attr.push [s_key(k.to_s), "\"#{s_quoted(v)}\""].join('=')
56
+ end
57
+ end
58
+
59
+ private def s_key(key)
60
+ key.gsub(/\W/, '')
61
+ end
62
+
63
+ private def s_quoted(value)
64
+ value.gsub(/"/, '&quot;')
65
+ end
66
+
67
+ private def s_txt(text)
68
+ text.gsub(ESCAPE_HTML_PATTERN, ESCAPE_HTML)
69
+ end
70
+
71
+ def map(arr, &block)
72
+ arr.each do |item|
73
+ @children.instance_exec item, &block
74
+ end
75
+ end
76
+
77
+ def to_s
78
+ spacer = ''
79
+ spacer = ' ' if @attr.length > 0
80
+ "<#{s_key(@name)}#{spacer}#{@attr.join(' ')}>#{s_txt(@text)}#{@children}</#{s_key(@name)}>"
81
+ end
82
+ end
83
+
84
+ class Document < Base
85
+ def initialize(spec=V5)
86
+ super()
87
+ @head = Collector.new
88
+ @body = Collector.new
89
+ @spec = spec
90
+ end
91
+
92
+ def head(&block)
93
+ @head.instance_eval(&block) if block
94
+ @head
95
+ end
96
+
97
+ def body(&block)
98
+ @body.instance_eval(&block) if block
99
+ @body
100
+ end
101
+
102
+ def to_s
103
+ "#{@spec}<html><head>#{@head}</head><body>#{@body}</body></html>"
104
+ end
105
+ end
106
+
107
+ class Collector < Belletrist::BaseCollector
108
+ def new_element(name, args)
109
+ Element.new(name, args)
110
+ end
111
+ end
112
+
113
+ V5 = '<!DOCTYPE html>'
114
+ V4 = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 strict//EN" "http://www.w3.org/TR/html4/strict.dtd">'
115
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Belletrist
4
+ VERSION = '1.0.3'
5
+ end
data/lib/belletrist.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'belletrist/version'
4
+ require_relative 'belletrist/html'
5
+
6
+ module Belletrist
7
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: belletrist
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Juniper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Belletrist is a collection of Ruby DSLs for generation of different data file types. Currently, HTML is supported, but
15
+ that will grow as my needs do, or if other people want or contribute any other DSLs, which would be pretty cool I think.
16
+
17
+ Important to note is that Belletrist has a focus on performance, not correctness. Belletrist ascribes to the rule of
18
+ "what goes in, must come out". Belletrist DSLs must output well-formed documents so long as the developer provides
19
+ Belletrist valid input, if that contract is broken the result is undefined.
20
+ email: me@junisoft.org
21
+ executables: []
22
+ extensions: []
23
+ extra_rdoc_files: []
24
+ files:
25
+ - CHANGELOG.md
26
+ - LICENSE
27
+ - README.md
28
+ - belletrist.gemspec
29
+ - lib/belletrist.rb
30
+ - lib/belletrist/abstract.rb
31
+ - lib/belletrist/html.rb
32
+ - lib/belletrist/version.rb
33
+ homepage: https://codeberg.org/juniper/Belletrist
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ source_code_uri: https://codeberg.org/juniper/Belletrist
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.7.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.3.26
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: A collection of Ruby DSLs for data file generation.
57
+ test_files: []