File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11# Changelog
2+
3+ ## 0.2.1 - 2021-05-20
4+
5+ - Add ` Block::generateIdsUsing `
Original file line number Diff line number Diff line change 99
1010class Block
1111{
12+ /**
13+ * @var null|callable
14+ */
15+ public static $ generateIdsUsing ;
16+
1217 /**
1318 * The language of the code that is being highlighted.
1419 *
@@ -80,7 +85,7 @@ public static function make($id = null)
8085 public function __construct ($ id = null )
8186 {
8287 // Generate a unique UUID.
83- $ this ->id = $ id ?? ( string )Str:: uuid ();
88+ $ this ->id = $ id ?? $ this -> generateId ();
8489
8590 // Set a default theme.
8691 $ this ->theme = config ('torchlight.theme ' );
@@ -94,6 +99,16 @@ public function id()
9499 return $ this ->id ;
95100 }
96101
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+
97112 /**
98113 * @return string
99114 */
Original file line number Diff line number Diff line change @@ -113,7 +113,20 @@ public function default_theme_is_used()
113113 $ block = Block::make ('id ' );
114114
115115 $ 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 ());
116128
129+ Block::$ generateIdsUsing = null ;
117130 }
118131
119132
You can’t perform that action at this time.
0 commit comments