Introducing merb-slices

May 21, 2008 | Author: fabien | Publisher: wycats

A quick runthrough of merb-slices, showing how to create a slice and then do some overrides from the main application.

Here are the basic steps performed in the screencast

It’s assumed that you installed Merb (>= 0.9.4). Make sure you install merb-more, which includes merb-slices.

Setup the application and slice

  1. create a sample host application: merb-gen app sliced-app
  2. generate the sample slice: merb-gen slice blog-slice
  3. install blog-slice using: rake install
  4. back in sliced-app edit config/init.rb to add: dependency ‘blog-slice’
  5. then in config/router.rb add: r.all_slices
  6. to copy over any assets etc. run: rake slices:blog_slice:install
  7. run merb and visit http://localhost:4000/blog-slice/main/index.html

Add a controller override

  1. create a file at slices/blog-slice/app/controllers/main.rb
  2. let’s add some code to override the index action
  3. restart merb and reload the browser

Override a view – the slice layout

  1. create a file at slices/blog-slice/app/views/layout/blog_slice.html.erb
  2. paste in the original code and change something
  3. restart merb and reload the browser
Download: slices.mov
Downloaded 3146 times.

Comments

On August 01, 2008 at 11:50 frostbytten says:

I am using 0.9.4 everything (merb-core, merb-more, dm-core, dm-more) and I am running into a syntax error when using hyphens in the merb-gen slice

On August 04, 2008 at 03:46 michael says:

what is the typical approach when developing a merb-slice.

Can I:

                
                  merb-gen slice test_slice
                  cd test_slice
                  merb-gen model Post title:string descr:text
                
                

...and then start it just like a normal standalone app?

                
                  merb
                
                

Or is it more like.. developing the app as usual and then extract the features and turn it into a slice?

I would personally prefer the first approach?! ....as it would be perfect for distributed development. E.g. Two programmers are raising their slices and afterwards put them together in the main (container) app.

Is there more documentation available regarding the creation and maintenance?

Thx!

/Michael

On August 05, 2008 at 00:14 fabien says:

@frostbytten

Due to some internal refactorings regarding the new Templater generators (git head), it’s possible that you experience some glitches. I suspect this the source of your error, but I will investigate.

@michael

The normal approach would be to have an ‘empty’ container-application which loads up your slice. In any case, generating models using merb-gen into a slice doesn’t work atm (though maybe it’s possible to have it recognize the slice’s context with the new generators – more investigation ahead). On the other hand, you probably want to spec out your slice before, which is fully supported and works standalone – so seperated from any host app – and will pick up if it’s run from within the host-app.

During initial development it helps to have your slice in Merb.root / ‘slices’ / ‘test_slice’ as it loads up directly, so you don’t have to install the gem over and over. This is the preferred approach, and extraction from a working application is also a good option.

I’m hoping to get some more work done on slices too (I’m currently on holiday), maybe even release a screencast or two.

On August 15, 2008 at 16:54 cenuij says:

Hi,

The vid was interesting but for me raised more questions than possible answers.

If you are replicating code for each slice ( assuming you are ), what then happens when you improve your core app? Does code need to be replicated again for each slice?

How do you keep track of application and module (slice) resources? If a slice has copies of js and css resources, how can you manage these effectively?

Why is it a good idea to replicate so much code, just to override a few lines? Why the hell would I want to replicate code in this fashion???

If I’m wrong, what did I miss? Is this not just multiple applications in different clothing?

On August 15, 2008 at 16:54 cenuij says:

Hi,

The vid was interesting but for me raised more questions than possible answers.

If you are replicating code for each slice ( assuming you are ), what then happens when you improve your core app? Does code need to be replicated again for each slice?

How do you keep track of application and module (slice) resources? If a slice has copies of js and css resources, how can you manage these effectively?

Why is it a good idea to replicate so much code, just to override a few lines? Why the hell would I want to replicate code in this fashion???

If I’m wrong, what did I miss? Is this not just multiple applications in different clothing?

On August 15, 2008 at 16:54 cenuij says:

Hi,

The vid was interesting but for me raised more questions than possible answers.

If you are replicating code for each slice ( assuming you are ), what then happens when you improve your core app? Does code need to be replicated again for each slice?

How do you keep track of application and module (slice) resources? If a slice has copies of js and css resources, how can you manage these effectively?

Why is it a good idea to replicate so much code, just to override a few lines? Why the hell would I want to replicate code in this fashion???

If I’m wrong, what did I miss? Is this not just multiple applications in different clothing?

On August 15, 2008 at 16:54 cenuij says:

please fix your submission code ¬_¬

On August 15, 2008 at 16:54 cenuij says:

please fix your submission code ¬_¬

On August 15, 2008 at 16:54 cenuij says:

please fix your submission code ¬_¬

Sign in to make your voice heard