theo-rails 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a47ba0ddf03dcfcfb0f712ada5463e4bc2226ce299b818c41f931eaf37337be1
4
- data.tar.gz: c595cc7b8548ccb085f8c11467fe01d611cdd56492bce78097c15d907d2c4e2c
3
+ metadata.gz: 6f522cd4a9045802867fb16443c798ed1cb1da0a07b20dfa00fe4c9b1f58c616
4
+ data.tar.gz: 8373f7e46efb666a7cbd07b15f51dd5001375131b2f8fec3bcdd7adb0957c812
5
5
  SHA512:
6
- metadata.gz: 8086955a23ee2389321b560033282045a56595366299739b3767454e74121c24b2a3bfd50bff46840984d7ca099a8205d80ebb0e0e6ac8536a81ef2e31e28978
7
- data.tar.gz: eccbd592a2d340674a8226d9d77cacabfd47aa99256edd2a6f14350a4408f1ad68efa04215d259244074224713d6282152b53fa42c488ade521ecc59554d2539
6
+ metadata.gz: '081b4756de992bdfc8fd63a17f6c593d639b2c586bd5a3bfc9cc8555757fac559d59f24e81142edd2b55333f07e1f22ef10147c3fc16b6dc1d53e30f427a7fbc'
7
+ data.tar.gz: 7221da0b1ef26ef372d5765a776bc89aa1af725b4595b02814b7832476edc05ee96ddde16d2877f9d8ffb16929f912bb82c7bf9014fc5efa56b4f9af541fc9d7
@@ -0,0 +1,4 @@
1
+ <%# locals: (form: nil, name:, **attributes) -%>
2
+ <% form ||= inject(:form) %>
3
+
4
+ <%= form.check_box name, **attributes %>
@@ -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
- PARTIAL_TAG = /(?<partial>[\w-]+-partial)/
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]).delete_suffix('-partial').underscore
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 = attribute(attributes.delete(: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.1.2
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-07-20 00:00:00.000000000 Z
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
@@ -16,6 +16,7 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - app/views/application/_check_box.html.erb
19
20
  - app/views/application/_email_field.html.erb
20
21
  - app/views/application/_form_with.html.erb
21
22
  - app/views/application/_label.html.erb