I'm not really fond of the idea of a "magic file" with special behavior.
It's not that hard to add a few "@imports," and it makes things much
more explicit. Sorry.
- Nathan
Haakon Sorensen wrote:
> I love the idea of being able to share constants between my sass/css
> files. I wanted to go one step further and not have to do the @import
> call. So, I made a modification to the engine/plugin which looks for
> the file "constants.sass" next to your sass file and reads the
> constants from there if the file exists (convention over
> configuration!). My change also makes the css files get regenerated
> if you make a change to the constants file. If this looks good, I
> would love to see my patch committed. Here are my svn diffs:
>
>
> ===================================================================
> --- plugin.rb (revision 529)
> +++ plugin.rb (working copy)
>
> private
>
> def template_filename(name)
> "#{@@options[:template_location]}/#{name}.sass"
> end
>
> def css_filename(name)
> "#{@@options[:css_location]}/#{name}.css"
> end
>
> def stylesheet_needs_update?(name)
> - !File.exists?(css_filename(name)) ||
> (File.mtime(template_filename(name)) - 2) >
> File.mtime(css_filename(name))
> + !File.exists?(css_filename(name)) ||
> + (File.mtime(template_filename(name)) - 2) >
> File.mtime(css_filename(name)) ||
> + needs_updating_by_constants(name)
> end
> +
> + def needs_updating_by_constants(name)
> + constants_file = template_filename('constants')
> + return false unless File.exist?(constants_file)
> + return File.mtime(constants_file) >
> File.mtime(css_filename(name))
> end
> +
> end
> + end
> end
>
>
> ===================================================================
> --- engine.rb (revision 529)
> +++ engine.rb (working copy)
> @@ -68,8 +68,25 @@
> @template = template.split(/\n\r|\n/)
> @lines = []
> @constants = {}
> +
> + load_global_constants
> end
>
> + def load_global_constants
> + constants_file = File.dirname(@options[:filename]) + '/
> constants.sass'
> + if File.exist? constants_file
> + # swap out template contents with the content of my constants
> file
> + original_template = @template
> + @template = File.read(constants_file)
> +
> + # do a render to populate constants hash
> + render
> +
> + # swap template contents back in
> + @template = original_template
> + end
> + end
> +
> # Processes the template and returns the result as a string.
> def render
> begin
>
>
> cheers,
> Haakon
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---