Arc Forumnew | comments | leaders | submit | namaste's commentslogin

This challenge has made me create three different solutions all present in the comments, but I'll show where they are within my custom Web Framework:

dewd@rubynho:~/code/libraries/web_rules/examples/arcchallenge$ ls

jsp_said.rtj php_said.rtj said.rb

The cool thing is that they work simultaneously, just like multiple "php pages" would in a PHP setup. The future should look like this in my opinion. :-)

-----


Here's the same thing translated into Ruby + custom Web Framework + Tenjin:

<?rb

  if @w.req.post?
    @w.session['said'] = @w.f('said')
    @w << '<a href="">click here</a>'
  else
    if @w.session['said']
      @w << "You said: #{@w.session['said']}"
      @w.session.unset 'said'
    else
      @w << '<form method="post">'
      @w << '<input type="text" name="said">'
      @w << '<input type="submit">'
      @w << '</form>'
    end
  end

?>

BTW, your example made me spot a bug and fix it and also add the "unset" method to the Session class. Cool enough. Thanks! :-)

-----


Here's this same thing translated to Ruby + custom Web Framework + Tenjin (which does the escaping with the ${} command. #{} and it does not escape.)

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <title>Contrived example</title></head><body><div>
  <?rb if not @w.session['page']
        @w.session['page'] = '1' ?>
        <form action="jsp_said" method="post">
        <div><label>Enter something <input type="text" name="foo"/>
        <input type="submit"/></label></div></form>
  <?rb elsif @w.session['page'] == '1'
        @w.session['page'] = '2'
        @w.session['value'] = @w.f('foo') ?>
        <a href="jsp_said">click here</a>
  <?rb elsif @w.session['page'] == '2'
        @w.session["page"] = nil ?>
        you said: ${@w.session['value']}
  <?rb end ?>
  </div></body></html>

-----


I've been able to create one using Ruby and my Web Framework like this:

  tt = [
      '<form method="POST"><input name="t" /><input type="submit" name="OK"></form>',
      '<a href="said?show=1">click here.</a>', 
      "you said: #{@w.session['t']}"
      ]
  ti = 0    
  if @w.f(:OK)
    @w.session['t'] = @w.f(:t) 
    ti = 1
  elsif @w.q(:show)
    @w.session['do_show'] = true
    @w.redirect 'said'
  elsif @w.session['do_show']
    @w.session['do_show'] = nil
    ti = 2
  end
  @w.content = tt[ti]
I'm not sure how other folks will solve it though. It's interesting that my Web Framework has support for both pure Ruby like this, and for a templated approach similar to PHP but using Tenjin: * http://www.kuwata-lab.com/tenjin/

I wanted to keep it all in one URL and without template for this though. I'm not sure I'd normally program it like that, as I enjoy multiple pages and URLs. Anyway, many ways to skin a cat, and Arc did good.

P.S. In the past my framework had a more "programming" approach which was based on ideas I grasped from Wee which was itself based on Seaside. But since it has been dropped, but your challenge reminds me of it.

-----

1 point by namaste 6175 days ago | link | parent | on: Congrats on the release

Yay! Good job! Kudos on your creation.

-----