您的位置:首页 > 编程语言 > Python开发

python 分析Google音乐下载地址(二)

2009-09-25 13:49 363 查看
Cells主页
http://cells.rubyforge.org/
Engine主页http://rails-engines.org/

我最先使用的是engine, 因为项目的需要, 接触这个东西, 整体感觉是根本不实用, 刚听起使用engine可以把rails项目当插件来使用, 确实是很吸引人的一个想法, 这样项目的可重用性很高, 可事实并不心如人意, 要知道模板项目并不总能尽如人意, 总会有跟实际需求不同之处, 遇到这样的问题, 个人觉得两种方式, 改模板项目(太不值得了, 可若是改动太大, 那不如直接全部重写controller),  或者扩展(小的冲突还可以这么做. 总之使用engine是一个两难的境地, 扩展进来相当的不愉悦.
之后, 发现cells 这么个东西, 说实话, 第一眼看起并不起眼, 当第一次兴趣使然去使用的时候发现, 这个正是我想要的东西, 扩展性相当的强. 而且不会破坏将有的controller, 使你的controller很简洁, 却又能很方便的引入其它的模块.
看个例子这里使用两个插件: cells, ym4r_gm(附件内有)ruby script/generate cell map google_map   (generate生成cell, 附件里有这个插件)
map_cell.rbclass MapCell < Cell::Base

    def google_map
        @map = GMap.new("map_div_id")    
        @map.control_init(:large_map => true, :map_type => true)    
        @map.center_zoom_init([75.5,-42.56], 4)
        marker = GMarker.new([75.6, -42.467], :title => "Where Am I?", :info_window => "Hello, Greenland")    
        @map.overlay_init(marker)
        nil # returning nil says "render the view named newest.html.[erb|haml|...]".
    end
end
google_map.html.erb<div id="joey">
  <%= @map.to_html %>    
  <%= @map.div(:width => 600, :height => 400) %>
</div>
<% #= link_to_remote :url => { :action => "update", :controller => "home"} %>
<%= link_to "hello"%>
home_controller.rbclass HomeController < ApplicationController
    
    def index
    end
end

home/index.html.erb<div><%= render_cell(:map, :google_map, :message => "hello joey") %></div>
如果你按上面所做成功, 那么home页面上面你就可以成功的看到google map了, 而从中你可以看见, 整个过程home controller内很简洁, 假若你在很多个页面上都需要google map, 那个只要同样的一句<div><%= render_cell(:map, :google_map, :message => "hello joey") %></div>即可
这是我首先体会到cells的好处, 但说实话, 还没了解其精髓.本文出自 “建四狼” 博客,请务必保留此出处http://andyss.blog.51cto.com/315552/100946
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: