将一个HTML模板、JavaScript和CSS打包,以供多个平台使用。

huangapple go评论88阅读模式
英文:

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:

&lt;script src=&quot;your_widgets.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;new Footer.render(&#39;id_of_dom_element_to_render_to&#39;);&lt;/script&gt;

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.

huangapple
  • 本文由 发表于 2015年4月28日 13:07:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/29910745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定