Class: Crystal::Processors::ScopedParams

Inherits:
Crystal::Processor show all
Defined in:
lib/crystal/html/processors/scoped_params.rb

Instance Attribute Summary

Attributes inherited from Crystal::Processor

#next_processor

Instance Method Summary collapse

Methods inherited from Crystal::Processor

#initialize, inspect

Constructor Details

This class inherits a constructor from Crystal::Processor

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/crystal/html/processors/scoped_params.rb', line 5

def call
  if workspace.params?
    to_delete = []
    workspace.params.each do |name, value|
      name.scan /(.+)\[(.+)\]/ do |scope_name, name_in_scope|
        scope = workspace.params[scope_name] ||= {}
      
        unless scope.is_a? Hash
          logger.warn "Owerriding :#{scope} param!"
          scope = {}
          workspace.params[scope_name] = scope
        end
      
        scope[name_in_scope] = value
        to_delete << name
      end
    end
    to_delete.each{|n| workspace.params.delete n}
  end
          
  next_processor.call
end