Giter Club home page Giter Club logo

dry_view's Introduction

dry_view

可以免去重复的view代码

Example

说明: 将常用的View公用, 统一了I18n

# Controller class BlogController < InheritedResources::Base dry_view :columns => [:title, :body] end

# Model class Blog def label self.title end end

Required

script/plugin install git://github.com/josevalim/inherited_resources.git script/plugin install git://github.com/alvin2ye/activerecord_dom_helper.git

引用

其中 form 的布局和 Css 来自 formtastic (github.com/justinfrench/formtastic/tree/master)

Useage

1 ./script/plugin install git://github.com/alvin2ye/dry_view.git 2 ./script/plugin install git://github.com/josevalim/inherited_resources.git 3 ./script/generate Model Company name:string addr:string 4 rake db:migrate 5 ruby script/generate controller companies 6

# app/controllers/companies_controller.rb class CompaniesController < InheritedResources::Base dry_view end

# app/models/company.rb class Company < ActiveRecord::Base def label self.name end end

# config/routes.rb map.resources :companies

7 rake dry_view:install 8 add to layout: <%= stylesheet_link_tag “formtastic” %>

I18n

# config/locales/zh.yml zh: dry_view: actions: “操作” view: “查看” edit: “编辑” remove: “删除” new: “新建” submit: “提交” required: “必填” cancel: “取消” return_index: “返回列表” are_you_sure: “你确认吗?”

Config

class CompaniesController < InheritedResources::Base

# Only display this columns, default is all columns except [:id, :created_at, :updated_at]
dry_view :columns => [:name, :code], :except_show => true

def set_dry_view_config
  # You can set @dry_view here
end

end

class Company < ActiveRecord::Base

def allow_show?
  ...
end

def allow_edit?
  ...
end

def allow_destroy?
  ...
end

end

Override

form

<%= render :partial => “#{c.name}_form_column”, :locals => {:column => c} %> so the file must named like: app/views/books/_name_form_column.html.erb

# app/helpers/books_helper.rb

def name_column(record) “ override #{record.name} ” end

feedback

Issue at agideo.lighthouseapp.com/projects/34756-dry_view/overview Copyright © 2009 Alvin Ye at Agideo, released under the MIT license

alvin.ye.cn(*)gmail.com

dry_view's People

Contributors

alvin2ye avatar jimjin avatar robinwu avatar

Stargazers

cjp avatar  avatar  avatar  avatar

Watchers

 avatar  avatar cjp avatar James Cloos avatar  avatar

Forkers

tom2cjp

dry_view's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.