在 Seaside 中动态生成 JavaScript 的简单方法是什么?
我正在尝试将 Disqus 添加到我正在撰写的博客中。为了处理 Seaside 会话,我需要向 JS 添加唯一的 discus_identifier 或 disqus_url。我重写了组件的 #script 方法,但它只能返回字符串文字。
我看到两个选项:
- 动态生成 JS,将其保存到文件中,然后将该文件加载到我的组件中。
- 为每个博客条目添加永久链接。
有更简单的方法吗?或者这些方法中的一种(或两种)很容易做到吗?我是 Smalltalk 和 Seaside 的新手,不确定如何完成这两件事。
I'm trying to add Disqus to a blog I'm writing. To deal with Seaside sessions I need to either add a unique discus_identifier or disqus_url to the JS. I overrode my component's #script method but it can only return a string literal.
I see two options:
- Dynamically generate the JS, save it to a file, and load that file in to my component.
- Add a permalink for each blog entry.
Is there an easier way? Or is one (or both) of these ways easy to do? I'm new to Smalltalk and Seaside and am unsure how to accomplish either of these two things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,有一个更简单的方法。您可以直接在#script方法中生成正确的Discus JS代码。它应该返回一个字符串文字,但您可以动态创建此字符串。例如通过使用 WriteStream。
您的博客条目还需要一个永久链接。您可以使用#initialRequest:方法来处理这些永久链接。
Yes there is an easier way. You can generate the correct Discus JS code directly in the #script method. It should return a String literal but you can create this String on the fly. For example by using a WriteStream.
You blog entries also need a permalink. You can use the #initialRequest: method to handle these permalinks.
动态 javascript 的东西
如果我是对的,那么转发按钮之类的东西也会出现这种情况。 (这是我手头上可以向您提供的示例)。
我在博客中所做的是一个名为 BITRetweet 的小型专用海边组件,您可以使用永久链接(以及用户名和样式首选项)对其进行配置。忘记文件的东西(这只会让事情变得复杂),一切都是动态的。它呈现如下:
BITRetweet>>renderContentOn: html
BITRetweet>>customizedJavascript
BITRetweet>>>buttonJavascriptSource
最后对 String 进行一些修改,如下所示:
String>>asJSObject
工作对于
永久链接部分,有两件事:
对于 1,您可以执行以下操作:
PostComponent>>updateUrl: anUrl
Post>>asURLNice
和 对于 2,您必须在主应用程序组件中执行类似的操作:
BlogApplication>>initialRequest: aRequestOrNil
实时示例,
您可以在 中看到所有实际操作我的博客或选择性创造力
我需要 asNonDiaritic,因为我的博客是三种语言的,但是如果您需要的话,可以在 squeaksource 中找到 DiariticSupport,如果您需要它,
请享受黑客攻击的乐趣
/
dynamic javascript stuff
if I'm right, that's the kind of scenario you'll get for things like retweet buttons too. (which is the thing I have at hand to provide you examples of).
What I did in my blog is a little specialized seaside component named BITRetweet that you configure with the permalink (and username and style preference). Forget the files stuff (that will only complicate things), everything is on the fly. It renders with this:
BITRetweet>>renderContentOn: html
BITRetweet>>customizedJavascript
BITRetweet>>>buttonJavascriptSource
and finally a little hack for String, like this:
String>>asJSObject
working with permalinks
for the permalink part, there are two things:
for 1 you can do something like this:
PostComponent>>updateUrl: anUrl
Post>>asURLNice
and for 2 you have to do something like this in your main application component:
BlogApplication>>initialRequest: aRequestOrNil
live examples
you can see all that in action in my blog or in selective creativity
the asNonDiacritical is needed for me because I blog trilingual but the DiacriticalSupport is available in squeaksource if you need it
have fun hacking
o/