My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
Customizing  
How to customize your Substruct site
Updated Aug 26, 2010 by subim...@gmail.com

Customizing The Client-Side Look and Feel

CSS and Layouts

Substruct doesn't ship with templates because customizing the look and feel is very simple.

You should never edit anything in the vendor/plugins/substruct directory

Here are the steps you should take if you wish to customize the look and feel of Substruct

  1. COPY the css files from /vendor/plugins/substruct/assets/stylesheets into public/stylesheets
  2. COPY layouts from /vendor/plugins/substruct/app/views/layouts into app/views/layouts
  3. MODIFY the copied layouts to include your new stylesheets copied in step 1.
    • (Make sure to point the CSS include tags to your new files using stylesheet_link_tag, not the engine one!)
  4. Edit your CSS files all day, and enjoy life.

Views

Copy anything out of the vendor/plugins/substruct/app/views folder with the same name and folder structure (/content_nodes, /store, etc) into your app/views folder.

For instance, if you wished to modify the store index file, you would do the following...

cd my_rails_app
mkdir -p app/views/store
cp vendor/plugins/substruct/app/views/store/index.rhtml app/views/store

This template will be used instead of the default one Substruct uses.

Customizing Code

Controllers

If you wish to add your own methods to the controllers inside Substruct, or perhaps modify the code that exists there for a custom modification, follow a similar process to customizing views.

In this example, let's assume we'd like to add something to the StoreController

cd my_rails_app
touch app/controllers/store_controller.rb

The contents of your new file would look something along these lines...

require_dependency RAILS_ROOT + "/vendor/plugins/substruct/app/controllers/store_controller"

class StoreController < ApplicationController

  # Any methods defined here overwrite the ones in the engines controller file.

end

Working in this way allows you to update the base Substruct code at any given time without disrupting custom modifications you've made.

Any new controllers should be placed in your app/controllers directory as well.

Models

Models are a little bit different, in that they require some tweaking to the copied file - but it's still a simple process.

Let's assume we'd like to add some new methods to the Order model.

cd my_rails_app
touch app/models/order.rb

The contents of this new order.rb file would look something like this...

require_dependency RAILS_ROOT + "/vendor/plugins/substruct/app/models/order"

class Order < ActiveRecord::Base

  # Define your methods here

end

Notice the first line...Rails Engines doesn't automatically know how to deal with extending model files, so we must require the proper model that we're extending.

You will of course, need to modify this based on whatever model you are extending.

Any new models should be placed in your app/models directory as well.

Comment by rogerpack2005, Apr 26, 2008

(Make sure to point the CSS include tags to your new files using stylesheet_link_tag, not the engine one!)

--this means go to your layouts that you just copied over and get rid of anything that says :plugin => substruct (just delete that part).

To customize images substruct uses, you'll either need to edit the ones that were auto copied to public/plugin_assets/substruct... or copy them from that directory to a new location in your public folder and have your .css files point to those new ones that you just copied somewhere else.

With regard to models, in reality you can just copy the model to your app/models directory and edit it there and it will replace the substruct one.

If, however, you want to ADD a single function to your controller or helper [i.e. extend it--not replace it], you must use the 'require_dependency' thing mentioned.

Comment by rogerpack2005, May 23, 2008

note that you can get some leverage by just creating filters for existing controller actions:

before_filter :some_custom_code, :only => [:articles]
http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html

Comment by rogerpack2005, May 23, 2008

to charles: the word 'substruct' is a preference in the admin interface, and if you want the right gifs you'll need to go in to where they're referenced and take out the :plugin => substruct that's there.

I suppose a rake task that takes out all :plugin references might be useful :) Also it might be good to note in the 'views' section that you may want to take out some references within the view to :plugin

Comment by baswilb...@gmail.com, Feb 12, 2009

The philosophy behind this is quite good, a rake task for this, however is very welcome. A perfect opportunity for me to dive right into rake.

Powered by Google Project Hosting