Skip to content

Commit

Permalink
Merge pull request #364 from macta/share-code-experiment
Browse files Browse the repository at this point in the history
Confirm sharing is ok, don't print default class comment
  • Loading branch information
macta authored May 22, 2019
2 parents b08cec1 + 90784b9 commit 6cc4a1d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 49 deletions.
38 changes: 38 additions & 0 deletions dev/src/ExercismDev/ExercismManager.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,44 @@ ExercismManager >> dependencyGraph [

]

{ #category : #'*ExercismDev' }
ExercismManager >> shareExercisePasteEE: package [
| source i result |
package = self class legacyExercismPackage
ifTrue: [ self error: 'Select the sub-package with your solution!' ].
source := String
streamContents: [ :s |
s << '{"description":"test","sections":['.
i := 0.
package solutionSources
keysAndValuesDo: [ :filename :code |
i > 0
ifTrue: [ s << ', ' ].
s
<<
('\{"name":"{1}","syntax":"{3}","contents":{2}\}'
format:
{filename.
code asJSON.
((filename endsWith: '.st')
ifTrue: [ 'smalltalk' ]
ifFalse: [ 'autodetect' ])}).
i := i + 1 ].
s << ']}' ].
result := ZnClient new
systemPolicy;
beOneShot;
https;
host: 'api.paste.ee';
path: '/v1/pastes';
setBasicAuthenticationUsername: 'ub4sqYh4qD5I1eLrYgn3M19DQza5F6ckpZDmPov2C'
password: '';
entity: (ZnEntity text: source);
contentType: ZnMimeType applicationJson;
post.
^ (STONJSON fromString: result) at: 'link'
]

{ #category : #'*ExercismDev' }
ExercismManager class >> trackActive [
^true
Expand Down
7 changes: 4 additions & 3 deletions dev/src/ExercismTools/ClassDescription.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ ClassDescription >> exPrintOutOn: aWriteStream [
nextPutAll: self definition;
nextPut: $.; cr; cr.

aWriteStream nextPut: $".
self comment trimBoth encodeDoublingDoubleQuotesOn: aWriteStream.
aWriteStream nextPut: $"; cr; cr.
self hasComment ifTrue: [
aWriteStream nextPut: $".
self comment trimBoth encodeDoublingDoubleQuotesOn: aWriteStream.
aWriteStream nextPut: $"; cr; cr ].

self exPrintOutCategoriesFor: self class on: aWriteStream.
self exPrintOutCategoriesFor: self on: aWriteStream
Expand Down
2 changes: 1 addition & 1 deletion dev/src/ExercismTools/ClyExercismFetchCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ClyExercismFetchCommand >> defaultMenuItemName [

{ #category : #accessing }
ClyExercismFetchCommand >> description [
^'Fetch a named exercise to begin solving it'
^'Fetch a named Exercism exercise to begin solving it'
]

{ #category : #execution }
Expand Down
2 changes: 1 addition & 1 deletion dev/src/ExercismTools/ClyExercismProgressCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ClyExercismProgressCommand >> defaultMenuItemName [

{ #category : #accessing }
ClyExercismProgressCommand >> description [
^'Open track progress in a web browser'
^'Open your Exercism track progress in a web browser'
]

{ #category : #execution }
Expand Down
33 changes: 29 additions & 4 deletions dev/src/ExercismTools/ClyExercismShareCommand.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Class {
#name : #ClyExercismShareCommand,
#superclass : #ClyExercismExerciseCommand,
#classVars : [
'hasConfirmedSharing'
],
#category : #'ExercismTools-Menus'
}

Expand All @@ -9,27 +12,49 @@ ClyExercismShareCommand class >> contextMenuOrder [
^15
]

{ #category : #accessing }
ClyExercismShareCommand class >> hasConfirmedSharing [
^ hasConfirmedSharing ifNil: [ false ]
]

{ #category : #accessing }
ClyExercismShareCommand class >> hasConfirmedSharing: aBoolean [
^hasConfirmedSharing := aBoolean
]

{ #category : #internal }
ClyExercismShareCommand >> confirmSharing [
self class hasConfirmedSharing
ifTrue: [ ^ true ].

^ (UIManager default
proceed:
'Please confirm you are happy to anonymously store your exercise code, on a temporary (7 day) random url at dpaste.com.\Exercism and Pharo.org are not associated with this service, it is provided as a convenience to help users\more easily discuss ideas with a wider community.' withCRs)
ifTrue: [ self class hasConfirmedSharing: true ]
ifFalse: [ false ]
]

{ #category : #accessing }
ClyExercismShareCommand >> defaultMenuIconName [
^#publish
]

{ #category : #accessing }
ClyExercismShareCommand >> defaultMenuItemName [
^'Share on web'
^'Share on web...'
]

{ #category : #accessing }
ClyExercismShareCommand >> description [
^'Share your proposed solution on the web to discuss with others'
^'Create a web link to anonymously share your proposed solution on dpaste.com to discuss with others'
]

{ #category : #execution }
ClyExercismShareCommand >> execute [
| exerciseName result url |

exerciseName := self selectedItem exerciseName.

self confirmSharing ifTrue: [
[ UIManager default
informUser: 'Sharing...'
during: [
Expand All @@ -49,5 +74,5 @@ ClyExercismShareCommand >> execute [
]
]
on: ExercismError
do: [ :ex | self reportError: ex for: nil ]
do: [ :ex | self reportError: ex for: nil ] ]
]
38 changes: 0 additions & 38 deletions dev/src/ExercismTools/ExercismManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -162,44 +162,6 @@ ExercismManager >> shareExerciseDPaste: exercise [
post
]

{ #category : #exercism }
ExercismManager >> shareExercisePasteEE: package [
| source i result |
package = self class legacyExercismPackage
ifTrue: [ self error: 'Select the sub-package with your solution!' ].
source := String
streamContents: [ :s |
s << '{"description":"test","sections":['.
i := 0.
package solutionSources
keysAndValuesDo: [ :filename :code |
i > 0
ifTrue: [ s << ', ' ].
s
<<
('\{"name":"{1}","syntax":"{3}","contents":{2}\}'
format:
{filename.
code asJSON.
((filename endsWith: '.st')
ifTrue: [ 'smalltalk' ]
ifFalse: [ 'autodetect' ])}).
i := i + 1 ].
s << ']}' ].
result := ZnClient new
systemPolicy;
beOneShot;
https;
host: 'api.paste.ee';
path: '/v1/pastes';
setBasicAuthenticationUsername: 'ub4sqYh4qD5I1eLrYgn3M19DQza5F6ckpZDmPov2C'
password: '';
entity: (ZnEntity text: source);
contentType: ZnMimeType applicationJson;
post.
^ (STONJSON fromString: result) at: 'link'
]

{ #category : #exercism }
ExercismManager >> shareExerciseStfx: package [
| source |
Expand Down
2 changes: 1 addition & 1 deletion dev/src/ExercismTools/RPackage.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RPackage >> exPrintOutExtensionsFor: aClass on: aWriteStream [

{ #category : #'*ExercismTools' }
RPackage >> exerciseName [
^ (name allRegexMatches: '\w+') last
^ (self name allRegexMatches: '\w+') last
]

{ #category : #'*ExercismTools' }
Expand Down
2 changes: 1 addition & 1 deletion dev/src/ExercismTools/RPackageTag.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RPackageTag >> definedClasses [
{ #category : #'*ExercismTools' }
RPackageTag >> exerciseName [
"Provided for legacy compatibility"
^self name
^self name asString
]

{ #category : #'*ExercismTools' }
Expand Down

0 comments on commit 6cc4a1d

Please sign in to comment.