Created
April 16, 2010 14:48
-
-
Save jszmajda/368498 to your computer and use it in GitHub Desktop.
This file contains 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
<%# bar baz %> | |
You put your <%= bar %> in my <%= baz %>! |
This file contains 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
module FooHelper | |
include PartialMethods | |
end |
This file contains 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
<%= p_some_partial("chocolate", "peanut butter") %> |
This file contains 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
require 'find' | |
module PartialMethods | |
def self.included(base) | |
path = "#{Rails.root}/app/views/#{base.name.sub(/Helper$/,"").downcase}" | |
Find.find(path) do |file| | |
if file =~ /#{path}\/_(.+)/ | |
partial = $~[1].split(/\./)[0] | |
required_arguments = [] | |
header = File.readlines(file)[0] | |
if header =~ /^<%# +?(.*?) +?%>$/ | |
puts "header: #{header}" | |
required_arguments = $~[1].split(/ +/) | |
end | |
method = Proc.new do |*args| | |
if args.length != required_arguments.length | |
raise ArgumentError, "wrong number of arguments (#{args.length} for #{required_argumentss.length})" | |
end | |
options = {} | |
required_arguments.each_with_index do |arg, i| | |
options[arg.to_sym] = args[i] | |
end | |
render partial.to_s, options | |
end | |
define_method "p_#{partial}".to_sym, &method | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment