Module: Deas::ErbTags::Capture::Methods
- Defined in:
- lib/deas-erbtags/capture.rb
Instance Method Summary collapse
- #capture(&content) ⇒ Object
- #capture_partial(*args, &content) ⇒ Object
- #capture_render(*args, &content) ⇒ Object
- #capture_tag(name, *args, &content) ⇒ Object
- #erb_outvar ⇒ Object
- #erb_outvar_name ⇒ Object
- #erb_write(content) ⇒ Object
Instance Method Details
#capture(&content) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/deas-erbtags/capture.rb', line 24 def capture(&content) outvar = self.erb_outvar_name begin orig_outvar = self.erb_outvar instance_variable_set(outvar, "\n") result = instance_eval(&(content || Proc.new {})) if instance_variable_get(outvar) == "\n" "\n#{result}" else instance_variable_get(outvar) end ensure instance_variable_set(outvar, orig_outvar) end end |
#capture_partial(*args, &content) ⇒ Object
51 52 53 |
# File 'lib/deas-erbtags/capture.rb', line 51 def capture_partial(*args, &content) self.erb_write self.partial(*args, &Proc.new{ capture(&content) }) end |
#capture_render(*args, &content) ⇒ Object
47 48 49 |
# File 'lib/deas-erbtags/capture.rb', line 47 def capture_render(*args, &content) self.erb_write self.render(*args, &Proc.new{ capture(&content) }) end |
#capture_tag(name, *args, &content) ⇒ Object
42 43 44 45 |
# File 'lib/deas-erbtags/capture.rb', line 42 def capture_tag(name, *args, &content) opts = args.last.kind_of?(::Hash) ? args.pop : {} self.erb_write tag(name, "#{capture(&content)}\n", opts) end |
#erb_outvar ⇒ Object
16 17 18 |
# File 'lib/deas-erbtags/capture.rb', line 16 def erb_outvar instance_variable_get(self.erb_outvar_name) end |
#erb_outvar_name ⇒ Object
12 13 14 |
# File 'lib/deas-erbtags/capture.rb', line 12 def erb_outvar_name self.sinatra_call.settings.erb[:outvar] end |
#erb_write(content) ⇒ Object
20 21 22 |
# File 'lib/deas-erbtags/capture.rb', line 20 def erb_write(content) self.erb_outvar << "#{content}\n" end |