将 Rails 视图存储在数据库中而不是文件系统中
An ActionView::Resolver implementation to store rails views (layouts, templates and partials) on database. Simply put: what you can do with views on filesystem, can be done on database.
NOTE: at the moment, only ActiveRecord is supported, I've planned to add more ORMs (see Todo). If you can't wait, adding other ORMs should be very trivial.
Add the following line to Gemfile:
gem "panoramic"Your model should have the following fields:
they're what the rails' Resolver API needs to lookup templates.
A simple macro in model will activate your new Resolver. You can use a dedicated model to manage all the views in your app, or just for specific needs (ex: you want a custom template for some static pages, the other views will be fetched from filesystem).
class TemplateStorage 'custom_template'
end
def custom_template
# use another model to fetch templates
prepend_view_path AnotherModel.resolver
end
endAnd let's say you want to use database template resolving in all your controllers, but want to use panoramic only for certain paths (prefixed with X) you can use
class ApplicationController 'use_this_prefix_only')
endThis helps reducing the number of database requests, if Rails for example tries to look for layouts per controller.
class MyEmail model.path)
endNeed more help? Check out spec/dummy/, you'll find a dummy rails app I used to make tests ;-)
Enter Panoramic gem path, run bundle install to install development and test dependencies, then rake spec.
Fork, make your changes, then send a pull request.
The main idea was heavily inspired from José Valim's awesome book Crafting Rails Applications. It helped me to better understand some Rails internals.
暂无开放 Issues,或尚未同步最近议题。