matte 0.1.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 +7 -0
- data/README.md +3 -0
- data/lib/matte.rb +164 -0
- metadata +59 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e4906e09f73262265f07c904dacd094d7bbcfe7e45bcf5c502bb9df908bea0bc
|
|
4
|
+
data.tar.gz: cdb023e7db2121980795407e44ae84f97effe69503ab147335eb299ef14d7a38
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d1f08ecab410b5d23273e0fd81e22e92b1f85f63b35d15614fca9f9bfc24a869e11dc71064081b1089321112a838cd2bb908ea8dc3ea512856c199b499cc7786
|
|
7
|
+
data.tar.gz: 7cfdb1bfa8d017860130a083b72d84db8d3fdf8764da6d0fb03fb385320717212c8bd6ed948de6994d9580ce8d412816a19b57f5515a0d9e8f902a6de29d49f5
|
data/README.md
ADDED
data/lib/matte.rb
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
require 'temple'
|
|
2
|
+
|
|
3
|
+
class Array
|
|
4
|
+
def start_with? other
|
|
5
|
+
take(other.length) == other
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# like find, but recursive
|
|
9
|
+
def select_recursive &proc
|
|
10
|
+
results = []
|
|
11
|
+
each do |element|
|
|
12
|
+
if proc.call element
|
|
13
|
+
results << element
|
|
14
|
+
end
|
|
15
|
+
if element.is_a? Array
|
|
16
|
+
results.push *(element.select_recursive(&proc))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
results
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module Matte
|
|
25
|
+
|
|
26
|
+
def self.find_all_sexps container, prefix
|
|
27
|
+
return nil unless container.is_a? Array
|
|
28
|
+
container.select_recursive { |e| Matte.sexp_is? e, prefix }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.find_first_sexp container, prefix
|
|
32
|
+
return nil unless container.is_a? Array
|
|
33
|
+
find_all_sexps(container, prefix).first
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.sexp_is? sexp, prefix
|
|
37
|
+
sexp.is_a? Array and sexp.start_with? prefix
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.get_attr_for_html html, key
|
|
41
|
+
find_first_sexp(find_first_sexp(html[3], [:html, :attr, key]), [:static])&.last
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# statically includes mixins in HTML.
|
|
45
|
+
class IncludeMixins
|
|
46
|
+
def initialize options = {}
|
|
47
|
+
@conf = options
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def call document
|
|
51
|
+
Matte.find_all_sexps(document, [:matte, :placeholder]).each do |placeholder|
|
|
52
|
+
placeholder_name = placeholder[2]
|
|
53
|
+
body = [:multi]
|
|
54
|
+
# include all mixins with same name
|
|
55
|
+
Matte.find_all_sexps(document, [:matte, :mixin, placeholder_name]).each do |mixin|
|
|
56
|
+
body << mixin[3]
|
|
57
|
+
mixin.clear
|
|
58
|
+
mixin << :multi
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
placeholder.clear
|
|
62
|
+
placeholder.push :multi, body
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# if there are any remaining mixins without corresponding placeholder, error
|
|
66
|
+
raise Temple::InvalidExpression.new "found mixin without corresponding placeholder" unless Matte.find_all_sexps(document, [:matte, :mixin]).empty?
|
|
67
|
+
|
|
68
|
+
document
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
class IncludeMixins
|
|
72
|
+
def initialize options = {}
|
|
73
|
+
@conf = options
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def call document
|
|
77
|
+
Matte.find_all_sexps(document, [:matte, :placeholder]).each do |placeholder|
|
|
78
|
+
placeholder_name = placeholder[2]
|
|
79
|
+
body = [:multi]
|
|
80
|
+
# include all mixins with same name
|
|
81
|
+
Matte.find_all_sexps(document, [:matte, :mixin, placeholder_name]).each do |mixin|
|
|
82
|
+
body << mixin[3]
|
|
83
|
+
mixin.clear
|
|
84
|
+
mixin << :multi
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
placeholder.clear
|
|
88
|
+
placeholder.push :multi, body
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# if there are any remaining mixins without corresponding placeholder, error
|
|
92
|
+
raise Temple::InvalidExpression.new "found mixin without corresponding placeholder" unless Matte.find_all_sexps(document, [:matte, :mixin]).empty?
|
|
93
|
+
|
|
94
|
+
document
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class ExpandMacros
|
|
99
|
+
def initialize options = {}
|
|
100
|
+
@conf = options
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def call exp
|
|
104
|
+
# TODO
|
|
105
|
+
exp
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
class Test
|
|
110
|
+
def initialize options = {}; end
|
|
111
|
+
|
|
112
|
+
def call exp
|
|
113
|
+
pp exp
|
|
114
|
+
exp
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# convert [:html] s-expressions into [:matte] s-expressions
|
|
119
|
+
class FromHTML
|
|
120
|
+
def initialize options = {}
|
|
121
|
+
@conf = options
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def call document
|
|
125
|
+
# document = Marshal.load Marshal.dump document # not the best solution, but at least it works!
|
|
126
|
+
|
|
127
|
+
Matte.find_all_sexps(document, [:html, :tag]).each do |tag|
|
|
128
|
+
next unless tag[2].start_with? 'matte:'
|
|
129
|
+
|
|
130
|
+
tag_name = tag[2].split(':').last.downcase
|
|
131
|
+
|
|
132
|
+
case tag_name
|
|
133
|
+
|
|
134
|
+
when "ph"
|
|
135
|
+
# get placeholder name
|
|
136
|
+
id = Matte.get_attr_for_html(tag, "id")
|
|
137
|
+
raise Temple::InvalidExpression.new "placeholder must have a constant name" unless id.is_a? String
|
|
138
|
+
|
|
139
|
+
tag.clear
|
|
140
|
+
tag.push :matte, :placeholder, id
|
|
141
|
+
|
|
142
|
+
when "mixin"
|
|
143
|
+
id = Matte.get_attr_for_html(tag, "id")
|
|
144
|
+
body = tag[4]
|
|
145
|
+
raise Temple::InvalidExpression.new "mixin must have a constant name" unless id.is_a? String
|
|
146
|
+
|
|
147
|
+
tag.clear
|
|
148
|
+
tag.push :matte, :mixin, id, body
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
pp document
|
|
153
|
+
document
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# initialization
|
|
159
|
+
if defined? Slim
|
|
160
|
+
# Slim::Engine.after Slim::CodeAttributes, Matte::Test
|
|
161
|
+
Slim::Engine.after Slim::CodeAttributes, Matte::ExpandMacros
|
|
162
|
+
Slim::Engine.after Slim::CodeAttributes, Matte::IncludeMixins
|
|
163
|
+
Slim::Engine.after Slim::CodeAttributes, Matte::FromHTML
|
|
164
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: matte
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- fmixolydian
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-01-15 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: temple
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.10'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0.10'
|
|
26
|
+
description: |2
|
|
27
|
+
Matte is a Temple compiler that processes macros (basically tags) and mixins in an HTML document
|
|
28
|
+
(formatted as an s-expression) and returns the resulting HTML, which is then compiled into Ruby by Temple.
|
|
29
|
+
|
|
30
|
+
Note that this doesn't actually come with a full built-in markup language compiler; rather it only contains a
|
|
31
|
+
compiler for processing Matte macros.
|
|
32
|
+
executables: []
|
|
33
|
+
extensions: []
|
|
34
|
+
extra_rdoc_files: []
|
|
35
|
+
files:
|
|
36
|
+
- README.md
|
|
37
|
+
- lib/matte.rb
|
|
38
|
+
homepage: https://git.disroot.org/acrylic/matte
|
|
39
|
+
licenses:
|
|
40
|
+
- BSD-3-Clause
|
|
41
|
+
metadata: {}
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '3.2'
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubygems_version: 3.6.3
|
|
57
|
+
specification_version: 4
|
|
58
|
+
summary: HTML Macro assembler for Temple
|
|
59
|
+
test_files: []
|