motley 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +23 -0
- data/lib/motley.rb +435 -0
- data/lib/motley/schemas/html.rb +89 -0
- data/lib/motley/schemas/mml.rb +49 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a9e0f14a51c85bea7c1ea733a3bfaeb8ef36d872607ec104dfc489a3afa17c65
|
4
|
+
data.tar.gz: ed2a4e82a4fe9c37ea1edaedd19c6de7dac432c6b6f782c3e61bcb3226363bf8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55e052d4e4a47729522c8d4c2cade43933d60ddeedaf46ebf763579790aea8503fa8c3ca18ac592b55548fd0cbfb88cb57c579ddef4f955362ee3e8b3ad17ae2
|
7
|
+
data.tar.gz: c6f6c21682a4568ae163e023f7a72126760c9e2eb0e13c9db44745b318f1ddcf4d4a4fe9e368829cd791a9df6f90213cee539fd0b14aa7027afaeb953e4b1be2
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Motley
|
2
|
+
|
3
|
+
Motley is an HTML generator. It provides its own markup language (MML) that is
|
4
|
+
compiled down to HTML, CSS, and JavaScript.
|
5
|
+
|
6
|
+
Motley is in the early stages of development.
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install motley
|
12
|
+
```
|
13
|
+
|
14
|
+
## Author
|
15
|
+
|
16
|
+
Mike O'Sullivan
|
17
|
+
mike@idocs.com
|
18
|
+
|
19
|
+
## History
|
20
|
+
|
21
|
+
| version | date | notes |
|
22
|
+
|---------|--------------|-------------------------------|
|
23
|
+
| 0.1 | May 9, 2020 | Initial upload. |
|
data/lib/motley.rb
ADDED
@@ -0,0 +1,435 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'classprop'
|
3
|
+
require 'standarderror/plus'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
|
7
|
+
#===============================================================================
|
8
|
+
# Motley
|
9
|
+
#
|
10
|
+
module Motley
|
11
|
+
# version
|
12
|
+
VERSION = '0.1'
|
13
|
+
end
|
14
|
+
#
|
15
|
+
# Motley
|
16
|
+
#===============================================================================
|
17
|
+
|
18
|
+
|
19
|
+
#===============================================================================
|
20
|
+
# Motley::Site
|
21
|
+
#
|
22
|
+
class Motley::Site
|
23
|
+
attr_accessor :root
|
24
|
+
attr_accessor :resources
|
25
|
+
|
26
|
+
#---------------------------------------------------------------------------
|
27
|
+
# initialize
|
28
|
+
#
|
29
|
+
def initialize(root, resources, opts={})
|
30
|
+
@root = root
|
31
|
+
@resources = resources
|
32
|
+
end
|
33
|
+
#
|
34
|
+
# initialize
|
35
|
+
#---------------------------------------------------------------------------
|
36
|
+
end
|
37
|
+
#
|
38
|
+
# Motley::Site
|
39
|
+
#===============================================================================
|
40
|
+
|
41
|
+
|
42
|
+
#===============================================================================
|
43
|
+
# Motley::AttSet
|
44
|
+
#
|
45
|
+
class Motley::AttSet
|
46
|
+
extend Forwardable
|
47
|
+
attr_reader :dfns
|
48
|
+
attr_reader :vals
|
49
|
+
|
50
|
+
# delegate
|
51
|
+
delegate %w([] each length clear delete keys values) => :vals
|
52
|
+
|
53
|
+
|
54
|
+
#---------------------------------------------------------------------------
|
55
|
+
# initialize
|
56
|
+
#
|
57
|
+
def initialize(dfns)
|
58
|
+
@dfns = dfns
|
59
|
+
@vals = {}
|
60
|
+
end
|
61
|
+
#
|
62
|
+
# initialize
|
63
|
+
#---------------------------------------------------------------------------
|
64
|
+
|
65
|
+
|
66
|
+
#---------------------------------------------------------------------------
|
67
|
+
# []=
|
68
|
+
#
|
69
|
+
def []=(key, val)
|
70
|
+
# $tm.hrm
|
71
|
+
|
72
|
+
# normalize key
|
73
|
+
key = key.downcase
|
74
|
+
|
75
|
+
# get att definition
|
76
|
+
dfn = @dfns[key]
|
77
|
+
|
78
|
+
# if no definition
|
79
|
+
if not dfn
|
80
|
+
exc = StandardError::Plus.new('/zax/attset/no-att-definition')
|
81
|
+
exc['att'] = key
|
82
|
+
raise exc
|
83
|
+
end
|
84
|
+
|
85
|
+
# XML and HTML do not have the concept of null, so if nil is assigned,
|
86
|
+
# we delete the hash element. Else we set the value
|
87
|
+
if val.nil?
|
88
|
+
@vals.delete(key)
|
89
|
+
else
|
90
|
+
@vals[key] = dfn.set(val)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
#
|
94
|
+
# []=
|
95
|
+
#---------------------------------------------------------------------------
|
96
|
+
end
|
97
|
+
#
|
98
|
+
# Motley::AttSet
|
99
|
+
#===============================================================================
|
100
|
+
|
101
|
+
|
102
|
+
#===============================================================================
|
103
|
+
# Motley::AttDef
|
104
|
+
#
|
105
|
+
class Motley::AttDef
|
106
|
+
attr_accessor :set_once
|
107
|
+
|
108
|
+
#---------------------------------------------------------------------------
|
109
|
+
# initialize
|
110
|
+
#
|
111
|
+
def initialize
|
112
|
+
@set_once = false
|
113
|
+
end
|
114
|
+
#
|
115
|
+
# initialize
|
116
|
+
#---------------------------------------------------------------------------
|
117
|
+
|
118
|
+
|
119
|
+
#---------------------------------------------------------------------------
|
120
|
+
# to_str
|
121
|
+
#
|
122
|
+
def to_str
|
123
|
+
raise 'zax/attdef/default/override-to-s'
|
124
|
+
end
|
125
|
+
#
|
126
|
+
# to_str
|
127
|
+
#---------------------------------------------------------------------------
|
128
|
+
end
|
129
|
+
#
|
130
|
+
# Motley::AttDef
|
131
|
+
#===============================================================================
|
132
|
+
|
133
|
+
|
134
|
+
#===============================================================================
|
135
|
+
# Motley::AttDef::Scalar
|
136
|
+
#
|
137
|
+
class Motley::AttDef::Scalar < Motley::AttDef
|
138
|
+
ALLOWED = [String, Integer, Float, TrueClass, FalseClass]
|
139
|
+
|
140
|
+
|
141
|
+
#---------------------------------------------------------------------------
|
142
|
+
# set
|
143
|
+
#
|
144
|
+
def set(val)
|
145
|
+
allowed_class(val)
|
146
|
+
return val
|
147
|
+
end
|
148
|
+
#
|
149
|
+
# set
|
150
|
+
#---------------------------------------------------------------------------
|
151
|
+
|
152
|
+
|
153
|
+
#---------------------------------------------------------------------------
|
154
|
+
# allowed_class
|
155
|
+
#
|
156
|
+
def allowed_class(val)
|
157
|
+
# loop through allowed classes
|
158
|
+
ALLOWED.each do |allowed|
|
159
|
+
if val.is_a?(allowed)
|
160
|
+
return true
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# raise exception
|
165
|
+
raise 'zax/attdef/scalar/allowed-class: ' + ALLOWED.to_s
|
166
|
+
end
|
167
|
+
#
|
168
|
+
# allowed_class
|
169
|
+
#---------------------------------------------------------------------------
|
170
|
+
|
171
|
+
|
172
|
+
#---------------------------------------------------------------------------
|
173
|
+
# to_str
|
174
|
+
#
|
175
|
+
def to_str(val)
|
176
|
+
return val.to_s
|
177
|
+
end
|
178
|
+
#
|
179
|
+
# to_str
|
180
|
+
#---------------------------------------------------------------------------
|
181
|
+
end
|
182
|
+
#
|
183
|
+
# Motley::AttDef::Scalar
|
184
|
+
#===============================================================================
|
185
|
+
|
186
|
+
|
187
|
+
#===============================================================================
|
188
|
+
# Motley::AttDef::URI
|
189
|
+
#
|
190
|
+
class Motley::AttDef::URI < Motley::AttDef
|
191
|
+
#---------------------------------------------------------------------------
|
192
|
+
# set
|
193
|
+
#
|
194
|
+
def set(val)
|
195
|
+
return URI(val)
|
196
|
+
end
|
197
|
+
#
|
198
|
+
# set
|
199
|
+
#---------------------------------------------------------------------------
|
200
|
+
|
201
|
+
|
202
|
+
#---------------------------------------------------------------------------
|
203
|
+
# to_str
|
204
|
+
#
|
205
|
+
def to_str(val)
|
206
|
+
return val.to_s
|
207
|
+
end
|
208
|
+
#
|
209
|
+
# to_str
|
210
|
+
#---------------------------------------------------------------------------
|
211
|
+
end
|
212
|
+
#
|
213
|
+
# Motley::AttDef::URI
|
214
|
+
#===============================================================================
|
215
|
+
|
216
|
+
|
217
|
+
#===============================================================================
|
218
|
+
# Motley::TagBase
|
219
|
+
#
|
220
|
+
class Motley::TagBase
|
221
|
+
attr_reader :atts
|
222
|
+
include ClassProp
|
223
|
+
define_class_prop 'att_defs', 'inherit'=>false
|
224
|
+
|
225
|
+
#---------------------------------------------------------------------------
|
226
|
+
# initialize
|
227
|
+
#
|
228
|
+
def initialize
|
229
|
+
@atts = Motley::AttSet.new(self.class.att_defs)
|
230
|
+
end
|
231
|
+
#
|
232
|
+
# initialize
|
233
|
+
#---------------------------------------------------------------------------
|
234
|
+
end
|
235
|
+
#
|
236
|
+
# Motley::TagBase
|
237
|
+
#===============================================================================
|
238
|
+
|
239
|
+
|
240
|
+
#===============================================================================
|
241
|
+
# Motley::Tag
|
242
|
+
#
|
243
|
+
class Motley::Tag < Motley::TagBase
|
244
|
+
attr_reader :children
|
245
|
+
|
246
|
+
# delegate
|
247
|
+
extend Forwardable
|
248
|
+
delegate %w([] []= each length keys values) => :atts
|
249
|
+
|
250
|
+
#---------------------------------------------------------------------------
|
251
|
+
# initialize
|
252
|
+
#
|
253
|
+
def initialize
|
254
|
+
# $tm.hrm
|
255
|
+
super()
|
256
|
+
@atts = Motley::AttSet.new(self.class.att_defs)
|
257
|
+
@children = []
|
258
|
+
end
|
259
|
+
#
|
260
|
+
# initialize
|
261
|
+
#---------------------------------------------------------------------------
|
262
|
+
|
263
|
+
|
264
|
+
#---------------------------------------------------------------------------
|
265
|
+
# set_atts
|
266
|
+
#
|
267
|
+
def self.set_atts
|
268
|
+
# initialize hash
|
269
|
+
if not self.att_defs
|
270
|
+
ads = self.att_defs = {}
|
271
|
+
ads['id'] = Motley::AttDef::Scalar.new
|
272
|
+
end
|
273
|
+
|
274
|
+
# yield
|
275
|
+
if block_given?
|
276
|
+
yield self.att_defs
|
277
|
+
end
|
278
|
+
end
|
279
|
+
#
|
280
|
+
# set_atts
|
281
|
+
#---------------------------------------------------------------------------
|
282
|
+
end
|
283
|
+
#
|
284
|
+
# Motley::Tag
|
285
|
+
#===============================================================================
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
#===============================================================================
|
290
|
+
# Motley::Tag::Nested
|
291
|
+
#
|
292
|
+
class Motley::Tag::Nested < Motley::Tag
|
293
|
+
attr_accessor :parent
|
294
|
+
|
295
|
+
#---------------------------------------------------------------------------
|
296
|
+
# initialize
|
297
|
+
#
|
298
|
+
def initialize(parent=nil)
|
299
|
+
super()
|
300
|
+
@parent = parent
|
301
|
+
end
|
302
|
+
#
|
303
|
+
# initialize
|
304
|
+
#---------------------------------------------------------------------------
|
305
|
+
end
|
306
|
+
#
|
307
|
+
# Motley::Tag::Nested
|
308
|
+
#===============================================================================
|
309
|
+
|
310
|
+
|
311
|
+
#===============================================================================
|
312
|
+
# Motley::Document
|
313
|
+
#
|
314
|
+
class Motley::Document
|
315
|
+
attr_reader :root
|
316
|
+
|
317
|
+
#---------------------------------------------------------------------------
|
318
|
+
# initialize
|
319
|
+
#
|
320
|
+
def initialize(opts={})
|
321
|
+
# root
|
322
|
+
@root = Motley::Tag::HTML.new(self)
|
323
|
+
end
|
324
|
+
#
|
325
|
+
# initialize
|
326
|
+
#---------------------------------------------------------------------------
|
327
|
+
end
|
328
|
+
#
|
329
|
+
# Motley::Document
|
330
|
+
#===============================================================================
|
331
|
+
|
332
|
+
|
333
|
+
#===============================================================================
|
334
|
+
# Motley::Schema
|
335
|
+
#
|
336
|
+
class Motley::Schema
|
337
|
+
attr_reader :tags
|
338
|
+
|
339
|
+
#---------------------------------------------------------------------------
|
340
|
+
# initialize
|
341
|
+
#
|
342
|
+
def initialize()
|
343
|
+
@tags = {}
|
344
|
+
end
|
345
|
+
#
|
346
|
+
# initialize
|
347
|
+
#---------------------------------------------------------------------------
|
348
|
+
end
|
349
|
+
#
|
350
|
+
# Motley::Schema
|
351
|
+
#===============================================================================
|
352
|
+
|
353
|
+
|
354
|
+
#===============================================================================
|
355
|
+
# Motley::Schema
|
356
|
+
#===============================================================================
|
357
|
+
|
358
|
+
|
359
|
+
#===============================================================================
|
360
|
+
# Motley::SchemaSet
|
361
|
+
#
|
362
|
+
class Motley::SchemaSet
|
363
|
+
attr_reader :schemas
|
364
|
+
attr_reader :tags
|
365
|
+
|
366
|
+
# delegate
|
367
|
+
extend Forwardable
|
368
|
+
delegate %w([] []= each push pop shift unshift length) => :schemas
|
369
|
+
|
370
|
+
|
371
|
+
#---------------------------------------------------------------------------
|
372
|
+
# initialize
|
373
|
+
#
|
374
|
+
def initialize
|
375
|
+
@schemas = []
|
376
|
+
@tags = Motley::SchemaSet::TagFinder.new(self)
|
377
|
+
end
|
378
|
+
#
|
379
|
+
# initialize
|
380
|
+
#---------------------------------------------------------------------------
|
381
|
+
end
|
382
|
+
#
|
383
|
+
# Motley::SchemaSet
|
384
|
+
#===============================================================================
|
385
|
+
|
386
|
+
|
387
|
+
#===============================================================================
|
388
|
+
# Motley::SchemaSet::TagFinder
|
389
|
+
#
|
390
|
+
class Motley::SchemaSet::TagFinder
|
391
|
+
attr_reader :schemaset
|
392
|
+
|
393
|
+
|
394
|
+
#---------------------------------------------------------------------------
|
395
|
+
# initialize
|
396
|
+
#
|
397
|
+
def initialize(schemaset)
|
398
|
+
@schemaset = schemaset
|
399
|
+
end
|
400
|
+
#
|
401
|
+
# initialize
|
402
|
+
#---------------------------------------------------------------------------
|
403
|
+
|
404
|
+
|
405
|
+
#---------------------------------------------------------------------------
|
406
|
+
# []
|
407
|
+
#
|
408
|
+
def [](key)
|
409
|
+
# $tm.hrm
|
410
|
+
|
411
|
+
# normalize key
|
412
|
+
key = key.downcase
|
413
|
+
|
414
|
+
# loop through schemas looking for tag
|
415
|
+
@schemaset.each do |schema|
|
416
|
+
if tag = schema.tags[key]
|
417
|
+
return tag
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
# didn't find the tag
|
422
|
+
return nil
|
423
|
+
end
|
424
|
+
#
|
425
|
+
# []
|
426
|
+
#---------------------------------------------------------------------------
|
427
|
+
end
|
428
|
+
#
|
429
|
+
# Motley::SchemaSet::TagFinder
|
430
|
+
#===============================================================================
|
431
|
+
|
432
|
+
|
433
|
+
# html
|
434
|
+
require 'motley/schemas/html'
|
435
|
+
require 'motley/schemas/mml'
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#===============================================================================
|
2
|
+
# Motley::Schema::HTML
|
3
|
+
#
|
4
|
+
class Motley::Schema::HTML < Motley::Schema
|
5
|
+
#---------------------------------------------------------------------------
|
6
|
+
# initialize
|
7
|
+
#
|
8
|
+
def initialize()
|
9
|
+
super()
|
10
|
+
|
11
|
+
# tags
|
12
|
+
@tags['html'] = Motley::HTML::HTML
|
13
|
+
@tags['a'] = Motley::HTML::A
|
14
|
+
end
|
15
|
+
#
|
16
|
+
# initialize
|
17
|
+
#---------------------------------------------------------------------------
|
18
|
+
end
|
19
|
+
#
|
20
|
+
# Motley::Schema::HTML
|
21
|
+
#===============================================================================
|
22
|
+
|
23
|
+
|
24
|
+
#===============================================================================
|
25
|
+
# Motley::HTML
|
26
|
+
#
|
27
|
+
module Motley::HTML
|
28
|
+
end
|
29
|
+
#
|
30
|
+
# Motley::HTML
|
31
|
+
#===============================================================================
|
32
|
+
|
33
|
+
|
34
|
+
#===============================================================================
|
35
|
+
# Motley::HTML::HTML
|
36
|
+
#
|
37
|
+
class Motley::HTML::HTML < Motley::Tag
|
38
|
+
attr_accessor :document
|
39
|
+
|
40
|
+
# name
|
41
|
+
def name; 'html'; end;
|
42
|
+
|
43
|
+
#---------------------------------------------------------------------------
|
44
|
+
# initialize
|
45
|
+
#
|
46
|
+
def initialize(document=nil)
|
47
|
+
super()
|
48
|
+
@document = document
|
49
|
+
end
|
50
|
+
#
|
51
|
+
# initialize
|
52
|
+
#---------------------------------------------------------------------------
|
53
|
+
|
54
|
+
|
55
|
+
#---------------------------------------------------------------------------
|
56
|
+
# set_atts
|
57
|
+
# <html> does not have any attributes beside id
|
58
|
+
#
|
59
|
+
self.set_atts
|
60
|
+
#
|
61
|
+
# set_atts
|
62
|
+
#---------------------------------------------------------------------------
|
63
|
+
end
|
64
|
+
#
|
65
|
+
# Motley::HTML::HTML
|
66
|
+
#===============================================================================
|
67
|
+
|
68
|
+
|
69
|
+
#===============================================================================
|
70
|
+
# Motley::HTML::A
|
71
|
+
#
|
72
|
+
class Motley::HTML::A < Motley::Tag::Nested
|
73
|
+
# name
|
74
|
+
def name; 'a'; end;
|
75
|
+
|
76
|
+
#---------------------------------------------------------------------------
|
77
|
+
# set_atts
|
78
|
+
#
|
79
|
+
self.set_atts do |defs|
|
80
|
+
defs['title'] = Motley::AttDef::Scalar.new
|
81
|
+
defs['href'] = Motley::AttDef::URI.new
|
82
|
+
end
|
83
|
+
#
|
84
|
+
# set_atts
|
85
|
+
#---------------------------------------------------------------------------
|
86
|
+
end
|
87
|
+
#
|
88
|
+
# Motley::HTML::A
|
89
|
+
#===============================================================================
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#===============================================================================
|
2
|
+
# Motley::Schema::MML
|
3
|
+
#
|
4
|
+
class Motley::Schema::MML < Motley::Schema
|
5
|
+
#---------------------------------------------------------------------------
|
6
|
+
# initialize
|
7
|
+
#
|
8
|
+
def initialize()
|
9
|
+
super()
|
10
|
+
|
11
|
+
# tags
|
12
|
+
@tags['a'] = Motley::MML::A
|
13
|
+
end
|
14
|
+
#
|
15
|
+
# initialize
|
16
|
+
#---------------------------------------------------------------------------
|
17
|
+
end
|
18
|
+
#
|
19
|
+
# Motley::Schema::HTML
|
20
|
+
#===============================================================================
|
21
|
+
|
22
|
+
|
23
|
+
#===============================================================================
|
24
|
+
# Motley::MML
|
25
|
+
#
|
26
|
+
module Motley::MML
|
27
|
+
end
|
28
|
+
#
|
29
|
+
# Motley::MML
|
30
|
+
#===============================================================================
|
31
|
+
|
32
|
+
|
33
|
+
#===============================================================================
|
34
|
+
# Motley::MML::A
|
35
|
+
#
|
36
|
+
class Motley::MML::A < Motley::Tag::Nested
|
37
|
+
#---------------------------------------------------------------------------
|
38
|
+
# set_atts
|
39
|
+
#
|
40
|
+
self.set_atts do |defs|
|
41
|
+
defs['aux'] = Motley::AttDef::Scalar.new
|
42
|
+
end
|
43
|
+
#
|
44
|
+
# set_atts
|
45
|
+
#---------------------------------------------------------------------------
|
46
|
+
end
|
47
|
+
#
|
48
|
+
# Motley::MML::A
|
49
|
+
#===============================================================================
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motley
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike O'Sullivan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A markup language that compiles to HTML, CSS, and JavaScript
|
14
|
+
email: mike@idocs.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/motley.rb
|
21
|
+
- lib/motley/schemas/html.rb
|
22
|
+
- lib/motley/schemas/mml.rb
|
23
|
+
homepage: https://rubygems.org/gems/motley
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.7.6
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: HTML superset
|
47
|
+
test_files: []
|