Module: Jekyll::Draft
- Defined in:
- lib/jekyll_draft/common/module_functions.rb
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
-
.draft?(doc) ⇒ Boolean
True by checking in this order: - document is in _drafts directory, detectable by doc==true - document front matter contains ‘published: false’.
-
.draft_html(doc) ⇒ Object
HTML that indicates if a doc is a draft or not.
-
.page_match(path_portion, error_if_no_match: true, verify_unique_match: false) ⇒ Object
APage whose href uniquely contains path_portion, or ‘path_portion` as a String for non-local URLs.
-
.root(doc, site) ⇒ Object
Path to root of the collection that doc is a member of.
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/jekyll_draft/common/module_functions.rb', line 5 def logger @logger end |
Class Method Details
.draft?(doc) ⇒ Boolean
Returns true by checking in this order:
-
document is in _drafts directory, detectable by doc==true
-
document front matter contains ‘published: false’.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jekyll_draft/common/module_functions.rb', line 13 def draft?(doc) if doc.respond_to?(:data) && doc.data.respond_to?(:key?) return !doc.data['published'] if doc.data.key? 'published' return doc.data['draft'] if doc.data.key? 'draft' end if doc.respond_to?(:key?) return !doc['published'] if doc.key? 'published' return doc['draft'] if doc.key? 'draft' end return doc.draft if doc.respond_to? :draft false rescue StandardError => e msg = e. if msg.length < 250 Draft.logger.error { msg } else Draft.logger.error { "#{msg[0..125]} ... #{msg[-125..msg.length]}" } end false end |
.draft_html(doc) ⇒ Object
Returns HTML that indicates if a doc is a draft or not.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jekyll_draft/common/module_functions.rb', line 38 def draft_html(doc) return '' unless draft? doc " <i class='jekyll_draft'>Draft</i>" rescue StandardError => e msg = e. if msg.length < 250 Draft.logger.error { msg } else Draft.logger.error { "#{msg[0..125]} ... #{msg[-125..msg.length]}" } end '' end |
.page_match(path_portion, error_if_no_match: true, verify_unique_match: false) ⇒ Object
Returns APage whose href uniquely contains path_portion, or ‘path_portion` as a String for non-local URLs.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jekyll_draft/common/module_functions.rb', line 54 def page_match(path_portion, error_if_no_match: true, verify_unique_match: false) return :non_local_url if path_portion.start_with? 'http:', 'https:', 'mailto' matching_pages = if verify_unique_match ::AllCollectionsHooks.sorted_lru_files.find(path_portion) else match = ::AllCollectionsHooks.sorted_lru_files.find(path_portion) match.nil? ? [] : [match] end case matching_pages.size when 0 return '' unless error_if_no_match Draft.logger.error do "No page or asset path has a href that includes the string '#{path_portion}'" end exit! 1 if @error_if_no_match when 1 matching_pages.first else Draft.logger.error do # :\n #{matching_pages.map(&:href).join("\n ")} "More than one page or asset path has a href that includes the string '#{path_portion}'" end exit! 2 # The user should fix this problem before allowing the website to generate end rescue StandardError => e msg = e. if msg.length < 250 Draft.logger.error { msg } else Draft.logger.error { "#{msg[0..125]} ... #{msg[-125..msg.length]}" } end end |
.root(doc, site) ⇒ Object
Returns path to root of the collection that doc is a member of.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jekyll_draft/common/module_functions.rb', line 89 def root(doc, site) return '/index.html' unless doc.respond_to?(:collection) collection_name = doc.collection docs = site.key?(collection_name) ? site[collection_name] : site.collections[collection_name].docs index = docs.find { |d| d.href.end_with? 'index.html' } return index.href if index docs.min.href rescue StandardError => e msg = e. if msg.length < 250 Draft.logger.error { msg } else Draft.logger.error { "#{msg[0..150]} ... #{msg[-150..msg.length]}" } end end |