Class: AllCollectionsHooks::APage

Inherits:
Object
  • Object
show all
Defined in:
lib/all_collections_hooks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ APage

Verify each property exists before accessing it; this helps write tests



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/all_collections_hooks.rb', line 73

def initialize(obj)
  @data = obj.data if obj.respond_to? :data

  @categories = @data['categories'] if @data.key? 'categories'
  @content = obj.content if obj.respond_to? :content
  @date = (@data['date'].to_date if @data&.key?('date')) || Date.today
  @description = @data['description'] if @data.key? 'description'

  # TODO: What _config.yml setting should be passed to destination()?
  @destination = obj.destination('') if obj.respond_to? :destination

  @draft = Jekyll::Draft.draft?(obj)
  @excerpt = @data['excerpt'] if @data.key? 'excerpt'
  @ext = obj.extname
  @ext ||= @data['ext'] if @data.key? 'ext'
  @extname = @ext # For compatibility with previous versions of all_collections
  @label = obj.collection.label if obj&.collection.respond_to? :label
  @last_modified = @data['last_modified'] || @data['last_modified_at'] || @date
  @last_modified_field = case @data
                         when @data.key?('last_modified')
                           'last_modified'
                         when @data.key?('last_modified_at')
                           'last_modified_at'
                         end
  @layout = @data['layout'] if @data.key? 'layout'
  @path = obj.path if obj.respond_to? :path
  @relative_path = obj.relative_path if obj.respond_to? :relative_path
  @tags = @data['tags'] if @data.key? 'tags'
  @title = @data['title'] if @data.key? 'title'
  @type = obj.type if obj.respond_to? :type
  @url = obj.url
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def content
  @content
end

#dataObject (readonly)

Returns the value of attribute data.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def data
  @data
end

#dateObject (readonly)

Returns the value of attribute date.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def description
  @description
end

#destinationObject (readonly)

Returns the value of attribute destination.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def destination
  @destination
end

#draftObject (readonly)

Returns the value of attribute draft.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def draft
  @draft
end

#excerptObject (readonly)

Returns the value of attribute excerpt.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def excerpt
  @excerpt
end

#extObject (readonly)

Returns the value of attribute ext.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def ext
  @ext
end

#extnameObject (readonly)

Returns the value of attribute extname.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def extname
  @extname
end

#labelObject (readonly)

Returns the value of attribute label.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def label
  @label
end

#last_modifiedObject (readonly)

Returns the value of attribute last_modified.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def last_modified
  @last_modified
end

#layoutObject (readonly)

Returns the value of attribute layout.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def layout
  @layout
end

#pathObject (readonly)

Returns the value of attribute path.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def path
  @path
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def relative_path
  @relative_path
end

#tagsObject (readonly)

Returns the value of attribute tags.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



69
70
71
# File 'lib/all_collections_hooks.rb', line 69

def url
  @url
end

Instance Method Details

#to_sObject



106
107
108
109
110
# File 'lib/all_collections_hooks.rb', line 106

def to_s
  return @label if @label

  @date.to_s
end