Ken Treis | 1 Jun 19:48 2007

Magritte pre-validation hooks?

Is there an easy way in Magritte to clean up user-supplied data  
before validation? I'm doing something like this:

> Address>>state: aString
> 	state := aString ifNotNil: [:s | s trimBlanks]
>
> Address class>>descriptionState
> 	^(MAStringDescription auto: 'state' label: 'State')
> 		addCondition: [:value | value trimBlanks size = 2] labelled:  
> 'Please enter a two-character abbreviation';
> 		yourself

In Rails, ActiveRecord offers a before_validation hook for this kind  
of cleanup. I have mostly used it to coerce empty strings to nil, but  
it looks like Magritte's default string reader at least does that  
part for me.

Should I implement my own StringReader to accomplish this in one place?

--
Ken Treis
Miriam Technologies, Inc.

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki

Martial Boniou | 1 Jun 22:50 2007

Re: PRComponentSettings disappeared and... PRStriketroughFormat is obsolete

In the yesterday fix in Pier, Lukas corrected the syntax error
PRStriketroughFormat to PRStrikethroughFormat. Like the PUSecurity
filtering proposed by Lukas in this thread, the following short script
could help anyone who's got a kernel with the old format:

| a f index |
#(#PRStriketroughFormat #PRStrikethroughFormat )
	pairsDo: [:badGroup :newGroup | PRDocumentGroup
		allSubInstancesDo: [:e | 
		f := e children.
		index := 0.
		[(index := index + 1) <= f size]
			whileTrue: [a := f at: index.
			a class isOsbolete
				ifTrue:
			[('*' , badGroup asString match: a class asString)
				ifTrue:
					[f at: index
					put; ((Smalltalk at: newGroup
ifAbsent: [PRParagraph]) new setChildren: a children copy)]]]]]

"end of script"

I hope Lukas will add those kind of messages to permutate the obsolete
PRFormat (even if it's happened one time).

Cheers,

--
Martial
(Continue reading)

Oleg Korsak | 2 Jun 05:08 2007
Picon

Pier Login and menu

Hello again :) How can I create my own link in the wiki page to the Login form (I want to hide Commands box)?
Also I have my own menu at http://kamikaze.seasidehosting.st/   but my links are constant and doesn't have any session data. So if somebody is logged in and presses any of top menu items - he is going to be logged off :| Any advices how to organize links in this menu? It is <UL> list items with <a> tags.


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Lukas Renggli | 2 Jun 10:02 2007
Picon
Picon

Re: Magritte pre-validation hooks?

> Is there an easy way in Magritte to clean up user-supplied data
> before validation? I'm doing something like this:
>
>> Address>>state: aString
>> 	state := aString ifNotNil: [:s | s trimBlanks]
>>
>> Address class>>descriptionState
>> 	^(MAStringDescription auto: 'state' label: 'State')
>> 		addCondition: [:value | value trimBlanks size = 2] labelled:
>> 'Please enter a two-character abbreviation';
>> 		yourself
>
> In Rails, ActiveRecord offers a before_validation hook for this kind
> of cleanup. I have mostly used it to coerce empty strings to nil, but
> it looks like Magritte's default string reader at least does that
> part for me.
>
> Should I implement my own StringReader to accomplish this in one  
> place?

There is no such thing in Magritte. Of course there are many places  
where you could introduce such a thing. The StringReader is something  
else, it transforms a string to a real object (e.g. a date object, a  
number, etc).

It would be probably the best if you create a new mechanism, similar  
to the one of the StringReader, that is responsible to do that?

Lukas

--

-- 
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki

Lukas Renggli | 2 Jun 10:02 2007
Picon
Picon

Re: PRComponentSettings disappeared and... PRStriketroughFormat is obsolete

> In the yesterday fix in Pier, Lukas corrected the syntax error
> PRStriketroughFormat to PRStrikethroughFormat. Like the PUSecurity
> filtering proposed by Lukas in this thread, the following short script
> could help anyone who's got a kernel with the old format:
>
> | a f index |
> #(#PRStriketroughFormat #PRStrikethroughFormat )
> 	pairsDo: [:badGroup :newGroup | PRDocumentGroup
> 		allSubInstancesDo: [:e |
> 		f := e children.
> 		index := 0.
> 		[(index := index + 1) <= f size]
> 			whileTrue: [a := f at: index.
> 			a class isOsbolete
> 				ifTrue:
> 			[('*' , badGroup asString match: a class asString)
> 				ifTrue:
> 					[f at: index
> 					put; ((Smalltalk at: newGroup
> ifAbsent: [PRParagraph]) new setChildren: a children copy)]]]]]
>
> "end of script"

Sometimes I need to change things like that. Unfortunately MC does  
not track class renames, therefor this problem. Thanks for the  
script. I now wonder how we could collect such scripts so that they  
get executed if necessary?

