changing complete layout in spree - ruby-on-rails

I am working on spree 1.0.0 and have been doing some research on it
for my e-commerce site.
I have already made and used some existing extensions in my app. Now,
I am working on layouts and have been trying to figure out that what
are the best possible ways for that.
My need is that I have to change the complete front end layout of my
store in comparison of what spree provides.
Some of the options from my point of view are
-> Use an extension to write all the views that overrides the templates that spree provides,
-> Use Deface to override views (which would be hectic as I have to change approx everything on almost every page)
-> Use mixed functionality of the above options.
or is there another way to do this.
thanks in advance.

You are likely to have a new issue soon: to tell your new controller to use your new spree_application layout.
The spree google group indicates that you can use inheritance to use the main application everywhere: https://groups.google.com/forum/?fromgroups#!topic/spree-user/mB02WqMnCnw%5B1-25%5D
However, I still haven't figured out how to solve the routing for those controllers.

You can do this by overriding the app/views/layouts/spree_application.html.erb by placing an identically named file inside your application's app/views directory.

Related

How to customize HTML structure in ActiveAdmin layout?

I am trying to change the structure and design of the components of the ActiveAdmin layout, such as the navbar menu, icons and customize it to my style. Is this possible?
I need to overwrite the source code to be able to change the HTML structure, but I have tried to do it by placing files in the / lib folder and I have not succeeded. How could I overwrite the ActiveAdmin source code within my Rails project?
It is possible but many developers have discovered it is not easy. If you look through the various plugins you will find examples like Custom Layout, Sidebar, Menu and SubNav that may inspire you. However, if you are new to ActiveAdmin and your first priority is to customize the layout heavily then consider Administrate or vanilla Rails instead: they are still difficult, but you will be fighting the framework less.

Overriding the default views in RailsAdmin

I am using Ruby on Rails 4.2.1 with RailsAdmin. The gem works excellent, but I have the requirement that the layout of the admin panel and the forms must look different than what is generated by default. For example, the navigation should be horizontal top, the forms should order the fields in two columns.
So far I haven't find a way to copy the views locally and modify them (like in Devise for example). I have tried to replicate the views manually in the respective path under my views folder by copying the original views, but I got problems with the helper methods that are part of RailsAdmin not being accessible from my views.
I dug deeper and found that there is a task copy_views, it was referred to in questions for the older versions of the gem, but if I try to use it now rake rails_admin:copy_views, it is not available anymore.
Am I doing something wrong, or is there another way to do this?
You can create folders in your app
app/views/rails_admin/main for https://github.com/sferik/rails_admin/tree/master/app/views/rails_admin/main
app/views/layouts/rails_admin/ for
https://github.com/sferik/rails_admin/tree/master/app/views/layouts/rails_admin
Put modified files there. It can get a little messy and you will need to update the files if the gem changes.

Issues with replacing Spree Commerce layouts?

I am currently starting to build a custom frontend for a Spree application and I was wondering how to go about it.
I have read the Spree Commerce Documentation and it sais there are two ways of customizing views.
the Deface library
replacing the views in the Rails folder
In the docs it is stated that
Whenever you copy an entire view into your extension or application you are adding a significant maintenance overhead to your application when it comes to upgrading to newer versions of Spree. When upgrading between versions you need to compare each template that’s been replaced to ensure to replicate any changes from the newer Spree version in your locally copied version.
To this end we strongly suggest you use Deface to achieve the desired customizations wherever possible.
I would have to replace all of the front-end views but I am afraid that this will prevent me or others to update to another version of Spree. Defacing seems a bit overly complicated in my case...
Can anyone tell me how big of a problem replacing the views will be in regard of the above stated?
There are around 48 views in the front end of Spree. By replacing all of them in your own application, every tie you want to upgrade Spree, you will need to determine what has changed between your views, and Spree's views between the two Spree versions, check if any templates have been added or removed, and then figure out how to modify your views to conform to the expectations of a new version of spree. This will be a lot of work.
I'd recommend you re-evalute why you need to change all of Spree's views? Take a look at the spree_fancy extension. They are able to completely change the look & feel of Spree while only replacing a small subset of the views, and using Deface to add content and markup where needed. An extensions like this would be much easier to port to future versions of Spree than if they had replaced all of the views. We manage many Spree sites, and have several significantly customized front ends, and have not yet had to resort to techniques beyond Deface, and CSS changes.
If your front end is radically different, and using the existing Spree front end will be too cumbersome, you may want to consider building your front end using the Spree API. The API is designed to have more stable inputs and output between versions, which will make upgrading Spree much easier.

Change spree application layout file to load

Is it possible to use my own application layout file in my main rails app instead of spree's? I have my main app already setup with devise and then added spree. Spree frontend uses
frontend/app/views/spree/layouts/spree_application.html.erb
in its own gem as its layout and I read how to override that file with my own in app/overrides or Deface, but I don't want to duplicate the content that is already in my app/views/layouts/application.html.erb.
I'm looking to use my own file instead or overriding spree's.
You have 2 options:
Create a app/view/spree/layouts/spree_application.html.erb in your rails app and rails will pick your file
Set your own layout with Spree::Config[:layout] in an initializer (ex: Spree::Config[:layout]='application')
Spree::Config[:layout]='application' worked for me. But when I tried to switch to the spree default layout by removing this line, it did not work. After spending almost an hour I was able to switch back to default Spree::Config[:layout]='spree/layouts/spree_application'
Adding this answer just in case someone else gets stuck with similiar error.

Creating Plugins in rubyonrails

I am creating a plugin which involves a controller, model & views. while i can move these files from the vendor/plugin directory to app/controllers, models & views respectively.
now i can run my controller & model just by copying them in lib folder of vendor/plugins/plugin_name/lib and they are directly accessible, but my views are not initialized from there, so i need a technique which can make my views in vendor/plugins/plugin_name/lib/views accessible to rails framework without copying.
i am trying to add them to actionview, but not sure how to do that.
please guide me on this.
There's ways you can add your plugin's views directory to the "search path" for ActionView, but the easiest way to handle all this is to just use something like the Rails Engines plugin to do all the hard work for you.
If you're looking to add models, views and controllers via a plugin, take a look at Desert: http://github.com/pivotal/desert. I'm not too keen on this approach, but Desert seems to work for people who like it.

Resources