theo-rails 0.4.8 → 0.4.10

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: 5a401291f906304981468d40dce7137ceebdc0342631ff1424cae4c6b6db8312
4
- data.tar.gz: ae1852a3117b671fe5b89afd7ed533db4b02b04ef05a291c040116f13c78199e
3
+ metadata.gz: 325afc2480b7d874e0c16a991ce5764bd74d114aa2296dce19ad536965a06a2f
4
+ data.tar.gz: 9282ab1407aa342bad6789b92e47041db23cc2833d8b4be2eada142ae3761ea2
5
5
  SHA512:
6
- metadata.gz: 97b3dedf124cd25ef17cff1368e754a43c9ac6829eb459ca4a601716e0e7c9cf1226a6743dec34cc760c8c62078e938f429560b68ca559520ba0095ede37c912
7
- data.tar.gz: 0006e7e118e3d963ed79c9811911ea6e80dd9f9ad9d66313fd0afcba4994a90d035afadb36573374673f2a4fbbaa3e3f5ee8b46fb4242cb4d58c8ee31cd7458c
6
+ metadata.gz: 0d3df600392370eeff52f2ddca2b3a9bdc52ef39045e652da28639eea9e3668da38e1d7d16ae616c93ff31811c9f582578500c07ac2e1340c0e19f1bdd307a9e
7
+ data.tar.gz: 3388d724991ef2872aff7c603f37a1dbd9979bf12c2f13f4aa24a23dbc18d89264d2263e5043d56a14bf782d17b07c82cb03055a48faac2de7bce74980408fd8
@@ -1,3 +1,3 @@
1
1
  <%# locals: (src:, **attributes) -%>
2
2
 
3
- <%= image_tag(src), **attributes %>
3
+ <%= image_tag src, **attributes %>
@@ -5,8 +5,12 @@ module Theo
5
5
  ATTRIBUTE = /(?:(?:#{ATTRIBUTE_NAME.source}\s*=\s*#{ATTRIBUTE_VALUE.source})|#{ATTRIBUTE_NAME.source})/
6
6
  DYNAMIC_ATTRIBUTE = /(?:(?:#{ATTRIBUTE_NAME.source}\s*%=\s*#{ATTRIBUTE_VALUE.source})|(?:#{ATTRIBUTE_NAME.source}%))/
7
7
  RESERVED_ATTRIBUTE_NAME = %w[alias and begin break case class def do else elsif end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield].to_set
8
+ CLASS_ATTRIBUTE=/(?:\s+class\s*=\s*#{ATTRIBUTE_VALUE.source})/
9
+ STYLE_ATTRIBUTE=/(?:\s+style\s*=\s*#{ATTRIBUTE_VALUE.source})/
8
10
  ATTRIBUTES = /(?<attrs>(?:\s+#{ATTRIBUTE.source})*)/
11
+ ATTRIBUTES_INCLUDING_DYNAMIC = /(?<attrs>(?:\s+#{ATTRIBUTE.source}|#{DYNAMIC_ATTRIBUTE.source})*)/
9
12
  LITERAL_ATTRIBUTES = %i[path as yields collection].freeze
13
+ TAG_WITH_DYNAMIC_ATTRIBUTE = /(?:<\w+#{ATTRIBUTES_INCLUDING_DYNAMIC.source}\s+#{DYNAMIC_ATTRIBUTE.source}#{ATTRIBUTES_INCLUDING_DYNAMIC.source}\s*\/?>)/m
10
14
  PARTIAL_TAG = /(?:(?<partial>[A-Z]\w+)|(?<partial>_[\w-]+))/
11
15
  PARTIAL = /(?:<#{PARTIAL_TAG.source}#{ATTRIBUTES.source}\s*>(?<content>.*?)<\/\k<partial>>)|(?:<#{PARTIAL_TAG.source}#{ATTRIBUTES.source}\s*\/>)/m
12
16
  DYNAMIC_EXPRESSION = /^<%=([^%]*)%>$/
@@ -14,15 +18,45 @@ module Theo
14
18
  class Theo
15
19
  def process(source)
16
20
  # Attributes
17
- source = source.gsub(DYNAMIC_ATTRIBUTE) do |_|
21
+ source = source.gsub(TAG_WITH_DYNAMIC_ATTRIBUTE) do |_|
18
22
  match = Regexp.last_match
19
23
 
20
- name = match[:name]
24
+ tag = match[0]
21
25
 
22
- # See https://island94.org/2024/06/rails-strict-locals-local_assigns-and-reserved-keywords for more info
23
- value = match[:value] || (RESERVED_ATTRIBUTE_NAME.include?(name) ? "binding.local_variable_get('#{name}')" : name)
26
+ remove_attributes = []
24
27
 
25
- "#{name}=\"<%= #{value} %>\""
28
+ tag = tag.gsub(DYNAMIC_ATTRIBUTE) do |_|
29
+ match = Regexp.last_match
30
+
31
+ name = match[:name]
32
+
33
+ # See https://island94.org/2024/06/rails-strict-locals-local_assigns-and-reserved-keywords for more info
34
+ value = match[:value] || (RESERVED_ATTRIBUTE_NAME.include?(name) ? "binding.local_variable_get('#{name}')" : name)
35
+
36
+ if name == 'class'
37
+ class_attribute = CLASS_ATTRIBUTE.match(tag)
38
+
39
+ if class_attribute
40
+ remove_attributes += [class_attribute[0]]
41
+ next "#{name}=\"<%= (#{value}).to_s + ' #{class_attribute[:value]}' %>\""
42
+ end
43
+ end
44
+
45
+ if name == 'style'
46
+ style_attribute = STYLE_ATTRIBUTE.match(tag)
47
+
48
+ if style_attribute
49
+ remove_attributes += [style_attribute[0]]
50
+ next "#{name}=\"<%= (#{value}).to_s + '; #{style_attribute[:value]}' %>\""
51
+ end
52
+ end
53
+
54
+ "#{name}=\"<%= #{value} %>\""
55
+ end
56
+
57
+ remove_attributes.each { |remove_attribute| tag = tag.sub(remove_attribute, '') }
58
+
59
+ tag
26
60
  end
27
61
 
28
62
  # Partials
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.8
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarek Lipski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-22 00:00:00.000000000 Z
11
+ date: 2025-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport