Created
October 21, 2014 23:21
-
-
Save emilebosch/9e5c25833b8f92dfd4db to your computer and use it in GitHub Desktop.
Make it possibe to have jade style mixins in slim http://jade-lang.com/reference/mixins/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mixin(name, &block) | |
@mixins ||= {} | |
@mixins[name] = block | |
method = %{ | |
def #{name}(*args, &block) | |
call_mixin(:#{name}, *args, &block) | |
end | |
} | |
eval(method) | |
end | |
def call_mixin(name, *args, &block) | |
x = args || [] | |
x.unshift block | |
capture *x, &@mixins[name] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- mixin :list do |block, title| | |
h1=title | |
ul==capture(&block) | |
= list "Ferrets" do | |
li Item Tobi | |
li Item Loki |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or use lambda