Web 代码重用,您如何组织脚本片段?

发布于 2024-09-15 20:48:01 字数 1432 浏览 3 评论 0原文

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

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

发布评论

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

评论(5

壹場煙雨 2024-09-22 20:48:01

也许这只是我的风格,但我不会在项目中进行大量复制和粘贴片段。如果某些东西足够好,可以重用,那么我会花时间为其创建适当的函数或类(包括 javadoc 样式文档,以便 eclipse 可以使用它)。然后在您的开发环境中“站点范围”安装它就很简单了。对于 php,将其添加到包含路径中,然后告诉您的 IDE 使用它。对于 JavaScript,请将某些内容放在本地网络服务器的根文件夹中(“/jslibs”等)。如果您使用 jQuery,您可以轻松地将 javascript 片段转换为适当的插件。

然而 CSS 是一个完整的 clusterf*ck。我对此没有任何真正的建议。

这里还有一些专门针对离线使用的建议:

  1. 用于记录事物的本地 wiki。如果您使用 subversion 或 git,我推荐 trac,因为它集成得很好。

  2. 如果您使用 Firefox,请获取剪贴簿插件。它允许您将网页或页面片段保存到本地可搜索数据库中。

Maybe it's just my style, but I don't do alot of copy&paste snippets across projects. If something is good enough to be reusable, then I take the time to create a proper function or class for it (including javadoc style documentation so eclipse can pick up on it). Then it's a simple matter to install it "site-wide" in your development environment. For php, add it in the include path and then tell your IDE to use it. For JavaScript, put something off the root folder of your local webserver ("/jslibs" or the like). If you use jQuery, you can easily turn your javascript snippets into proper plugins.

CSS however, is a complete clusterf*ck. I don't have any real suggestions for that.

Here are a couple more suggestions specifically for offline use:

  1. a local wiki to document things. If you're using subversion or git, I'd recommend trac as it integrates nicely.

  2. If you use firefox, get the Scrapbook plugin. It allows you to save web pages or snipptes of pages into a local searchable database.

把时间冻结 2024-09-22 20:48:01

在我的公司,我们将它们构建成库。我们有一个名为 XD(体验设计)的库,用于可重用的 UI 组件。由于我们使用 Maven 构建,因此我们使用标准目录布局来放置 Java。 Flex 和 JavaScript 组件位于不同的树中,但它们都在同一个项目中,并且绝对处于版本控制中。

如果您使用此方法(为每种语言构建库),则无需剪切和粘贴;只需包括图书馆。一个项目的任何改进都可以使所有项目受益。

In my company, we build them into libraries. We have libraries called XD (experience design) for reusable UI components. Since we build with Maven, we use the standard directory layout to put Java. Flex, and JavaScript components in different trees, but they're all in the same project, and DEFINITELY in version control.

If you use this method (building libraries for each language) you don't have to cut and paste; just include the library. And any improvements made on one project can benefit all projects.

我不咬妳我踢妳 2024-09-22 20:48:01

我将复制意大利面代码保存在 Google 笔记本中。 (诸如元重定向和其他非常具体且难以记住的内容。)Google Notebook 不再向新帐户开放,但有诸如 OneNote

我使用的 IDE 支持模板,这些模板是您可以在创建新文件时随时加载的框架文件(而不是创建一个空白的 CSS 或 Javascript 文件,您可以拥有所有基本的 CSS 规则或 JS 函数)。我发现模板非常有用。

最后,您可以创建自己的库并像部署任何其他库或框架(jQuery 等)一样部署它们。我在 其中一两个。 google.com/" rel="nofollow noreferrer">Google 代码,我可以轻松地使用 Mercurial 提取该代码并将其转储到新项目或服务器中。

I keep my copy-pasta code in Google Notebook. (Things like meta redirects and other stuff that's really specific and hard to remember.) Google Notebook is no longer open to new accounts, but there services / applications like OneNote.

The IDE I use supports templates, which are skeleton files you can load any time you create a new file (instead of creating a blank CSS or Javascript file, you can have all of your basic CSS rules or JS functions). I find templates very useful.

And finally, you can create your own libraries and deploy them as you would any other library or framework (jQuery, etc.). I have one or two of these on Google Code that I can easily pull with Mercurial and dump into a new project or server.

叶落知秋 2024-09-22 20:48:01

它都是 Smalltalk,并且像所有 Smalltalk 代码一样进行组织、打包、搜索和重构:在版本控制的 monticello 包中。大型 javascript 库有自己的包,框架包依赖它们,客户包依赖框架包。

It is all smalltalk and organized, packaged, searched and refactored like all smalltalk code: in monticello packages that are versioned. The large javascript libraries have their own packages, the framework packages have dependencies on them and the customer packages depend on the framework packages.

聆听风音 2024-09-22 20:48:01

似乎 Snippets (Mac 应用程序)就是为此而制作的。可以找到详细回答您的问题(离线使用、语言分类等)的博客文章 此处

It seems Snippets (Mac app) has been made just for this. A blog post answering your questions in detail (offline use, language categorization, etc) can be found here.

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