Spree, Rails 3, and theming

做~自己de王妃 提交于 2019-12-03 00:19:16
Rytis Lukoševičius
  1. The solution that worked for me was to create my own extension say 'site' with rails g spree:extention site then I've look at my gems path and just opened the whole spree-core gem in another editor project and copied over the app/views/layouts/spree_application.html.erb.

If your html is not that different (mine is quite different at http://daugpigiau.lt) from default spree shop you might be able to only use hooks and override some of the parts. Still the only way I've found to know hook names was to look inside those spree core gems and templates that were interesting for me. After you know what hooks are of interest to you you can do something like:

class PigiauHooks < Spree::ThemeSupport::HookListener
  # custom hooks go here
  insert_after :admin_inside_head, 'shared/admin/ckeditor_include'
  insert_before :admin_product_form_meta, 'shared/admin/product_editor'
  insert_before :admin_product_form_additional_fields, 'shared/admin/unavailable_on'
end

These are just my own partials for the places I wanted to change.

  1. Yes you can undo the extension generation part as any other generation you just need to run rails destroy spree:extension your_extension_name and it will revert all the operation that were performed during it's generation

I've strugled with the overriding part at first cause documentation on this one has a bit too much blank spaces for the first time user to grasp.

To change the default theme of Spree you need to generate your own extension and override the view files from spree_core-0.30.1/app/views in it. However, there's a little bug in the current version of Spree that can make theming and extension creation really confusing. According to the docs, to create a new extension you should run the following command:

$ rails g spree:extension myext

And it should produce the following output:

 create  myext
 create  myext/db
 create  myext/public
 create  myext/LICENSE
 create  myext/Rakefile
 create  myext/README.md
 create  myext/.gitignore
 create  myext/myext.gemspec
 create  myext/lib/tasks/install.rake
 create  myext/app
 create  myext/app/controllers
 create  myext/app/helpers
 create  myext/app/models
 create  myext/app/views
 create  myext/spec
  exist  myext/lib
 create  myext/lib/myext_hooks.rb
 create  myext/lib/tasks/myext.rake
 create  myext/lib/myext.rb
 create  myext/spec/spec_helper.rb
gemfile  myext

However, the output is:

create  myext
create  myext/config
create  myext/db
create  myext/public
create  myext/LICENSE
create  myext/Rakefile
create  myext/README.md
Could not find ".gitignore" in any of your source paths. Your current source paths are:

The current workaround is to change the line

gem 'spree'

in your Gemfile to

gem 'spree', :git => "git://github.com/railsdog/spree.git", :tag => "v0.30.1"

then run bundle install and rails g spree:extension myext again. It will create all the files correctly and plug it into your Gemfile. Then you can override all the necessary files in myext/app/views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!