• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: XHTML/WO help for XCode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XHTML/WO help for XCode


  • Subject: Re: XHTML/WO help for XCode
  • From: Frank Hoffsümmer <email@hidden>
  • Date: Sun, 16 May 2004 22:54:23 +0200

hello Mike,
I am new to WebObjects, but I found your post extremely interesting and relevant. thanks for sharing this!


Following your instructions I noticed that through the use of osascript, you can get rid of the extra applescript. So all I did was create a file "10-convertToXHTML.sh" in the directory /Library/Application Support/Apple/Developer Tools/Scripts/10-User Scripts/70-WebObjects that looks a bit like this:


#!/bin/sh # # -- PB User Script Info -- # %%%{PBXName=HTML -> XHTML}%%% # %%%{PBXKeyEquivalent=}%%%

/sw/bin/tidy -config /sw/etc/tidy_wo.config %%%{PBXFilePath}%%%

/usr/bin/osascript <<EOF
tell application "Finder"
	activate
end tell
tell application "Xcode"
	activate
end tell
EOF

(I used fink to install tidy, hence my tidy is found in /sw/bin. I put your tidy.config into /sw/etc/tidy_wo.config)
This works like a charm, except that the toggle between Finder and XCode doesn't refresh the tidied document (I have to close and re-open it)
...strange. But to my delight, WO Builder operates on the converted files just fine


(here is hoping that there will be major WO and XCode updates around WWDC2004)

thanks again
-frank








On 2004-04-19, at 05.28, Michael Engelhart wrote:

I apologize to any Windows/Eclipse users but this tip is only useful XCode users (although the process could probably be duplicated in either of those environments as well using different means).

I noticed there was a fair amount of interest in having XCode display XHTML code instead of the HTML code that WOBuilder generates. I had played around with different ideas and my last system was to open the document in BBEdit and use it's "Format" utility tool to clean up the code. This worked but was clunky because I didn't want to switch editors and if you don't have BBEdit it doesn't work at all. :-)

I just created a new solution if anyone is interested that uses the HTML Tidy library (http://tidy.sourceforge.net/ and http://www.w3.org/People/Raggett/tidy/) and integrates it with Xcode's scripting capability. Tidy has a ton of options for generating and cleaning up HTML/XHTML/XML documents and also has the ability to read a configuration file that you can tweak which allows for custom versions of what I've made for my use - see here: http://tidy.sourceforge.net/docs/quickref.html
so it's not just useful for converting to XHTML, it will also fix errors in your HTML like closing attribute quotes, etc. See documentation for what all it can do.



Here's what I did (many of these steps except installing HTML Tidy can be modified to your liking - i.e. directory names, script names, etc.)


1) Download HTML Tidy from the SourceForge site and configure, make, make install - just follow the instructions included in the src distribution. It installs into /usr/local/bin by default. There's also a binary for Mac OS X if you just want to do that although I didn't try that option and can't vouch for it.
2) Create a directory called "70-WebObjects" in your /Library/Application Support/Apple/Developer Tools/Scripts/10-User Scripts/ directory. This puts a WebObjects submenu in the scripting menu of XCode
3) Create an AppleScript script called "Refresh-XCode.scpt" with following code (I'll explain later):


tell application "Finder"
	activate
end tell
tell application "Xcode"
	activate
end tell

and save it in this new 70-WebObjects directory as a script file.

4) Create a file called "10-convertToXHTML.sh" and put the following code in it:

#! /bin/sh
#
# tidy.config is stored in /usr/local/etc/
#
# -- PB User Script Info --
# %%%{PBXName=HTML -> XHTML}%%%
# %%%{PBXKeyEquivalent=}%%%

/usr/local/bin/tidy -config /usr/local/etc/tidy.config %%%{PBXFilePath}%%%
osascript "/Library/Application Support/Apple/Developer Tools/Scripts/10-User Scripts/70-WebObjects/Refresh-XCode.scpt"


5) Create a file called tidy.config and put it in /usr/local/etc ( you may need to create this or modify the script in step 4 to point to where you saved it) with this information (you can modify this later to your liking):

new-inline-tags: webobject
output-xhtml: true
doctype: strict
indent: true
write-back: true
tidy-mark: false
show-warnings: false
quiet: true
wrap: 0

6) Quit out of XCode and open a project that has some standard WebObjects HTML in it's WOD file. I suggest using a test project since the output this creates may not be to your liking. This setup actually rewrites the file so you can't undo it after you've run the script on a file.

7) Click in the text area of an HTML file in XCode, go to the Scripts menu (AppleScript icon to the left of Help) and select WebObjects:HTML -> XHTML. You should now have valid XHTML in the HTML file completely rewritten by Tidy.

Again, I can't stress enough that this may not be what you want to happen so please test it out on some backup versions of projects or use the Example proejcts in the /Developer directory. Now the reason for step 3 and running the osascript command that switches the frontmost process to the FInder and back to XCode is because for some reason, XCode won't update it's view when the underlying file has changed at least by a script. I thought XCode did monitor for file changes but I couldn't figure out why and this little script forces a refresh to show you the new XHTML version. If anyone knows why this is needed or how to fix, let me know.

ANyway, I can see a lot of other ways to extend the shell script to doing a project wide update by looping through the HTML files in the different directories but have only started playing around with it for an hour or so. Enjoy.

Mike
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: To Many Fault and Locking
  • Next by Date: Off Topic : WWDC Birds of Feather
  • Previous by thread: Re: To Many Fault and Locking
  • Next by thread: Re: XHTML/WO help for XCode
  • Index(es):
    • Date
    • Thread