桃之夭夭
知天之所为,知人之所为者,至矣。知天之所为者,天而生也;知人之所为者,以其知之所知以养其知之所不知,终其天年而不中道夭者:是知之盛也。
BlogJava | 首页 | 发新随笔 | 发新文章 | 联系 | 聚合 | 管理

2007年11月28日

Add primitive Progression Enhancement support of Rails
Currently the concept of Progressive Enhancement is getting hotter and hotter. It emphasizes accessibility, semantic markup, and the importance of separating the complex rich interaction logic into well modularized javascript files. It's really a usefully way of thinking about how to modularize and manage web presentation components. But the Rails framework doesn't have good support for PE, so we have to define our own convention and helpers to make our life easier.

Usually, I'd like to organize js files in the Rails convention, which means we'll have something like this:

app
  |
  - views
      |
      - admin
          |
          _  new.html.erb
          -  index.html.erb
public
  |
  - javascripts
       |
       - admin
           |
           - new.js
           - index.js

And new.js looks similar to:
$(document).ready(function() {
  enhanceInteractionOnElements();
  
});

function helper_methods() {
  
}


Then, add the follow method to ApplicationHelper module:

def page_javascript_include_tag
  file 
= "#{params[:controller]}/#{params[:action]}.js"
  File.exist
?("#{RAILS_ROOT}/public/javascripts/#{file}") ? javascript_include_tag(file) : ""
end

this method will look for js file for a particular page. And in you layout file, add one line in the head sectin:
<%= page_javascript_include_tag %>

That's it. Whenever you request an action of a particular controller, it will find and include the PE js files automatically. Now we've very very primitive support of PE in Rails framework now.

 


 
posted @ 2009-03-18 14:38 Raimundox 阅读(4351) | 评论 (0) | 编辑 收藏
 
Misquotation
前几天在JavaEye海阔被标题党阴了一把,看了一篇转的文章叫《被中国人误传了数千年的七句话》,颇有些哭笑不得的感慨:

1. 这些话的确是被误传了不假,但是最多也就一百年吧。中国知识分子不读四书五经史子集的坏风气大抵是开始于所谓的新文化运动吧。再往前的人,对于这些典籍字字爬梳,提了上句马上背下句,就算是以章句式解读为主的宋元,也不应该随随便便就被忽悠了,更不用说反对宋儒理学讲究正本清源的明清了。

2. 古人断章取义是一种风雅的言谈习惯,所谓“雅言”是要字字出典的,有点像对暗号。比如我们家猫跑了,搁古代我肯定问“谁之过欤?”,十有八九会回答说,“言是典守者之过也”,这句射的是“虎兕出于柙”,正好应景。甚至为了诙谐应景,故意曲解文义的情况也是很常见的。如果以此为证说误传的话,恐怕只能算是牛嚼牡丹了。顺便多说一句,其实这个毛病现代人也有,不过不再是古文了,大多数是电影电视台词:“空气在颤抖仿佛天空在燃烧。是啊,暴风雨就要来了”,“道哥,牌子啊”,“你看我的英语,有没有长进”之类的,虽不复古韵,但也还算有趣。


P.S. : 今天team里有人把David Wheeler的名言,贴在了Quote Wall上:“Any problem in computer science can be solved with another layer of indirection.”

这到的确算是一句被误传的名言吧,原文是“Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem.”
posted @ 2007-11-28 18:08 Raimundox 阅读(4423) | 评论 (1) | 编辑 收藏
 
随笔:36 文章:0 评论:93 引用:0
<2007年11月>
日一二三四五六
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

常用链接

  • 我的随笔
  • 我的评论
  • 我的参与
  • 最新评论

留言簿(21)

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔分类

  • ThoughtBlog(21) (rss)
  • 学而篇第一(15) (rss)

随笔档案

  • 2009年3月 (1)
  • 2007年11月 (1)
  • 2007年9月 (2)
  • 2007年8月 (1)
  • 2007年7月 (1)
  • 2007年6月 (1)
  • 2007年5月 (2)
  • 2007年3月 (8)
  • 2007年1月 (1)
  • 2006年10月 (1)
  • 2006年8月 (1)
  • 2006年3月 (1)
  • 2006年1月 (3)
  • 2005年12月 (12)

搜索

  •  

最新评论

  • 1. re: 丧钟为谁鸣?(4)
  • 通讯模型!
  • --ic
  • 2. re: A Patch for Ruby Watir Test Framework
  • 忘记附上我的邮箱(如果能得到你的答复,万分感谢)
    mac_cf@163.com
  • --mac_cf
  • 3. re: A Patch for Ruby Watir Test Framework
  • 评论内容较长,点击标题查看
  • --mac_cf
  • 4. re: 丧钟为谁鸣?(1)
  • 反复研究了几遍SICP。同时看了录像和书(感谢曹老师下的Video),是什么?求~
  • --qixinkui@qq.com
  • 5. re: Apologize to Object-Oriented Methodology
  • 拜读!开阔了视野!
  • --qixinkui@qq.com

阅读排行榜

  • 1. Selenium Better Pratice(8145)
  • 2. Feng Shui for Standard ML Programmers(7116)
  • 3. 丧钟为谁鸣?(1)(6940)
  • 4. Erlang Ring Benchmark(6713)
  • 5. The Keyword 'end' Drives Me Crazy(6684)

评论排行榜

  • 1. Selenium Better Pratice(11)
  • 2. 丧钟为谁鸣?(1)(11)
  • 3. A Day of Two Pragmatic Programmers' Life(9)
  • 4. ANTLR Lexer Tips(4)
  • 5. A Patch for Ruby Watir Test Framework(4)

Powered by: 博客园
模板提供:沪江博客
Copyright ©2025 Raimundox