File tree 3 files changed +33
-1
lines changed
3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
+
3
+ ## 0.2.1 - 2021-05-20
4
+
5
+ - Add ` Block::generateIdsUsing `
Original file line number Diff line number Diff line change 9
9
10
10
class Block
11
11
{
12
+ /**
13
+ * @var null|callable
14
+ */
15
+ public static $ generateIdsUsing ;
16
+
12
17
/**
13
18
* The language of the code that is being highlighted.
14
19
*
@@ -80,7 +85,7 @@ public static function make($id = null)
80
85
public function __construct ($ id = null )
81
86
{
82
87
// Generate a unique UUID.
83
- $ this ->id = $ id ?? ( string )Str:: uuid ();
88
+ $ this ->id = $ id ?? $ this -> generateId ();
84
89
85
90
// Set a default theme.
86
91
$ this ->theme = config ('torchlight.theme ' );
@@ -94,6 +99,16 @@ public function id()
94
99
return $ this ->id ;
95
100
}
96
101
102
+ /**
103
+ * @return string
104
+ */
105
+ protected function generateId ()
106
+ {
107
+ $ id = is_callable (static ::$ generateIdsUsing ) ? call_user_func (static ::$ generateIdsUsing ) : Str::uuid ();
108
+
109
+ return (string )$ id ;
110
+ }
111
+
97
112
/**
98
113
* @return string
99
114
*/
Original file line number Diff line number Diff line change @@ -113,7 +113,20 @@ public function default_theme_is_used()
113
113
$ block = Block::make ('id ' );
114
114
115
115
$ this ->assertEquals ('a new default ' , $ block ->theme );
116
+ }
117
+
118
+ /** @test */
119
+ public function can_specify_an_id_generator ()
120
+ {
121
+ Block::$ generateIdsUsing = function () {
122
+ return 'generated_via_test ' ;
123
+ };
124
+
125
+ $ block = Block::make ();
126
+
127
+ $ this ->assertEquals ('generated_via_test ' , $ block ->id ());
116
128
129
+ Block::$ generateIdsUsing = null ;
117
130
}
118
131
119
132
You can’t perform that action at this time.
0 commit comments