Crab Log

Entries categorized as ‘Smalltalk’

onAnswer Hack

Maio 31, 2008 · Não Há Comentários

Este hack mostra como usar #onAnswer. Para mais detalhes veja o link lá embaixo.

Criaremos 4 classe e seus métodos para obter imagens fáceis de seguir.

Crie a primeira classe com o código:

SeasideHack subclass: #OnAnswerHack

instanceVariableNames: ‘a’

classVariableNames:

poolDictionaries:

category: ‘Seaside-Hacks’

E os métodos:

initialize

super initialize.

a := A new

renderContentOn: html

html render: a

children

^ Array with: a

Crie a segunda classe com:

SeasideHack subclass: #A

instanceVariableNames:

classVariableNames:

poolDictionaries:

category: ‘Seaside-Hacks’

E os métodos:

renderContentOn: html

html div id: ‘letter-A’;

with: [html text: 'A'.

html

form: [html submitButton text: 'call B';

callback: [self call: B new]]]

style

^ ‘#letter-A {background-color: hotpink; width: 300px; height: 300px}’

Crie a terceira classe com:

SeasideHack subclass: #B

instanceVariableNames: ‘c’

classVariableNames:

poolDictionaries:

category: ‘Seaside-Hacks’

Com os métodos:

initialize

super initialize.

c := C new

renderContentOn: html

html div id: ‘letter-B’;

with: [html text: 'B'.

html render: c.

html

form: [html submitButton text: 'answer';

callback: [self answer]]]

style

^ ‘#letter-B {background-color: darkseagreen; width: 200px; height: 200px}’

children

^ Array with: c

E finalmente a quarta classe:

SeasideHack subclass: #C

instanceVariableNames:

classVariableNames:

poolDictionaries:

category: ‘Seaside-Hacks’

E os métodos:

renderContentOn: html

html div id: ‘letter-C’;

with: [html text: 'C'.

html

form: [html submitButton text: 'answer';

callback: [self answer]]]

style

^ ‘#letter-C {background-color: aquamarine; width: 100px; height: 100px}’

Para registrar a aplicação no Seaside execute:

OnAnswerHack registerAsApplication: ‘onanswerhack’

A execução da aplicação leva à aparição da seguinte figura:

Um clique no botão call B substitui o componente A pelo componente B e faz aparecer a figura:

O botão answer do componente B (botão de baixo) invoca self answer que retorna ao componente A, mas o botão answer no componente C, embedded em B, envia a mensagem self answer que não retorna para nenhum componente pois o componente C não foi invocado com self call:. No componente B a última linha do código abaixo (que você deve inserir agora) serve para interceptar o retorno e redirecioná-lo para o componente que invocou o componente B (o componente A):

initialize

super initialize.

c := C new.

c

onAnswer: [:dummy | self answer]

Fonte: Aprendendo a usar o método #onAnswer: em Seaside na prática: autenticação de usuários

Categorias: Smalltalk
Tagged: ,

Alphabetic Batched List Hack

Maio 31, 2008 · Não Há Comentários

WAAlphabeticBatchedList efetua a paginação de uma lista de forma alfabética.

Para testar crie a classe com o código:

WAComponent subclass: #AlphabeticBatchedListHack

instanceVariableNames: ‘items batchedlist’

classVariableNames:

poolDictionaries:

category: ‘Seaside-Hacks’

Os métodos são:

initialize

super initialize.

items := Collection allSubclasses..

batchedlist := WAAlphabeticBatchedList new.

batchedlist items: items

renderContentOn: html

html heading: self class description.

html heading: ‘All subclasses of Collection’ level: 2.

batchedlist batch

do: [:item | html render: item. html break].

html render: batchedlist

children

^ Array with: batchedlist

A página apresentada é como abaixo:

Categorias: Smalltalk
Tagged: ,

Batched List Hack

Maio 30, 2008 · Não Há Comentários

Neste hack colocamos alguns códigos que podem esclarecer como usar o componente WABatchedList no Seaside. Primeiro crie a classe de teste com:

WAComponent subclass: #BatchedListHack

instanceVariableNames: ‘items batchedlist’

classVariableNames:

poolDictionaries:

category: ‘Seaside-Hacks’

Depois implemente os seguintes métodos:

initialize
super initialize.
items := OrderedCollection new.
1
to: 100
do: [:k | items add: 'item ' , (k asString padded: #left to: 3 with: $0)].
batchedlist := WABatchedList new.
batchedlist batchSize: 15.
batchedlist items: items

renderContentOn: html

html heading: ‘Batched List Test’.

batchedlist batch

do: [:item |

html render: item.

html break].

html render: batchedlist

children

^ Array with: batchedlist

A página gerada é como abaixo:

Categorias: Smalltalk
Tagged: ,

Smalltalk is dangerous. It is a drug.

Maio 30, 2008 · Não Há Comentários

“Smalltalk is dangerous. It is a drug. My advice to you would be don’t try it; it could ruin your life. Once you take the time to learn it (to REALLY learn it) you will see that there is nothing out there (yet) to touch it. Of course, like all drugs, how dangerous it is depends on your character. It may be that once you’ve got to this stage you’ll find it difficult (if not impossible) to “go back” to other languages and, if you are forced to, you might become an embittered character constantly muttering ascerbic comments under your breath. Who knows, you may even have to quit the software industry altogether because nothing else lives up to your new expectations.”

Andy Bower

Fonte: Seaside, ROR and retiring Java from the spotlight of web applications

Categorias: Smalltalk · Software · Tecnologia

Smalltalk em *batteries not included

Abril 27, 2008 · 2 Comentários

O blog de Daniel Martins, além da abordagem agradável de outros assuntos, é também uma excelente fonte de esclarecimentos sobre Smalltalk, Squeak, Seaside e Magritte.

Ah, o filme também é bacana.

Categorias: Smalltalk · post-citação
Tagged: , , ,

Smalltalk Quine

Abril 26, 2008 · Não Há Comentários

null
Um quine em Smalltalk:

| prog quote |
quote := Character value: 39.
prog := '| prog quote |
quote := Character value: 39.
prog := .
Transcript show: (prog copyFrom: 1 to: 53).
Transcript show: quote asString; show: prog; show: quote asString.
Transcript show: (prog copyFrom: 54 to: 212).
'.
Transcript show: (prog copyFrom: 1 to: 53).
Transcript show: quote asString; show: prog; show: quote asString.
Transcript show: (prog copyFrom: 54 to: 212).

Fonte: http://www.nyx.net/~gthompso/self_smalltalk.txt

Links relacionados:

Categorias: Smalltalk
Tagged:

Seaside reference

Abril 22, 2008 · Não Há Comentários

  • Seaside dandelionOutput
  • Dandelion
  • Dandelion is a generic Smalltalk code analysis/output framework. You can analyze your code and output the information in various formats (currently HTML, SMIX, Petal, XMI).Dandelion looks like a “doclet” in Smalltalk. And the impression is 80% right. However, I believe Dandelion has more flexibility. You can customize not only outputting format, but also analysis policy(what/how code elements will be analyzed) and analyzed information storage(how the analysis information is stored).

Categorias: Smalltalk
Tagged:

Encontrando código no Squeak

Abril 19, 2008 · Não Há Comentários

Categorias: Knowledge Base · Smalltalk
Tagged:

Dr. Geo II

Março 25, 2008 · Não Há Comentários

Há alguns anos, inspirado no programa Geometer Sketchpad (por sua vez inspirado no programa Cabri Géomètre) comecei a fazer um similar em Object Pascal (Delphi). Recentemente encontrei uma implementação open source muito boa em Squeak: o Dr Geo II, um programa para experimentação dinâmica com geometria. Brinquei um pouco com ele e gostei bastante (Clique na imagem abaixo para ampliá-la).

drgeoii.png

Links relacionados:

Categorias: Matemática · Smalltalk · Software

What to do if Squeak crashes or freezes

Fevereiro 13, 2008 · Não Há Comentários

Categorias: Knowledge Base · Smalltalk · Software · Tecnologia · post-citação