Class: Jekyll::Drops::ActivityDrop
- Inherits:
-
Drop
- Object
- Drop
- Jekyll::Drops::ActivityDrop
- Extended by:
- Forwardable
- Defined in:
- lib/jekyll/drops/activity_drop.rb
Overview
Converts an activity into a liquid drop that can be dereferenced on demand.
Instance Method Summary collapse
-
#all_items ⇒ Array
Iterate over all items of a collection.
-
#available ⇒ Object
This means we could dereference the object, Liquid can use it to check if it’s possible to use it.
- #fallback_data ⇒ Object
-
#initialize(obj) ⇒ ActivityDrop
constructor
different objects.
- #to_s ⇒ Object
Constructor Details
#initialize(obj) ⇒ ActivityDrop
TODO:
Still no idea why Liquid/Jekyll initialize this with
different objects
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/jekyll/drops/activity_drop.rb', line 81 def initialize(obj) id = case obj when Jekyll::Page obj['id'] || obj.url when DistributedPress::V1::Social::ReferencedObject obj['id'] when Hash obj[:object]['id'] end raise StandardError unless id Jekyll.logger.info 'ActivityPub:', "Referencing #{id}" @original_obj = obj @@objects ||= {} @obj = @@objects[id] ||= case obj when Jekyll::Page DistributedPress::V1::Social::ReferencedObject.new(object: JSON.parse(obj.to_json), dereferencer: Jekyll::ActivityPub::Notifier.dereferencer) when DistributedPress::V1::Social::ReferencedObject obj when Hash obj[:object] else raise StandardError end rescue StandardError => e Jekyll.logger.warn 'ActivityPub:', "Error" end |
Instance Method Details
#all_items ⇒ Array
Iterate over all items of a collection
67 68 69 70 71 |
# File 'lib/jekyll/drops/activity_drop.rb', line 67 def all_items return nil unless @obj.respond_to?(:each) @all_items ||= @obj.each.to_a.uniq { |x| x.uri } end |
#available ⇒ Object
This means we could dereference the object, Liquid can use it to check if it’s possible to use it.
75 76 77 |
# File 'lib/jekyll/drops/activity_drop.rb', line 75 def available true end |
#fallback_data ⇒ Object
116 117 118 |
# File 'lib/jekyll/drops/activity_drop.rb', line 116 def fallback_data @obj end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/jekyll/drops/activity_drop.rb', line 112 def to_s @obj.object.to_json end |