bonsai icon indicating copy to clipboard operation
bonsai copied to clipboard

use mustache (fork)

Open microspino opened this issue 12 years ago • 4 comments

I really like Bonsai and i would like to add mustache templates to it, although I know Tilt doesn't suport it. How do I have to proceed? Do I need to fork your project?. Do you think it's a bad idea? Is there anything against using it in parallel but separated from tilt. Sorry github and gem newbie here this will be the first fork for me, I don't know ethics or etiquette of doing it.

microspino avatar Feb 10 '12 23:02 microspino

Hmm. InterestingBonsai used to use mustache in the beginning but it was removed from 'tilt'. I recently saw a gem that re-added support for it. (https://github.com/Becojo/tilt-mustache)

So, I'd try installing the gem, then try requiring it in bonsai by adding a file called extensions.rb in the root directory of your bonsai site. Then, you could require 'tilt-mustache'.

Just an idea, I haven't tried it but I'm reasonably sure it would work.

Good luck!

On 11/02/2012, at 10:33 AM, Daniele Spinosa wrote:

I really like Bonsai and i would like to add mustache templates to it, although I know Tilt doesn't suport it. How do I have to proceed? Do I need to fork your project (sorry github and gem nnewbie here).


Reply to this email directly or view it on GitHub: https://github.com/benschwarz/bonsai/issues/23

benschwarz avatar Feb 24 '12 09:02 benschwarz

Any luck, Daniele?

On 11/02/2012, at 10:33 AM, Daniele [email protected] wrote:

I really like Bonsai and i would like to add mustache templates to it, although I know Tilt doesn't suport it. How do I have to proceed? Do I need to fork your project (sorry github and gem nnewbie here).


Reply to this email directly or view it on GitHub: https://github.com/benschwarz/bonsai/issues/23

benschwarz avatar Mar 14 '12 12:03 benschwarz

Hello, sorry for the lack feedback. In a few word: "it works with some glitches". Here is the commented content of my extensions.rb.

require 'tilt-mustache'

module Bonsai
  class Navigation
    # without this i can't generate the main navigation links
    def self.tree
      pages = Page.all(Page.path, "*").select{|p| !p.floating? }.sort_by{|p| p.disk_path }
      pages.map {|p| {:permalink => p.permalink, :name => p.name}}
    end
  end

  class Page
    # without this i can't generate Fig, Maple, Magic, links under varieties
    def children
      pages = Page.all(File.dirname(disk_path), "*").delete_if{|p| p.floating? }
      pages.map {|p| {:permalink => p.permalink, :name => p.name}}
    end
  end
end

If I don't reopen Navigation and Page classes I get: undefined method 'permalink' for #. There are, probably, better ways to fix my issues but i'm not a strong ruby coder...As of today, i promise you to improve :) I've used only the default.mustache and products.mustache templates until now. Here are they:

default.mustache

<!DOCTYPE html>
<html lang="en">
  {{>templates/shared/head}}
  <body id="{{slug}}">
    <section id="wrapper">
      {{>templates/shared/header}}

      <article>
        <h2>{{headline}}</h2>
        <section role="main">
          {{{body}}}
        </section>
      </article>

      {{>templates/shared/footer}}
    </section>
    {{>templates/shared/analytics}}
  </body>
</html>

products.mustache

<!DOCTYPE html>
<html lang="en">
  {{>templates/shared/head}}
  <body id="{{slug}}">
    <section id="wrapper">
      {{>templates/shared/header}}

      <article>
        <h2>{{headline}}</h2>
        <section role="main">
          {{body}}
        </section>
      </article>

      <nav id="sub-navigation">
        <ol>
          {{#children}}
            <li><a href="{{permalink}}">{{name}}</a></li>
          {{/children}}
        </ol>
      </nav>

      {{>templates/shared/footer}}
    </section>

  </body>
  {{>templates/shared/analytics}}
</html>

Please let me know if could help more or improve this.

microspino avatar Mar 15 '12 09:03 microspino

Hey,

That's really excellent Daniele, well done!

If I get time I'll have a go myself.

Cheers,

Ben

On Thursday, 15 March 2012 at 8:58 PM, Daniele Spinosa wrote:

Hello, sorry for the lack feedback. In a few word: "it works with some glitches". Here is the commented content of my extensions.rb.

require 'tilt-mustache'

module Bonsai class Navigation

without this i can't generate the main navigation links

def self.tree pages = Page.all(Page.path, "*").select{|p| !p.floating? }.sort_by{|p| p.disk_path } pages.map {|p| {:permalink => p.permalink, :name => p.name}} end end class Page

without this i can't generate Fig, Maple, Magic, links under varieties

def children pages = Page.all(File.dirname(disk_path), "*").delete_if{|p| p.floating? } pages.map {|p| {:permalink => p.permalink, :name => p.name}} end end end

If I don't reopen Navigation and Page classes I get: undefined method 'permalink' for #. There are, probably, better ways to fix my issues but i'm not a strong ruby coder...As of today, i promise you to improve :) I've used only the default.mustache and products.mustache templates until now. Here are they:

default.mustache

{{>templates/shared/head}}
{{>templates/shared/header}}

{{headline}}

{{{body}}}
{{>templates/shared/footer}}
{{>templates/shared/analytics}}

products.mustache

{{>templates/shared/head}}
{{>templates/shared/header}}

{{headline}}

{{body}}
{{>templates/shared/footer}}
{{>templates/shared/analytics}} Please let me know if could help more or improve this.

Reply to this email directly or view it on GitHub: https://github.com/benschwarz/bonsai/issues/23#issuecomment-4516655

benschwarz avatar Mar 15 '12 10:03 benschwarz