jekyll-rpg 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16f14fd9c3d40e94808552f1b4a38813cb1f75e97a50ab5f69acbd57026dadb2
4
- data.tar.gz: 770ce2e9837de58c045cf32a2b20272f65b237420f3c733ade1081d6aee6d7b4
3
+ metadata.gz: c75f941d938f99bcb95405f25776adc34ceba10009d7183eec136145f3eba72b
4
+ data.tar.gz: 0050b660cb0c708f39e1cc723f65456d6c4e7010b1e0950503aab8ed95250496
5
5
  SHA512:
6
- metadata.gz: 3e0dd4929f15a759ead437924a0ed5efc49e336a1cdb14474b5b008e060af0300f693c8280e8e7e9f921c8a40eaad10070b7acac786cbcadc0bc5a86ba198018
7
- data.tar.gz: 620e850bb614a48458c7b78326af3d3a45f47c620b597d8a4aef217f9ded8106a2be791cb7278224f0f35d892f79c7b72b0fce1a279fa6fefebdeefcbd8f8aad
6
+ metadata.gz: fe0a31e5458c3744523ca3ddfa188f703b64c056539abecff50bb0971a4c0f1e7e9f42a78822229138d715f58bae51bbe4338841e6712387842628533f996f3c
7
+ data.tar.gz: b8777aa50b266366be65540da516a90043feeaabda8321e5d4bd751e2550ec3ca2a623bc7343222d76006c8b7f12c51b64782181240db3444f7c70d617f4cc18
@@ -1,36 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllRPG
4
- # Represents a document that may be in a Jekyll collection
4
+ # Represents a document that may be in a Jekyll collection,
5
+ # extracted from either a document itself, or a markdown
6
+ # link.
5
7
  class CollectionDocument
6
- attr_accessor :name, :collection, :slug, :written
8
+ attr_accessor :name, :collection, :slug, :viewable
7
9
 
8
10
  def extract_doc(doc)
9
11
  @name = doc.data['name']
10
12
  @collection = doc.collection.label
11
13
  @slug = doc.data['slug']
12
- @written = true
14
+ @viewable = true
13
15
  self
14
16
  end
15
17
 
16
18
  # extracts link text, collection and slug
17
- # [@name](/@collection/@slug)
18
19
  def extract_markdown(site, link)
19
- @collection = link[%r{(?<=/).*(?=/)}]
20
- @slug = link[%r{(?<=/)(?:(?!/).)*?(?=\))}]
21
- @written = document_exists(site)
22
- @name = @written ? find_document(site).data['name'] : link[/(?<=\[).*?(?=\])/]
20
+ @site = site
21
+ @collection = link.collection
22
+ @slug = link.slug
23
+ @viewable = viewable
24
+ @name = @viewable ? find_document.data['name'] : link.name
23
25
  self
24
26
  end
25
27
 
26
28
  # Checks whether document exists in a site
27
- def document_exists(site)
28
- !site.collections[@collection].nil? && !find_document(site).nil?
29
+ def document_exists
30
+ !@site.collections[@collection].nil? && !find_document.nil?
29
31
  end
30
32
 
31
33
  # Find a document based on its collection and slug
32
- def find_document(site)
33
- site.collections[@collection].docs.find { |doc| doc.data['slug'] == @slug }
34
+ def find_document
35
+ @site.collections[@collection].docs.find { |doc| doc.data['slug'] == @slug }
36
+ end
37
+
38
+ def viewable
39
+ return unless document_exists
40
+
41
+ @site.config['dm_mode'] || !find_document.data['dm']
34
42
  end
35
43
 
36
44
  def markdown_link
@@ -35,9 +35,9 @@ module JekyllRPG
35
35
  end
36
36
 
37
37
  # Based on the graph, returns documents that are referenced, but do not exist yet
38
- def unwritten
38
+ def unviewable
39
39
  @edges.reject do |edge|
40
- edge.reference.written
40
+ edge.reference.viewable
41
41
  end
42
42
  end
43
43
 
@@ -10,7 +10,22 @@ module JekyllRPG
10
10
  ref = References.new(site)
11
11
 
12
12
  site.data['graph'] = ref.graph.hash
13
-
14
13
  site.data['broken_links'] = ref.broken_links
15
14
  end
15
+
16
+ # DM tag to hide content
17
+ class RenderDMContent < Liquid::Block
18
+ def render(context)
19
+ text = ''
20
+ if context.registers[:site].config['dm_mode']
21
+ text += "> # DM Note: \n"
22
+ super.each_line do |line|
23
+ text += '>> ' + line
24
+ end
25
+ end
26
+ text
27
+ end
28
+ end
16
29
  end
30
+
31
+ Liquid::Template.register_tag('dm', JekyllRPG::RenderDMContent)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllRPG
4
+ # A markdown link with components extracted from text
5
+ # [name](/collection/slug)
6
+ class MarkdownLink
7
+ def initialize(link)
8
+ @link = link
9
+ end
10
+
11
+ def name
12
+ @link[/(?<=\[).*?(?=\])/]
13
+ end
14
+
15
+ def slug
16
+ @link[%r{(?<=/)(?:(?!/).)*?(?=\))}]
17
+ end
18
+
19
+ def collection
20
+ @link[%r{(?<=/).*(?=/)}]
21
+ end
22
+ end
23
+ end
@@ -24,7 +24,7 @@ module JekyllRPG
24
24
 
25
25
  def refs_table(refs)
26
26
  table = <<~TABLE
27
- # Referenced By:
27
+ \n# Referenced By:
28
28
  <table>
29
29
  <thead>
30
30
  <tr>
@@ -3,6 +3,7 @@
3
3
  require 'collection_document'
4
4
  require 'edge'
5
5
  require 'graph'
6
+ require 'markdown_link'
6
7
  require 'reference_table'
7
8
 
8
9
  module JekyllRPG
@@ -12,6 +13,7 @@ module JekyllRPG
12
13
 
13
14
  def initialize(site)
14
15
  @site = site
16
+ @dm_mode = @site.config['dm_mode']
15
17
  @graph = Graph.new
16
18
  @broken_links = []
17
19
  @collection_keys = @site.collections.keys - ['posts']
@@ -20,7 +22,7 @@ module JekyllRPG
20
22
  referent_pass
21
23
 
22
24
  # Create list of broken links
23
- @graph.unwritten.each do |edge|
25
+ @graph.unviewable.each do |edge|
24
26
  @broken_links.push(edge.hash)
25
27
  end
26
28
  end
@@ -31,14 +33,31 @@ module JekyllRPG
31
33
  collection_documents.each do |doc|
32
34
  # Do not publish or reference a page if the site is not in DM Mode
33
35
  # And the page is marked as for dms
34
- if doc.data['dm'] && !@site.config['dm_mode']
36
+ doc_dm = doc.data['dm']
37
+ if doc_dm && !@dm_mode
35
38
  doc.data['published'] = false
36
39
  else
40
+ unviewable_links = []
41
+ # Extract details of the referent from the document
37
42
  referent = CollectionDocument.new.extract_doc(doc)
43
+
44
+ # make a reference from each link on the page
38
45
  markdown_links(doc).each do |link|
39
- reference = CollectionDocument.new.extract_markdown(@site, link)
46
+ md_link = MarkdownLink.new(link)
47
+ reference = CollectionDocument.new.extract_markdown(@site, md_link)
48
+
49
+ # if the reference isn't viewable in the current configuration
50
+ # append that link to the array of links to strikethrough
51
+ unviewable_links << reference.markdown_link unless reference.viewable
52
+
53
+ # Make a new edge on the graph
40
54
  @graph.edges.push(Edge.new(referent, reference))
41
55
  end
56
+
57
+ # Unviewable links are struck through
58
+ unviewable_links.uniq.each do |link|
59
+ doc.content = doc.content.sub! link, "~~#{link}~~"
60
+ end
42
61
  end
43
62
  end
44
63
  end
metadata CHANGED
@@ -1,71 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-rpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lockwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-20 00:00:00.000000000 Z
11
+ date: 2019-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.8.6
17
20
  - - "~>"
18
21
  - !ruby/object:Gem::Version
19
- version: '3'
22
+ version: 4.0.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.8.6
24
30
  - - "~>"
25
31
  - !ruby/object:Gem::Version
26
- version: '3'
32
+ version: 4.0.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: factory_bot
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0'
39
+ version: 5.0.2
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - ">="
44
+ - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '0'
46
+ version: 5.0.2
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: pry
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - ">="
51
+ - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0'
53
+ version: 0.12.2
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - ">="
58
+ - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '0'
60
+ version: 0.12.2
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rspec
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - ">="
65
+ - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '0'
67
+ version: 3.8.0
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - ">="
72
+ - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '0'
74
+ version: 3.8.0
69
75
  description: ''
70
76
  email: tom@lockwood.dev
71
77
  executables: []
@@ -76,6 +82,7 @@ files:
76
82
  - lib/edge.rb
77
83
  - lib/graph.rb
78
84
  - lib/jekyll-rpg.rb
85
+ - lib/markdown_link.rb
79
86
  - lib/reference_table.rb
80
87
  - lib/references.rb
81
88
  homepage: https://github.com/tomlockwood/jekyll-rpg