pakyow-presenter/lib/presenter/binder.rb in pakyow-presenter-0.9.1 vs pakyow-presenter/lib/presenter/binder.rb in pakyow-presenter-0.10.0

- old
+ new

@@ -45,22 +45,26 @@ # @param bindable [Symbol] the data being bound # @param bindings [Symbol] additional bindings to take into consideration when determining the value # @param context [Symbol] context passed through to the defined bindings # def value_for_scoped_prop(scope, prop, bindable, bindings, context) - binding_fn = @sets.lazy.map { |set| - set[1].match_for_prop(prop, scope, bindable, bindings) - }.find { |match| - !match.nil? - } + if @sets.empty? + binding_fn = bindings[prop] + else + binding_fn = @sets.lazy.map { |set| + set[1].match_for_prop(prop, scope, bindable, bindings) + }.find { |match| + !match.nil? + } + end if binding_fn binding_eval = BindingEval.new(prop, bindable, context) binding_eval.instance_exec(binding_eval.value, bindable, context, &binding_fn) else # default value if bindable.is_a?(Hash) - bindable[prop] + bindable.fetch(prop) { bindable[prop.to_s] } elsif bindable.class.method_defined?(prop) bindable.send(prop) end end end @@ -80,9 +84,19 @@ def options_for_scoped_prop(scope, prop, bindable, context) @sets.lazy.map { |set| set[1].options_for_prop(scope, prop, bindable, context) }.find { |options| !options.nil? + } + end + + def bindings_for_scope(scope, bindings = {}) + return bindings if @sets.empty? + + @sets.map { |set| + set[1].bindings_for_scope(scope, bindings) + }.inject({}) { |acc, bindings| + acc.merge(bindings) } end end end end