我有以下项目结构:
/app
/config
/db
...
/themes
/default
/assets
/images
/stylesheets
/...
/views
/...
/theme1
/assets
/...
/views
/...
默认情况下应该使用'default'主题:)。 'theme1' - 应覆盖任何内容,例如logo.png或view(application.erb)。
它应该以这种方式工作:如果不存在,尝试从'theme1'获取资产 - 使用'default'。
非常简单的观点:
self.prepend_view_path ::ActionView::FileSystemResolver.new(theme_view_path_for(name))
self.prepend_view_path ::ActionView::FileSystemResolver.new(default_theme_path)
但我无法用资产来解决它。
config.assets.paths << "#{Rails.root}/themes/default/assets/stylesheets"
config.assets.paths << "#{Rails.root}/themes/default/assets/images"
config.assets.paths << "#{Rails.root}/themes/default/assets/javascript"
这会像往常一样添加资产,例如可以使用url'res assets / logo.png'访问资产,但我需要前缀 - “assets / theme1 / logo.png”。 此外,如果'theme1'未通过“assets / theme1 / logo.png”覆盖logo.png,则应返回“默认”主题徽标。 (与上面的观点类似)。
我尝试过themes_for_rails - 但它不合适,因为它们会覆盖整个资产结构(自己的控制器以供服务等)。
此外,有能力挂钩资产解决方案, 访问logo1.png时,应该可以使用我的控制器提供它,例如从数据库返回。
感谢您的任何建议,我会在完成后分享结果。
Kirill Salykin
答案 0 :(得分:0)
默认情况下,第一级中的文件夹将被轨道中的Sprocket忽略。您可以在默认应用程序中验证这一点,您可以在其中看到编译的文件缺少初始javascripts / images /或stylesheets /文件夹。
更好的结构是:
/themes
/stylesheets
/default
/theme1
/images
/default
/theme1
然后将目录添加为:
config.assets.paths << "#{Rails.root}/stylesheets"
config.assets.paths << "#{Rails.root}/images"
想要引用主题中的文件吗?
= image_tag("#{theme_name}/background.png")
= stylesheet_tag("#{theme_name}/application.css")
这应该有效。