Comments (15)
Hey, I'm gonna add this feature through a config var probably, but for now, you could alias :index to :blog by adding this code to your config.ru
:
class Toto::Site
alias :blog :index
end
This will make them identical, but will show up as /blog
in the url.
from toto.
Brilliant! That works as a charme... Love this..
Need to polish my Sinatra code-fu, would love to add compass support with haml/sass/blueprint etc.. what's your take on that?
Could it be made extendable so the toto core stay's lean and mean.
Peter.
from toto.
Additional preprocessing, like Sass could probably be handled by a Rack middleware — I'm sure someone already wrote something like that.
For templating, I'd have to expose the template engine, which is something I could do pretty easily through a config var, or at least make it really easy to monkey-patch. You can get that functionality right now though by overwriting this:
http://github.com/cloudhead/toto/blob/master/lib/toto.rb#L22-25
by something which calls haml.
from toto.
cool.. thanks.. I will give it a shot this weekend...
from toto.
incidently, just pushed 0.2.6, which gives access to @articles
from all pages — for your scenario, I still think the alias makes more sense, because /blog is actually the index.
note that @articles
is lazy-loading, so it won't load the actual articles until you try to access a property of it.
from toto.
nice!
Found how to use sass :
use Sass::Plugin::Rack
it's already there in the haml gem... :)
from toto.
And this for Haml processing
module Toto
module Template
def to_html page, &blk
path = (page == :layout ? Paths[:templates] : Paths[:pages])
Haml::Engine.new(File.read("#{path}/#{page}.haml"),:attr_wrapper => '"', :filename => path ).render(binding)
end
end
end
from toto.
nice. I think giving the ability to pass a rendering lambda to the config would be ideal in this case, something like:
set :renderer, lambda do |page|
Haml::Engine.new(File.read("#{path}/#{page}.haml"),:attr_wrapper => '"', :filename => path ).render(binding)
end
and then evaluating it in to_html.
could open up lots of possibilities.
from toto.
I just pushed 0.4.0
, which makes this possible through the :to_html
setting:
set :to_html, lambda do |path, page, binding|
Haml::Engine.new(File.read("#{path}/#{page}.haml"),
:attr_wrapper => '"',
:filename => path ).render(binding)
end
I haven't tested with Haml specifically, but there's no reason it shouldn't work
from toto.
very nice!! Still haven't had time to finish my webpage with toto, but it's still in the pipeline. This feature is very a very nice addition.
from toto.
I am trying to switch to Haml rendering and get this with the new code:
config.ru:29:in lambda': tried to create Proc object without a block (ArgumentError) from config.ru:29 from /var/lib/gems/1.8/gems/toto-0.4.0/lib/toto.rb:316:in
instance_eval'
from /var/lib/gems/1.8/gems/toto-0.4.0/lib/toto.rb:316:in `initialize'
from toto.
I am using the config.ru:
set :to_html, lambda { |path, page, binding|
Haml::Engine.new(File.read("#{path}/#{page}.haml"),
:attr_wrapper => '"',
:filename => page ).render(binding)
}
but now Haml barks about things with a trace...
Traceback (innermost first)
/var/lib/gems/1.8/gems/haml-2.2.17/lib/haml/engine.rb: in eval
eval(precompiled + ";" + precompiled_method_return_value,...
/var/lib/gems/1.8/gems/haml-2.2.17/lib/haml/engine.rb: in render
eval(precompiled + ";" + precompiled_method_return_value,...
config.ru: in nil
Haml::Engine.new(File.read("#{path}/#{page}.haml"),...
/var/lib/gems/1.8/gems/toto-0.4.0/lib/toto.rb: in call
config[:to_html].call(path, page, binding)...
/var/lib/gems/1.8/gems/toto-0.4.0/lib/toto.rb: in to_html
config[:to_html].call(path, page, binding)...
/var/lib/gems/1.8/gems/toto-0.4.0/lib/toto.rb: in render
type == :html ? to_html(:layout, @config, &Proc.new { to_html page, @config }) : send(:"to_#{type}", :feed)
The dump of the lamda parameters:
Path blog/templates, page layout, binding #Binding:0x7f47da9b4258
The File object is good.. represents layout.haml
from toto.
ahm, it's just the :filename => page
should be :filename => path
— I have no idea what that does though.
gonna fix the example.
from toto.
Excellent... Good eye... I missed that too when looking at the Haml docs. Works like a charm. Very nice having Haml templates!! W00t. Thanks!
from toto.
np, just pushed an update to be able to pass blocks instead of lambdas, should be prettier:
set :to_html do |page|
# do stuff
end
from toto.
Related Issues (20)
- 404 Error with Phusion Passenger HOT 1
- HTML tags are ignored HOT 4
- RSS xml malformation on Heroku.
- Dorothy - read on link does not work from fresh clone HOT 2
- Invalid ATOM Xml using default builder HOT 2
- How to cache the page and at the same time offer dynamic redirects
- Access 'articles' from outside of index page
- not working on heroku cedar? HOT 10
- non-blog usage, custom URLs
- Respond to HEAD requests with 200, not 400 HOT 1
- Smart-mode of markdown not documented
- Unmaintained repository HOT 2
- Error with routing to more Info HOT 1
- Having a lot of trouble getting toto to work on heroku
- a issue using thin with toto HOT 4
- 304 Headers
- Update code on rubygems HOT 2
- Content-length error prevents page load and leads lint error
- In Ruby 2.7 basically the tainting mechanism, leads to stackoverflow
- This looks really interesting! - GitLab instead of Heroku?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from toto.