rblade 0.2.3 → 0.2.4

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: 89abc20ace497e0f051bb38ed620c44bf4bc7067cfeb20d7d7af9f13b98337ae
4
+ data.tar.gz: '0971c951b39f2cf94833a1d3d55eb3c561666995049d7d6f4fff553837615676'
5
5
  SHA512:
6
- metadata.gz: 471317c2ab315af661a02787968e56e8adafad586153cd9a8b7e26d04c61dd86bc183d1538f3e9b63e6d913f25a27f38a54fece06b524df665146e3a598d794b
7
- data.tar.gz: 73cbf2f77bf9eb05b144bfe98b6841d9fbf73b31eb658c8f8a78058cb981b8b599bc13c7008166a59c6636fbc14b5d9dbac9ba5a31dabeab75bb755e1ec4cbf4
6
+ metadata.gz: 73f515630bcfc90ea39862b6014d4b4a4afb4b29b33a09ae8ac58e8ead98786e26be03c4e63d5711c82a6728afd37e02549b56417bf5833d833d8f7ee473ed34
7
+ data.tar.gz: 8965f3fe015315e49c3dfe5b31b8aa949f0f609ffd7664a87ab875ca9a2f0cf494ac0a2236896479dfe007e2ebe45e5acdafbdb9d6384197acc9390383f7365e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.2.4 [2024-07-23]
2
+ - Improve merging of classes
3
+
1
4
  ## 0.2.3 [2024-07-23]
2
5
  - Fix attributes in components that have multiple lines
3
6
 
@@ -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
@@ -3,10 +3,27 @@ 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.freeze
6
15
  end
7
16
 
8
17
  def to_h
9
- @attributes
18
+ attributes = @attributes.dup
19
+ if !attributes[:class].nil?
20
+ attributes[:_class] = attributes.delete :class
21
+ end
22
+ if !attributes[:style].nil?
23
+ attributes[:_style] = attributes.delete :style
24
+ end
25
+
26
+ attributes
10
27
  end
11
28
 
12
29
  def to_s attributes = nil
@@ -42,18 +59,12 @@ module RBlade
42
59
 
43
60
  @attributes.each do |key, value|
44
61
  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
62
+ new_attributes[key] = mergeClasses(new_attributes[key], value.to_s)
49
63
  next
50
64
  end
51
65
 
52
66
  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
67
+ new_attributes[key] = mergeStyles(new_attributes[key], value.to_s)
57
68
  next
58
69
  end
59
70
 
@@ -62,5 +73,41 @@ module RBlade
62
73
 
63
74
  self.class.new new_attributes
64
75
  end
76
+
77
+ private
78
+
79
+ def mergeClasses(classes_1, classes_2)
80
+ if classes_1.nil?
81
+ return classes_2
82
+ end
83
+ if classes_2.nil?
84
+ return classes_1
85
+ end
86
+
87
+ classes_combined = classes_1
88
+ unless classes_combined.end_with? " "
89
+ classes_combined << " "
90
+ end
91
+ classes_combined << classes_2.to_s
92
+
93
+ classes_combined
94
+ end
95
+
96
+ def mergeStyles(styles_1, styles_2)
97
+ if styles_1.nil?
98
+ return styles_2
99
+ end
100
+ if styles_2.nil?
101
+ return styles_1
102
+ end
103
+
104
+ styles_combined = styles_1
105
+ unless styles_combined.end_with? ";"
106
+ styles_combined << ";"
107
+ end
108
+ styles_combined << styles_2.to_s
109
+
110
+ styles_combined
111
+ end
65
112
  end
66
113
  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.4"
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon J