Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper functions in haml #10

Closed
danieldkim opened this issue May 26, 2010 · 6 comments
Closed

helper functions in haml #10

danieldkim opened this issue May 26, 2010 · 6 comments

Comments

@danieldkim
Copy link
Contributor

need a mechanism to make helper functions accessible from haml code.

i've committed a simple solution in my fork:

http://github.com/danieldkim/picard/commit/95ebf42150a7fc78de2e73157f47bcf53821af6a

please merge if it looks reasonable.

@danieldkim
Copy link
Contributor Author

ok, the solution above wasn't quite enough for my needs. i've implemented something a bit more interesting in:

http://github.com/danieldkim/picard/commit/5cba5a48c308b07e786093c09d6fe25df7812034

this makes the request scope available to the mixin functions through this.

@danieldkim
Copy link
Contributor Author

you can ignore the previous comment as that commit was just a more convoluted way of providing what the previous commit already did. argh, it's way past my bedtime ...

@dantebronto
Copy link
Owner

Thanks for your contributions Daniel. I still haven't had a chance to look into this yet, I'll try and take a gander this weekend.

@danieldkim
Copy link
Contributor Author

np, dante. happy to contribute. this little change allows me to do something like this in my configuration:

picard.env = {
  root: __filename.replace(/\/config\/environments\/\w+.js$/, ''),
  mode: 'development',
  port: 9900,
  public_dir: '/public',
  views: '/views',
  scope_mixin: {    
    is_blank: function is_blank(var_name) {
      with(this) {
        try {
          var the_var = eval('(' + var_name + ')');
          return the_var == undefined || the_var == null || the_var == '';
        } catch (e) {
          if (e.constructor.name == 'ReferenceError') return true;
          else throw Error("Caught exception when eval'ing " + var_name + ":" + e);
        }
      }
    }
  }  
}

and then use that is_blank() function in my haml code.

btw, there's a few other things that i've built on top of picard in my own project that may or may not make sense to pull into picard in some form (although the more of this stuff that picard takes on the less "micro" it becomes):

  • notion of controllers and models, and automated loading of controllers and models based on file conventions
  • before and around filters on controller methods
  • standardized parsing of object attributes encoded in html forms
  • respond_to-like functionality with automated format resolution
    and routing to appropriate template files for rendering

@dantebronto
Copy link
Owner

Today's release of several commits (soon to be 0.2 release) Resolves this issue. Merging custom objects with the view scope is now supported by calling helpers().

@danieldkim
Copy link
Contributor Author

thanks, the helpers functionality works nicely. i also like the improved exception handling, toned-down logging, template caching (though there is an issue with that that i'll log shortly), and less-verbose haml syntax -- overall, a great release!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants