動的なJavaScriptのもの
私が正しければ、それはリツイートボタンのようなものでも得られるようなシナリオです。(これは私があなたに例を提供するために手元にあるものです)。
私のブログで行ったことは、パーマリンク(およびユーザー名とスタイルの設定)を使用して構成するBITRetweetという名前の小さな特殊な海辺のコンポーネントです。ファイルのものを忘れてください(それは物事を複雑にするだけです)、すべてがその場で行われます。これでレンダリングされます:
BITRetweet>>renderContentOn: html
html script with: self customizedJavascript.
html script url: self buttonJavascriptSource.
BITRetweet>>customizedJavascript
| script |
script := JSScript new.
script add: (('"',self permalink,'"') asJSObject assignTo: 'tweetmeme_url').
isCompact ifTrue:[
script add: ('"compact"' asJSObject assignTo: 'tweetmeme_style')].
script add: (('"',username,'"') asJSObject assignTo: 'tweetmeme_source').
script add: (('"',shortener,'"') asJSObject assignTo: 'tweetmeme_service').
^ script
BITRetweet>>>buttonJavascriptSource
"Answers the url to the source of the script for the button.
See:
http://help.tweetmeme.com/2009/04/06/tweetmeme-button/"
^ 'http://tweetmeme.com/i/scripts/button.js'
and finally a little hack for String, like this:
String>>asJSObject
^ JSObject new alias: self
パーマリンクの操作
パーマリンク部分には、次の2つがあります。
- それを生成する
- それを使用する(リクエストが付属しているときにアプリが反応するようにする)
1の場合、次のようなことができます。
PostComponent>>updateUrl: anUrl
super updateUrl: anUrl.
anUrl addToPath: model asURLNice
Post>>asURLNice
"Answers the receiver in an (destructive) encoded
way which is url friendly"
^ String streamContents: [:stream|
self do:[:char|
char isSeparator
ifTrue:[stream nextPut: $-]
ifFalse:[
char isAlphaNumeric ifTrue:[
stream nextPut: char asLowercase asNonDiacritical]]]]
2の場合、メインアプリケーションコンポーネントで
次のようなことを行う必要があります。
BlogApplication>>initialRequest: aRequestOrNil
| paths |
super initialRequest: aRequestOrNil.
aRequestOrNil ifNil:[^ nil].
(aRequestOrNil url asString endsWith: '/sitemap.xml') ifTrue:[
^ self respondSitemap].
paths := aRequestOrNil url path.
paths size < 2 ifTrue:[^nil].
(Post atURLTitle: paths last) ifNotNilDo: [:value |
^ self readPost: value].
実例
私のブログで実際に動作していることや、選択的な創造性ですべてを見ることができます。
私は3か国語でブログを書いているので、asNonDiacriticalが必要ですが、必要に応じてsqueaksourceでDiacriticalSupportを利用できます。
ハッキングを楽しんでください
o/