totally separate layout and view paths

66 views
Skip to first unread message

Julien Ammous

unread,
Aug 16, 2013, 6:36:30 AM8/16/13
to scor...@googlegroups.com
Hi,
I know there is a similar topic already but my problem is somewhat different, I am using scorched for a gem which only provide the base layouts and methods to create the final web application but
let the user application define these views.


Here is an example of what I am trying to achieve: https://gist.github.com/schmurfy/6248855
I can't figure out a way to make this works, is this something that can be done currently ?

Tom Wardrop

unread,
Aug 16, 2013, 7:50:10 AM8/16/13
to scor...@googlegroups.com
I can't see why that wouldn't work. Is there a particular problem you're running into? 

Tom Wardrop

unread,
Aug 16, 2013, 8:20:59 AM8/16/13
to scor...@googlegroups.com
Oh hang on, I understand your concern now. You want the layout set in your gem to not be affected by the user changing the view directory in their code. I was going to simply suggest specifying the view for your layout as an absolute path, but that has just brought my attention to the fact I'm using File#join for joining view file paths to the view directory, instead of File#expand_path. I've just made the change locally which I'll push up soon, and which will be included in v0.17. This allows absolute paths to be used, which are unaffected by the view directory which only affects relative paths.

There's plenty of other ways to handle this though. One method would be to simply load the contents of your layout and assign the string to `render_defaults[:layout]`, e.g.

render_defaults[:layout] = open('/my/awesome/layout').read

But otherwise, if you can wait for v0.17, you can just specify an absolute file path...

render_defaults[:layout] = :'/my/awesome/layout'

Which in your actual code would probably look more like this...

render_defaults[:layout] = :"#{File.expand_path('../views/layout.erb', __FILE__)}"

Tom

On Friday, 16 August 2013 20:36:30 UTC+10, Julien Ammous wrote:

Julien Ammous

unread,
Aug 19, 2013, 5:47:29 AM8/19/13
to scor...@googlegroups.com
I ended up using the first of your suggestions, thanks :)
I never liked rails and sinatra is a nice but a little too low level for most needs but scorched is nearly perfect !

I totally agree with the level of magic involved in rails and that's driving me crazy sometimes, every time I need to dig deeper to understand what the hell is happening
that's a nightmare (I use activerecord on work projects without rails).

Now I just need to wrap my head around the fact that my web app is now a standard ruby app and I can use what I am used to like a good old File.open xD
(btw you can just call File.read ^^)

Tom Wardrop

unread,
Aug 19, 2013, 6:16:42 AM8/19/13
to scor...@googlegroups.com
But File.read requires one more key press - holding the shift key for the capital "F" :-)

I'm glad others are enjoying using Scorched for the same reasons that motivated me to create the project. 

Cheers,
Tom

Ted Milker

unread,
Aug 19, 2013, 12:53:38 PM8/19/13
to scor...@googlegroups.com
I have to mirror Julien's opinions.  I was spending a ton of time deciphering Rails magic and what it was doing(or messing up) and it gets extremely frustrating wasting all that time.  I wanted to switch to Sinatra or Padrino but found SInatra was too basic and Padrino had too many weird quirks.

Back when scorched was just a README.md, I had started building a framework on top of Sinatra that added the functionality I needed with no frills.  Then I got busy with other projects and when I came back to my old research to pick it up again, I found scorched had developed into a real thing and had everything I was thinking of.

I'm getting really close to using it in a real app.  However, I am finding that I have dealt with so much magic for so long that I'm having to stop myself from hunting for incantations and just write the basic ruby code that I'm supposed to use with scorched.

Tom Wardrop

unread,
Aug 20, 2013, 5:30:19 AM8/20/13
to scor...@googlegroups.com
Exactly. A framework like Scorched forces you to find your own solutions to the problems you face, as opposed to being dependant on the solutions already established by others. A framework like Rails makes it quick to get an application up and running, because it provides solutions to a lot of those common problems for you. This is what lulls so many people into it. The problem is however, the time you save in that early phase of a project is often lost as the project develops further and matures. Pretty soon you begin to run into limitations imposed by those pre-made solutions, and this is where you're forced to delve into the land of magic, learning how it works, so you can make the amendments you need to make.

The problem with spending time in the land of magic, is that you're investing time and energy into learning something very domain-specific, i.e. you're spending time learning how to master problems specific to Rails and certain Rails components - knowledge that is unlikely to be very useful outside the scope of that Rails domain. When on the other hand you're forced to find your own solutions, the time you invest goes into knowledge and experience that will likely prove to be useful in a wider range of contexts, regardless of whether that solution is merely finding a library and applying it, or coding something from scratch.

That's kind of how I look at it anyway, plus, as much as I strive for that end product, being creative is what I enjoy most about programming and application development. I'm not suggesting Rails doesn't allow you to be creative, but the lower-level the framework or the less that is solved for you, the more opportunity there is for creativity.

Tom

Tom Wardrop

unread,
Sep 11, 2013, 8:20:00 PM9/11/13
to scor...@googlegroups.com
FYI, v0.17 has now been released which includes the fix as mentioned earlier.

Tom

On Monday, 19 August 2013 19:47:29 UTC+10, Julien Ammous wrote:

Julien Ammous

unread,
Oct 2, 2013, 8:57:06 AM10/2/13
to scor...@googlegroups.com
nice, thanks !:)
Reply all
Reply to author
Forward
0 new messages