Class: PeekAView::View
- Inherits:
-
ActiveSupport::OrderedOptions
- Object
- ActiveSupport::OrderedOptions
- PeekAView::View
- Defined in:
- lib/peek_a_view/view.rb
Instance Method Summary collapse
- #fixture(name) ⇒ Object
-
#initialize(name, common_block = nil) ⇒ View
constructor
A new instance of View.
- #layout ⇒ Object
- #params=(new_params) ⇒ Object
- #record(block) ⇒ Object
- #template ⇒ Object
- #variables(options = {}) ⇒ Object
Constructor Details
#initialize(name, common_block = nil) ⇒ View
Returns a new instance of View.
3 4 5 6 7 8 |
# File 'lib/peek_a_view/view.rb', line 3 def initialize(name, common_block = nil) @name = name self.params = nil # just to initialize params @blocks = [] record(common_block) if common_block end |
Instance Method Details
#fixture(name) ⇒ Object
32 33 34 35 36 |
# File 'lib/peek_a_view/view.rb', line 32 def fixture(name) fixture_dir = Rails.root + 'spec/fixtures/peek_a_view' # TODO config file = File.join(fixture_dir, name) File.read(file) end |
#layout ⇒ Object
18 19 20 |
# File 'lib/peek_a_view/view.rb', line 18 def layout 'application' # TODO be smarter end |
#params=(new_params) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/peek_a_view/view.rb', line 22 def params=(new_params) *controller, action = template.split('/') augmented = (new_params || { }).reverse_merge( controller: controller.join('/'), action: action ) super(augmented) augmented end |
#record(block) ⇒ Object
10 11 12 |
# File 'lib/peek_a_view/view.rb', line 10 def record(block) @blocks << block end |
#template ⇒ Object
14 15 16 |
# File 'lib/peek_a_view/view.rb', line 14 def template super || @name end |
#variables(options = {}) ⇒ Object
38 39 40 41 |
# File 'lib/peek_a_view/view.rb', line 38 def variables( = {}) @blocks.flatten.each { |block| block.call(self, ) } self end |