Lukas

--

-- 
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki

Lukas Renggli | 2 Jun 10:02 2007
Picon
Picon

Re: Pier Login and menu

> Hello again :) How can I create my own link in the wiki page to the  
> Login form (I want to hide Commands box)?
> Also I have my own menu at http://kamikaze.seasidehosting.st/   but  
> my links are constant and doesn't have any session data. So if  
> somebody is logged in and presses any of top menu items - he is  
> going to be logged off :| Any advices how to organize links in this  
> menu? It is <UL> list items with <a> tags.

To create a link to a particular structure (the expression in brakets  
creates a copy of the current context pointing to aStructure):

html anchor
	goto: (self context
		structure: aStructure);
	with: aStructure title

As you can see in the command and tree widgets there are different  
other forms possible ...

html anchor
	goto: (self context
		structure: aStructure
		command: aCommand);
	with: 'Foo bar'

Lukas

--

-- 
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki

Ken Treis | 4 Jun 19:17 2007

Re: Magritte pre-validation hooks?

On Jun 2, 2007, at 1:02 AM, Lukas Renggli wrote:

>> Should I implement my own StringReader to accomplish this in one
>> place?
>
> There is no such thing in Magritte. Of course there are many places
> where you could introduce such a thing. The StringReader is something
> else, it transforms a string to a real object (e.g. a date object, a
> number, etc).
>
> It would be probably the best if you create a new mechanism, similar
> to the one of the StringReader, that is responsible to do that?

Hi Lukas,

Even though Rails implements something more generic (pre-validation  
hooks where any transformation could happen), I realized that I  
really only needed it for this one specific situation (trimming  
blanks off of strings and coercing them to nil if they are empty).

So I implemented my own StringReader subclass that overrides one method:

PruningStringReader>>visitStringDescription: aDescription
	| trimmed |
	trimmed := self contents trimBlanks.
	self object: (trimmed isEmpty ifTrue: [nil] ifFalse: [trimmed])

This solves the problem that set me out on this quest in the first  
place. I'm using this as my default string reader, since I can't  
think of any situations in my apps where leading or trailing blanks  
would be significant.

Thanks,

--
Ken Treis
Miriam Technologies, Inc.

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki

Oleg Korsak | 5 Jun 02:21 2007
Picon

visitor

Hi! Why there are "super visit*: anObject" in some visit* methods of PRWikiWriter? For example #visitHeader and #visitListItem. But some methods doesn't use "super visit*: anObject". Where is a difference of this need to use "super visit*: anObject" or not?

Thanks


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Lukas Renggli | 5 Jun 07:31 2007
Picon
Picon

Re: visitor

> Hi! Why there are "super visit*: anObject" in some visit* methods  
> of PRWikiWriter? For example #visitHeader and #visitListItem. But  
> some methods doesn't use "super visit*: anObject". Where is a  
> difference of this need to use "super visit*: anObject" or not?

It is probably the easiest if you put a #halt somewhere and stop  
trough the code, then you see what actually happens.

To explain it in words: you are walking over the wiki document AST.  
It has leaf (PRText, PRAnchor, PRHorizontalRule, ...) and non-leaf  
nodes (PRParagraph, PRTableCell, PRFormat, ...). All the non-leaf  
nodes are subclasses of PRDocumentGroup that defines the logic for  
child-elements.

Now in the visitor, if you have for example a look at

     PRWikiWriter>>visitHorizontalRule: anObject
         self newLine; nextPutAll: anObject class markup

With PRParagraph this looks different:

     PRWikiWriter>>visitParagraph: anObject
         self newLine.
         super visitParagraph: anObject

If you have a look at the super implementation you see it delegates  
(along its hierarchy) to

     PRVisitor>>visitParagraph: anObject
         self visitDocumentGroup: anObject

and finally to

     PRVisitor>>visitDocumentGroup: anObject
         self visitAll: anObject children

So it is used to get the default behavior of the superclass, what is  
"visit my children" in this case.

All visitors basically delegate along their hierarchy to get default  
behavior. In rare cases I use shortcuts (for example the search), to  
avoid walking trough the whole model.

So, not implementing means default behavior. Calling super means  
added behavior + default behavior.

Does that make sense?

Lukas

--

-- 
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki

Steven Noble | 7 Jun 03:30 2007
Picon

MAMultiselectListComponent>>renderEditorOn: sends an unknown message #beMultiple

Hi,

I've just started playing with pier and I've hit a little problem.  I
installed Pier-Security and it is using a MAMultiselectListComponent
which is attempting to send #beMultiple to an html select.  However,
the default WASelectTag does not understand #beMultiple.

I clearly don't have some class installed that I need.  Anyone know what it is?

Cheers,
Steven

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


Gmane