Giter Club home page Giter Club logo

Comments (15)

cloudhead avatar cloudhead commented on July 23, 2024

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.

peterberkenbosch avatar peterberkenbosch commented on July 23, 2024

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.

cloudhead avatar cloudhead commented on July 23, 2024

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.

peterberkenbosch avatar peterberkenbosch commented on July 23, 2024

cool.. thanks.. I will give it a shot this weekend...

from toto.

cloudhead avatar cloudhead commented on July 23, 2024

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.

peterberkenbosch avatar peterberkenbosch commented on July 23, 2024

nice!

Found how to use sass :
use Sass::Plugin::Rack

it's already there in the haml gem... :)

from toto.

peterberkenbosch avatar peterberkenbosch commented on July 23, 2024

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.

cloudhead avatar cloudhead commented on July 23, 2024

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.

cloudhead avatar cloudhead commented on July 23, 2024

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.

peterberkenbosch avatar peterberkenbosch commented on July 23, 2024

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.

resistorsoftware avatar resistorsoftware commented on July 23, 2024

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:ininstance_eval'
from /var/lib/gems/1.8/gems/toto-0.4.0/lib/toto.rb:316:in `initialize'

from toto.

resistorsoftware avatar resistorsoftware commented on July 23, 2024

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.

cloudhead avatar cloudhead commented on July 23, 2024

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.

resistorsoftware avatar resistorsoftware commented on July 23, 2024

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.

cloudhead avatar cloudhead commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.