Forum: Ruby ruby html (or xhtml) forms class...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7a1d3c7a520355e32375a272b237036f?d=identicon&s=25 Skeets (Guest)
on 2006-02-13 21:23
(Received via mailing list)
does one exist?  i use an excellent php based forms class when i code
in php.  it includes javascriput validation, server side validation,
regex validation and a lot more.

does ruby have something similar, or will i have to 1. code my own (not
gonna happen anytime soon) or 2. just write the html out every time
(not good)?

tia...
8f6770aa18a37c249412a24fb2570bf8?d=identicon&s=25 Ian Whitney (Guest)
on 2006-02-13 21:30
(Received via mailing list)
After not finding anything that met my needs, I'm writing one. But
it's a couple months away from being ready.

Ian
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-02-13 22:13
(Received via mailing list)
On Tue, 14 Feb 2006, Ian Whitney wrote:

> After not finding anything that met my needs, I'm writing one. But it's a
> couple months away from being ready.

try this out

   http://rubyforge.org/frs/download.php/8234/xx-0.1.0.tgz


info about it


NAME

   xx - twice as dirty

SYNOPSIS

   > gem install "double x"

   require "xx"

   include XX::XHTML

   doc = xhtml_{
     html_{
       head_{ title_{ " go xx! " } }
       body_{ " one more and it would be illegal " }
     }
   }


URI

   http://rubyforge.org/frs/?group_id=1024


DESCRIPTION

   xx is a library designed to extend ruby objects with html, xhtml, and
xml
   generation methods.  the syntax provided by xx aims to make the
generation of
   xml or xhtml as clean looking and natural as ruby it self.

   the approach taken, that of extending objects, allows natural
document
   generation while preserving access to instance data.  in essence it
provides
   ruby objects (including the top level 'main' object) an intuitive
means to
   generate various markup views of their data in a way that is correct
and
   elegant.

   xx is brought to you by the good folks at http://eparklabs.com.


SAMPLES

   <========< sample/a.rb >========>

   ~ > cat sample/a.rb

     require "xx"
     include XX::XHTML
     #
     # xx modules extend the current object to allow natural document
markup
     #
     doc = xhtml_{
       html_{
         head_{ title_{ " go xx! " } }
         body_{ " one more and it would be illegal " }
       }
     }
     puts doc.pretty


   ~ > ruby sample/a.rb

         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
         <html lang='en' xml:lang='en'
xmlns='http://www.w3.org/1999/xhtml'>
           <head>
             <title> go xx! </title>
           </head>
           <body> one more and it would be illegal </body>
         </html>


   <========< sample/b.rb >========>

   ~ > cat sample/b.rb

     require "xx"
     #
     # xml is as easy as html.  xx extends your object very carefully,
adding an
     # one method that is not prefaced with 'xx_' : 'method_missing'.
the
     # method_missing defined is conservatively, recognizing only
methods that end
     # with underscore ('_') as 'tag' methods intended to generate
markup. as with
     # html, attributes may be passed to any tag method as either symbol
or string.
     #

     class Table < ::Array
       include XX::XML
       attr "fields"
       def initialize *a, &b
         @fields = a.shift
         replace a
       end
       def self::[] *a, &b
         new *a, &b
       end
       def to_xml
         xml_{
           table_{
             each do |row|
               row_{
                 fields.zip(row) do |field, value|
                   field_(:name => field, 'width' => value.size){ value
}
                 end
               }
             end
           }
         }
       end
     end

     table = Table[
       %w( first_name last_name ssn ),
       %w( jane doe 424-24-2424 ),
       %w( john buck 574-86-4242 ),
     ]

     puts table.to_xml.pretty

   ~ > ruby sample/b.rb

         <?xml version='1.0'?>
         <table>
           <row>
             <field name='first_name' width='4'>jane</field>
             <field name='last_name' width='3'>doe</field>
             <field name='ssn' width='11'>424-24-2424</field>
           </row>
           <row>
             <field name='first_name' width='4'>john</field>
             <field name='last_name' width='4'>buck</field>
             <field name='ssn' width='11'>574-86-4242</field>
           </row>
         </table>


   <========< sample/c.rb >========>

   ~ > cat sample/c.rb

     require "xx"
     #
     # xx makes it impossible to generate invalid (syntactically)
