theo-rails 0.1.3 → 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.
- checksums.yaml +4 -4
- data/lib/theo-rails/theo.rb +18 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f522cd4a9045802867fb16443c798ed1cb1da0a07b20dfa00fe4c9b1f58c616
|
4
|
+
data.tar.gz: 8373f7e46efb666a7cbd07b15f51dd5001375131b2f8fec3bcdd7adb0957c812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '081b4756de992bdfc8fd63a17f6c593d639b2c586bd5a3bfc9cc8555757fac559d59f24e81142edd2b55333f07e1f22ef10147c3fc16b6dc1d53e30f427a7fbc'
|
7
|
+
data.tar.gz: 7221da0b1ef26ef372d5765a776bc89aa1af725b4595b02814b7832476edc05ee96ddde16d2877f9d8ffb16929f912bb82c7bf9014fc5efa56b4f9af541fc9d7
|
data/lib/theo-rails/theo.rb
CHANGED
@@ -5,7 +5,8 @@ module Theo
|
|
5
5
|
ATTRIBUTE = /(?:(?:(?<name>#{ATTRIBUTE_NAME.source})\s*=\s*#{ATTRIBUTE_VALUE.source})|(?<name>#{ATTRIBUTE_NAME.source}))/
|
6
6
|
DYNAMIC_ATTRIBUTE = /(?:(?<name>#{ATTRIBUTE_NAME.source})\s*%=\s*#{ATTRIBUTE_VALUE.source})/
|
7
7
|
ATTRIBUTES = /(?<attrs>(?:\s+#{ATTRIBUTE.source})*)/
|
8
|
-
|
8
|
+
LITERAL_ATTRIBUTES = %i[path as yields].freeze
|
9
|
+
PARTIAL_TAG = /(?<partial>_[\w-]+)/
|
9
10
|
PARTIAL = /(?:<#{PARTIAL_TAG.source}#{ATTRIBUTES.source}\s*>(?<content>.*?)<\/\k<partial>>)|(?:<#{PARTIAL_TAG.source}#{ATTRIBUTES.source}\s*\/>)/im
|
10
11
|
DYNAMIC_EXPRESSION = /^<%=([^%]*)%>$/
|
11
12
|
|
@@ -17,22 +18,17 @@ module Theo
|
|
17
18
|
# Partials
|
18
19
|
source.gsub(PARTIAL) do |_|
|
19
20
|
match = Regexp.last_match
|
20
|
-
partial = (match[:partial]).
|
21
|
+
partial = (match[:partial]).delete_prefix('_')
|
21
22
|
attributes = match[:attrs] || ''
|
22
23
|
content = match[:content]&.strip
|
23
24
|
|
24
|
-
attributes =
|
25
|
-
attributes
|
26
|
-
.gsub(ATTRIBUTE)
|
27
|
-
.map { Regexp.last_match }
|
28
|
-
.map { |attr| [attr[:name].to_sym, attr[:value] || ''] }
|
29
|
-
.to_h
|
25
|
+
attributes = process_attributes(attributes)
|
30
26
|
|
31
27
|
partial = "#{attributes.delete(:path)}/#{partial}" if attributes[:path]
|
32
28
|
|
33
29
|
collection = ''
|
34
30
|
if attributes[:collection]
|
35
|
-
collection =
|
31
|
+
collection = attributes.delete(:collection)
|
36
32
|
|
37
33
|
as = ''
|
38
34
|
if attributes[:as]
|
@@ -44,8 +40,6 @@ module Theo
|
|
44
40
|
|
45
41
|
yields = "|#{attributes.delete(:yields)}|" if attributes[:yields]
|
46
42
|
|
47
|
-
attributes.transform_values! { |value| attribute(value) }
|
48
|
-
|
49
43
|
if content
|
50
44
|
output = "<%= render '#{partial}', {#{attributes.map {|k,v| "'#{k}': #{v}"}.join(', ')}} do #{yields || ''} %>#{process(content)}<% end %>"
|
51
45
|
else
|
@@ -56,6 +50,19 @@ module Theo
|
|
56
50
|
end
|
57
51
|
end
|
58
52
|
|
53
|
+
def process_attributes(attributes)
|
54
|
+
attributes
|
55
|
+
.gsub(ATTRIBUTE)
|
56
|
+
.map { Regexp.last_match }
|
57
|
+
.map do |attr|
|
58
|
+
name = attr[:name].to_sym
|
59
|
+
value = attr[:value]
|
60
|
+
value = attribute(value) if LITERAL_ATTRIBUTES.exclude?(name)
|
61
|
+
[name, value]
|
62
|
+
end
|
63
|
+
.to_h
|
64
|
+
end
|
65
|
+
|
59
66
|
def attribute(source)
|
60
67
|
# TODO: support attributes like "a<%= b %>c
|
61
68
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: theo-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarek Lipski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: HTML-like template language for Rails with natural partial syntax
|
14
14
|
email: jarek@jareklipski.com
|