On 16 Jun 2018, at 15:38, Ben Coman <btc@openInWorld.com> wrote:Le 16/06/2018 �� 10:43, Ben Coman a ��crit��:How can a fileout/filein be done using Tonel format?
In the first case as a script?
and secondly as a possible menu option for Pharo?
This is to facilitate transfer of student coding exercises for Exercism.
http://exercism.io/languages/pharo/launch
Could Tonel handle a full package export in one file?On 16 June 2018 at 17:13, Hilaire <hilaire@drgeo.eu> wrote:Hi Ben,
I am not sure, but the purpose of Tonel is to propose a file representation of "one class=one file".Sure thats how Tonel came about, and its how we mostly use it, but is this an inherent limitation?��Each method is prefixed with its class, so from my 100ft viewpoint it seems feasible to transport a whole package in one Tonel file.��Why not using Fileout st files to transfer the code?The same question might be asked why Iceberg didn't just use a Fileout at class level.��The Tonel��format is more readable, especially minus the scattering of exclamation marks.��I also meant to ask, what methods are used to file-in a Tonel file ?Or more the point, what method process a string in Tonel format that has been downloaded from a website?Actually, hunting around a bit I found....TonelParserTest >> testMethodDefListshows that... ((TonelParser on: tonelString readStream) perform:��#methodDefList)returns an array of MCMethodDefinitions that respond to #loadwith...MCMethodDefinition >>��loadself actualClasscompile: sourceclassified: categorywithStamp: timeStampnotifying: nilAnd...��TonelParserTest >>��testTypeDefshows that ((TonelParser on: tonelString��readStream) perform: #typeDef)returns a��MCClassDefinition that also responds to #loadwith...MCClassDefinition >> loadself createClassSo as an experiment I deleted MCMockClassD,then in playground evaluated...�� �� tonelString := (ZnEasy get: 'https://raw.githubusercontent.com/pharo- ') contents.project/pharo/development/src/ MonticelloMocks/MCMockClassD. class.st �� �� parser := (TonelParser on: tonelString readStream).�� �� classDef := parser perform: #typeDef.�� �� methodDefs := parser perform: #methodDefList.�� �� classDef load.�� �� methodDefs do: [ :md | md load ].and super cool...�� ��MCMockClassD>>one�� was restored.So is that the correct way to use it?cheers -ben
On 29 Jun 2018, at 17:11, Tim Mackinnon <tim@testit.works> wrote:Just as a followup to this - Bens suggestion can be slightly simplified (and less dependent on implementation details) as:tonelStream := ������path���./src/Polymorph-Widgets-Rules/IconShortcutRule .class.st ' asFileReference readStream.parser := (TonelParser on: tonelStream).parser document do: [ :item | item load ��].If you want to load an entire directory you can use a reader (but sadly the reader doesn���t let you load only one file)tonelLocator := ������path���./src/Polymorph-Widgets-Rules/IconShortcutRule .class.st ' asFileReference.(TonelReader on: tonelLocator fileName: tonelLocator path parent pathString ) loadDefinitions.Thought this might help someone in the future (particularly if you are recovering a deleted file(s) from git ;)Tim
As another output (and an answer to Ben���s question) - to output, you need a snapshot - the easiest I could work out was something like:TonelWriter new sourceDir: '.' asFileReference; writeSnapshot: (MCPackage named: HelloWorldTest package name) snapshot.