invalid documents
     # - unless to instruct it in insert raw html or xml using the 'h_'
or 'x_'
     # methods.  text inserted with 't_' is automatically escaped.  like
all xx
     # methods these can have one or more underscores after them in case
there is a
     # collision with another method or the tag 'h', 'x', or 't' needs
to be
     # generated.
     #
     include XX::XML

     doc = xml_{
       root_{
         div_{ t_ "this is escaped < > & text" }
         div_{ h_ "this is raw <html>. & is not escaped" }
         div_{ x_ "<raw> xml </raw>" }
         div_{ x_{ even_{ entire_{ documents_{ "nest" } } } } }
       }
     }
     puts doc.pretty

   ~ > ruby sample/c.rb

         <?xml version='1.0'?>
         <root>
           <div>this is escaped &lt; &gt; &amp; text</div>
           <div>this is raw <html>. & is not escaped</div>
           <div><raw> xml </raw></div>
           <div><even><entire><documents>nest</documents></entire></even></div>
         </root>


   <========< sample/d.rb >========>

   ~ > cat sample/d.rb

     require "xx"
     #
     # xx has only a few methods which end in '_'.  these methods,
therefore, cannot
     # be used in conjuction with method_missing to auto-generate tags.
for those
     # methods a tag of the same method can be generated using and
escaped form,
     # namely two or more underscores always mean 'generate a tag'.
those methods
     # are:
     #
     #   - g_
     #   - text_
     #   - t_
     #   - h_
     #   - x_
     #   - c_
     #   - at_
     #   - att_
     #   - yat_
     #
     include XX::XML

     doc = xml_{
       root_{

         t_{ "this is a text element" }
         t__{ "this is not text, but a __tag__ called t" }

         x_{ "this un-escaped & < > stuff" }
         x__{ "this is not un-escaped & < > stuff but a tag called x" }
       }
     }
     puts doc.pretty


   ~ > ruby sample/d.rb

         <?xml version='1.0'?>
         <root>this is a text element<t>this is not text, but a __tag__
called t</t>this un-escaped & < > stuff<x>this is not un-escaped &amp;
&lt; &gt; stuff but a tag called x</x>
         </root>


HISTORY

   0.1.0:
     - added the "g_" method, which generates any tag
                                                    ^
         g_("anytag", "key" => "value"){ b_{ "bold" } }

     - added at_ and att_ methods to parse yaml and k=v strings as
hashes.

         at_("src : image.jpg, width : 100%")

           #=> {"src"=>"image.jpg", "width"=> "100%"}

   0.0.0:
     - initial version


AUTHORS

   dan fitzpatrick <dan@eparklabs.com>
   ara.t.howard <ara.t.howard@eparklabs.com>


BUGS

   please send bug reports to /dev/null.  patches to addresses above.
;-)


LICENSE

   ePark Labs Public License version 1 Copyright (c) 2005, ePark Labs,
Inc. and
   contributors All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
are met:

     1. Redistributions of source code must retain the above copyright
notice,
     this list of conditions and the following disclaimer.

     2. Redistributions in binary form must reproduce the above
copyright notice,
     this list of conditions and the following disclaimer in the
documentation
     and/or other materials provided with the distribution.

     3. Neither the name of ePark Labs nor the names of its contributors
may be
     used to endorse or promote products derived from this software
without
     specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS"
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE
   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE
   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR
   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER
   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY,
   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-a
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2006-02-13 22:18
(Received via mailing list)
ara.t.howard@noaa.gov wrote:

