# Extracting HTML/Javascript from Rails

**URL:** <https://www.ruby-forum.com/t/extracting-html-javascript-from-rails/85873>\
**Category:** Rails\
**Created:** [February 17, 2007, 1:42am UTC](https://www.ruby-forum.com/t/extracting-html-javascript-from-rails/85873 "2007-02-17T01:42:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@bryan82](https://www.ruby-forum.com/u/bryan82)\
**Post date:** [February 17, 2007, 1:42am UTC](https://www.ruby-forum.com/t/extracting-html-javascript-from-rails/85873/1 "2007-02-17T01:42:12Z")

</div>

Hi.

Is there a way, or has anyone written anything that would let me extract  
the HTML and Javascript code that Rails generates? I’m going to be  
applying for a front-end design position, and would like to be able to  
show some samples from my Rails work without having to run the apps. I  
can only get so much with View Source.

I also love developing using helpers, RJS and HAML. It would be awesome  
to be able to use these tools, and output straight XHTML and Javascript  
for a non-Rails environment.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![bryan82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@bryan82](https://www.ruby-forum.com/u/bryan82)\
**Post date:** [February 17, 2007, 2:07am UTC](https://www.ruby-forum.com/t/extracting-html-javascript-from-rails/85873/2 "2007-02-17T02:07:44Z")

</div>

Bryan M. wrote:

> Hi.
> 
> Is there a way, or has anyone written anything that would let me extract  
> the HTML and Javascript code that Rails generates? I’m going to be  
> applying for a front-end design position, and would like to be able to  
> show some samples from my Rails work without having to run the apps. I  
> can only get so much with View Source.
> 
> I also love developing using helpers, RJS and HAML. It would be awesome  
> to be able to use these tools, and output straight XHTML and Javascript  
> for a non-Rails environment.
> 
> Any thoughts?

Turn on page caching for all your actions in all your controllers, and  
then go to all the pages in your browser.

All your html would dumped to the public directory. However things like  
redirects after form submit would not work.

---

<div class="post-metadata">

**Author:** ![bryan82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@bryan82](https://www.ruby-forum.com/u/bryan82)\
**Post date:** [February 17, 2007, 4:09am UTC](https://www.ruby-forum.com/t/extracting-html-javascript-from-rails/85873/3 "2007-02-17T04:09:40Z")

</div>

WebDeveloper Toolbar for firefox has an option called view generated  
source. You can also view the generated JS with that tool. Another  
little neat tool is View Source Chart for Firefox which lets you see  
the generated DOM tree.

> I also love developing using helpers, RJS and HAML. It would be awesome  
> to be able to use these tools, and output straight XHTML and Javascript  
> for a non-Rails environment.

I can only think of XPath/XSLTs for this.

On Feb 16, 7:42 pm, Bryan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![bryan82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@bryan82](https://www.ruby-forum.com/u/bryan82)\
**Post date:** [February 17, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/extracting-html-javascript-from-rails/85873/4 "2007-02-17T16:02:45Z")

</div>

removed\_email\_address@domain.invalid wrote:

> WebDeveloper Toolbar for firefox has an option called view generated  
> source. You can also view the generated JS with that tool. Another  
> little neat tool is View Source Chart for Firefox which lets you see  
> the generated DOM tree.
> 
> > I also love developing using helpers, RJS and HAML. It would be awesome  
> > to be able to use these tools, and output straight XHTML and Javascript  
> > for a non-Rails environment.
> 
> I can only think of XPath/XSLTs for this.
> 
> On Feb 16, 7:42 pm, Bryan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thank you both!

---

<div class="post-metadata">

**Author:** ![bryan82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@bryan82](https://www.ruby-forum.com/u/bryan82)\
**Post date:** [March 1, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/extracting-html-javascript-from-rails/85873/5 "2007-03-01T18:28:03Z")

</div>

Haml can actually be generated in a non-Rails environment.

Just install the gem

gem install haml

and then include it

require ‘rubygems’  
require ‘haml’

haml\_object = Haml::Engine.new(“%haml”)  
haml\_object.render #returns the XHTML

Hope this helps!

-hampton.

On Feb 17, 10:02 am, Bryan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
