开发者

Are there tools to translate any website into the templates its framework is using?

开发者 https://www.devze.com 2022-12-19 21:46 出处:网络
Rails, for example, has a defined set of patterns it uses to define ids and other attributes in html, for example <input id=\"project[task_attributes][]\" .../> is the result of something like &

Rails, for example, has a defined set of patterns it uses to define ids and other attributes in html, for example <input id="project[task_attributes][]" .../> is the result of something like <%= fields_for :task %> nested inside of <%= form_for :project %>. I'm sure other frameworks do the same.

This means that if you went to a random webpage开发者_如何学Python and you saw that structure, via some regular expression magic, you could convert that html back to its template!

Has anybody ever tried to build anything like that? Do you think it's even possible?

Update:

I myself am only interested in Ruby on Rails applications (not just the form as the above example shows, but everything on the html page), but if it were possible for everything, even better.

Once you generated the template HTML file (the ERB file in Rails), you could them manually go through and figure out the model and controller. You'd have to have the program compare all of the generated ERB files to figure out how to build the model and the controllers which might be an even bigger task. But that would be the end goal


It is possible but it is a "massive task" of at least several man years.

Given a HTML page with the forms:

<form name=login>
    <input name=user></user>
    <input name=password></user>
</form>

<form name=add_comment>
    <input name=comment></user>
    <input name=your_id></user>
</form>

You would have code which does (psuedocode):

erb = ""
for each <form>
    for each <input>
        erb = erb + "<%=" + <input>.name + "%>"

This is not the exact code, but psuedocode as I said. Anyway, then you would need to decide on how the submit button is processed for each form. Do you want this automatically generated as well in the Rails controller?

0

精彩评论

暂无评论...
验证码 换一张
取 消