rblade 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3810116e4f41e107ce2a017836d4c16272a59c6abdd3e44430d1012069511a7
4
- data.tar.gz: 40e715cd082834c83b4ccf7eb65ba2a96c4b656974b8ead1c217c05b24298ce4
3
+ metadata.gz: 418e9e009d866abaf770d8fee42675919627c041fdb6753a628710d41875d75d
4
+ data.tar.gz: 4f51870487d92dadbc8fddcd413c26cbcade77cc5bdd16b3be664912c0de70ac
5
5
  SHA512:
6
- metadata.gz: 471317c2ab315af661a02787968e56e8adafad586153cd9a8b7e26d04c61dd86bc183d1538f3e9b63e6d913f25a27f38a54fece06b524df665146e3a598d794b
7
- data.tar.gz: 73cbf2f77bf9eb05b144bfe98b6841d9fbf73b31eb658c8f8a78058cb981b8b599bc13c7008166a59c6636fbc14b5d9dbac9ba5a31dabeab75bb755e1ec4cbf4
6
+ metadata.gz: 99a62b7cd0e707fce89b84cc082daaff2776b32d16b170f502db8b5b42dc2dd89d0c821d78a24ac2ebb0c8ef99442373b5ca2464a726d037b9fded893e625659
7
+ data.tar.gz: bf2d3d6ae6437ecf9a770180ea9cf8d3becd1223375313d3027ce16252d0083cb91b712067bb1a0da7e157e98041c8251edfc043229e1824c85e119640e60427
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.5 [2024-07-23]
2
+ - Improve how @props sets local variables
3
+
4
+ ## 0.2.4 [2024-07-23]
5
+ - Improve merging of classes
6
+
1
7
  ## 0.2.3 [2024-07-23]
2
8
  - Fix attributes in components that have multiple lines
3
9
 
@@ -77,8 +77,7 @@ module RBlade
77
77
  next
78
78
  end
79
79
  if attribute[:type] == "attributes"
80
- attribute_arguments.push "**attributes.to_h"
81
- attribute_assignments.push "_style = attributes[:style];"
80
+ attribute_arguments.push "**(#{attribute[:value]}).to_h"
82
81
 
83
82
  next
84
83
  end
@@ -11,9 +11,9 @@ module RBlade
11
11
  props = extractProps args[0]
12
12
  props.map do |key, value|
13
13
  if value == "_required"
14
- "if !defined?(#{key});raise \"Props statement: #{key} is not defined\";end;"
14
+ "if !defined?(#{key})&&!attributes.has?(:'#{RBlade::escape_quotes(key)}');raise \"Props statement: #{key} is not defined\";end;#{key.sub /[^a-zA-Z0-9_]/, '_'}=attributes.default(:'#{RBlade::escape_quotes(key)}');"
15
15
  else
16
- "if !defined?(#{key});#{key}=#{value};end;"
16
+ "#{key.sub /[^a-zA-Z0-9_]/, '_'}=attributes.default(:'#{RBlade::escape_quotes(key)}',#{value});"
17
17
  end
18
18
  end.join
19
19
  end
@@ -3,10 +3,39 @@ module RBlade
3
3
  @attributes = {}
4
4
  def initialize attributes
5
5
  @attributes = attributes
6
+
7
+ if !@attributes[:_class].nil?
8
+ @attributes[:class] = mergeClasses(@attributes[:class], @attributes.delete(:_class))
9
+ end
10
+ if !@attributes[:_style].nil?
11
+ @attributes[:style] = mergeClasses(@attributes[:style], @attributes.delete(:_style))
12
+ end
13
+
14
+ @attributes
15
+ end
16
+
17
+ def default(key, default = nil)
18
+ if @attributes[key].nil? && !default.nil?
19
+ @attributes[key] = default
20
+ end
21
+
22
+ @attributes[key]
23
+ end
24
+
25
+ def has?(key)
26
+ !@attributes[key].nil?
6
27
  end
7
28
 
8
29
  def to_h
9
- @attributes
30
+ attributes = @attributes.dup
31
+ if !attributes[:class].nil?
32
+ attributes[:_class] = attributes.delete :class
33
+ end
34
+ if !attributes[:style].nil?
35
+ attributes[:_style] = attributes.delete :style
36
+ end
37
+
38
+ attributes
10
39
  end
11
40
 
12
41
  def to_s attributes = nil
@@ -42,18 +71,12 @@ module RBlade
42
71
 
43
72
  @attributes.each do |key, value|
44
73
  if key == :class && !new_attributes[key].nil?
45
- unless new_attributes[key].end_with? " "
46
- new_attributes[key] << " "
47
- end
48
- new_attributes[key] << value.to_s
74
+ new_attributes[key] = mergeClasses(new_attributes[key], value.to_s)
49
75
  next
50
76
  end
51
77
 
52
78
  if key == :style && !new_attributes[key].nil?
53
- unless new_attributes[key].end_with? ";"
54
- new_attributes[key] << ";"
55
- end
56
- new_attributes[key] << value.to_s
79
+ new_attributes[key] = mergeStyles(new_attributes[key], value.to_s)
57
80
  next
58
81
  end
59
82
 
@@ -62,5 +85,41 @@ module RBlade
62
85
 
63
86
  self.class.new new_attributes
64
87
  end
88
+
89
+ private
90
+
91
+ def mergeClasses(classes_1, classes_2)
92
+ if classes_1.nil?
93
+ return classes_2
94
+ end
95
+ if classes_2.nil?
96
+ return classes_1
97
+ end
98
+
99
+ classes_combined = classes_1
100
+ unless classes_combined.end_with? " "
101
+ classes_combined << " "
102
+ end
103
+ classes_combined << classes_2.to_s
104
+
105
+ classes_combined
106
+ end
107
+
108
+ def mergeStyles(styles_1, styles_2)
109
+ if styles_1.nil?
110
+ return styles_2
111
+ end
112
+ if styles_2.nil?
113
+ return styles_1
114
+ end
115
+
116
+ styles_combined = styles_1
117
+ unless styles_combined.end_with? ";"
118
+ styles_combined << ";"
119
+ end
120
+ styles_combined << styles_2.to_s
121
+
122
+ styles_combined
123
+ end
65
124
  end
66
125
  end
data/rblade.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rblade"
3
- s.version = "0.2.3"
3
+ s.version = "0.2.5"
4
4
  s.summary = "Blade templates for ruby"
5
5
  s.description = "A port of the Laravel blade templating engine to ruby"
6
6
  s.authors = ["Simon J"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rblade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon J