英文:
Packaging an html template, javascript and css to be consumed by multiple platforms
问题
我有一个庞大的Rails应用程序,我想将其拆分为较小的应用程序。这个应用程序的一个通用部分是页眉和页脚。我想将页眉和页脚的HTML、JavaScript和CSS提取到一个独立的包中,每个应用程序都可以加载和渲染。
我遇到的主要问题是这些应用程序可能不全都是用Rails编写的。有些可能是用Express.js编写的,有些可能是用Go编写的,还有一些可能是用其他语言编写的,所以我的解决方案需要是语言无关的。
我的想法是将HTML、CSS和JavaScript提取到一个独立的Git仓库中,使用Mustache模板来处理HTML,然后使用Grunt或类似的构建工具来构建一个Gem、一个package.json结构和一个Golang模块。可能每个都是作为自己的Git子模块。
我想知道是否有更标准化的方法来实现这一目标。或者是否有人知道更简单的方法来实现这个目标。
英文:
I have a large rails application that I am wanting to split out into smaller applications. The one piece of this application that will be universal to all smaller applications is the mast and footer. I would like to extract the html, javascript and css for the mast and footer into it's own package that each app can load and render.
The main issue I'm running into is that the apps will likely not all be written in rails. Some will be rails, some will be expressjs, some written in Go, and some may end up being written in other languages, so my solution needs to be language agnostic.
My thought is that I can extract the html, css and javascript into it's own git repo, use mustache templates for the html, and then use grunt or a similar build tool to build a gem, a package.json structure and a golang module. Possibly each in it's own git submodule.
I'm curious if there is a more standardized way of doing this. Or if anyone knows of a simpler way of achieving this goal.
答案1
得分: 1
听起来常见的技术是HTML/JS/CSS。
将页眉和页脚导出为一个独立的JS库,或者更准确地说,导出为小部件,这样不是更好吗?
这样,无论应用程序服务器的技术栈是什么,你都可以以以下形式生成HTML:
<script src="your_widgets.js"></script>
<script>new Footer.render('id_of_dom_element_to_render_to');</script>
通过这样做,无论你想让小部件库加载模板,还是想将模板嵌入到小部件库中,或者只是使用HTMLFragment简单地构建它,都不会受到服务器技术选择的限制。
英文:
Sounds like the technology in common is HTML/JS/CSS.
Wouldn't it be better to export the mast and footer as a self contained JS library, or more precisely, as widgets?
So whatever the application server tech stack would be, you could always generate the HTML in the form of:
<script src="your_widgets.js"></script>
<script>new Footer.render('id_of_dom_element_to_render_to');</script>
By doing so, whether you want the widget library to load the template or you want to embed the template into the widget library or whether you want to simply just construct it using HTMLFragment will not be limited by the server tech choice.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论