rblade 0.2.2 → 0.2.4

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: aef0eb02d400c2a6af0c114d0952d9871cb83866fa6fbdf43d72eddd555344c2
4
- data.tar.gz: 72c5ae0785f172248afd031acd15f3608f6f7cb2e313fcfeeaaa432dcf5bc344
3
+ metadata.gz: 89abc20ace497e0f051bb38ed620c44bf4bc7067cfeb20d7d7af9f13b98337ae
4
+ data.tar.gz: '0971c951b39f2cf94833a1d3d55eb3c561666995049d7d6f4fff553837615676'
5
5
  SHA512:
6
- metadata.gz: 0425f57b22af0ced7dbe28fe25a88da21d5d5cfd4960ebb22a6fd6b53108cb9af6eb2e01b31e9fae919478cc38ddca9bffe23f05439e58f3f4dbb2665ee39fa2
7
- data.tar.gz: 64c90f0edddc6b534f1104240788bb8fe7afc7dd78a06ca037d24228b5127746380d41fabb7473c827c7327abe26362c97a8ad5e2090393b68887061e0d3fbad
6
+ metadata.gz: 73f515630bcfc90ea39862b6014d4b4a4afb4b29b33a09ae8ac58e8ead98786e26be03c4e63d5711c82a6728afd37e02549b56417bf5833d833d8f7ee473ed34
7
+ data.tar.gz: 8965f3fe015315e49c3dfe5b31b8aa949f0f609ffd7664a87ab875ca9a2f0cf494ac0a2236896479dfe007e2ebe45e5acdafbdb9d6384197acc9390383f7365e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.4 [2024-07-23]
2
+ - Improve merging of classes
3
+
4
+ ## 0.2.3 [2024-07-23]
5
+ - Fix attributes in components that have multiple lines
6
+
1
7
  ## 0.2.2 [2024-07-23]
2
8
  - Change comments to be compiled first
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
@@ -147,7 +147,7 @@ module RBlade
147
147
  \s*
148
148
  >
149
149
  )
150
- /x)
150
+ /xm)
151
151
  end
152
152
 
153
153
  def tokenizeAttributes segment
@@ -181,7 +181,7 @@ module RBlade
181
181
  )
182
182
  )
183
183
  (?=\s|$)
184
- /x).flatten.compact
184
+ /xm).flatten.compact
185
185
  end
186
186
  end
187
187
  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.2"
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.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon J