Amrita question(s)

Ara.T.Howard wrote:

2 Is there a way to mask out non-data elements if a data-element
doesn’t
exist?
Suppose I have in my html:

Name:

I don’t want “Name:” to show if the :name id doesn’t exist. I’m
sure
I’m overlooking something fundamental here, but I’ve just started
so
not sure where to look.

simply do not put ‘:name’ into you data structure:

~/eg/ruby > cat b.rb

require ‘amrita/template’; include Amrita

t = TemplateText.new ‘not
included

t.expand STDOUT, :foo => 42

This would require that I put my field names (in my example above,
“Name:”) in the model, which I’d like not to do, since it’s not PART
of my model, it’s part of my markup.

Perhaps my example is overloaded too much on terms; let me rephrase.

I want the following to display IFF my model contains the data
element “element”.

Field Label: element

Now, I can do this like so:

code: {:element => “Field Label: element” }
html:

or something like

code: {:elementlabel => "Field Label: ", :element => “element” }
html:

but neither is very satisfying. I don’t like either solution as they
put my markup directly into the code (and my model data), and in the
second case, requires that I manipulate 2 values for every labelled
output.

What I’d LIKE somehow is to have

html: Field Label:

and some version of code that omits the “Field Label:” part if
:element doesn’t exist; I understand the actual value referenced by
the :element key already won’t show. In other words, “sometag” is
just a conditional “is it there or not?” test, where “span” tests for
existence AND displays it.

I can’t use “span” as “sometag” above, since if the value DOES
exist, the “Field Label:” text will not be used, but rather replaced
with said value.

Do I need to write my own tag?

As for your comment about blocking out big chunks of HTML, how do you
do that? If you have sections separated by

, how do you make the Amrita parser
not replace the HTML code with the value of the :commentoutthischunk
value? YOu can’t use {:commentoutthischunk => nil}, but any other
non-nil value you use will not only eliminate your HTML, but be
printed in its place. (Or do you use a space or something innocuous?
)

Thanks,

Michael

···

Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

> Perhaps my example is overloaded too much on terms; let me rephrase. > > I want the following to display IFF my model contains the data element > "element". > > Field Label: element > > Now, I can do this like so: > > code: {:element => "Field Label: element" } html: > > or something like > > code: {:elementlabel => "Field Label: ", :element => "element" } html: id=elementlabel> > > but neither is very satisfying. I don't like either solution as they put my > markup directly into the code (and my model data), and in the second case, > requires that I manipulate 2 values for every labelled output. > > What I'd *LIKE* somehow is to have > > html: Field Label: > > and some version of code that omits the "Field Label:" part if :element > doesn't exist; I understand the actual value referenced by the :element key > already won't show. In other words, "sometag" is just a conditional "is it > there or not?" test, where "span" tests for existence AND displays it.

amrita can accept a proc as it’s model data, with it you can do pretty much
whatever you want:

~/eg/ruby > cat c.rb
require ‘amrita/template’
include Amrita

t = TemplateText.new <<-html
Label :
html

here’s one way

data = { :element => lambda{|e| e.body + ‘foobar’} }
t.expand STDOUT, data

you could simply automate this too

def append txt; lambda{|e| e.body + txt}; end
data = {:element => append(‘foobar’)}
t.expand STDOUT, data

and of course it doesn’t show up at all if no key is given

data = {:element => nil}
t.expand STDOUT, data

~/eg/ruby > ruby c.rb
Label : foobar
Label : foobar

~/eg/ruby > # note blank line above for last case

other ways i can think of include things like

def label_maker key, txt
{key => {:label=>true,:txt=>txt}}
end

and then something like:

t = TemplateText.new <<-html
Label :
html

data = {
:element => label_maker(:element, ‘foobar’),
}

> As for your comment about blocking out big chunks of HTML, how do you do > that? If you have sections separated by
... >
, how do you make the Amrita parser not replace the HTML code with the > value of the :commentoutthischunk value? YOu can't use > {:commentoutthischunk => nil}, but any other non-nil value you use will not > only eliminate your HTML, but be printed in its place. (Or do you use a > space or something innocuous?)

i just meant nil or not. my usage is something like:

t = TemplateText.new <<-html









html

and i simply do

page # => :main_page, :page_0, :page_1

data = Hash[page => {}][page] # begin in a sub hash for this page

then proceed normally

-a

···

On Sat, 20 Dec 2003, Michael Campbell wrote:

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

Ara.T.Howard wrote:

amrita can accept a proc as it’s model data, with it you can do pretty much
whatever you want:

Bingo, that’s the missing “gem” of info. I’m still new to ruby, and don’t think in “procs” yet; my knowledge of lisp (etc.) is academic at best.

Thanks,

Michael