Class: JekyllSupport::APage

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

Overview

Time.new is -4712-01-01

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, origin) ⇒ APage

Returns a new instance of APage.

Parameters:

  • obj

    can be a ‘Jekyll::Document` or a Hash with properties

  • origin

    values: ‘collection’, ‘individual_page’, and ‘static_file’ (See method JekyllSupport.apages_from_objects)



90
91
92
93
94
95
96
# File 'lib/hooks/a_page.rb', line 90

def initialize(obj, origin)
  @logger = obj.logger
  @origin = origin
  build obj
rescue StandardError => e
  ::JekyllSupport.error_short_trace(@logger, e)
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def categories
  @categories
end

#collection_nameObject (readonly)

Returns the value of attribute collection_name.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def collection_name
  @collection_name
end

#contentObject (readonly)

Returns the value of attribute content.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def content
  @content
end

#dataObject (readonly)

Returns the value of attribute data.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def data
  @data
end

#dateObject (readonly)

Returns the value of attribute date.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def description
  @description
end

#destinationObject (readonly)

Returns the value of attribute destination.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def destination
  @destination
end

#draftObject (readonly)

Returns the value of attribute draft.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def draft
  @draft
end

#excerptObject (readonly)

Returns the value of attribute excerpt.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def excerpt
  @excerpt
end

#extObject (readonly)

Returns the value of attribute ext.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def ext
  @ext
end

#extnameObject (readonly)

Returns the value of attribute extname.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def extname
  @extname
end

#hrefObject (readonly)

Returns the value of attribute href.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def href
  @href
end

#labelObject (readonly)

Returns the value of attribute label.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def label
  @label
end

#last_modifiedObject (readonly)

Returns the value of attribute last_modified.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def last_modified
  @last_modified
end

#last_modified_fieldObject (readonly)

Returns the value of attribute last_modified_field.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def last_modified_field
  @last_modified_field
end

#layoutObject (readonly)

Returns the value of attribute layout.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def layout
  @layout
end

#loggerObject (readonly)

Returns the value of attribute logger.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def name
  @name
end

#originObject (readonly)

Returns the value of attribute origin.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def origin
  @origin
end

#pathObject (readonly)

Returns the value of attribute path.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def path
  @path
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def relative_path
  @relative_path
end

#tagsObject (readonly)

Returns the value of attribute tags.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



83
84
85
# File 'lib/hooks/a_page.rb', line 83

def url
  @url
end

Instance Method Details

#field(name, use_default: true) ⇒ Object

Parameters:

  • name

    can be either a String or a Symbol



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/hooks/a_page.rb', line 99

def field(name, use_default: true)
  default_value = case name
                  when :date, :last_modified, :last_modified_at
                    END_OF_DAYS
                  else
                    ''
                  end

  result = data[name.to_sym] || data[name.to_s] if data.key?(name.to_sym) || data.key?(name.to_s)
  return result if result

  default_value if use_default
end

#obj_field(obj, key) ⇒ Object

Look within @data (if the property exists), then self for the given key as a symbol or a string

Parameters:

  • key

    must be a symbol

Returns:

  • value of data if key exists as a string or a symbol, else nil



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/hooks/a_page.rb', line 116

def obj_field(obj, key)
  if obj.respond_to? :data
    return obj.data[key] if obj.data.key? key

    return obj.data[key.to_s] if obj.data.key? key.to_s
  end
  return obj.send(key) if obj.respond_to?(key)

  return unless obj.respond_to?(:key?)
  return obj[key] if obj.key?(key)

  obj[key.to_s] if obj.key?(key.to_s)
end

#orderObject



130
131
132
133
134
135
136
# File 'lib/hooks/a_page.rb', line 130

def order
  if data.key?('order') || data.key?(:order)
    data['order'] || data[:order]
  else
    FIXNUM_MAX
  end
end

#to_sObject



138
139
140
# File 'lib/hooks/a_page.rb', line 138

def to_s
  @label || @date.to_s
end