Interesting approach ! Should be a good intermediate step, ... ... what I was thinking of (don't know yet if it's possible at all ;-) ... is a wysiwyg html editor combined with a syntax highlighter (for the embedded Python code)
here is a first attempt, I'm making for totally other project, the code syntax is not highlighted yet, but you can embed nicely indented Python code. The idea is to reserve a range of tags to indicate code. In the example above, the Python code is extended with a lot of global functions (like in web2py ;-) and the Python language is made case insensitive, that all for non-programmers to make programs. cheers, Stef Mientki On 04-08-2010 15:39, Michael Ellis wrote: > As my application's views have become more complex, I've also been > considering the same questions concerning Python vs HTML coding. I've > tried using the helpers but my brain finds the stacks of parentheses > even more confusing than HTML closing tags. Currently, I'm defining > functions in my views that encapsulate frequently used blocks of HTML > in triple-quoted strings. I use standard python dictionary > substitution, %(name)s to inject parameters. Here's a relatively > simple example. > > def responseslider(inp,inpid,label): > inpval = inp['_value'] > html = """ > <li class=respond.slider> > <table class=respond> > <tr> > <td class="inset"></td> > <td> > <div class="slider_wrapper"> > %(inp)s > <div id="slider_%(inpid)s" ></div> > <span id="slider_%(inpid)s_val">% > (inpval)s</span> > </div> > </td> > <td>%(label)s</td> > </tr> > </table> > </li> > """%locals() > return XML(html) > > This seems, for my application at least, to be the best approach I've > found so far. > > One thing that's occurred to me is how nice it would be if we could > use python-style indentation instead of closing tags when writing HTML > in views. So in the example above, suppose the HTML could be > simplified to: > > <li class=respond.slider> > <table class=respond> > <tr> > <td class="inset"> > <td> > <div class="slider_wrapper"> > %(inp)s > <div id="slider_%(inpid)s" > > <span id="slider_%(inpid)s_val">% > (inpval)s > <td>%(label)s > > The indentation rules would be similar to Python's. Any opening tag > would behave like colon-terminated python conditional; the parser > would defer generating a closing tag until the indentation level > returned to the original level. I believe there would be no ambiguity > as long as the indentation is correct, but perhaps there's a case I > haven't thought of. I searched to see if someone has done something > like this before but so far haven't found anything. > > I think it's worth noting that when HTML came into being in the late > 80's the universe of digital documents contained a lot of text files > that just needed a little markup to render them more attractively -- > so a language with closing tags made sense because the ratio of markup > to text was very low and transmission bandwidth was limited. Nowadays > the situation is largely the opposite. Most web pages are mostly > markup because users have come to expect very high-quality > presentation. The markup to text ratio in a typical page from the > online web2py book -- surely a text-heavy document as web pages go -- > is more than 5 to 1. > > It's clear that, as web authors, we need all the help we can get. > > Cheers, > Mike > > On Aug 4, 5:16 am, Phyo Arkar <[email protected]> wrote: >> Current way is good enough , it gives programmers choices. >> Many of us want to code in HTML as Long as they are static >> . >> May be pure python templating system which can be enable from response.view >> >> >> >> On Wed, Aug 4, 2010 at 3:40 PM, mdipierro <[email protected]> wrote: >>> This is a good point. >>> to do it with the current web2py the code at best would look like >>> this: >>> Stef Mientki >>> View profile Translate to Translated (View Original) >>> More options Aug 4, 3:39 am >>> From: Stef Mientki <[email protected]> >>> Date: Wed, 04 Aug 2010 10:39:48 +0200 >>> Local: Wed, Aug 4 2010 3:39 am >>> Subject: this must be asked a 1000 times, but I couldn't find the >>> answer >>> Reply | Reply to author | Forward | Print | Individual message | Show >>> original | Remove | Report this message | Find messages by this author >>> please forgive my ignorance, >>> but I wonder why views are not written in Python, instead of html >>> ( see comparison below of te first >>> part of default\index.html. >>> The advantage of using Python: >>> - the user can stick to 1 language >>> - no redundant information in the closing tags, like <ul> , </ul> >>> - most editors checks the closing brackets >>> - normal indentation, no problems with missing "pass" >>> The disavantages of using Python: >>> - ??? >>> thanks, >>> Stef Mientki >>> {{extend 'layout.html' }} >>> {{ >>> if 'message' in globals () : >>> =H2 ( message ) >>> else: >>> =BEAUTIFY ( response._vars ) >>> pass >>> = HR () >>> = H1 ( 'README' ) >>> = UL ( >>> LI ( T ( 'You are successfully running web2py' ) ), >>> LI ( T ( 'This is a copy of the scaffolding application' ) ), >>> LI ( T ( 'You can modify this application and adapt it to your >>> needs' ) ), >>> LI ( T ( A ( B ( T ( "click here for the administrative >>> interface")), >>> __href = URL ( 'admin', 'default', 'index' ) ) )) ), >>> LI ( A ( T ( "click here for online examples"), >>> _href = URL ( 'examples', 'default', 'index' ) ) ), >>> '...') >>> }} >>> I.e. >>> - extend, include, block and pieces of code must be between different >>> sets {{...}}. >>> - printed values must have the = prefix >>> - close blocks with pass >>> Removing completely the {{...}} and "=" would require some changes in >>> the template system. >>> I guess it could be an option. >>> On Aug 4, 3:39 am, Stef Mientki <[email protected]> wrote: >>>> please forgive my ignorance, >>>> but I wonder why views are not written in Python, instead of html ( see >>> comparison below of te first >>>> part of default\index.html. >>>> The advantage of using Python: >>>> - the user can stick to 1 language >>>> - no redundant information in the closing tags, like <ul> , </ul> >>>> - most editors checks the closing brackets >>>> - normal indentation, no problems with missing "pass" >>>> The disavantages of using Python: >>>> - ??? >>>> thanks, >>>> Stef Mientki >>>> # *************************************************************** >>>> extend ( 'layout.html' ) >>>> if 'message' in globals () : >>>> H2 ( message ) >>>> else: >>>> DISPLAY ( BEAUTIFY ( response._vars ) ) >>>> HR () >>>> H1 ( 'README' ) >>>> UL ( >>>> LI ( T ( 'You are successfully running web2py' ) ), >>>> LI ( T ( 'This is a copy of the scaffolding application' ) ), >>>> LI ( T ( 'You can modify this application and adapt it to your needs' ) >>> ), >>>> LI ( T ( A ( B ( T ( "click here for the administrative interface")), >>>> _HREF ( URL ( 'admin', 'default', 'index' ) ) ) ) ), >>>> LI ( A ( T ( "click here for online examples"), >>>> _HREF ( URL ( 'examples', 'default', 'index' ) ) ) ), >>>> LI ( HREF ( "http://web2py.com", 'web2py.com' ) ), >>>> LI ( HREF ( "http://web2py.com/book", T ( 'documentation' ) ) ) ) >>>> # *************************************************************** >>>> {{extend 'layout.html'}} >>>> {{if 'message' in >>> globals():}}{{=H2(message)}}{{else:}}{{=BEAUTIFY(response._vars)}}{{pass}} >>>> <hr /> >>>> <h1>README</h1> >>>> <ul> >>>> <li>{{=T('You are successfully running web2py')}}</li> >>>> <li>{{=T('This is a copy of the scaffolding application')}}</li> >>>> <li>{{=T('You can modify this application and adapt it to your >>> needs')}}</li> >>>> <li>{{=A(B(T("click here for the administrative interface")), >>>> _href=URL('admin','default','index'))}}</li> >>>> <li>{{=A(T("click here for online examples"), >>> _href=URL('examples','default','index'))}}</li> >>>> <li><a href="http://web2py.com">web2py.com</a></li> >>>> <li><a href="http://web2py.com/book">{{=T('documentation')}}</a></li> >>>> </ul>
<<inline: moz-screenshot.png>>

