2

I have Javascript, Django templates, Python code, and CSS which all work with the same configuration data. Where's the best place to configure it?

Specifically, I have a browser-side entry widget in Javascript which controls an embedded Java app. When the user is done, the Javascript asks the Java applet for an image of the result, which will be embeded in the HTML. The user can specify if the image should be small, medium, or large. That image and the choice are sent via an AJAX call to my Django app, which does some input validation. When the HTML is displayed it includes my CSS, which has special a[href^=http://internal.server] markup to show those images in a different way than other images.

While someone asked a similar question, the answers were either: "use a DSL" or "use a format like XML or JSON." Neither of which work with CSS.

The two solutions I came up with are:

  • put the data in Python and have it generate the HTML through a Django form/template. Also have Django dynamically generate the Javascript configuration and generate that CSS.

I don't like this because I would rather serve all my Javascript and CSS statically.

  • Introduce a build step where configuration data gets applied to a template to build the respective Javascript, HTML, CSS, and Python files.

Which makes things more complicated because I'll have special "*.in" or such files which build the actual files, and everyone will have to watch out that they know which files are the ones to edit.

What do you do?

4

2 回答 2

4

使用 JSON。动态生成 CSS,使用缓存来减少负载。

于 2010-12-07T10:56:18.163 回答
0

我认为一个非常好的方法是通过使用某种编码约定布局的 JSON 数据结构来有效地间接表达 DSL,再加上一个单独的构建步骤,该步骤使用它来创建所需的配置文件。如果此构建步骤的工具是用 Python 编写的,那么创建、维护和增强它或它们应该相对容易。

于 2010-12-07T11:43:05.523 回答