Module: ApplicationHelper
- Defined in:
- lib/easypartials.rb
Constant Summary collapse
- METHOD_REGEXP =
/^_(.+)$/
Instance Method Summary collapse
-
#concat_partial(partial_name, locals = {}, &block) ⇒ Object
Concat the given partial.
- #method_missing_with_easy_partials(method_name, *args, &block) ⇒ Object (also: #method_missing)
- #respond_to_with_easy_partials(method_name, inc_priv = false) ⇒ Object (also: #respond_to?)
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object Also known as: method_missing_without_easy_partials
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/easypartials.rb', line 64 def method_missing_with_easy_partials(method_name, *args, &block) method_str = method_name.to_s if method_str =~ METHOD_REGEXP partial_name = method_str[METHOD_REGEXP, 1] self.class.class_eval <<ENDEVAL def #{method_str}(*args, &block) begin concat_partial "#{partial_name}", *args, &block rescue ActionView::MissingTemplate last_exc = nil done = false dirs = Easypartials.shared_directories dirs.each do |shared| begin concat_partial shared + "/#{partial_name}", *args, &block done = true rescue ActionView::MissingTemplate => exc last_exc = exc end break if done end unless done exc = ActionView::MissingTemplate.new dirs, "#{partial_name}" raise exc end end end ENDEVAL self.send(method_str, *args, &block) else method_missing_without_easy_partials method_name, *args, &block end end |
Instance Method Details
#concat_partial(partial_name, locals = {}, &block) ⇒ Object
Concat the given partial.
68 69 70 71 72 73 74 75 76 |
# File 'lib/easypartials.rb', line 68 def concat_partial(partial_name, locals = {}, &block) unless block.nil? locals.merge! :body => capture(&block) end content = render :partial => partial_name, :locals => locals concat content nil end |
#method_missing_with_easy_partials(method_name, *args, &block) ⇒ Object Also known as: method_missing
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/easypartials.rb', line 28 def method_missing_with_easy_partials(method_name, *args, &block) method_str = method_name.to_s if method_str =~ METHOD_REGEXP partial_name = method_str[METHOD_REGEXP, 1] self.class.class_eval <<ENDEVAL def #{method_str}(*args, &block) begin concat_partial "#{partial_name}", *args, &block rescue ActionView::MissingTemplate last_exc = nil done = false dirs = Easypartials.shared_directories dirs.each do |shared| begin concat_partial shared + "/#{partial_name}", *args, &block done = true rescue ActionView::MissingTemplate => exc last_exc = exc end break if done end unless done exc = ActionView::MissingTemplate.new dirs, "#{partial_name}" raise exc end end end ENDEVAL self.send(method_str, *args, &block) else method_missing_without_easy_partials method_name, *args, &block end end |
#respond_to_with_easy_partials(method_name, inc_priv = false) ⇒ Object Also known as: respond_to?
22 23 24 25 26 |
# File 'lib/easypartials.rb', line 22 def respond_to_with_easy_partials(method_name, inc_priv = false) return true if method_name =~ METHOD_REGEXP respond_to_without_easy_partials(method_name, inc_priv) end |