Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/props_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def set!(key, options = {}, &block)
@builder.item_context = found_item
set!(key, found_options, &found_block)
end
else
elsif block || options.is_a?(Props::Options)
@builder.set!(key, options, &block)
else
@builder.set_value!(key, options)
end
end

Expand Down
17 changes: 16 additions & 1 deletion lib/props_template/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ def set!(key, value = nil)
nil
end

def set_value!(key, value)
if @scope == :array
raise InvalidScopeForObjError.new("Attempted to set! on an array! scope")
end

if @scope.nil?
@scope = :object
@stream.push_object
end

@stream.push_value(value, format_key(key))

nil
end

def handle_collection_item(collection, item, index, options)
@item_context = item

Expand Down Expand Up @@ -124,7 +139,7 @@ def extract!(object, *values)
[value, value]
end

set!(
set_value!(
key,
object.is_a?(Hash) ? object.fetch(attribute) : object.public_send(attribute)
)
Expand Down
2 changes: 1 addition & 1 deletion lib/props_template/base_with_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def traveled_path!
end

def set_content!(options = {})
return super if !@em.has_extensions(options)
return super if options.empty? || !@em.has_extensions(options)

@em.handle(options, item_context) do
yield
Expand Down
4 changes: 4 additions & 0 deletions lib/props_template/searcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def set_content!(*args)
yield
end

def set_value!(key, value)
nil
end

def set!(key, options = {}, &block)
return if @found_block || !block && !options.is_a?(Props::Options)

Expand Down
Loading