Railsers: I have this friend who keeps claiming that all HTML in a website should be pure XHTML. He claims this ideal follows a general and a specific guideline. The general guideline is that all code should be of the highest possible quality, with no compromises. Specifically, HTML should never rely on "browser forgiveness", and get by with mis-matched tags, ill-formed markup, missing required attributes, etc. No more programming websites in Notepad. The specific guideline is that if your code is pure XHTML, you can parse it with XPath at test time. XPath makes a great way to query into a page and chop out details, competitive with assert_select() or assert_tag(). So I don''t want to tell my friend that Rails doesn''t produce pure XHTML. For example, here''s a generated script tag: <script type=''text/javascript'' src=''/javascripts/dragdrop.js?1162442777'' > "What''s the hell is wrong with that???" I hear you scream (clear across the ''net). It''s the first problem XPath finds: the > should be /> Any chance of fixing this, for all of Rails? To appease my friend?? -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phlip wrote:> Railsers: > > I have this friend who keeps claiming that all HTML in a website > should be pure XHTML. > > So I don''t want to tell my friend that Rails doesn''t produce pure > XHTML. For example, here''s a generated script tag: > > <script > type=''text/javascript'' > src=''/javascripts/dragdrop.js?1162442777'' > > > "What''s the hell is wrong with that???" I hear you scream (clear > across the ''net). > > It''s the first problem XPath finds: the > should be /> > > Any chance of fixing this, for all of Rails? To appease my friend??Your friend is a smart dude. But so is Rails. according to my uses, javascript_include_tag(:foo) produces: <script src="/javascripts/foo.js" type="text/javascript"></script> And javascript_tag("alert(''foo'')") produces: <script type="text/javascript"> //<![CDATA[ alert(''foo''); //]]> </script> Both of which are perfectly valid XHTML -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alex Wayne wrote:> according to my uses, javascript_include_tag(:foo) produces: > > <script src="/javascripts/foo.js" type="text/javascript"></script>Uh, Edge? My standard layout sez: <%= stylesheet_link_tag(''application'') + javascript_include_tag(''prototype'') + javascript_include_tag(:defaults) %> (Someone got creative with the style there.) Curiously, look what it''s producing: <link href=''/stylesheets/application.css?1163738349'' rel=''Stylesheet'' type=''text/css'' media=''screen'' /> <script type=''text/javascript'' src=''/javascripts/prototype.js?1162442777''> The LINK has a /> on the end and the SCRIPT> > And javascript_tag("alert(''foo'')") produces: > > <script type="text/javascript"> > //<![CDATA[<script type=''text/javascript''> //<![CDATA[<![CDATA[> alert(''foo''); > //]]> > </script> > > Both of which are perfectly valid XHTML > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alex Wayne wrote:> according to my uses, javascript_include_tag(:foo) produces:> <script src="/javascripts/foo.js" type="text/javascript"></script>Uh, Edge? My standard layout sez: <%= stylesheet_link_tag(''application'') + javascript_include_tag(''prototype'') + javascript_include_tag(:defaults) %> (Someone got creative with the style there;) Curiously, look what it produces: <link href=''/stylesheets/application.css?1163738349'' rel=''Stylesheet'' type=''text/css'' media=''screen'' /> <script type=''text/javascript'' src=''/javascripts/prototype.js?1162442777''> The LINK has a /> on the end and the SCRIPT tag doesn''t!> And javascript_tag("alert(''foo'')") produces:> <script type="text/javascript"> > //<![CDATA[One of my JavaScript generators, periodically_call_remote(), produces this: <script type=''text/javascript''> //<![CDATA[<![CDATA[ That SCRIPT contents sure is insulated from decade-old browsers! All this is from ''puts html_document.root'', in a functional test. I''m not concerned about the specific details so long as XHTML is the general goal... -- Phlip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Sun, 19 Nov 2006, Phlip wrote:> My standard layout sez: > > <%= stylesheet_link_tag(''application'') + > javascript_include_tag(''prototype'') + > javascript_include_tag(:defaults) %> > > (Someone got creative with the style there;) > > Curiously, look what it produces: > > <link href=''/stylesheets/application.css?1163738349'' rel=''Stylesheet'' > type=''text/css'' media=''screen'' /> > <script type=''text/javascript'' > src=''/javascripts/prototype.js?1162442777''>I guess it''s fixed in edge; I dropped your lines into a layout and got: <link href="/stylesheets/application.css" media="screen" rel="Stylesheet" type="text/css" /> <script src="/javascripts/prototype.js?1163852948" type="text/javascript"></script> <script src="/javascripts/prototype.js?1163852948" type="text/javascript"></script> <script src="/javascripts/effects.js?1163852948" type="text/javascript"></script> <script src="/javascripts/dragdrop.js?1163852948" type="text/javascript"></script> <script src="/javascripts/controls.js?1163852948" type="text/javascript"></script> <script src="/javascripts/application.js?1163852948" type="text/javascript"></script> David -- David A. Black | dblack-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Nov 19, 2006 at 06:49:28AM +0100, Alex Wayne wrote: } Phlip wrote: } > Railsers: } > } > I have this friend who keeps claiming that all HTML in a website } > should be pure XHTML. } > } > So I don''t want to tell my friend that Rails doesn''t produce pure } > XHTML. For example, here''s a generated script tag: } > } > <script } > type=''text/javascript'' } > src=''/javascripts/dragdrop.js?1162442777'' > } > } > "What''s the hell is wrong with that???" I hear you scream (clear } > across the ''net). } > } > It''s the first problem XPath finds: the > should be /> } > } > Any chance of fixing this, for all of Rails? To appease my friend?? } } Your friend is a smart dude. But so is Rails. [...] I haven''t tried this on edge, but I will mention that current stable Rails actually strips out the / on empty XML tags. For example, if I have <wbr /> in a .rhtml file, when it gets to the browser it has become <wbr>. I hope this is fixed in edge, but I don''t have time to check. --Greg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Sun, 19 Nov 2006, Gregory Seidman wrote:> I haven''t tried this on edge, but I will mention that current stable Rails > actually strips out the / on empty XML tags. For example, if I have <wbr /> > in a .rhtml file, when it gets to the browser it has become <wbr>. I hope > this is fixed in edge, but I don''t have time to check.A brief test (sticking <br/> into my default layout) suggests that it''s been fixed in edge. David -- David A. Black | dblack-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gregory Seidman wrote:> I haven''t tried this on edge, but I will mention that current stable Rails > actually strips out the / on empty XML tags. For example, if I have <wbr />Parenthetically, what''s <wbr/>?> in a .rhtml file, when it gets to the browser it has become <wbr>. I hope > this is fixed in edge, but I don''t have time to check.This gets us close to the FAQ "should I switch to Edge?" The answer is, as usual, "If you have to ask, you shouldn''t!" Any project should use that metric as the definition for its Edge version! ;-) Now here''s why we like XPath. I have a simple assert_xpath that works like this: @xdoc = Document.new(someFragment) assert_xpath ''//span[@id="defeat_myspace"]'' do assert_xpath ''/img[@src="goForIt.png"]'' end The source is below my sig. Currently, I can''t drop an entire (non-Edge) page into someFragment, so I use assert_tag or assert_select to extract one, or I get one directly from one of my own XHTML-generating methods. The assertion passes a node to the sought path into its block. This allows the inner block to assert as if all the outer block''s path were prepended to its own path. So in just a few lines of code I compete with assert_select(), and blow assert_tag() away. XPath''s query system is awesome enough to let me embed the = != < > criteria right into its selection string. For my next magical trick, I will create an XPath generator that lets you go assert_xpath.span(:id=>''defeat_myspace) etc. Ruby is at the forefront of the languages that make dicking with your test rig much more fun that working on your smegging project! ;-) -- Phlip class Test::Unit::TestCase def assert_xpath(path, &block) node = XPath.first(@xdoc, path) assert_not_nil node was_xdoc = @xdoc @xdoc = node block.call(@xdoc) if block return node ensure @xdoc = was_xdoc end # CONSIDER better diagnostics? def assert_no_xpath path node = XPath.first(@xdoc, path) assert_nil node end end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
There''s talk here of "fixed on edge", but I''m *not* running edge, and my code generates perfectly good XHTML. No stripping of trailing slashes, and script tags are closed. I''m running rails 1.1.6, ruby 1.8.4 on win32. -Brian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 19 Nov 2006, at 05:21, Phlip wrote:> I have this friend who keeps claiming that all HTML in a website > should be pure XHTML. > > He claims this ideal follows a general and a specific guideline. The > general guideline is that all code should be of the highest possible > quality, with no compromises. Specifically, HTML should never rely on > "browser forgiveness", and get by with mis-matched tags, ill-formed > markup, missing required attributes, etc. No more programming websites > in Notepad.For browsers, it won''t really make a difference. In fact, some of the current browsers don''t understand XHTML at all (Internet Exploder 6 for example). Other browsers like Safari do, but only if the header coming from the server tells it it''s XHTML (application/xhtml+xml). You should really read this blog article from "Surfin Safari". It''s an eye-opener and is valid for all current browsers. http://webkit.org/blog/?p=68 That said, I like to develop my sites using XHTML and validating at W3C (the validator doesn''t need the http header, it valides according to the doctype set), just to refrain myself from mixing in presentation tags (which belong in the CSS file). Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The spectre of and its ilk raise their ugly head. I suspect that some XMLs deny the existence of , so you have to add some hack, such as the matching Unicode point. But maybe I''m only experienced with REXML idiosyncracies. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Nov 19, 2006 at 06:10:14PM -0000, Phlip wrote: } } The spectre of and its ilk raise their ugly head. } } I suspect that some XMLs deny the existence of , so you have to } add some hack, such as the matching Unicode point. } } But maybe I''m only experienced with REXML idiosyncracies. See http://www.tbray.org/ongoing/When/200x/2006/11/09/Optimizing-Ruby for some discussion of XML parsing in Ruby. --Greg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---