1
|
1 |
"{ Package: 'stx:goodies/cypress' }"!
|
|
2 |
|
2
|
3 |
!Array methodsFor:'*Cypress-Structure'!
|
|
4 |
|
|
5 |
asCypressPropertyObject
|
|
6 |
|
|
7 |
^self collect: [:each | each asCypressPropertyObject ]
|
|
8 |
! !
|
|
9 |
|
|
10 |
!Array methodsFor:'*Cypress-Structure'!
|
|
11 |
|
|
12 |
writeCypressJsonOn: aStream forHtml: forHtml indent: startIndent
|
|
13 |
|
4
|
14 |
| indent |
|
|
15 |
aStream
|
|
16 |
nextPutAll: '[';
|
|
17 |
cr.
|
|
18 |
indent := startIndent + 1.
|
|
19 |
1 to: self size do: [:index | | item |
|
|
20 |
item := self at: index.
|
|
21 |
aStream tab: indent.
|
5
|
22 |
item writeCypressJsonOn: aStream forHtml: "forHtml"false indent: indent.
|
4
|
23 |
index < self size ifTrue: [ aStream nextPutAll: ','; cr ]].
|
|
24 |
self size = 0 ifTrue: [ aStream tab: indent ].
|
|
25 |
aStream nextPutAll: ' ]'
|
|
26 |
|
5
|
27 |
"Modified: / 31-08-2012 / 09:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
2
|
28 |
! !
|
|
29 |
|
|
30 |
!Boolean methodsFor:'*Cypress-Structure'!
|
|
31 |
|
|
32 |
writeCypressJsonOn: aStream forHtml: forHtml indent: startIndent
|
|
33 |
|
|
34 |
aStream
|
|
35 |
nextPutAll: self printString
|
|
36 |
! !
|
|
37 |
|
|
38 |
!Character methodsFor:'*Cypress-Structure'!
|
|
39 |
|
|
40 |
isSafeForHTTP
|
|
41 |
"whether a character is 'safe', or needs to be escaped when used, eg, in a URL"
|
|
42 |
|
|
43 |
^ asciivalue < 128
|
|
44 |
and: [ self isAlphaNumeric
|
|
45 |
or: [ '.-_' includes: self ]]
|
|
46 |
|
|
47 |
"Modified: / 30-08-2012 / 13:57:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
48 |
! !
|
|
49 |
|
1
|
50 |
!CharacterArray methodsFor:'Compatibility-Cuis'!
|
|
51 |
|
|
52 |
withLineEndings: lineEndString
|
|
53 |
| stringColl |
|
|
54 |
|
|
55 |
self assert: lineEndString size == 1.
|
|
56 |
|
|
57 |
stringColl := self asStringCollection.
|
|
58 |
|
|
59 |
^stringColl
|
|
60 |
asStringWith: lineEndString first
|
|
61 |
from:1 to:(stringColl size)
|
|
62 |
compressTabs:false
|
|
63 |
final:nil
|
|
64 |
|
|
65 |
"Created: / 30-08-2012 / 11:27:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
66 |
! !
|
|
67 |
|
|
68 |
!CharacterArray class methodsFor:'Compatibility-Cuis'!
|
|
69 |
|
|
70 |
lfString
|
|
71 |
|
|
72 |
^String with: Character lf.
|
|
73 |
|
|
74 |
"Created: / 30-08-2012 / 11:27:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
75 |
! !
|
|
76 |
|
2
|
77 |
!Class methodsFor:'*Cypress-Definitions'!
|
|
78 |
|
|
79 |
asCypressClassDefinition
|
|
80 |
^CypressClassDefinition
|
|
81 |
name: self name
|
|
82 |
superclassName: self superclass name
|
|
83 |
category: self category
|
|
84 |
instVarNames: self instVarNames
|
|
85 |
classInstVarNames: self class instVarNames
|
|
86 |
comment: self comment
|
|
87 |
! !
|
|
88 |
|
|
89 |
!Dictionary methodsFor:'*Cypress-Structure'!
|
|
90 |
|
|
91 |
asCypressPropertyObject
|
|
92 |
self associations do: [ :assoc | self at: assoc key put: assoc value asCypressPropertyObject ]
|
|
93 |
! !
|
|
94 |
|
|
95 |
!Dictionary methodsFor:'*Cypress-Structure'!
|
|
96 |
|
|
97 |
writeCypressJsonOn: aStream forHtml: forHtml indent: startIndent
|
|
98 |
| indent count |
|
|
99 |
indent := startIndent.
|
|
100 |
aStream
|
|
101 |
nextPutAll: '{';
|
4
|
102 |
cr.
|
2
|
103 |
count := 0.
|
|
104 |
indent := indent + 1.
|
4
|
105 |
(self keys asSortedCollection: [ :a :b | a <= b ])
|
2
|
106 |
do: [ :key |
|
|
107 |
| value |
|
|
108 |
value := self at: key.
|
|
109 |
count := count + 1.
|
|
110 |
aStream tab: indent.
|
5
|
111 |
key writeCypressJsonOn: aStream forHtml: "forHtml"false indent: indent.
|
2
|
112 |
aStream nextPutAll: ' : '.
|
5
|
113 |
value writeCypressJsonOn: aStream forHtml: "forHtml"false indent: indent.
|
2
|
114 |
count < self size
|
|
115 |
ifTrue: [
|
|
116 |
aStream
|
|
117 |
nextPutAll: ',';
|
4
|
118 |
cr ] ].
|
2
|
119 |
self size = 0
|
|
120 |
ifTrue: [ aStream tab: indent ].
|
|
121 |
aStream nextPutAll: ' }'
|
4
|
122 |
|
5
|
123 |
"Modified: / 31-08-2012 / 09:17:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
2
|
124 |
! !
|
|
125 |
|
3
|
126 |
!Method methodsFor:'converting'!
|
|
127 |
|
|
128 |
asCypressMethodDefinition
|
|
129 |
|
|
130 |
^CypressMethodDefinition
|
|
131 |
className: (self methodClass isMeta ifTrue: [ self methodClass theNonMetaClass ] ifFalse: [ self methodClass ]) name
|
|
132 |
classIsMeta: self methodClass isMeta
|
|
133 |
selector: self selector
|
|
134 |
category: self category
|
6
|
135 |
source: self source
|
3
|
136 |
timeStamp: self timeStamp
|
|
137 |
|
|
138 |
"Created: / 30-08-2012 / 14:05:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
139 |
! !
|
|
140 |
|
2
|
141 |
!Number methodsFor:'*Cypress-Structure'!
|
|
142 |
|
|
143 |
writeCypressJsonOn: aStream forHtml: forHtml indent: startIndent
|
|
144 |
|
|
145 |
aStream
|
|
146 |
nextPutAll: self printString
|
|
147 |
! !
|
|
148 |
|
|
149 |
!Object methodsFor:'*Cypress-Structure'!
|
|
150 |
|
|
151 |
asCypressPropertyObject
|
|
152 |
|
|
153 |
^self
|
|
154 |
! !
|
|
155 |
|
|
156 |
!String methodsFor:'*Cypress-Structure'!
|
|
157 |
|
|
158 |
asCypressPropertyObject
|
|
159 |
|
|
160 |
^self unescapePercents withLineEndings: String lfString
|
|
161 |
! !
|
|
162 |
|
|
163 |
!String methodsFor:'*Cypress-Structure'!
|
|
164 |
|
|
165 |
encodeForHTTP
|
5
|
166 |
"change dangerous characters to their %XX form, for use in HTTP transactions"
|
|
167 |
| encodedStream |
|
|
168 |
encodedStream := WriteStream on: (String new).
|
|
169 |
|
|
170 |
1 to: self size do: [ :n | | c |
|
|
171 |
c := self at: n.
|
|
172 |
c isSafeForHTTP ifTrue: [ encodedStream nextPut: c ] ifFalse: [
|
|
173 |
encodedStream nextPut: $%.
|
|
174 |
encodedStream nextPutAll: ((c asciiValue // 16) printStringRadix: 16).
|
|
175 |
encodedStream nextPutAll: ((c asciiValue \\ 16) printStringRadix: 16).
|
|
176 |
]
|
|
177 |
].
|
|
178 |
^encodedStream contents.
|
|
179 |
|
|
180 |
"Modified: / 30-08-2012 / 11:31:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
2
|
181 |
! !
|
|
182 |
|
|
183 |
!String methodsFor:'*Cypress-Structure'!
|
|
184 |
|
|
185 |
writeCypressJsonOn: aStream forHtml: forHtml indent: startIndent
|
|
186 |
|
5
|
187 |
aStream
|
|
188 |
nextPutAll: '"';
|
|
189 |
nextPutAll: ("forHtml"false
|
|
190 |
ifTrue: [ (self withLineEndings: String lfString) encodeForHTTP ]
|
|
191 |
ifFalse: [ self withLineEndings: String lfString ]);
|
|
192 |
nextPutAll: '"'
|
|
193 |
|
|
194 |
"Modified: / 31-08-2012 / 09:17:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
2
|
195 |
! !
|
|
196 |
|
1
|
197 |
!stx_goodies_cypress class methodsFor:'documentation'!
|
|
198 |
|
|
199 |
extensionsVersion_SVN
|
|
200 |
^ '$Id:: $'
|
|
201 |
! ! |