>   http://rubyforge.org/frs/download.php/8234/xx-0.1.0.tgz

I'd like to play around with this, as an alternative to Amrita.

But the tests are broken because here is no sample dir installed with
the gem. Is this fixable with gems?
Eb9493c94d8db9887e5f15284d2c767f?d=identicon&s=25 unknown (Guest)
on 2006-02-13 23:29
(Received via mailing list)
In article <1139862052.181308.280630@g14g2000cwa.googlegroups.com>,
Skeets <skillet3232@yahoo.com> wrote:
>does one exist?  i use an excellent php based forms class when i code
>in php.  it includes javascriput validation, server side validation,
>regex validation and a lot more.
>
>does ruby have something similar, or will i have to 1. code my own (not
>gonna happen anytime soon) or 2. just write the html out every time
>(not good)?
>

What about _why's Markaby:
http://markaby.rubyforge.org/

Phil
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-02-14 00:33
(Received via mailing list)
On Tue, 14 Feb 2006, Joel VanderWerf wrote:

> ara.t.howard@noaa.gov wrote:
>
>>   http://rubyforge.org/frs/download.php/8234/xx-0.1.0.tgz
>
> I'd like to play around with this, as an alternative to Amrita.
>
> But the tests are broken because here is no sample dir installed with
> the gem. Is this fixable with gems?

hmmm.  i'm not sure what to do - but i'm open to suggestion!  maybe i
should
just reloate the samples directory into the test directory?

for now you can just grab the tarball - sorry for inconvenience.

cheers.

-a
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2006-02-14 00:42
(Received via mailing list)
ara.t.howard@noaa.gov wrote:
>
> hmmm.  i'm not sure what to do - but i'm open to suggestion!  maybe i
> should
> just reloate the samples directory into the test directory?
>
> for now you can just grab the tarball - sorry for inconvenience.
>
> cheers.
>
> -a
>

Tnx! tests pass now.

However, the example at the end of xx.rb seems to be failing:

$ ruby lib/xx.rb
------------------------------------------
------------------------------------------
lib/xx.rb:200:in `method_missing': undefined method `cdata_' for [["0",
"1", "2"], ["a", "b", "c"]]:Table (NoMethodError)
        from lib/xx.rb:704:in `doc'
        from lib/xx.rb:72:in `create'
        from lib/xx.rb:48:in `tracking_additions'
        from lib/xx.rb:71:in `create'
        from (eval):10:in `script_'
        from lib/xx.rb:208:in `method_missing'
        from lib/xx.rb:704:in `doc'
        from lib/xx.rb:72:in `create'
         ... 10 levels...
        from lib/xx.rb:578:in `xhtml_'
        from lib/xx.rb:708:in `to_xhtml'
        from lib/xx.rb:724
        from lib/xx.rb:722
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-02-14 00:53
(Received via mailing list)
On Tue, 14 Feb 2006, Joel VanderWerf wrote:

