是否有工具可以将任何网站转换为其框架正在使用的模板?

发布于 2024-08-21 19:35:33 字数 531 浏览 5 评论 0原文

例如,Rails 有一组已定义的模式,用于在 html 中定义 id 和其他属性,例如 <%= fields_for :task %> 嵌套在 <%= form_for :project %> 中的结果。我确信其他框架也会做同样的事情。

这意味着,如果您访问一个随机网页并且看到该结构,通过一些正则表达式魔法,您可以将该 html 转换回其模板!

有人尝试过建造类似的东西吗?你认为这可能吗?

更新:

我自己只对 Ruby on Rails 应用程序感兴趣(不仅仅是上面示例所示的表单,而是 html 页面上的所有内容),但如果一切都可以的话,那就更好了。

一旦生成了 HTML 模板文件(Rails 中的 ERB 文件),您就可以手动检查并找出模型和控制器。您必须让程序比较所有生成的 ERB 文件,以找出如何构建模型和控制器,这可能是一项更大的任务。但这将是最终目标

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 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-08-28 19:35:33

这是可能的,但这是一项至少需要几个人年的“艰巨任务”。

给定一个具有以下形式的 HTML 页面:

<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>

您将拥有执行以下操作的代码 (psuedocode):

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

这不是确切的代码,而是正如我所说的 psuedocode。无论如何,您需要决定如何处理每个表单的提交按钮。您是否希望在 Rails 控制器中自动生成此内容?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文