Re: XHTML/WO help for XCode
Re: XHTML/WO help for XCode
- Subject: Re: XHTML/WO help for XCode
- From: Michael Engelhart <email@hidden>
- Date: Sun, 23 May 2004 17:11:11 -0500
Not sure why it didn't work but the scripting mechanism is a bit
bizarre and in my experience is a bit touchy. I did it at home first
and tried it at work and it didn't work the first attempt either.
Anyway, I also ran into the WORepition problem just the other day and
am trying to come up with a way to work around that with one of the
tidy switches. I'll post back if I find anything.
Mike
On May 23, 2004, at 5:08 PM, D Tim Cummings wrote:
I tried this and it didn't work (never worked out why). However, I
modified the script based on the example in Sort File and it worked in
place and gave the ability to undo and doesn't need the Applescript.
This worked great except my files often use WORepetition's around <tr>
tags and 'tidy' cleans out all tags in a table and puts them before
the table, so in the end it wasn't much use to me.
#! /bin/sh
#
# -- PB User Script Info --
# %%%{PBXName=HTML -> XHTML}%%%
# %%%{PBXInput=AllText}%%%
# %%%{PBXOutput=ReplaceAllText}%%%
# %%%{PBXKeyEquivalent=}%%%
echo -n "%%%{PBXSelection}%%%"
/usr/local/bin/tidy -config /usr/local/etc/tidy.config <&0
echo -n "%%%{PBXSelection}%%%"
On 19/04/2004, at 13: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.