theo-rails 0.3.0 → 0.3.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/theo-rails/theo.rb +14 -4
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a08de40e9205127777dc501ee41131f7c56b5d49ce3d793171a4f5fee114c087
4
- data.tar.gz: 7285c684000a300aefd5c71b9b287656153303fb7eea410a4d59af474e21d494
3
+ metadata.gz: f2b210d661f6fd028694497e83aa3b205c5fd89a6d3136fbc1faca2f4e4ddb29
4
+ data.tar.gz: 734ea63e9962dac3a87a207b0cb82d165c0f4d54a6d791b5398c46dfda15cbc4
5
5
  SHA512:
6
- metadata.gz: b5e8ae5ee062f9891934034acaf20e6d652162acdb08c587a2330989b6b10a7fd19a674dbc4ad13a4ce7e370300f3b6cc18de1d990bb6d8ab452855ae4563108
7
- data.tar.gz: aa2cee291cfc7ec96588b068cd52645e0502c53d87bec1f3c69d6e83e74879aede4aa47ef0b25c69219171a669d4ad6bcff430e3fef7de26efb6b9906c00de07
6
+ metadata.gz: 85d866b6839ed5736b50dd5026b65e925f9dae25de88e24d47a9856e7454820fa9f7e8e855a022534ee636c2dfbc0b78584eb16f31543d97e327c1ff14a63b92
7
+ data.tar.gz: 0b21d4fddb3b4a3618117d23fc2e846881ffc2f7e2b5667187ff33d220cea790ea18c6728a7d2167e228cfea83bed0d7dcab86210eb9cfbf4365ab25a2c8692d
@@ -1,9 +1,10 @@
1
1
  module Theo
2
2
  module Rails
3
- ATTRIBUTE_NAME = /[\w\-:@]+/
3
+ ATTRIBUTE_NAME = /(?<name>[a-z][\w\-:@]*)/
4
4
  ATTRIBUTE_VALUE = /(?:(?:"(?<value>[^"]*)")|(?:'(?<value>[^']*)'))/
5
- ATTRIBUTE = /(?:(?:(?<name>#{ATTRIBUTE_NAME.source})\s*=\s*#{ATTRIBUTE_VALUE.source})|(?<name>#{ATTRIBUTE_NAME.source}))/
6
- DYNAMIC_ATTRIBUTE = /(?:(?<name>#{ATTRIBUTE_NAME.source})\s*%=\s*#{ATTRIBUTE_VALUE.source})/
5
+ ATTRIBUTE = /(?:(?:#{ATTRIBUTE_NAME.source}\s*=\s*#{ATTRIBUTE_VALUE.source})|#{ATTRIBUTE_NAME.source})/
6
+ DYNAMIC_ATTRIBUTE = /(?:(?:#{ATTRIBUTE_NAME.source}\s*%=\s*#{ATTRIBUTE_VALUE.source})|(?:#{ATTRIBUTE_NAME.source}%))/
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
7
8
  ATTRIBUTES = /(?<attrs>(?:\s+#{ATTRIBUTE.source})*)/
8
9
  LITERAL_ATTRIBUTES = %i[path as yields collection].freeze
9
10
  PARTIAL_TAG = /(?<partial>_\w+)/
@@ -16,7 +17,16 @@ module Theo
16
17
  class Theo
17
18
  def process(source)
18
19
  # Attributes
19
- source = source.gsub(DYNAMIC_ATTRIBUTE, '\k<name>="<%= \k<value> %>"')
20
+ source = source.gsub(DYNAMIC_ATTRIBUTE) do |_|
21
+ match = Regexp.last_match
22
+
23
+ name = match[:name]
24
+
25
+ # See https://island94.org/2024/06/rails-strict-locals-local_assigns-and-reserved-keywords for more info
26
+ value = match[:value] || (RESERVED_ATTRIBUTE_NAME.include?(name) ? "binding.local_variable_get('#{name}')" : name)
27
+
28
+ "#{name}=\"<%= #{value} %>\""
29
+ end
20
30
 
21
31
  # Partials
22
32
  source.gsub(TEMPLATE) do |_|
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theo-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
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-09-28 00:00:00.000000000 Z
11
+ date: 2024-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3'
27
27
  description: HTML-like template language for Rails with natural partial syntax
28
28
  email: jarek@jareklipski.com
29
29
  executables: []