reediting erbs

52 views
Skip to first unread message

hrvoje

unread,
Oct 26, 2011, 12:02:27 PM10/26/11
to babushka_app
What would be best way for dep to rewrite file if erb changed?

For example

met? { babushka_config? config_filename }
meet { render_erb "rabbit_config.erb", :to => config_filename, :sudo
=> true }


this doesn't work since it doesn't detect if erb changed, so it
doesn't render again.


I tried also:

met? { File.read(config_filename) == render_erb("rabbit_config.erb") }

which doesn't work either, because it generates config file every time
I run it, because "generated by babushka" comments include timestamp.
So config file is rewritten every time.

Ideas?

hrvoje

unread,
Oct 26, 2011, 1:09:45 PM10/26/11
to babushka_app
Another problems is # Comments are not supported in some languaged,
erlange for example, so config file created by babushka has syntax
error.

Ben Hoskings

unread,
Oct 26, 2011, 7:37:24 PM10/26/11
to babush...@googlegroups.com
You can customise those things when using #render_erb, like so:

render_erb 'nginx/nginx.launchd.erb',
:to => '/Library/LaunchDaemons/org.nginx.plist',
:sudo => true,
:comment => '<!--',
:comment_suffix => '-->'

The core problem here is that I haven't documented #render_erb properly. I've been working hard on docs over the last week or so: http://babushka.me -- but there's rdoc work to do too.

Patches welcome :)

- Ben

> --
> To post, email babush...@googlegroups.com
> To unsubscribe, email babushka_app...@googlegroups.com
> ~
> http://babushka.me
> http://github.com/benhoskings/babushka
> http://groups.google.com/group/babushka_app

Chris Berkhout

unread,
Oct 26, 2011, 10:49:37 PM10/26/11
to babush...@googlegroups.com
When I hit this issue I started using my own rendering helpers:
https://github.com/chrisberkhout/babushka-deps/blob/master/helpers/erb.rb

But that's pretty hacky. I'd recommend figuring out the proper babushka way.

Cheers,
Chris

Ben Hoskings

unread,
Oct 26, 2011, 7:34:19 PM10/26/11
to babush...@googlegroups.com
There's a thing just for this :)

met? { Babushka::Renderable.new(config_filename).from?(dependency.load_path.parent / "rabbit_config.erb") }


meet { render_erb "rabbit_config.erb", :to => config_filename, :sudo => true }

(The syntax is still a bit wordy. I'll fix that soon.)

Here's how it works: the line written to the top of the rendered file includes two hashes. One is of the template the file was rendered from, and one is of the output file (excluding that top line).

So, babushka can use those hashes to tell if the file was rendered from the template as it stands now, and also if the rendered file has since been altered.

Ben

hrvoje

unread,
Nov 1, 2011, 5:52:02 AM11/1/11
to babushka_app
Wow, cool, I was wondering what those hashes mean. I'll test this
today and let you know.

thomas.s...@9elements.com

unread,
Aug 12, 2013, 4:04:06 PM8/12/13
to babush...@googlegroups.com
It would be nice to be able to define a method that returns an object which can be used both in the met? and the meet block, to reduce duplication and noise.
Reply all
Reply to author
Forward
0 new messages