Module: Dumpers

Defined in:
lib/dumpers.rb

Overview

Methods to display Jekyll variable contents

Class Method Summary collapse

Class Method Details

.attributes_as_string(object, attrs) ⇒ Object



166
167
168
# File 'lib/dumpers.rb', line 166

def attributes_as_string(object, attrs)
  attrs.map { |attr| "    #{attr.to_s.delete_prefix("@")} = #{object.instance_variable_get(attr)}" }
end

.collection_as_string(collection, indent_spaces) ⇒ Object

See github.com/jekyll/jekyll/blob/master/lib/jekyll/collection.rb

attr_reader :site, :label, :metadata
attr_writer :docs
Metadata is a hash with at least these keys: output[Boolean], permalink[String]
selected methods: collection_dir, directory, entries, exists?, files, filtered_entries, relative_directory


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dumpers.rb', line 8

def collection_as_string(collection, indent_spaces)
  indent = ' ' * indent_spaces
  result = <<~END_COLLECTION
    '#{collection.label}' collection within '#{collection.relative_directory}' subdirectory
      #{indent}Directory: #{collection.directory}
      #{indent}Does the directory exist and is it not a symlink if in safe mode? #{collection.exists?}
      #{indent}Collection_dir: #{collection.collection_dir}
      #{indent}Metadata: #{collection.}
      #{indent}Static files: #{collection.files}
      #{indent}Filtered entries: #{collection.filtered_entries}
  END_COLLECTION
  result.chomp
end

.count_lines(string) ⇒ Object



22
23
24
25
26
# File 'lib/dumpers.rb', line 22

def count_lines(string)
  return string.split("\n").length if string

  0
end

.dump_document(logger, msg, document) ⇒ Object

Parameters:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dumpers.rb', line 43

def dump_document(logger, msg, document)
  attributes = attributes_as_string(document, [:@path, :@extname, :@type])
  data = document.data.map { |k, v| "    #{k} = #{safe_to_s(v)}" }
  logger.info do
    <<~END_DOC
      #{msg}
        document dated #{document.date.to_date}:
          relative_path: #{document.relative_path}:
      #{attributes.join("\n")}
          Is it a draft? #{document.draft?}
          collection = #{collection_as_string(document.collection, 4)}
          content not dumped because it would likely be too long
          site not dumped also
          data:
        #{data.join("\n  ").rstrip.chomp}
    END_DOC
  end
end

.dump_page(logger, msg, page) ⇒ Object

Parameters:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/dumpers.rb', line 66

def dump_page(logger, msg, page)
  attributes = attributes_as_string(page, [:@basename, :@ext, :@name])
  # site = page.site available if you need it
  data = page.data.map { |k, v| "    #{k} = #{v}" }
  logger.info do
    <<~END_PAGE
      #{msg}\n  page at #{page.dir}:
      #{attributes.join("\n")}
          Is it HTML? #{page.html?}; is it an index? #{page.index?}
          Permalink: #{page.permalink}
          URL: #{page.url}
          content not dumped because it would likely be too long
          site not dumped also
          Excerpt: "#{page.excerpt}"
        data:
      #{data.join("\n")}
    END_PAGE
  end
end

.dump_payload(logger, msg, payload) ⇒ Object

payload.page is a Jekyll::Drops::DocumentDrop, which contains this payload, see github.com/jekyll/jekyll/blob/master/lib/jekyll/drops/document_drop.rb

Parameters:



92
93
94
95
96
97
98
99
100
101
# File 'lib/dumpers.rb', line 92

def dump_payload(logger, msg, payload)
  result = <<~END_INFO
    #{msg} payload:
      content contains #{count_lines(payload.content)} lines.#{first_5_lines(payload.content)}
      layout = #{payload.layout}
      highlighter_prefix = #{payload.highlighter_prefix}
      paginator and site not dumped.
  END_INFO
  logger.info { result.chomp }
end

.dump_site(logger, msg, site) ⇒ Object

Parameters:

  • msg (String)
  • site (Jekyll::Site)

    github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb attr_accessor :baseurl, :converters, :data, :drafts, :exclude,

    :file_read_opts, :future, :gems, :generators, :highlighter,
    :include, :inclusions, :keep_files, :layouts, :limit_posts,
    :lsi, :pages, :permalink_style, :plugin_manager, :plugins,
    :reader, :safe, :show_drafts, :static_files, :theme, :time,
    :unpublished
    

    attr_reader :cache_dir, :config, :dest, :filter_cache, :includes_load_paths,

    :liquid_renderer, :profiler, :regenerator, :source
    


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/dumpers.rb', line 120

def dump_site(logger, msg, site) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  logger.info do
    <<~END_INFO
      #{msg} site
      site is of type #{site.class}
      site.time = #{site.time}
    END_INFO
  end
  env = site.config['env']
  if env
    mode = env['JEKYLL_ENV']
    logger.info { "site.config['env']['JEKYLL_ENV'] = #{mode}" }
  else
    logger.info { "site.config['env'] is undefined" }
  end
  site.collections.each do |key, _|
    logger.info { "site.collections.#{key}" }
  end

  # key env contains all environment variables, quite verbose so output is reduced to just the "env" key
  logger.info { "site.config has #{site.config.length} entries:" }
  site.config.sort.each { |key, value| logger.info { "  site.config.#{key} = '#{value}'" unless key == "env" } }

  logger.info { "site.data has #{site.data.length} entries:" }
  site.data.sort.each { |key, value| logger.info { "  site.data.#{key} = '#{value}'" } }

  logger.info { "site.documents has #{site.documents.length} entries." }
  site.documents.each { |key, _value| logger.info "site.documents.#{key}" }

  logger.info do
    <<~END_INFO
      site.keep_files has #{site.keep_files.length} entries.
      site.keep_files: #{site.keep_files.sort}
      site.pages has #{site.pages.length} entries.
    END_INFO
  end

  site.pages.each { |key, _value| logger.info "site.pages.#{key}" }

  logger.info { "site.posts has #{site.posts.docs.length} entries." }
  site.posts.docs.each { |key, _value| logger.info "site.posts.docs.#{key}" }

  logger.info { "site.tags has #{site.tags.length} entries." }
  site.tags.sort.each { |key, value| logger.info { "site.tags.#{key} = '#{value}'" } }
end

.first_5_lines(string) ⇒ Object



103
104
105
106
107
108
# File 'lib/dumpers.rb', line 103

def first_5_lines(string)
  lines = string ? string.split("\n")[0..4] : []
  return "\n    first 5 lines:\n    #{lines.join("\n    ")}\n" if lines.length.positive?

  ""
end

.safe_to_s(value) ⇒ Object

Calling value.to_s blows up when a Jekyll::Excerpt Error message is unrelated to the problem, makes it hard to track down Be careful when converting values to string!



31
32
33
34
35
36
37
# File 'lib/dumpers.rb', line 31

def safe_to_s(value)
  return value.content if value.is_a? Jekyll::Excerpt

  value.to_s
rescue StandardError => e
  e.message
end