>>> the gem. Is this fixable with gems?
>>
>        from lib/xx.rb:704:in `doc'
>        from lib/xx.rb:724
>        from lib/xx.rb:722

oops!  typo.  here's a fix


     harp:~/xx-0.1.0/xx-0.1.0 > diff -u lib/xx.rb.org lib/xx.rb
     --- lib/xx.rb.org       2006-02-13 16:50:38.000000000 -0700
     +++ lib/xx.rb   2006-02-13 16:50:52.000000000 -0700
     @@ -356,6 +356,7 @@
      #--}}}
            end
            alias_method "c_", "xx_cdata_"
     +      alias_method "cdata_", "xx_cdata_"
            def xx_parse_attributes string
      #--{{{
              string = string.to_s


i'll incorporate the fix into the next release - and hopefully figure
out the
test/sample bit too.  cheers.


-a
7a1d3c7a520355e32375a272b237036f?d=identicon&s=25 Skeets (Guest)
on 2006-02-14 01:03
(Received via mailing list)
the only reason i haven't jumped into rails head first is the forms
class...  regex, js and server validation, simple js commands
(background color, etc...), length, width and a ton more.

it will be tough to let go - since so much of good web development is
tied up in forms generation and validation.

decisions, decisions.
B2561fdd05855be51aca982c54eb9f81?d=identicon&s=25 John N. Alegre (Guest)
on 2006-02-16 21:09
(Received via mailing list)
Phil Tomson wrote:

> What about _why's Markaby:
> http://markaby.rubyforge.org/
>
> Phil
How can I install Markaby?

will

gem install markaby

work?

john
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-16 21:22
(Received via mailing list)
On Feb 16, 2006, at 12:08 PM, John N. Alegre wrote:

> gem install markaby
>
> work?
>
> john
>

yes

-Ezra
B2561fdd05855be51aca982c54eb9f81?d=identicon&s=25 John N. Alegre (Guest)
on 2006-02-16 23:29
(Received via mailing list)
On a similar note ....

Is there a class to parse a form and send the results in email?  I am
looking for something as "plug and play" as possible.

All comments welcome
john
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-02-17 00:20
(Received via mailing list)
DÅ?a Å tvrtok 16 Február 2006 23:28 John N. Alegre napísal:
> On a similar note ....
>
> Is there a class to parse a form and send the results in email?  I am
> looking for something as "plug and play" as possible.
>
> All comments welcome
> john
>

If very desperate, you can put a YAML dump of the form data in an
e-mail.

Personally, I don't think I'd use such a magic solution - I prefer a
good HTTP
request parser and a good mailer as separate components, than a
half-baked
mix and match of both.

David Vallner
B2561fdd05855be51aca982c54eb9f81?d=identicon&s=25 John N. Alegre (Guest)
on 2006-02-17 01:15
(Received via mailing list)
David (and list) ...

The parser is no issue that would be pretty much unique to the form and
I
have lots of experience with parser code.  What I really need is a
mailer
that will take SMTP host name or IP and the parsed form info and send it
of
to the correct (and sometimes different) email addy.

Any suggestions?
john
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-02-17 01:54
(Received via mailing list)
DÅ?a Piatok 17 Február 2006 01:13 John N. Alegre napísal:
> David Vallner wrote:
> > Personally, I don't think I'd use such a magic solution - I prefer a good
> > HTTP request parser and a good mailer as separate components, than a
> > half-baked mix and match of both.
> >
> > David Vallner

Net::SMTP? Not really a mailer though. I know Rails includes a Mailer
component. If I have my facts right, it uses a library called TMail to
create
the mail messages... The Net::SMTP documentation also recommends
RubyMail as
an option for mail generation.

So, you get the data from the form, compose the mail object to send
using
TMail or RubyMail, then use Net::SMTP to send the mail object. If what
you're
doing is simple enough to go without a full blown webapp framework, this
should work perfectly.

David Vallner
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-17 05:59
(Received via mailing list)
> Jon-


	Here is a little snippet that might help for sending emails from a
ruby script:


require 'net/smtp'



def send_mail(to, from, subject, body)
   msgstr = <<EOM
From: #{from}
To: #{to)
Subject: #{ subject }
MIME-Version: 1.0
Content-Type: text/html;

<html>
<style type='text/css'>
#m_b div { border: 1px solid #aaa; }
</style>
<body>
The following email is about...:<br />
<hr />
<div id='m_b'>
<div>#{ body }</div></div>
</body></html>
EOM
     Net::SMTP.start('mail.example.com', 25, 'mail.com', 'username',
'password', :login) do |smtp|
       smtp.send_message msgstr, "#{from}", "#{to}"
     end
     puts "Mail sent."
     puts "*"*30
     puts msgstr
end


heers-
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
http://yakimaherald.com
ezra@yakima-herald.com
blog: http://brainspl.at
This topic is locked and can not be replied to.