weblet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 188d4008035db1c75dee24819614915edc2a32eadd6ead9e5b792d9381458655
4
+ data.tar.gz: 68136024110f77153101601d8115607c966e36c660e42c0e1b2b708cebd16e27
5
+ SHA512:
6
+ metadata.gz: b7a4492500cab87adf86d969e0ef4324ec4ea41d46fd389d84e37895f19f166729e5eb4b2f54ce649d7d2dbf6834d5e3dbe9aaec8b4d9b13dd2802209fe913c0
7
+ data.tar.gz: 67d9cca9a3aa8ff32edc6137c614b8ae3cb6e020643c91b20fc445a48b7699897c0a54242c499d9d72504a5ccb2c38e6ab3eedc8f2728a196f1a1beba8e448a2
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/lib/weblet.rb ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: weblet.rb
4
+
5
+ require 'rexle'
6
+
7
+
8
+ class WebletBuilder
9
+
10
+ def initialize(s)
11
+
12
+ @a = build(scan(s.strip))
13
+ @a.unshift *['weblet', {}, '']
14
+
15
+ end
16
+
17
+ def to_a()
18
+ @a
19
+ end
20
+
21
+ private
22
+
23
+ def scan(s, indent=0)
24
+
25
+ a = s.split(/(?=^#{' ' * indent}#)/)
26
+ return a unless a.length > 1
27
+
28
+ a.map {|x| scan(x, indent+1)}
29
+
30
+ end
31
+
32
+ def build(a)
33
+
34
+ a.map do |x|
35
+
36
+ if x.is_a? String then
37
+ head, body = x.split("\n",2)
38
+ [:node, {id: head[/#(\w+)/,1]}, body.strip]
39
+ else
40
+ x.flatten!(1)
41
+ head, body = x.shift.split("\n",2)
42
+ [:node, {id: head[/#(\w+)/,1].rstrip}, body.rstrip, *build(x)]
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+
51
+ class Weblet
52
+
53
+ def initialize(raws, b)
54
+
55
+ raws.strip!
56
+ obj = raws[0] == '<' ? raws : WebletBuilder.new(raws).to_a
57
+ doc = Rexle.new(obj)
58
+ @h = scan doc.root
59
+ @b = b
60
+
61
+ end
62
+
63
+ def to_h()
64
+ @h
65
+ end
66
+
67
+ def render(*args)
68
+
69
+ if args.first.is_a? String then
70
+ path = args.first.split('/',2).map(&:to_sym)
71
+ else
72
+ path = *args.flatten(1)
73
+ end
74
+
75
+ r = @h.dig *path
76
+ eval('%Q(' + r + ')', @b) if r
77
+
78
+ end
79
+
80
+ private
81
+
82
+ def scan(node)
83
+
84
+ a = node.elements.map do |e|
85
+
86
+ nodes = e.xpath('node')
87
+
88
+ r = nodes.any? ? scan(e) : e.children.join()
89
+
90
+ [e.attributes[:id].to_sym, r]
91
+
92
+ end.to_h
93
+
94
+ end
95
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weblet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwNDAyMjA1NjE2WhcN
15
+ MjIwNDAyMjA1NjE2WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDeT7iZ
17
+ 2Rq2gB9JMjpvuSywAjBJd904yMTINVnue+yGshnh6t2xg9BPXbnuSdjS8pg2vyJ4
18
+ EgkwsZvsTbAgeg0D/+fDxPKNj4765QwLDOWGGNgD7XbLwOcqVdtmqxH8Q3/vgklC
19
+ OlPJxI5ea/gEHVezAiaKYBhIUQ+9unBQdTiOfO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AjAqJ6c
35
+ mKbvoKGru7nPXh4E/ArWQ70Yz24o3lwGZW3XLzwdLPKB8MiOOGuTARkCWFEYT5tE
36
+ We42rjyhFeidBuSZp6/7Wwlo
37
+ -----END CERTIFICATE-----
38
+ date: 2021-04-02 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: rexle
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.5'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.5.10
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.5'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.5.10
60
+ description:
61
+ email: digital.robertson@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - lib/weblet.rb
67
+ homepage: https://github.com/jrobertson/weblet
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.7.10
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Intended for retrieving HTML templates from a convenient to use Hash-like
91
+ object.
92
+ test_files: []
metadata.gz.sig ADDED
Binary file