Introducing WysiHat Engine
Posted: October 1st, 2009 | Author: Jeff Kreeftmeijer | Filed under: Ruby on Rails | 13 Comments »Since we were tired of the ugliness and size of TinyMCE — our previous WYSIWYG solution —, we decided to see if we could find a good replacement.
Luckily 37signals released a WYSIWYG editor last year called WysiHat, the “eventually better open source WYSIWYG editor”, so we tried it out. It was simple, no fancy themes or color schemes, just the backend code.
After playing with it for a while, we found a lot of hidden and undocumented features like including images or adding unordered lists. We decided to fork the project to write some more examples.
WysiHat is a great project and has a lot of potential, but probably hasn’t got the attention it deserves for a while now. There are some missing features you’d expect from a WYSIWYG editor, but the general idea is very, very good.
Joshua Peek told us the project is on hold; “We’re planning to revisit the wysiwyg stuff in early 2010. So you can expect me to jump back in then.”, but we hope there will be more activity from the rest of the community before that.
The Engine
We built the standard stuff like image uploading and html editing using WysiHat for a project we’re working on and we thought others could use it so we built the “WysiHat Rails Engine” and released it to the world.
The goal for the engine was to quickly and easily be able to implement WysiHat editors in a project and doing so as pretty as possible. We extended the Rails Formbuilder to add the wysihat_editor form field. We added facebox and some other javascript goodness and worked out an easy to use uploader. This means you could do something like this, which would give you a fully functional WYSIWYG editor:
<% form_for(@page) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :content %><br />
<%= f.wysihat_editor :content %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
% end %>
This will give you a full editor. The Engine also includes stylesheets and a bunch of icons so it looks good out of the box:
- WysiHat Engine creates a full-featured editor.
- You can edit the HTML right out of the box.
- Uploading images and including them is super easy as well.
There’s a complete installation guide and an examples page in the github project wiki if you want to check it out.
Like WysiHat, this project is in a very early stage and like WysiHat, we would love you to help out and make this a great piece of software.
So if you have any issues, suggestions or ideas, don’t hesitate to create an issue on github, fork the project or contact us directly.
UPDATE – October 3
I got a lot of work done on the Engine yesterday. It’s a gem now and it’s hosted on gemcutter. The installation guide is updated, so that shouldn’t be a problem.
The ugly rake task is removed and I built a little generator, so all the stray folders in the root — like /public — are gone. I also removed the included plugins to add gem dependencies (paperclip and resource_controller) and added the responds_to_parent plugin installation to the generator, so you don’t have to worry about that. Installing the gem and running the generator is as simple as:
sudo gem install wysihat-engine
script/generate wysihat
While I was working on this, I realized the resource_controller gem is an unnecessary dependency. It will be removed as soon as possible to make place for a good ol’ controller. I think this will help users understand and use the gem better in their applications.
And let me say this one more time; have issues, ideas, suggestions or want to help out? Be sure to let us know!



WysiHat was always meant to be a small and focused core and allow for easy extension. I’ve been waiting a while to see some cool toolbar sets or plugins from the community.
This Rails plugin is really awesome. The image uploading flow is a great example of how a wysiwyg editor can improve the user experience.
Looks very promising! If they can fix the “paste from Word” issue I’d switch in an instant.
Hi Martijn,
We built a :buttons option called :paste. This allows you to copy anything and paste it in without the layout.
That’s probably not what you meant. If I understand correctly, you’re talking about a feature that will allow you to paste content from word and preserve the layout, rather than removing it (something like TinyMCE has).
I think that would be an awesome feature and maybe that kind of (backend) functionality would even be great to put into the WysiHat core. I will definitely look into this!
If you have any ideas on how to do this or if you would like to help building this that’d be great!
I’ve had sanitization built in from the start to address this problem.
// Custom sanitization
editor.outputFilter = function(text) {
return text.formatHTMLOutput().sanitize({
tags: ['span', 'p', 'br', 'strong', 'em', 'a'],
attributes: ['id', 'href']
});
};
// Clean up editor on paste
editor.observe("wysihat:paste", function(event) {
setTimeout(function() {
event.target.reload();
}, 1);
});
Nothing but pure brilliance!
A while back I was looking for (asked around twitter, searched through google, even asked Jeff Kreeftmeijer himself for his opinion and suggestions!) to find a good WYSIWYG editor I could repeatedly use without switching back and forth editors per project. (Inconsistency is one of the things I truly hate).
I’ve used a couple of rich text editors, but always found them way to heavy or inflexible and extremely irritating to implement and customize. I prefer keeping all my logic bundled inside my Rails application. By “logic” I mean scripting/programming logic. So having to go into Javascript mode to do all sorts of things to my “text area” to get it working inside a different layer of my application, which does not consist of a single line of Ruby.. No Thanks!
Enter: “WysiHat Engine”.
Giving me a WYSIWYG’d text area by replacing “form.text_area” with “form.wysihat_editor” and, on the same line, telling it what buttons I wish to use? Brilliant! Need image uploading? :buttons => [:image]. Now, the other part I like, is the fact that this does not come with a whole pre-installed GUI like basically every other WYSIWYG out there. It gets wrapped inside of divs and you get all the flexibility to style the GUI to your web application’s style with ease.
All I can say is thank you for bringing me “the missing WYSIWYG editor” to us in such an elegant, easy to use and robust way!
And all I can do is FORK and SUGGEST!
I would love to see both this “WysiHat Engine” as well as the “WysiHat Javascript Core” evolve over time!
@josh thanks! I’ll be replacing that piece of code to use your sanitize feature!
@michael thanks for your kind words, but the credit for this goes to Joshua Peek:
“thank you for bringing me “the missing WYSIWYG editor” to us in such an elegant, easy to use and robust way!”
@jeff no problem. Thank you!
Regarding the Quote:
I gave you credit for “bringing” the missing editor to us in an elegant, easy to use and robust way!
Cause without the WysiHat Engine I might’ve never looked into WysiHat itself at all! And now I don’t really “have” to thanks to this Engine.
So, thank you for that, my friend! ;)
While I love that you picked up Josh’ work on WysiHat, I’d love to see this be more unobtrusive – that inline JS just looks scary as hell. Why not make it unobtrusive by just adding a :class => ‘wysiwyg’ to the textarea and handle the rest in JS? Or am I missing something?
@Clemens: You are absolutely right. I must admit that we haven’t had a good look at the front-end yet, and we should definitely do that on a short term.
Hi Clemens,
You’re absolutely right and I’m planning on doing that. At first, the javascript code needed was pretty small so I put it inline. But as I added helpers it grew.
Expect a fix very soon and thanks for pointing it out!
Update – October 3, 9:39 PM
We just pushed a new version of the gem. It has a file called wysihat_engine.js which holds most of the javascript that was inline (except for the addButton() calls). :)
I’d like to see a jQuery version or even better an agnostic one
@Santiago: WysiHat was created on top of Prototype. Although it would certainly be great to be able to use it with other JS frameworks (or none at all), it’s outside of the scope of this project. We would be happy to implement support for non-Prototype based WysiHat forks in our engine though.
I want a image insert button ( Insert an image with url), how can I add it?