Skip to content

Commit

Permalink
book: add compatibility patches for squeak60
Browse files Browse the repository at this point in the history
  • Loading branch information
LinqLover committed Nov 21, 2023
1 parent 6aa4d21 commit e1842b6
Show file tree
Hide file tree
Showing 24 changed files with 185 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .squot
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ OrderedDictionary {
'SmalltalkSources/SBE-Monticello.package' : #SquotCypressCodeSerializer,
'SmalltalkSources/SBE-Tests.package' : #SquotCypressCodeSerializer,
'SmalltalkSources/SBE-Book.package' : #SquotCypressCodeSerializer,
'SmalltalkSources/SBE-ExtractBook.package' : #SquotCypressCodeSerializer
'SmalltalkSources/SBE-ExtractBook.package' : #SquotCypressCodeSerializer,
'SmalltalkSources/SBE-BookCompatibility-Squeak60.package' : #SquotCypressCodeSerializer
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ baseline: spec
#'SBE-QuickTour'
#'SBE-Streams'
#'SBE-Testing'
#'SBE-Tests')].
#'SBE-Tests')].

spec for: #(#'squeak6.0.x.release') do: [
spec package: #'SBE-BookCompatibility-Squeak60'.
spec package: #'SBE-Book' with: [
spec includes: #'SBE-BookCompatibility-Squeak60']].
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
accessing
customProjectAttributes

| attributes |
attributes := super customProjectAttributes.
(Smalltalk classNamed: #SystemVersion) ifNotNil: [:versionClass |
versionClass current isRelease ifTrue:
[attributes := attributes ,
(MetacelloPlatform current defaultPlatformAttributes
select: [:ea | ea matchesRegex: 'squeak\d.*']
thenCollect: [:ea | ea , '.release'])]].
^ attributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"class" : {
},
"instance" : {
"baseline:" : "ct 11/21/2023 17:10",
"baseline:" : "ct 11/21/2023 21:15",
"customProjectAttributes" : "ct 11/7/2023 12:22",
"projectClass" : "ct 11/21/2023 19:54" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"noMethodMetaData" : true,
"separateMethodMetaAndSource" : false,
"useCypressPropertiesFile" : true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SquotTrackedObjectMetadata {
#objectClassName : #PackageInfo,
#id : UUID [ '16fa07be5b1e4df7a4ea725e677c5eda' ],
#objectsReplacedByNames : true,
#serializer : #SquotCypressCodeSerializer
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
*SBE-BookCompatibility-Squeak60-private
getImage: uri

(uri beginsWith: 'cid:' caseSensitive: false) ifTrue: [
"Content-ID, used in nested MIMEDocuments, e.g., for emails with inline images"
(Smalltalk classNamed: #MIMEContentRequest) ifNotNil: [:class |
| cid |
cid := uri allButFirst: 4.
(class signal: cid) ifNotNil: [:document |
^ [document image] ifError: [nil]]].
^ nil].

(uri beginsWith: 'code://' caseSensitive: false) ifTrue: [
| expression |
"Same support for Smalltalk expressions as in TextURL >> #actOnClickFor:."
self shallEvaluateResources ifFalse: [^ nil].
expression := uri allButFirst: 7.
^ ([Compiler evaluate: expression] ifError: [nil])
ifNotNil: [:object | object isForm ifTrue: [object] ifFalse: [nil]]].

(uri beginsWith: 'data:' caseSensitive: false) ifTrue: [ | data mediaType separator |
separator := uri indexOf: $, ifAbsent: [^ nil].
mediaType := uri copyFrom: 6 to: separator - 1.
data := uri allButFirst: separator.
data := (mediaType endsWith: ';base64' caseSensitive: false)
ifTrue: [
mediaType := mediaType allButLast: 7.
[Base64MimeConverter mimeDecodeToBytes: data readStream] ifError: [nil]]
ifFalse: [data asByteArray readStream].
^ [ImageReadWriter formFromStream: data] ifError: [nil]].

self shallDownloadResources ifFalse: [^ nil].
^ (Smalltalk classNamed: #WebClient) ifNotNil: [:client |
"Maybe we can have this via an AppRegistry at some point. Maybe extend WebBrowser."
([client httpGet: uri] ifError: [nil]) ifNotNil: [:response |
response code = 200 ifFalse: [nil] ifTrue: [
[Form fromBinaryStream: response content asByteArray readStream]
ifError: [nil]]]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*SBE-BookCompatibility-Squeak60-private
hasTag: aTag name: tagNameLt

| after |
(aTag beginsWith: tagNameLt caseSensitive: false) ifFalse: [^ false].
after := aTag at: tagNameLt size + 1 ifAbsent: [^ true].
^ after = $> or: [after isSeparator]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*SBE-BookCompatibility-Squeak60-private
htmlEscape: aString

| escapeSequence |
escapeSequence := aString copyFrom: 2 to: aString size - 1.
escapeSequence first = $# ifTrue: [^ self htmlEscapeNumber: escapeSequence allButFirst].
(String htmlEntities at: (aString copyFrom: 2 to: aString size - 1) ifAbsent: [])
ifNotNil: [:char | ^ char].
^ nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*SBE-BookCompatibility-Squeak60-private
htmlEscapeNumber: aString

| number |
number := aString first = $x
ifTrue: ['16r', aString allButFirst]
ifFalse: [aString].
^ number asNumber asCharacter

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*SBE-BookCompatibility-Squeak60-private
htmlEscapes: aString

| lastIndex nextIndex |
nextIndex := aString indexOf: $& startingAt: (lastIndex := 1) ifAbsent: [^ aString].
^ String new: aString size * 11 // 10 "+10%" streamContents: [:tmpStream |
[tmpStream next: nextIndex - lastIndex putAll: aString startingAt: lastIndex.
nextIndex := aString indexOf: $; startingAt: (lastIndex := nextIndex) ifAbsent: [^ aString].
tmpStream nextPut: (self htmlEscape: (aString copyFrom: lastIndex to: nextIndex))]
doWhileTrue: [(nextIndex := aString indexOf: $& startingAt: (lastIndex := nextIndex + 1)) > 0].
tmpStream next: aString size - lastIndex + 1 putAll: aString startingAt: lastIndex]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*SBE-BookCompatibility-Squeak60-private
searchTag: aTag forAttribute: attributeName

| startIndex stopIndex |
startIndex := aTag findString: attributeName startingAt: 1 caseSensitive: false.
startIndex = 0 ifTrue: [^ nil].

startIndex := startIndex + attributeName size - 1.
[(aTag at: (startIndex := startIndex + 1)) isSeparator] whileTrue.
(aTag at: startIndex) = $= ifFalse: [^ nil].

[(aTag at: (startIndex := startIndex + 1)) isSeparator] whileTrue.
(aTag at: startIndex) = $"
ifTrue: [
startIndex := startIndex + 1.
stopIndex := aTag indexOf: $" startingAt: startIndex + 1]
ifFalse: [
stopIndex := aTag indexOfAnyOf: ' >' startingAt: startIndex + 1].
stopIndex = 0 ifTrue: [^ nil].
^ self htmlEscapes: (aTag copyFrom: startIndex to: stopIndex - 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"class" : {
},
"instance" : {
"getImage:" : "ct 5/20/2023 18:10",
"hasTag:name:" : "ct 5/20/2023 14:20",
"htmlEscape:" : "ct 5/20/2023 17:34",
"htmlEscapeNumber:" : "ct 5/20/2023 17:35",
"htmlEscapes:" : "mt 5/22/2023 11:01",
"searchTag:forAttribute:" : "ct 5/19/2023 23:36" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "SBEHtmlReadWriter" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*SBE-BookCompatibility-Squeak60
sbeBeginsWith: sequence caseSensitive: caseSensitive
"Answer if the receiver starts with the argument collection."

| index sequenceSize |
caseSensitive ifTrue: [^ self beginsWith: sequence].
sequenceSize := sequence size.
self size < sequenceSize ifTrue: [ ^false ].
index := 0.
[ (index := index + 1) <= sequenceSize ] whileTrue: [
((sequence at: index) sameAs: (self at: index)) ifFalse: [ ^false ] ].
^true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*SBE-BookCompatibility-Squeak60
sbeEndsWith: sequence caseSensitive: caseSensitive
"Answer if the receiver ends with the argument collection."

| index sequenceSize offset |
caseSensitive ifTrue: [^ self endsWith: sequence].
sequence isString ifFalse: [ ^super endsWith: sequence ].
sequenceSize := sequence size.
(offset := self size - sequenceSize) < 0 ifTrue: [ ^false ].
index := 0.
[ (index := index + 1) <= sequenceSize ] whileTrue: [
((sequence at: index) sameAs: (self at: index + offset)) ifFalse: [ ^false ] ].
^true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"class" : {
},
"instance" : {
"sbeBeginsWith:caseSensitive:" : "ct 11/21/2023 21:11",
"sbeEndsWith:caseSensitive:" : "ct 11/21/2023 21:11" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "String" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*SBE-BookCompatibility-Squeak60-accessing-pseudo-override
findString: subString

^ self asString findString: subString
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"findString:" : "ct 11/21/2023 21:11" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "Text" }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SystemOrganization addCategory: #'SBE-BookCompatibility-Squeak60'!
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}

0 comments on commit e1842b6

Please sign in to comment.